License conversion from Flora to Apache 2.0
[platform/core/uifw/dali-core.git] / dali / public-api / object / base-handle.cpp
1 /*
2  * Copyright (c) 2014 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 // EXTERNAL INCLUDES
19 #include <typeinfo>
20
21 // CLASS HEADER
22 #include <dali/public-api/object/base-handle.h>
23 #include <dali/public-api/object/type-registry.h>
24
25 // INTERNAL INCLUDES
26 #include <dali/internal/event/common/object-impl.h>
27 #include <dali/integration-api/debug.h>
28
29 namespace Dali
30 {
31
32 BaseHandle::BaseHandle(Dali::BaseObject* handle)
33 : mObjectHandle(handle)
34 {
35 }
36
37 BaseHandle::BaseHandle()
38 {
39 }
40
41 BaseHandle::~BaseHandle()
42 {
43 }
44
45 BaseHandle::BaseHandle(const BaseHandle& handle)
46   : mObjectHandle(handle.mObjectHandle)
47 {
48 }
49
50 BaseHandle& BaseHandle::operator=(const BaseHandle& rhs)
51 {
52   if( this != &rhs )
53   {
54     this->mObjectHandle = rhs.mObjectHandle;
55   }
56
57   return *this;
58 }
59
60 BaseHandle& BaseHandle::operator=(BaseHandle::NullType* rhs)
61 {
62   DALI_ASSERT_ALWAYS( (rhs == NULL) && "Can only assign NULL pointer to handle");
63   Reset();
64   return *this;
65 }
66
67 bool BaseHandle::DoAction(const std::string& command, const std::vector<Property::Value>& attributes)
68 {
69   return GetImplementation(*this).DoAction( command, attributes );
70 }
71
72 const std::string& BaseHandle::GetTypeName() const
73 {
74   return GetImplementation(*this).GetTypeName();
75 }
76
77 BaseObject& BaseHandle::GetBaseObject()
78 {
79   DALI_ASSERT_ALWAYS( mObjectHandle.Get() && "BaseHandle is empty" );
80
81   return static_cast<BaseObject&>(*mObjectHandle);
82 }
83
84 const BaseObject& BaseHandle::GetBaseObject() const
85 {
86   DALI_ASSERT_ALWAYS(mObjectHandle.Get() && "BaseHandle is empty" );
87
88   return static_cast<const BaseObject&>(*mObjectHandle);
89 }
90
91 void BaseHandle::Reset()
92 {
93   mObjectHandle = NULL;
94 }
95
96 BaseHandle::operator BaseHandle::BooleanType() const
97 {
98   return mObjectHandle ? &BaseHandle::ThisIsSaferThanReturningVoidStar : NULL;
99 }
100
101 bool BaseHandle::operator==(const BaseHandle& rhs) const
102 {
103   return this->mObjectHandle == rhs.mObjectHandle;
104 }
105
106 bool BaseHandle::operator!=(const BaseHandle& rhs) const
107 {
108   return this->mObjectHandle != rhs.mObjectHandle;
109 }
110
111 Dali::RefObject* BaseHandle::GetObjectPtr() const
112 {
113   return mObjectHandle.Get();
114 }
115
116 bool BaseHandle::DoConnectSignal( ConnectionTrackerInterface* connectionTracker, const std::string& signalName, FunctorDelegate* functor )
117 {
118   return GetImplementation(*this).DoConnectSignal( connectionTracker, signalName, functor );
119 }
120
121 bool operator<(const BaseHandle& lhs, const BaseHandle& rhs)
122 {
123   return lhs.GetObjectPtr() < rhs.GetObjectPtr();
124 }
125
126 } // namespace Dali