Merge remote-tracking branch 'origin/tizen' into new_text
[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 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 // INTERNAL INCLUDES
22 #include <dali/public-api/common/map-wrapper.h>
23 #include <dali/public-api/object/type-registry.h>
24 #include <dali/public-api/object/base-handle.h>
25 #include <dali/public-api/object/base-object.h>
26 #include <dali/internal/event/common/type-info-impl.h>
27
28 namespace Dali
29 {
30
31 namespace Internal
32 {
33
34 ////////////////////////////////////////////////////////////////////////////////
35 class TypeRegistry;
36
37 /*
38 * @copydoc Dali::TypeRegistry
39 */
40 class TypeRegistry : public Dali::BaseObject
41 {
42 public:
43   /**
44    * Get the TypeRegistry
45    */
46   static TypeRegistry *Get();
47
48   /*
49    * @copydoc Dali::TypeRegistry::GetTypeInfo
50    */
51   Dali::TypeInfo GetTypeInfo( const std::string &uniqueTypeName );
52
53   /*
54    * @copydoc Dali::TypeRegistry::GetTypeInfo
55    */
56   Dali::TypeInfo GetTypeInfo( const std::type_info& registerType );
57
58   /*
59    * @copydoc Dali::TypeRegistry::GetTypeNames
60    */
61   Dali::TypeRegistry::NameContainer GetTypeNames() const;
62
63   /*
64    * Register a creation function under a unique name.
65    * @param [in] theTypeInfo Type info for the type to be registered
66    * @param [in] baseTypeInfo Type info for its base class
67    * @param [in] createInstance Instance creation function
68    * @param [in] callCreateOnInit If true call createInstance on dali initialisation
69    * @return true if the name could be registered.
70    */
71   bool Register( const std::type_info& theTypeInfo, const std::type_info& baseTypeInfo,
72                  Dali::TypeInfo::CreateFunction createInstance, bool callCreateOnInit );
73
74   /*
75    * Register a creation function under a unique name.
76    * @param [in] name The name type to be registered (must be unique)
77    * @param [in] baseTypeInfo Type info for its base class
78    * @param [in] createInstance Instance creation function
79    * @param [in] callCreateOnInit If true call createInstance on dali initialisation
80    * @return true if the name could be registered.
81    */
82   bool Register( const std::string& name, const std::type_info& baseTypeInfo,
83                  Dali::TypeInfo::CreateFunction createInstance, bool callCreateOnInit  );
84
85   /*
86    * Register a signal connector function to a type
87    * @param [in] typeRegistration TypeRegistration object used to register the type
88    * @param [in] name Signal name
89    * @param [in] func Signal connector function
90    */
91   void RegisterSignal( TypeRegistration& typeRegistration, const std::string& name, Dali::TypeInfo::SignalConnectorFunction func );
92
93   /*
94    * Register an action function to a type
95    * @param [in] registered TypeRegistration object used to register the type
96    * @param [in] name Action name
97    * @param [in] f Action function
98    * @return true if registered
99    */
100   bool RegisterAction( TypeRegistration &registered, const std::string &name, Dali::TypeInfo::ActionFunction f);
101
102   /**
103    * Register an event-thread only property with a type
104    * @param [in] registered TypeRegistration object used to register the type
105    * @param [in] name Property name
106    * @param [in] index Property index
107    * @param [in] type Property type
108    * @param [in] setFunc The function to set the property (Can be NULL).
109    * @param [in] getFunc The function to get the value of a property.
110    * @return true if registered
111    */
112   bool RegisterProperty( TypeRegistration& registered, const std::string& name, Property::Index index, Property::Type type, Dali::TypeInfo::SetPropertyFunction setFunc, Dali::TypeInfo::GetPropertyFunction getFunc );
113
114   /**
115    * Register a scene graph only property with a type
116    * @param [in] registered TypeRegistration object used to register the type
117    * @param [in] name Property name
118    * @param [in] index Property index
119    * @param [in] type Property type
120    * @return true if registered
121    */
122   bool RegisterAnimatableProperty( TypeRegistration& registered, const std::string& name, Property::Index index, Property::Type type );
123
124   /*
125    * @copydoc Dali::Internal::TypeInfo::DoActionTo
126    * Walks all base types until it finds a doer.
127    */
128   bool DoActionTo( BaseObject * const object, const std::string &actionName, const std::vector<Property::Value> &properties);
129
130   /**
131    * @copydoc Dali::BaseHandle::ConnectSignal()
132    */
133   bool ConnectSignal( BaseObject* object, ConnectionTrackerInterface* connectionTracker, const std::string& signalName, FunctorDelegate* functor );
134
135   /*
136    * Return the type info for a given BaseObject pointer
137    * @param [in] pBaseObject Pointer to a BaseObject
138    * @return TypeInfo for the BaseObject.
139    */
140   Dali::TypeInfo GetTypeInfo(const Dali::BaseObject * const pBaseObject);
141
142   /*
143    * Calls any type creation functions that have been flagged as initialization functions
144    */
145   void CallInitFunctions(void) const;
146
147 public:
148
149   /*
150    * Return the name derived from type_info used to register the type
151    * @param [in] registerType Type info for the type to be registered
152    * @return registered name
153    */
154   static std::string RegistrationName( const std::type_info& registerType );
155
156 private:
157   /*
158    * Map from type name to TypeInfo
159    */
160   typedef std::map<std::string, Dali::TypeInfo> RegistryMap;
161   RegistryMap mRegistryLut;
162
163   typedef std::vector<Dali::TypeInfo::CreateFunction> InitFunctions;
164   InitFunctions mInitFunctions;
165
166 private:
167   TypeRegistry();
168   ~TypeRegistry();
169
170   /**
171    * @brief Undefined Copy Constructor
172    */
173   TypeRegistry(TypeRegistry &);
174
175   /**
176    * @brief Undefined Assignment Operator
177    */
178   TypeRegistry& operator=(const TypeRegistry &);
179 };
180
181
182 } // namespace Internal
183
184 // Helpers for public-api forwarding methods
185
186 inline Internal::TypeRegistry& GetImplementation(Dali::TypeRegistry& typeRegistry)
187 {
188   DALI_ASSERT_ALWAYS(typeRegistry);
189
190   BaseObject& handle = typeRegistry.GetBaseObject();
191
192   return static_cast<Internal::TypeRegistry&>(handle);
193 }
194
195 inline const Internal::TypeRegistry& GetImplementation(const Dali::TypeRegistry& typeRegistry)
196 {
197   DALI_ASSERT_ALWAYS(typeRegistry);
198
199   const BaseObject& handle = typeRegistry.GetBaseObject();
200
201   return static_cast<const Internal::TypeRegistry&>(handle);
202 }
203
204 } // namespace Dali
205
206 #endif // __DALI_INTERNAL_TYPE_REGISTRY_H__