• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef OHOS_UTILS_MEMORY_LIBPURGEABLEMEM_CPP_INCLUDE_PURGEABLE_MEM_BUILDER_H
17 #define OHOS_UTILS_MEMORY_LIBPURGEABLEMEM_CPP_INCLUDE_PURGEABLE_MEM_BUILDER_H
18 
19 #include <memory> /* unique_ptr */
20 
21 namespace OHOS {
22 namespace PurgeableMem {
23 /*
24  * Class PurgeableMemBuilder is a base class of user's builder.
25  * PurgeableMem users can define their builders by inheriting this class.
26  * In its member func Build(), user should define how to build the content of a PurgeableMem obj.
27  */
28 class PurgeableMemBuilder {
29 public:
30     virtual ~PurgeableMemBuilder();
31 
32     /*
33      * User should define how to build the content of a PurgeableMem obj in this func.
34      * Input:   data: data ptr, ponits to start address of a PurgeableMem obj's content.
35      * Input:   size: data size of the content.
36      * Return:  build content result, true means success, while false is fail.
37      */
38     virtual bool Build(void *data, size_t size) = 0;
39 
40 private:
41     std::unique_ptr<PurgeableMemBuilder> nextBuilder_ = nullptr;
42 
43     /* Only called by its friend */
44     void AppendBuilder(std::unique_ptr<PurgeableMemBuilder> builder);
45     bool BuildAll(void *data, size_t size);
46     friend class PurgeableMem;
47 };
48 } /* namespace PurgeableMem */
49 } /* namespace OHOS */
50 #endif /* OHOS_UTILS_MEMORY_LIBPURGEABLEMEM_CPP_INCLUDE_PURGEABLE_MEM_BUILDER_H */
51