Fix interface to take sink argument by value.
[platform/core/uifw/dali-core.git] / dali / public-api / object / handle.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/handle.h>
20
21 // INTERNAL INCLUDES
22 #include <dali/integration-api/debug.h>
23 #include <dali/internal/event/animation/constraint-impl.h>
24 #include <dali/internal/event/common/object-impl.h>
25 #include <dali/public-api/animation/constraint.h>
26 #include <dali/public-api/object/property-conditions.h>
27 #include <dali/public-api/object/property-notification.h>
28
29 namespace Dali
30 {
31 Handle::Handle(Dali::Internal::Object* handle)
32 : BaseHandle(handle)
33 {
34 }
35
36 Handle::Handle()
37 {
38 }
39
40 Handle Handle::New()
41 {
42   return Handle(Internal::Object::New().Get());
43 }
44
45 Handle::~Handle()
46 {
47 }
48
49 Handle::Handle(const Handle& handle) = default;
50
51 Handle& Handle::operator=(const Handle& rhs) = default;
52
53 Handle::Handle(Handle&& rhs) = default;
54
55 Handle& Handle::operator=(Handle&& rhs) = default;
56
57 Handle Handle::DownCast(BaseHandle handle)
58 {
59   return Handle(dynamic_cast<Dali::Internal::Object*>(handle.GetObjectPtr()));
60 }
61
62 bool Handle::Supports(Capability capability) const
63 {
64   return GetImplementation(*this).Supports(capability);
65 }
66
67 uint32_t Handle::GetPropertyCount() const
68 {
69   return GetImplementation(*this).GetPropertyCount();
70 }
71
72 std::string Handle::GetPropertyName(Property::Index index) const
73 {
74   return GetImplementation(*this).GetPropertyName(index);
75 }
76
77 Property::Index Handle::GetPropertyIndex(Property::Key key) const
78 {
79   return GetImplementation(*this).GetPropertyIndex(key);
80 }
81
82 bool Handle::IsPropertyWritable(Property::Index index) const
83 {
84   return GetImplementation(*this).IsPropertyWritable(index);
85 }
86
87 bool Handle::IsPropertyAnimatable(Property::Index index) const
88 {
89   return GetImplementation(*this).IsPropertyAnimatable(index);
90 }
91
92 bool Handle::IsPropertyAConstraintInput(Property::Index index) const
93 {
94   return GetImplementation(*this).IsPropertyAConstraintInput(index);
95 }
96
97 Property::Type Handle::GetPropertyType(Property::Index index) const
98 {
99   return GetImplementation(*this).GetPropertyType(index);
100 }
101
102 void Handle::SetProperty(Property::Index index, Property::Value propertyValue)
103 {
104   GetImplementation(*this).SetProperty(index, std::move(propertyValue));
105 }
106
107 Property::Index Handle::RegisterProperty(std::string name, Property::Value propertyValue)
108 {
109   return GetImplementation(*this).RegisterProperty(std::move(name), std::move(propertyValue));
110 }
111
112 Property::Index Handle::RegisterProperty(Property::Index key, std::string name, Property::Value propertyValue)
113 {
114   return GetImplementation(*this).RegisterProperty(std::move(name), key, std::move(propertyValue));
115 }
116
117 Property::Index Handle::RegisterProperty(std::string name, Property::Value propertyValue, Property::AccessMode accessMode)
118 {
119   return GetImplementation(*this).RegisterProperty(std::move(name), std::move(propertyValue), accessMode);
120 }
121
122 Property::Value Handle::GetProperty(Property::Index index) const
123 {
124   return GetImplementation(*this).GetProperty(index);
125 }
126
127 Property::Value Handle::GetCurrentProperty(Property::Index index) const
128 {
129   return GetImplementation(*this).GetCurrentProperty(index);
130 }
131
132 void Handle::SetProperties(const Property::Map& properties)
133 {
134   GetImplementation(*this).SetProperties(properties);
135 }
136
137 void Handle::GetProperties(Property::Map& properties)
138 {
139   GetImplementation(*this).GetProperties(properties);
140 }
141
142 void Handle::GetPropertyIndices(Property::IndexContainer& indices) const
143 {
144   GetImplementation(*this).GetPropertyIndices(indices);
145 }
146
147 bool Handle::DoesCustomPropertyExist(Property::Index index)
148 {
149   return GetImplementation(*this).DoesCustomPropertyExist(index);
150 }
151
152 Dali::PropertyNotification Handle::AddPropertyNotification(Property::Index          index,
153                                                            const PropertyCondition& condition)
154 {
155   return GetImplementation(*this).AddPropertyNotification(index, -1, condition);
156 }
157
158 Dali::PropertyNotification Handle::AddPropertyNotification(Property::Index          index,
159                                                            int                      componentIndex,
160                                                            const PropertyCondition& condition)
161 {
162   return GetImplementation(*this).AddPropertyNotification(index, componentIndex, condition);
163 }
164
165 void Handle::RemovePropertyNotification(Dali::PropertyNotification propertyNotification)
166 {
167   GetImplementation(*this).RemovePropertyNotification(propertyNotification);
168 }
169
170 void Handle::RemovePropertyNotifications()
171 {
172   GetImplementation(*this).RemovePropertyNotifications();
173 }
174
175 void Handle::RemoveConstraints()
176 {
177   GetImplementation(*this).RemoveConstraints();
178 }
179
180 void Handle::RemoveConstraints(uint32_t tag)
181 {
182   GetImplementation(*this).RemoveConstraints(tag);
183 }
184
185 IndirectValue Handle::operator[](Property::Index index)
186 {
187   // Will assert on access if handle is empty
188   return IndirectValue(*this, index);
189 }
190
191 IndirectValue Handle::operator[](const std::string& name)
192 {
193   // Will assert immediately when GetPropertyIndex is called if handle is empty
194   return IndirectValue(*this, GetPropertyIndex(name));
195 }
196
197 Handle::PropertySetSignalType& Handle::PropertySetSignal()
198 {
199   return GetImplementation(*this).PropertySetSignal();
200 }
201
202 namespace WeightObject
203 {
204 const Property::Index WEIGHT = PROPERTY_CUSTOM_START_INDEX;
205
206 Handle New()
207 {
208   Handle handle = Handle::New();
209
210   handle.RegisterProperty("weight", 0.0f);
211
212   return handle;
213 }
214
215 } // namespace WeightObject
216
217 } // namespace Dali