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 #include "property_handle.h"
16 
17 #include <base/containers/type_traits.h>
18 #include <core/log.h>
19 
20 CORE3D_BEGIN_NAMESPACE()
21 using CORE_NS::IPropertyApi;
22 
PropertyHandle(IPropertyApi * owner,void * data,const size_t size)23 PropertyHandle::PropertyHandle(IPropertyApi* owner, void* data, const size_t size) noexcept
24     : IPropertyHandle(), owner_(owner), data_(data), size_(size)
25 {}
26 
PropertyHandle(PropertyHandle && other)27 PropertyHandle::PropertyHandle(PropertyHandle&& other) noexcept
28     : IPropertyHandle(), owner_(BASE_NS::exchange(other.owner_, nullptr)),
29       data_(BASE_NS::exchange(other.data_, nullptr)), size_(BASE_NS::exchange(other.size_, 0U))
30 {}
31 
operator =(PropertyHandle && other)32 PropertyHandle& PropertyHandle::operator=(PropertyHandle&& other) noexcept
33 {
34     if (&other != this) {
35         owner_ = BASE_NS::exchange(other.owner_, nullptr);
36         data_ = BASE_NS::exchange(other.data_, nullptr);
37         size_ = BASE_NS::exchange(other.size_, 0U);
38     }
39     return *this;
40 }
41 
Owner() const42 const IPropertyApi* PropertyHandle::Owner() const
43 {
44     return owner_;
45 }
46 
Size() const47 size_t PropertyHandle::Size() const
48 {
49     return size_;
50 }
51 
WLock()52 void* PropertyHandle::WLock()
53 {
54     CORE_ASSERT(!locked_);
55     locked_ = true;
56     return data_;
57 }
WUnlock()58 void PropertyHandle::WUnlock()
59 {
60     CORE_ASSERT(locked_);
61     locked_ = false;
62 }
63 
RLock() const64 const void* PropertyHandle::RLock() const
65 {
66     CORE_ASSERT(!locked_);
67     locked_ = true;
68     return data_;
69 }
RUnlock() const70 void PropertyHandle::RUnlock() const
71 {
72     CORE_ASSERT(locked_);
73     locked_ = false;
74 }
75 CORE3D_END_NAMESPACE()
76