Merge "Include the algorithm header file" into devel/master
[platform/core/uifw/dali-core.git] / dali / public-api / object / ref-object.h
1 #ifndef DALI_REF_OBJECT_H
2 #define DALI_REF_OBJECT_H
3
4 /*
5  * Copyright (c) 2020 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <cstdint> // uint32_t
23
24 // INTERNAL INCLUDES
25 #include <dali/public-api/common/dali-common.h>
26 #include <dali/public-api/common/intrusive-ptr.h>
27
28 namespace Dali
29 {
30 /**
31  * @addtogroup dali_core_object
32  * @{
33  */
34
35 class Value;
36
37 /**
38  * @brief Base class for reference counted objects.
39  *
40  * Typically this should be used with an intrusive pointer,
41  * instead of calling Reference() and Unreference() methods directly.
42  * @SINCE_1_0.0
43  */
44 class DALI_CORE_API RefObject
45 {
46 public:
47   /**
48    * @brief Increments the object's reference count.
49    * @SINCE_1_0.0
50    */
51   void Reference();
52
53   /**
54    * @brief Decrements the object's reference count.
55    *
56    * When the reference count drops to zero, the object will self-destruct.
57    * @SINCE_1_0.0
58    */
59   void Unreference();
60
61   /**
62    * @brief Retrieves the object's reference count.
63    *
64    * @SINCE_1_0.0
65    * @return The reference count
66    */
67   uint32_t ReferenceCount();
68
69 protected:
70   /**
71    * @brief Default constructor.
72    * @SINCE_1_0.0
73    */
74   RefObject();
75
76   /**
77    * @brief RefObject is intended as a base class.
78    *
79    * A RefObject may only be deleted when its reference count is zero.
80    * @SINCE_1_0.0
81    */
82   virtual ~RefObject();
83
84   /**
85    * @brief Copy constructor.
86    *
87    * The newly copied object will have a reference count of zero.
88    * @SINCE_1_0.0
89    * @param[in] rhs The object to copy
90    */
91   RefObject(const RefObject& rhs);
92
93   /**
94    * @brief Assignment operator.
95    *
96    * The newly copied object will have a reference count of zero.
97    * @SINCE_1_0.0
98    * @param[in] rhs The object to copy
99    * @return A reference to this
100    */
101   RefObject& operator=(const RefObject& rhs);
102
103 private:
104   volatile uint32_t mCount; ///< Reference count
105 };
106
107 /**
108  * @}
109  */
110 } // namespace Dali
111
112 #endif // DALI_REF_OBJECT_H