Optimize type-info-impl and type-registry-impl
[platform/core/uifw/dali-core.git] / dali / public-api / object / base-object.cpp
1 /*
2  * Copyright (c) 2015 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/base-object.h>
20
21 // INTERNAL INCLUDES
22 #include <dali/public-api/object/type-registry.h>
23 #include <dali/integration-api/debug.h>
24 #include <dali/internal/event/common/object-registry-impl.h>
25 #include <dali/internal/event/common/stage-impl.h>
26 #include <dali/internal/event/common/type-registry-impl.h>
27
28 namespace Dali
29 {
30
31 BaseObject::BaseObject()
32 {
33 }
34
35 BaseObject::~BaseObject()
36 {
37 }
38
39 void BaseObject::RegisterObject()
40 {
41   Internal::Stage* stage = Internal::Stage::GetCurrent();
42   if( stage )
43   {
44     stage->RegisterObject( this );
45   }
46 }
47
48 void BaseObject::UnregisterObject()
49 {
50   // Guard to allow handle destruction after Core has been destroyed
51   Internal::Stage* stage = Internal::Stage::GetCurrent();
52   if( stage )
53   {
54     stage->UnregisterObject( this );
55   }
56 }
57
58 bool BaseObject::DoAction(const std::string& actionName, const Property::Map& attributes)
59 {
60   Dali::Internal::TypeRegistry* registry = Dali::Internal::TypeRegistry::Get();
61
62   if( registry )
63   {
64     return registry->DoActionTo(this, actionName, attributes);
65   }
66
67   return false;
68 }
69
70 const std::string& BaseObject::GetTypeName() const
71 {
72   Dali::Internal::TypeRegistry* registry = Dali::Internal::TypeRegistry::Get();
73
74   if( registry )
75   {
76     Internal::TypeRegistry::TypeInfoPointer typeInfo = registry->GetTypeInfo(this);
77     if( typeInfo )
78     {
79       return typeInfo->GetName();
80     }
81   }
82
83   // Return an empty string if type-name not found.
84   DALI_LOG_WARNING( "TypeName Not Found\n" );
85   static std::string empty;
86   return empty;
87 }
88
89 bool BaseObject::GetTypeInfo(Dali::TypeInfo& typeInfo) const
90 {
91   Dali::Internal::TypeRegistry* registry = Dali::Internal::TypeRegistry::Get();
92
93   Internal::TypeRegistry::TypeInfoPointer info = registry->GetTypeInfo(this);
94   if(info)
95   {
96     typeInfo = Dali::TypeInfo( info.Get() );
97     return true;
98   }
99   else
100   {
101     return false;
102   }
103 }
104
105 bool BaseObject::DoConnectSignal( ConnectionTrackerInterface* connectionTracker, const std::string& signalName, FunctorDelegate* functor )
106 {
107   Dali::Internal::TypeRegistry* registry = Dali::Internal::TypeRegistry::Get();
108
109   if( registry )
110   {
111     return registry->ConnectSignal( this, connectionTracker, signalName, functor );
112   }
113
114   return false;
115 }
116
117 } // namespace Dali
118