License conversion from Flora to Apache 2.0
[platform/core/uifw/dali-core.git] / capi / dali / public-api / object / ref-object.h
1 #ifndef __DALI_REF_OBJECT_H__
2 #define __DALI_REF_OBJECT_H__
3
4 /*
5  * Copyright (c) 2014 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 /**
22  * @addtogroup CAPI_DALI_OBJECT_MODULE
23  * @{
24  */
25
26 // EXTERNAL INCLUDES
27 #include <dali/public-api/common/dali-common.h>
28 #include <dali/public-api/common/intrusive-ptr.h>
29
30 namespace Dali DALI_IMPORT_API
31 {
32
33 class Value;
34
35 /**
36  * @brief Base class for reference counted objects.
37  *
38  * Typically this should be used with a Boost instrusive pointer,
39  * instead of calling Reference() and Unreference() methods directly.
40  */
41 class RefObject
42 {
43 public:
44
45   /**
46    * @brief Increment the object's reference count.
47    */
48   void Reference();
49
50   /**
51    * @brief Decrement the object's reference count.
52    *
53    * When the reference count drops to zero, the object will self-destruct.
54    */
55   void Unreference();
56
57   /**
58    * @brief Retrieve the object's reference count.
59    *
60    * @return The reference count
61    */
62   int ReferenceCount();
63
64 protected:
65
66   /**
67    * @brief Default constructor.
68    */
69   RefObject();
70
71   /**
72    * @brief RefObject is intended as a base class.
73    *
74    * A RefObject may only be deleted when its reference count is zero.
75    */
76   virtual ~RefObject();
77
78   /**
79    * @brief Copy constructor.
80    *
81    * The newly copied object will have a reference count of zero.
82    * @param[in] rhs The object to copy
83    */
84   RefObject(const RefObject& rhs);
85
86   /**
87    * @brief Assignment operator.
88    *
89    * The newly copied object will have a reference count of zero.
90    * @param[in] rhs The object to copy
91    * @return a reference to this
92    */
93   RefObject& operator=(const RefObject& rhs);
94
95 private:
96
97   volatile int mCount; ///< Reference count
98 };
99
100 } // namespace Dali
101
102
103 /**
104  * @}
105  */
106 #endif // __DALI_REF_OBJECT_H__