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