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 CORE_PROPERTY_PROPERTY_HANDLE_H
17 #define CORE_PROPERTY_PROPERTY_HANDLE_H
18 
19 #include <3d/namespace.h>
20 #include <core/property/intf_property_handle.h>
21 
CORE3D_BEGIN_NAMESPACE()22 CORE3D_BEGIN_NAMESPACE()
23 // NOTE: this handle does not own the data at any point.
24 // it just stores the raw pointer given to it, and the owning property api.
25 class PropertyHandle : public CORE_NS::IPropertyHandle {
26 public:
27     PropertyHandle() = delete;
28     PropertyHandle(CORE_NS::IPropertyApi* owner, void* data, const size_t size) noexcept;
29     PropertyHandle(const PropertyHandle& other) = delete;
30     PropertyHandle(PropertyHandle&& other) noexcept;
31     ~PropertyHandle() override = default;
32     PropertyHandle& operator=(const PropertyHandle& other) = delete;
33     PropertyHandle& operator=(PropertyHandle&& other) noexcept;
34 
35     const CORE_NS::IPropertyApi* Owner() const override;
36     size_t Size() const override;
37 
38     void* WLock() override;
39     const void* RLock() const override;
40     void RUnlock() const override;
41     void WUnlock() override;
42 
43 protected:
44     mutable bool locked_ { false };
45     CORE_NS::IPropertyApi* owner_;
46     void* data_;
47     size_t size_;
48 };
49 CORE3D_END_NAMESPACE()
50 
51 #endif // CORE_PROPERTY_PROPERTY_HANDLE_H
52