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