Revert "License conversion from Flora to Apache 2.0"
[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    * Register an event-thread only property with a type
103    * @param [in] registered TypeRegistration object used to register the type
104    * @param [in] name Property name
105    * @param [in] index Property index
106    * @param [in] type Property type
107    * @param [in] setFunc The function to set the property (Can be NULL).
108    * @param [in] getFunc The function to get the value of a property.
109    * @return true if registered
110    */
111   bool RegisterProperty( TypeRegistration& registered, const std::string& name, Property::Index index, Property::Type type, Dali::TypeInfo::SetPropertyFunction setFunc, Dali::TypeInfo::GetPropertyFunction getFunc );
112
113   /*
114    * @copydoc Dali::Internal::TypeInfo::DoActionTo
115    * Walks all base types until it finds a doer.
116    */
117   bool DoActionTo( BaseObject * const object, const std::string &actionName, const std::vector<Property::Value> &properties);
118
119   /**
120    * @copydoc Dali::BaseHandle::ConnectSignal()
121    */
122   bool ConnectSignal( BaseObject* object, ConnectionTrackerInterface* connectionTracker, const std::string& signalName, FunctorDelegate* functor );
123
124   /*
125    * Return the type info for a given BaseObject pointer
126    * @param [in] pBaseObject Pointer to a BaseObject
127    * @return TypeInfo for the BaseObject.
128    */
129   Dali::TypeInfo GetTypeInfo(const Dali::BaseObject * const pBaseObject);
130
131   /*
132    * Calls any type creation functions that have been flagged as initialization functions
133    */
134   void CallInitFunctions(void) const;
135
136 public:
137
138   /*
139    * Return the name derived from type_info used to register the type
140    * @param [in] registerType Type info for the type to be registered
141    * @return registered name
142    */
143   static std::string RegistrationName( const std::type_info& registerType );
144
145 private:
146   /*
147    * Map from type name to TypeInfo
148    */
149   typedef std::map<std::string, Dali::TypeInfo> RegistryMap;
150   RegistryMap mRegistryLut;
151
152   typedef std::vector<Dali::TypeInfo::CreateFunction> InitFunctions;
153   InitFunctions mInitFunctions;
154
155 private:
156   TypeRegistry();
157   ~TypeRegistry();
158
159   /**
160    * @brief Undefined Copy Constructor
161    */
162   TypeRegistry(TypeRegistry &);
163
164   /**
165    * @brief Undefined Assignment Operator
166    */
167   TypeRegistry& operator=(const TypeRegistry &);
168 };
169
170
171 } // namespace Internal
172
173 // Helpers for public-api forwarding methods
174
175 inline Internal::TypeRegistry& GetImplementation(Dali::TypeRegistry& typeRegistry)
176 {
177   DALI_ASSERT_ALWAYS(typeRegistry);
178
179   BaseObject& handle = typeRegistry.GetBaseObject();
180
181   return static_cast<Internal::TypeRegistry&>(handle);
182 }
183
184 inline const Internal::TypeRegistry& GetImplementation(const Dali::TypeRegistry& typeRegistry)
185 {
186   DALI_ASSERT_ALWAYS(typeRegistry);
187
188   const BaseObject& handle = typeRegistry.GetBaseObject();
189
190   return static_cast<const Internal::TypeRegistry&>(handle);
191 }
192
193 } // namespace Dali
194
195 #endif // __DALI_INTERNAL_TYPE_REGISTRY_H__