Merge "DALi Version 1.0.4" into tizen
[platform/core/uifw/dali-core.git] / dali / public-api / object / type-registry.cpp
1 /*
2  * Copyright (c) 2014 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.h>
25 #include <dali/internal/event/common/type-registry-impl.h>
26 #include <dali/internal/event/common/property-index-ranges.h>
27
28 namespace Dali
29 {
30
31 TypeRegistry::TypeRegistry()
32 {
33 }
34
35 TypeRegistry::~TypeRegistry()
36 {
37 }
38
39 TypeRegistry::TypeRegistry(const TypeRegistry& copy)
40 : BaseHandle(copy)
41 {
42 }
43
44 TypeRegistry& TypeRegistry::operator=(const TypeRegistry& rhs)
45 {
46   BaseHandle::operator=(rhs);
47   return *this;
48 }
49
50 TypeRegistry& TypeRegistry::operator=(BaseHandle::NullType* rhs)
51 {
52   DALI_ASSERT_ALWAYS( (rhs == NULL) && "Can only assign NULL pointer to handle");
53   Reset();
54   return *this;
55 }
56
57 TypeRegistry TypeRegistry::Get()
58 {
59   return TypeRegistry(Internal::TypeRegistry::Get());
60 }
61
62 Dali::TypeInfo TypeRegistry::GetTypeInfo( const std::string &uniqueTypeName )
63 {
64   return GetImplementation(*this).GetTypeInfo( uniqueTypeName );
65 }
66
67 Dali::TypeInfo TypeRegistry::GetTypeInfo( const std::type_info& registerType )
68 {
69   return GetImplementation(*this).GetTypeInfo( registerType );
70 }
71
72 TypeRegistry::NameContainer TypeRegistry::GetTypeNames() const
73 {
74   return GetImplementation(*this).GetTypeNames();
75 }
76
77 TypeRegistry::TypeRegistry(Internal::TypeRegistry* internal)
78 : BaseHandle(internal)
79 {
80 }
81
82 TypeRegistration::TypeRegistration( const std::type_info& registerType, const std::type_info& baseType,
83                                     TypeInfo::CreateFunction f )
84   : mReference(Internal::TypeRegistry::Get())
85 {
86   Internal::TypeRegistry *impl = Internal::TypeRegistry::Get();
87
88   if( impl->Register( registerType, baseType, f, false ) )
89   {
90     mName = impl->RegistrationName( registerType );
91   }
92 }
93
94 TypeRegistration::TypeRegistration( const std::type_info& registerType, const std::type_info& baseType,
95                                     TypeInfo::CreateFunction f, bool callCreateOnInit )
96   : mReference(Internal::TypeRegistry::Get())
97 {
98   Internal::TypeRegistry *impl = Internal::TypeRegistry::Get();
99
100   if( impl->Register( registerType, baseType, f, callCreateOnInit ) )
101   {
102     mName = impl->RegistrationName( registerType );
103   }
104 }
105
106 TypeRegistration::TypeRegistration( const std::string& name, const std::type_info& baseType,
107                                     TypeInfo::CreateFunction f )
108   : mReference(Internal::TypeRegistry::Get())
109 {
110   Internal::TypeRegistry *impl = Internal::TypeRegistry::Get();
111
112   if( impl->Register( name, baseType, f, false ) )
113   {
114     mName = name;
115   }
116 }
117
118
119 const std::string TypeRegistration::RegisteredName() const
120 {
121   return mName;
122 }
123
124 SignalConnectorType::SignalConnectorType( TypeRegistration& typeRegistration, const std::string& name, TypeInfo::SignalConnectorFunctionV2 func )
125 {
126   Internal::TypeRegistry::Get()->RegisterSignal( typeRegistration, name, func );
127 }
128
129 TypeAction::TypeAction( TypeRegistration &registered, const std::string &name, TypeInfo::ActionFunction f)
130 {
131   Internal::TypeRegistry::Get()->RegisterAction( registered, name, f );
132 }
133
134 PropertyRegistration::PropertyRegistration( TypeRegistration& registered, const std::string& name, Property::Index index, Property::Type type, TypeInfo::SetPropertyFunction setFunc, TypeInfo::GetPropertyFunction getFunc )
135 {
136   DALI_ASSERT_ALWAYS( ( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX ) );
137
138   Internal::TypeRegistry::Get()->RegisterProperty( registered, name, index, type, setFunc, getFunc );
139 }
140
141 } // namespace Dali