[SRUK] Initial copy from Tizen 2.2 version
[platform/core/uifw/dali-core.git] / dali / internal / event / common / type-registry-impl.h
1 #ifndef __DALI_INTERNAL_TYPE_REGISTRY_H__
2 #define __DALI_INTERNAL_TYPE_REGISTRY_H__
3
4 //
5 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
6 //
7 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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 // INTERNAL INCLUDES
21 #include <dali/public-api/common/map-wrapper.h>
22 #include <dali/public-api/object/type-registry.h>
23 #include <dali/public-api/object/base-handle.h>
24 #include <dali/public-api/object/base-object.h>
25 #include <dali/internal/event/common/type-info-impl.h>
26
27 namespace Dali
28 {
29
30 namespace Internal
31 {
32
33 ////////////////////////////////////////////////////////////////////////////////
34 class TypeRegistry;
35
36 /*
37 * @copydoc Dali::TypeRegistry
38 */
39 class TypeRegistry : public Dali::BaseObject
40 {
41 public:
42   /**
43    * Get the TypeRegistry
44    */
45   static TypeRegistry *Get();
46
47   /*
48    * @copydoc Dali::TypeRegistry::GetTypeInfo
49    */
50   Dali::TypeInfo GetTypeInfo( const std::string &uniqueTypeName );
51
52   /*
53    * @copydoc Dali::TypeRegistry::GetTypeInfo
54    */
55   Dali::TypeInfo GetTypeInfo( const std::type_info& registerType );
56
57   /*
58    * @copydoc Dali::TypeRegistry::GetTypeNames
59    */
60   Dali::TypeRegistry::NameContainer GetTypeNames() const;
61
62   /*
63    * Register a creation function under a unique name.
64    * @param [in] theTypeInfo Type info for the type to be registered
65    * @param [in] baseTypeInfo Type info for its base class
66    * @param [in] createInstance Instance creation function
67    * @param [in] callCreateOnInit If true call createInstance on dali initialisation
68    * @return true if the name could be registered.
69    */
70   bool Register( const std::type_info& theTypeInfo, const std::type_info& baseTypeInfo,
71                  Dali::TypeInfo::CreateFunction createInstance, bool callCreateOnInit );
72
73   /*
74    * Register a creation function under a unique name.
75    * @param [in] name The name type to be registered (must be unique)
76    * @param [in] baseTypeInfo Type info for its base class
77    * @param [in] createInstance Instance creation function
78    * @param [in] callCreateOnInit If true call createInstance on dali initialisation
79    * @return true if the name could be registered.
80    */
81   bool Register( const std::string& name, const std::type_info& baseTypeInfo,
82                  Dali::TypeInfo::CreateFunction createInstance, bool callCreateOnInit  );
83
84   /*
85    * Register a signal connector function to a type
86    * @param [in] typeRegistration TypeRegistration object used to register the type
87    * @param [in] name Signal name
88    * @param [in] func Signal connector function
89    */
90   void RegisterSignal( TypeRegistration& typeRegistration, const std::string& name, Dali::TypeInfo::SignalConnectorFunctionV2 func );
91
92   /*
93    * Register an action function to a type
94    * @param [in] registered TypeRegistration object used to register the type
95    * @param [in] name Action name
96    * @param [in] f Action function
97    * @return true if registered
98    */
99   bool RegisterAction( TypeRegistration &registered, const std::string &name, Dali::TypeInfo::ActionFunction f);
100
101   /*
102    * @copydoc Dali::Internal::TypeInfo::DoActionTo
103    * Walks all base types until it finds a doer.
104    */
105   bool DoActionTo( BaseObject * const object, const std::string &actionName, const std::vector<Property::Value> &properties);
106
107   /**
108    * @copydoc Dali::BaseHandle::ConnectSignal()
109    */
110   bool ConnectSignal( BaseObject* object, ConnectionTrackerInterface* connectionTracker, const std::string& signalName, FunctorDelegate* functor );
111
112   /*
113    * Return the type info for a given BaseObject pointer
114    * @param [in] pBaseObject Pointer to a BaseObject
115    * @return TypeInfo for the BaseObject.
116    */
117   Dali::TypeInfo GetTypeInfo(Dali::BaseObject * const pBaseObject);
118
119   /*
120    * Calls any type creation functions that have been flagged as initialization functions
121    */
122   void CallInitFunctions(void) const;
123
124 public:
125
126   /*
127    * Return the name derived from type_info used to register the type
128    * @param [in] registerType Type info for the type to be registered
129    * @return registered name
130    */
131   static std::string RegistrationName( const std::type_info& registerType );
132
133 private:
134   /*
135    * Map from type name to TypeInfo
136    */
137   typedef std::map<std::string, Dali::TypeInfo> RegistryMap;
138   RegistryMap mRegistryLut;
139
140   typedef std::vector<Dali::TypeInfo::CreateFunction> InitFunctions;
141   InitFunctions mInitFunctions;
142
143 private:
144   TypeRegistry();
145   ~TypeRegistry();
146
147   TypeRegistry(TypeRegistry &);
148   TypeRegistry &operator()(const TypeRegistry &);
149 };
150
151
152 } // namespace Internal
153
154 // Helpers for public-api forwarding methods
155
156 inline Internal::TypeRegistry& GetImplementation(Dali::TypeRegistry& typeRegistry)
157 {
158   DALI_ASSERT_ALWAYS(typeRegistry);
159
160   BaseObject& handle = typeRegistry.GetBaseObject();
161
162   return static_cast<Internal::TypeRegistry&>(handle);
163 }
164
165 inline const Internal::TypeRegistry& GetImplementation(const Dali::TypeRegistry& typeRegistry)
166 {
167   DALI_ASSERT_ALWAYS(typeRegistry);
168
169   const BaseObject& handle = typeRegistry.GetBaseObject();
170
171   return static_cast<const Internal::TypeRegistry&>(handle);
172 }
173
174 } // namespace Dali
175
176 #endif // __DALI_INTERNAL_TYPE_REGISTRY_H__