[dali_2.3.25] Merge branch 'devel/master'
[platform/core/uifw/dali-core.git] / dali / public-api / object / ref-object.cpp
1 /*
2  * Copyright (c) 2021 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali/public-api/object/ref-object.h>
20
21 // INTERNAL INCLUDES
22 #include <dali/public-api/common/dali-common.h>
23
24 // EXTERNAL INCLUDES
25 #include <stdint.h>
26
27 namespace Dali
28 {
29 RefObject::RefObject()
30 : mCount(0)
31 {
32 }
33
34 RefObject::RefObject(const RefObject&)
35 : mCount(0) // Do not copy the reference count
36 {
37 }
38
39 RefObject::~RefObject()
40 {
41 #ifdef ENABLE_DEBUG
42   if(mCount)
43   {
44     DALI_LOG_ERROR("mCount should be zero, deleting referenced object!\n");
45   }
46 #endif // ENABLE_DEBUG
47 }
48
49 RefObject& RefObject::operator=(const RefObject&)
50 {
51   // Do not copy the reference count
52   return *this;
53 }
54
55 void RefObject::Reference()
56 {
57   ++mCount;
58 }
59
60 void RefObject::Unreference()
61 {
62   if((--mCount) == 0)
63   {
64     delete this;
65   }
66 }
67
68 uint32_t RefObject::ReferenceCount() const
69 {
70   return mCount;
71 }
72
73 } // namespace Dali