1 #ifndef DALI_REF_OBJECT_H
2 #define DALI_REF_OBJECT_H
5 * Copyright (c) 2022 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
23 #include <cstdint> // uint32_t
26 #include <dali/public-api/common/dali-common.h>
27 #include <dali/public-api/common/intrusive-ptr.h>
32 * @addtogroup dali_core_object
39 * @brief Base class for reference counted objects.
41 * Typically this should be used with an intrusive pointer,
42 * instead of calling Reference() and Unreference() methods directly.
45 class DALI_CORE_API RefObject
49 * @brief Increments the object's reference count.
55 * @brief Decrements the object's reference count.
57 * When the reference count drops to zero, the object will self-destruct.
63 * @brief Retrieves the object's reference count.
66 * @return The reference count
68 uint32_t ReferenceCount();
72 * @brief Default constructor.
78 * @brief RefObject is intended as a base class.
80 * A RefObject may only be deleted when its reference count is zero.
86 * @brief Copy constructor.
88 * The newly copied object will have a reference count of zero.
90 * @param[in] rhs The object to copy
92 RefObject(const RefObject& rhs);
95 * @brief Assignment operator.
97 * The newly copied object will have a reference count of zero.
99 * @param[in] rhs The object to copy
100 * @return A reference to this
102 RefObject& operator=(const RefObject& rhs);
106 RefObject(RefObject&& rhs) = delete; ///< Deleted move constructor
107 RefObject& operator=(RefObject&& rhs) = delete; ///< Deleted move assignment operator
110 std::atomic_uint32_t mCount{0u}; ///< Reference count
118 #endif // DALI_REF_OBJECT_H