1 #ifndef __DALI_TYPE_REGISTRY_H__
2 #define __DALI_TYPE_REGISTRY_H__
5 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
11 // http://floralicense.org/license/
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.
21 * @addtogroup CAPI_DALI_FRAMEWORK
29 #include <dali/public-api/object/base-handle.h>
30 #include <dali/public-api/object/type-info.h>
32 namespace Dali DALI_IMPORT_API
35 namespace Internal DALI_INTERNAL
41 * The TypeRegistry allows registration of type instance creation functions.
42 * These can then be created later by name and down cast to the appropriate type.
44 * Usage: (Registering)
48 * // Note: object construction in namespace scope is defined in a translation unit as being
49 * // in appearance order (C++ standard 3.6/2). So TypeRegistration is declared first in
50 * // the cpp file below. Signal, action and property declarations follow in any order.
53 * TypeRegistration myActorType(typeid(MyActor), typeid(Actor), CreateMyActor );
55 * SignalConnectorType( myActorType, "highlighted", ConnectSignalForMyActor );
56 * TypeAction( myActorType, "open", DoMyActorAction );
57 * TypeAction( myActorType, "close", DoMyActorAction );
58 * PropertyRegistration( myActorType, "status", PropertyRegistration::START_INDEX, Property::BOOLEAN, SetPropertyFunction, GetPropertyFunction );
65 * TypeRegistry::TypeInfo type = TypeRegistry::Get().GetTypeInfo("MyActor");
66 * MyActor a = MyActor::DownCast(type.CreateInstance());
75 * Actors that inherit from the CustomActor framework must ensure the implementation
76 * class has an identical name to the Actor class. This is to ensure the class can be
77 * found at runtime for signals and actions. Otherwise these will silently fail.
79 * As namespaces are discarded the convention is to use a namespace ie
81 * 'class MyActor {}; namespace Internal { class MyActor {}; }'
83 * Warning: this arrangement will silently fail
85 * 'class MyActor {}; class MyActorImpl {};'
89 * Signal and action names follow properties and are by convention lower case hyphen
90 * separated ie 'next-page'. This maintains consistency with the scripted interface.
93 class TypeRegistry : public BaseHandle
96 typedef std::vector<std::string> NameContainer;
99 * Get Type Registry handle
100 * @return TypeRegistry handle
102 static TypeRegistry Get();
105 * Allows the creation of an empty typeRegistry handle.
115 * @copydoc Dali::BaseHandle::operator=
117 using BaseHandle::operator=;
120 * Get TypeInfo for a registered type
121 * @param [in] uniqueTypeName A unique type name
122 * @return TypeInfo if the type exists otherwise an empty handle
124 TypeInfo GetTypeInfo( const std::string &uniqueTypeName );
127 * Get TypeInfo for a registered type
128 * @param [in] registerType The registered type info
129 * @return TypeInfo if the type exists otherwise an empty handle
131 TypeInfo GetTypeInfo( const std::type_info& registerType );
135 * @return list of known types by name
137 NameContainer GetTypeNames() const;
139 public: // Not intended for application developers
142 * This constructor is used by Dali Get() method
143 * @param [in] typeRegistry A pointer to a Dali resource
145 explicit DALI_INTERNAL TypeRegistry(Internal::TypeRegistry*typeRegistry);
149 * Register a type from type info
151 class TypeRegistration
155 * Constructor registers the type creation function
156 * @param [in] registerType the type info for the type to be registered
157 * @param [in] baseType the base type info of registerType
158 * @param [in] f registerType instance creation function
160 TypeRegistration( const std::type_info& registerType, const std::type_info& baseType,
161 TypeInfo::CreateFunction f );
164 * Constructor registers the type creation function
165 * @param [in] registerType the type info for the type to be registered
166 * @param [in] baseType the base type info of registerType
167 * @param [in] f registerType instance creation function
168 * @param [in] callCreateOnInit If true the creation function is called as part of Dali initialisation
170 TypeRegistration( const std::type_info& registerType, const std::type_info& baseType,
171 TypeInfo::CreateFunction f, bool callCreateOnInit );
174 * Constructor registers the type creation function for a named class or type.
175 * This allows types to be created dynamically from script. The name must be
176 * unique for successful registration.
177 * @param [in] name the name of the type to be registered
178 * @param [in] baseType the base type info of registerType
179 * @param [in] f registerType instance creation function
181 TypeRegistration( const std::string& name, const std::type_info& baseType,
182 TypeInfo::CreateFunction f );
185 * The name the type is registered under (derived from type_info)
186 * @return the registered name or empty if unregistered
188 const std::string RegisteredName() const;
191 TypeRegistry mReference;
196 * Register a signal connector function to a registered type
198 class SignalConnectorType
202 * Constructor registers the type creation function
203 * @param [in] typeRegistration The TypeRegistration object
204 * @param [in] name The signal name
205 * @param [in] func The signal connector function
207 SignalConnectorType( TypeRegistration& typeRegistration, const std::string& name, TypeInfo::SignalConnectorFunctionV2 func );
211 * Register an action function
217 * Constructor registers the type creation function
218 * @param [in] registered The TypeRegistration object
219 * @param [in] name The action name
220 * @param [in] f The action function
222 TypeAction( TypeRegistration ®istered, const std::string &name, TypeInfo::ActionFunction f);
226 * Register a property for the given type.
228 class PropertyRegistration
232 // Enumerations are being used here rather than static constants so that switch statements can be used to compare property indices
235 START_INDEX = 10000000, ///< The index for this type should start from this number
236 MAX_INDEX = 19999999 ///< The maximum index supported for this type
240 * This constructor registers the property with the registered type. This constructor is for event-thread
241 * only properties where the value of the property can be retrieved and set via specified functions.
243 * Functions of the following type may be used for setFunc and getFunc respectively:
245 * void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
246 * Property::Value GetProperty( BaseObject* object, Property::Index index );
249 * @param [in] registered The TypeRegistration object
250 * @param [in] name The name of the property
251 * @param [in] index The property index. Must be a value between START_INDEX and MAX_INDEX inclusive.
252 * @param [in] type The property value type.
253 * @param [in] setFunc The function to call when setting the property. If NULL, then the property becomes read-only.
254 * @param [in] getFunc The function to call to retrieve the current value of the property. MUST be provided.
256 * @note The "index" value must be between START_INDEX and MAX_INDEX inclusive.
257 * @note If "setFunc" is NULL, then the property becomes a read-only property.
258 * @note "getFunc" MUST be provided
260 * @pre "registered" must be registered with the TypeRegistry.
262 PropertyRegistration( TypeRegistration& registered,
263 const std::string& name, Property::Index index, Property::Type type,
264 TypeInfo::SetPropertyFunction setFunc, TypeInfo::GetPropertyFunction getFunc );