40686c91583f5364810509442c4595d5ddd1dbbf
[platform/core/uifw/dali-core.git] / dali / public-api / object / type-registry.cpp
1 /*
2  * Copyright (c) 2018 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/type-registry.h>
20
21 // EXTERNAL INCLUDES
22
23 // INTERNAL INCLUDES
24 #include <dali/public-api/object/property-index-ranges.h>
25 #include <dali/internal/event/common/type-registry-impl.h>
26
27 namespace Dali
28 {
29
30 TypeRegistry::TypeRegistry()
31 {
32 }
33
34 TypeRegistry::~TypeRegistry()
35 {
36 }
37
38 TypeRegistry::TypeRegistry(const TypeRegistry& copy)
39 : BaseHandle(copy)
40 {
41 }
42
43 TypeRegistry& TypeRegistry::operator=(const TypeRegistry& rhs)
44 {
45   BaseHandle::operator=(rhs);
46   return *this;
47 }
48
49 TypeRegistry TypeRegistry::Get()
50 {
51   return TypeRegistry(Internal::TypeRegistry::Get());
52 }
53
54 Dali::TypeInfo TypeRegistry::GetTypeInfo( const std::string &uniqueTypeName )
55 {
56   return GetImplementation(*this).GetTypeInfo( uniqueTypeName );
57 }
58
59 Dali::TypeInfo TypeRegistry::GetTypeInfo( const std::type_info& registerType )
60 {
61   return GetImplementation(*this).GetTypeInfo( registerType );
62 }
63
64 size_t TypeRegistry::GetTypeNameCount() const
65 {
66   return GetImplementation(*this).GetTypeNameCount();
67 }
68
69 std::string TypeRegistry::GetTypeName(size_t index) const
70 {
71   return GetImplementation(*this).GetTypeName(index);
72 }
73
74 TypeRegistry::TypeRegistry(Internal::TypeRegistry* internal)
75 : BaseHandle(internal)
76 {
77 }
78
79 TypeRegistration::TypeRegistration( const std::type_info& registerType, const std::type_info& baseType,
80                                     TypeInfo::CreateFunction f )
81   : mReference(Internal::TypeRegistry::Get())
82 {
83   Internal::TypeRegistry *impl = Internal::TypeRegistry::Get();
84
85   if( impl->Register( registerType, baseType, f, false ) )
86   {
87     mName = impl->RegistrationName( registerType );
88   }
89 }
90
91 TypeRegistration::TypeRegistration( const std::type_info& registerType, const std::type_info& baseType,
92                                     TypeInfo::CreateFunction f, bool callCreateOnInit )
93   : mReference(Internal::TypeRegistry::Get())
94 {
95   Internal::TypeRegistry *impl = Internal::TypeRegistry::Get();
96
97   if( impl->Register( registerType, baseType, f, callCreateOnInit ) )
98   {
99     mName = impl->RegistrationName( registerType );
100   }
101 }
102
103 TypeRegistration::TypeRegistration( const std::string& name, const std::type_info& baseType,
104                                     TypeInfo::CreateFunction f )
105   : mReference(Internal::TypeRegistry::Get())
106 {
107   Internal::TypeRegistry *impl = Internal::TypeRegistry::Get();
108
109   if( impl->Register( name, baseType, f, false ) )
110   {
111     mName = name;
112   }
113 }
114
115
116 const std::string TypeRegistration::RegisteredName() const
117 {
118   return mName;
119 }
120
121 SignalConnectorType::SignalConnectorType( TypeRegistration& typeRegistration, const std::string& name, TypeInfo::SignalConnectorFunction func )
122 {
123   Internal::TypeRegistry::Get()->RegisterSignal( typeRegistration, name, func );
124 }
125
126 TypeAction::TypeAction( TypeRegistration &registered, const std::string &name, TypeInfo::ActionFunction f)
127 {
128   Internal::TypeRegistry::Get()->RegisterAction( registered, name, f );
129 }
130
131 PropertyRegistration::PropertyRegistration( TypeRegistration& registered, const std::string& name, Property::Index index, Property::Type type, TypeInfo::SetPropertyFunction setFunc, TypeInfo::GetPropertyFunction getFunc )
132 {
133   DALI_ASSERT_ALWAYS( ( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX ) );
134
135   Internal::TypeRegistry::Get()->RegisterProperty( registered, name, index, type, setFunc, getFunc );
136 }
137
138 AnimatablePropertyRegistration::AnimatablePropertyRegistration( TypeRegistration& registered, const std::string& name, Property::Index index, Property::Type type )
139 {
140   DALI_ASSERT_ALWAYS( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) );
141
142   Internal::TypeRegistry::Get()->RegisterAnimatableProperty( registered, name, index, type );
143 }
144
145 AnimatablePropertyRegistration::AnimatablePropertyRegistration( TypeRegistration& registered, const std::string& name, Property::Index index, const Property::Value& value )
146 {
147   DALI_ASSERT_ALWAYS( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) );
148
149   Internal::TypeRegistry::Get()->RegisterAnimatableProperty( registered, name, index, value );
150 }
151
152 AnimatablePropertyComponentRegistration::AnimatablePropertyComponentRegistration( TypeRegistration& registered, const std::string& name, Property::Index index, Property::Index baseIndex, uint32_t componentIndex)
153 {
154   DALI_ASSERT_ALWAYS( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) );
155
156   Internal::TypeRegistry::Get()->RegisterAnimatablePropertyComponent( registered, name, index, baseIndex, componentIndex );
157 }
158
159 ChildPropertyRegistration::ChildPropertyRegistration( TypeRegistration& registered, const std::string& name, Property::Index index, Property::Type type )
160 {
161   DALI_ASSERT_ALWAYS( ( index >= CHILD_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= CHILD_PROPERTY_REGISTRATION_MAX_INDEX ) );
162
163   Internal::TypeRegistry::Get()->RegisterChildProperty( registered, name, index, type );
164 }
165
166 ChildPropertyRegistration::ChildPropertyRegistration( const std::string& registered, const std::string& name, Property::Index index, Property::Type type )
167 {
168   DALI_ASSERT_ALWAYS( ( index >= CHILD_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= CHILD_PROPERTY_REGISTRATION_MAX_INDEX ) );
169
170   Internal::TypeRegistry::Get()->RegisterChildProperty( registered, name, index, type );
171 }
172
173
174 } // namespace Dali