• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 API_CORE_PROPERTY_TOOLS_PROPERTY_API_IMPL_H
17 #define API_CORE_PROPERTY_TOOLS_PROPERTY_API_IMPL_H
18 
19 #include <cstddef>
20 #include <cstdint>
21 
22 #include <base/containers/array_view.h>
23 #include <base/namespace.h>
24 #include <core/namespace.h>
25 #include <core/property/intf_property_api.h>
26 #include <core/property/intf_property_handle.h>
27 
28 CORE_BEGIN_NAMESPACE()
29 struct Property;
30 
31 template<typename BlockType>
32 class PropertyApiImpl : public IPropertyApi, protected IPropertyHandle {
33 public:
34     PropertyApiImpl();
35     PropertyApiImpl(BlockType* data, BASE_NS::array_view<const Property> props);
36     ~PropertyApiImpl() override = default;
37 
38     IPropertyHandle* GetData();
39     const IPropertyHandle* GetData() const;
40 
41     uint32_t GetGeneration() const;
42     // IPropertyApi
43     size_t PropertyCount() const override;
44     const Property* MetaData(size_t index) const override;
45     BASE_NS::array_view<const Property> MetaData() const override;
46     IPropertyHandle* Create() const override;
47     IPropertyHandle* Clone(const IPropertyHandle*) const override;
48     void Release(IPropertyHandle*) const override;
49 
50 protected:
51     const IPropertyApi* Owner() const override;
52     size_t Size() const override;
53     const void* RLock() const override;
54     void RUnlock() const override;
55     void* WLock() override;
56     void WUnlock() override;
57     uint64_t Type() const override;
58 
59 private:
60     const IPropertyApi* owner_ { nullptr };
61     BlockType* data_ { nullptr };
62     BASE_NS::array_view<const Property> componentMetadata_;
63     uint64_t typeHash_ { 0 };
64     uint32_t generationCount_ { 0 };
65 #ifndef NDEBUG
66     mutable uint32_t rLocked_ { 0 };
67     mutable bool wLocked_ { false };
68 #endif
69 };
70 CORE_END_NAMESPACE()
71 
72 #endif // API_CORE_PROPERTY_TOOLS_PROPERTY_API_IMPL_H
73