Making DALi public API typesafe using guaranteed types; uint8_t, uint32_t
[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) 2018 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   /**
49    * @brief Increments the object's reference count.
50    * @SINCE_1_0.0
51    */
52   void Reference();
53
54   /**
55    * @brief Decrements the object's reference count.
56    *
57    * When the reference count drops to zero, the object will self-destruct.
58    * @SINCE_1_0.0
59    */
60   void Unreference();
61
62   /**
63    * @brief Retrieves the object's reference count.
64    *
65    * @SINCE_1_0.0
66    * @return The reference count
67    */
68   uint32_t ReferenceCount();
69
70 protected:
71
72   /**
73    * @brief Default constructor.
74    * @SINCE_1_0.0
75    */
76   RefObject();
77
78   /**
79    * @brief RefObject is intended as a base class.
80    *
81    * A RefObject may only be deleted when its reference count is zero.
82    * @SINCE_1_0.0
83    */
84   virtual ~RefObject();
85
86   /**
87    * @brief Copy constructor.
88    *
89    * The newly copied object will have a reference count of zero.
90    * @SINCE_1_0.0
91    * @param[in] rhs The object to copy
92    */
93   RefObject(const RefObject& rhs);
94
95   /**
96    * @brief Assignment operator.
97    *
98    * The newly copied object will have a reference count of zero.
99    * @SINCE_1_0.0
100    * @param[in] rhs The object to copy
101    * @return A reference to this
102    */
103   RefObject& operator=(const RefObject& rhs);
104
105 private:
106
107   volatile uint32_t mCount; ///< Reference count
108 };
109
110 /**
111  * @}
112  */
113 } // namespace Dali
114
115 #endif // __DALI_REF_OBJECT_H__