Clean up the code to build successfully on macOS
[platform/core/uifw/dali-core.git] / dali / internal / update / animation / property-accessor.h
1 #ifndef DALI_INTERNAL_SCENE_GRAPH_PROPERTY_ACCESSOR_H
2 #define DALI_INTERNAL_SCENE_GRAPH_PROPERTY_ACCESSOR_H
3
4 /*
5  * Copyright (c) 2019 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  */
20
21 // INTERNAL INCLUDES
22 #include <dali/public-api/common/dali-common.h>
23 #include <dali/internal/update/common/animatable-property.h>
24 #include <dali/internal/update/manager/transform-manager-property.h>
25
26 namespace Dali
27 {
28
29 namespace Internal
30 {
31
32 /**
33  * A wrapper class for getting/setting a property.
34  * Animators use this instead of accessing properties directly.
35  */
36 template < typename PropertyType >
37 class PropertyAccessor
38 {
39 public:
40
41   /**
42    * Create a property component.
43    * @param [in] property The property to access.
44    */
45   PropertyAccessor( SceneGraph::PropertyBase* property )
46   : mProperty( static_cast< SceneGraph::AnimatableProperty<PropertyType>* >(property) ) // we know the type
47   {
48   }
49
50   /**
51    * Non-virtual destructor; PropertyAccessor is not suitable as a base class.
52    */
53   ~PropertyAccessor()
54   {
55   }
56
57   /**
58    * Query whether the accessor is set.
59    * @return True if set.
60    */
61   bool IsSet() const
62   {
63     return mProperty != nullptr;
64   }
65
66   /**
67    * Reset the property accessor
68    * @post Calling any other PropertyAccessor is invalid.
69    */
70   void Reset()
71   {
72     mProperty = nullptr;
73   }
74
75   /**
76    * @copydoc Dali::Internal::SceneGraph::PropertyBase::IsClean()
77    */
78   bool IsClean() const
79   {
80     return mProperty->IsClean();
81   }
82
83   /**
84    * Read access to the property.
85    * @param [in] bufferIndex The current update buffer index.
86    */
87   const PropertyType& Get( BufferIndex bufferIndex ) const
88   {
89     DALI_ASSERT_DEBUG( nullptr != mProperty && "PropertyAccessor::Get() mProperty was nullptr" );
90     return mProperty->Get( bufferIndex );
91   }
92
93   /**
94    * @copydoc AnimatableProperty<float>::Set()
95    */
96   void Set( BufferIndex bufferIndex, const PropertyType& value ) const
97   {
98     DALI_ASSERT_DEBUG( nullptr != mProperty && "PropertyAccessor::Set() mProperty was nullptr" );
99     mProperty->Set( bufferIndex, value );
100   }
101
102   /**
103    * @copydoc AnimatableProperty<float>::Bake()
104    */
105   void Bake( BufferIndex bufferIndex, const PropertyType& value ) const
106   {
107     DALI_ASSERT_DEBUG( nullptr != mProperty && "PropertyAccessor::Bake() mProperty was nullptr" );
108     mProperty->Bake( bufferIndex, value );
109   }
110
111 private:
112
113   // Undefined
114   PropertyAccessor() = delete;
115   PropertyAccessor(const PropertyAccessor& property) = delete;
116   PropertyAccessor& operator=(const PropertyAccessor& rhs) = delete;
117
118 private:
119
120   SceneGraph::AnimatableProperty<PropertyType>* mProperty; ///< The real property
121
122 };
123
124 /**
125  * A wrapper class for getting/setting a transform manager property
126  * Animators use this instead of accessing properties directly.
127  */
128 template <typename T>
129 class TransformManagerPropertyAccessor
130 {
131 public:
132
133   /**
134    * Create a property component.
135    * @param [in] property The property to access.
136    */
137   TransformManagerPropertyAccessor( SceneGraph::PropertyBase* property )
138   : mProperty( static_cast< SceneGraph::TransformManagerPropertyHandler<T>* >(property) ) // we know the type
139   {
140   }
141
142   /**
143    * Non-virtual destructor; PropertyAccessor is not suitable as a base class.
144    */
145   ~TransformManagerPropertyAccessor()
146   {
147   }
148
149   /**
150    * Query whether the accessor is set.
151    * @return True if set.
152    */
153   bool IsSet() const
154   {
155     return mProperty != nullptr;
156   }
157
158   /**
159    * Reset the property accessor
160    * @post Calling any other PropertyAccessor is invalid.
161    */
162   void Reset()
163   {
164     mProperty = nullptr;
165   }
166
167   /**
168    * @copydoc Dali::Internal::SceneGraph::PropertyBase::IsClean()
169    */
170   bool IsClean() const
171   {
172     return mProperty->IsClean();
173   }
174
175   /**
176    * Read access to the property.
177    * @param [in] bufferIndex The current update buffer index.
178    * @return The value of the property
179    */
180   const T& Get( BufferIndex bufferIndex ) const
181   {
182     DALI_ASSERT_DEBUG( nullptr != mProperty && "PropertyAccessor::Get() mProperty was nullptr" );
183     return mProperty->Get( bufferIndex );
184   }
185
186   /**
187    * @copydoc AnimatableProperty<float>::Set()
188    */
189   void Set( BufferIndex bufferIndex, const T& value ) const
190   {
191     DALI_ASSERT_DEBUG( nullptr != mProperty && "PropertyAccessor::Set() mProperty was nullptr" );
192     mProperty->Set( bufferIndex, value );
193   }
194
195   /**
196    * @copydoc AnimatableProperty<float>::Bake()
197    */
198   void Bake( BufferIndex bufferIndex, const T& value ) const
199   {
200     DALI_ASSERT_DEBUG( nullptr != mProperty && "PropertyAccessor::Bake() mProperty was nullptr" );
201     mProperty->Bake( bufferIndex, value );
202   }
203
204 private:
205
206   // Undefined
207   TransformManagerPropertyAccessor() = delete;
208   TransformManagerPropertyAccessor(const TransformManagerPropertyAccessor& property) = delete;
209   TransformManagerPropertyAccessor& operator=(const TransformManagerPropertyAccessor& rhs) = delete;
210
211 private:
212
213   SceneGraph::TransformManagerPropertyHandler<T>* mProperty; ///< The real property
214
215 };
216
217 /**
218  * A wrapper class for getting/setting a transform manager property component
219  * Animators use this instead of accessing properties directly.
220  */
221 template <typename T, uint32_t COMPONENT>
222 class TransformManagerPropertyComponentAccessor
223 {
224 public:
225
226   /**
227    * Create a property component.
228    * @param [in] property The property to access.
229    */
230   TransformManagerPropertyComponentAccessor( SceneGraph::PropertyBase* property )
231   : mProperty( static_cast< SceneGraph::TransformManagerPropertyHandler<T>* >(property) ) // we know the type
232   {
233   }
234
235   /**
236    * Non-virtual destructor; PropertyAccessor is not suitable as a base class.
237    */
238   ~TransformManagerPropertyComponentAccessor()
239   {
240   }
241
242   /**
243    * Query whether the accessor is set.
244    * @return True if set.
245    */
246   bool IsSet() const
247   {
248     return mProperty != nullptr;
249   }
250
251   /**
252    * Reset the property accessor
253    * @post Calling any other PropertyAccessor is invalid.
254    */
255   void Reset()
256   {
257     mProperty = nullptr;
258   }
259
260   /**
261    * @copydoc Dali::Internal::SceneGraph::PropertyBase::IsClean()
262    */
263   bool IsClean() const
264   {
265     return mProperty->IsClean();
266   }
267
268   /**
269    * Read access to the property.
270    * @param [in] bufferIndex The current update buffer index.
271    * @return The value of the component of the property
272    */
273   float Get( BufferIndex bufferIndex ) const
274   {
275     DALI_ASSERT_DEBUG( nullptr != mProperty && "PropertyAccessor::Get() mProperty was nullptr" );
276     return mProperty->GetFloatComponent( COMPONENT );
277   }
278
279   /**
280    * @copydoc AnimatableProperty<float>::Set()
281    */
282   void Set( BufferIndex bufferIndex, float value ) const
283   {
284     DALI_ASSERT_DEBUG( nullptr != mProperty && "PropertyAccessor::Set() mProperty was nullptr" );
285     mProperty->SetFloatComponent( value, COMPONENT );
286   }
287
288   /**
289    * @copydoc AnimatableProperty<float>::Bake()
290    */
291   void Bake( BufferIndex bufferIndex, float value ) const
292   {
293     DALI_ASSERT_DEBUG( nullptr != mProperty && "PropertyAccessor::Bake() mProperty was nullptr" );
294     mProperty->BakeFloatComponent( value, COMPONENT );
295   }
296
297 private:
298
299   // Undefined
300   TransformManagerPropertyComponentAccessor() = delete;
301   TransformManagerPropertyComponentAccessor(const TransformManagerPropertyComponentAccessor& property) = delete;
302   TransformManagerPropertyComponentAccessor& operator=(const TransformManagerPropertyComponentAccessor& rhs) = delete;
303
304 private:
305
306   SceneGraph::TransformManagerPropertyHandler<T>* mProperty; ///< The real property
307
308 };
309
310 } // namespace Internal
311
312 } // namespace Dali
313
314 #endif // DALI_INTERNAL_SCENE_GRAPH_PROPERTY_ACCESSOR_H