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