Merge "use modern construct '= default' for special functions." into devel/master
[platform/core/uifw/dali-core.git] / dali / internal / update / animation / property-component-accessor.h
1 #ifndef DALI_INTERNAL_SCENE_GRAPH_PROPERTY_COMPONENT_ACCESSOR_H
2 #define DALI_INTERNAL_SCENE_GRAPH_PROPERTY_COMPONENT_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
25 namespace Dali
26 {
27
28 namespace Internal
29 {
30
31 /**
32  * A wrapper class for getting/setting a float component of another property.
33  * Animators use this instead of accessing properties directly.
34  */
35 template < typename PropertyType >
36 class PropertyComponentAccessorX
37 {
38 public:
39
40   /**
41    * Create a property component.
42    * @param [in] property The property which holds a float component.
43    */
44   PropertyComponentAccessorX( SceneGraph::PropertyBase* property )
45   : mProperty( static_cast< SceneGraph::AnimatableProperty<PropertyType>* >(property) ) // we know the type
46   {
47   }
48
49   /**
50    * Non-virtual destructor; PropertyComponentAccessorX is not suitable as a base class.
51    */
52   ~PropertyComponentAccessorX() = default;
53
54   /**
55    * Query whether the accessor is set.
56    * @return True if set.
57    */
58   bool IsSet() const
59   {
60     return mProperty != nullptr;
61   }
62
63   /**
64    * Reset the property accessor
65    * @post Calling any other PropertyComponentAccessorX is invalid.
66    */
67   void Reset()
68   {
69     mProperty = nullptr;
70   }
71
72   /**
73    * @copydoc Dali::Internal::SceneGraph::PropertyBase::IsClean()
74    */
75   bool IsClean() const
76   {
77     return mProperty->IsClean();
78   }
79
80   /**
81    * Read access to the property.
82    * @param [in] bufferIndex The current update buffer index.
83    */
84   float Get( BufferIndex bufferIndex ) const
85   {
86     DALI_ASSERT_DEBUG( nullptr != mProperty && "PropertyComponentAccessorX::Get() mProperty was nullptr" );
87     return mProperty->Get( bufferIndex ).x; // X Component only!
88   }
89
90   /**
91    * @copydoc SceneGraph::AnimatableProperty<float>::Set()
92    */
93   void Set( BufferIndex bufferIndex, float value ) const
94   {
95     DALI_ASSERT_DEBUG( nullptr != mProperty && "PropertyComponentAccessorX::Set() mProperty was nullptr" );
96     mProperty->SetX( bufferIndex, value );
97   }
98
99   /**
100    * @copydoc SceneGraph::AnimatableProperty<float>::Bake()
101    */
102   void Bake( BufferIndex bufferIndex, float value ) const
103   {
104     DALI_ASSERT_DEBUG( nullptr != mProperty && "PropertyComponentAccessorX::Bake() mProperty was nullptr" );
105     mProperty->BakeX( bufferIndex, value );
106   }
107
108 private:
109
110   // Undefined
111   PropertyComponentAccessorX() = delete;
112   PropertyComponentAccessorX(const PropertyComponentAccessorX& property) = delete;
113   PropertyComponentAccessorX& operator=(const PropertyComponentAccessorX& rhs) = delete;
114
115 private:
116
117   SceneGraph::AnimatableProperty<PropertyType>* mProperty; ///< The real property
118
119 };
120
121 /**
122  * A wrapper class for getting/setting a float component of another property.
123  * Animators use this instead of accessing properties directly.
124  */
125 template < typename PropertyType >
126 class PropertyComponentAccessorY
127 {
128 public:
129
130   /**
131    * Create a property component.
132    * @param [in] property The property which holds a float component.
133    */
134   PropertyComponentAccessorY( SceneGraph::PropertyBase* property )
135   : mProperty( static_cast< SceneGraph::AnimatableProperty<PropertyType>* >(property) ) // we know the type
136   {
137   }
138
139   /**
140    * Non-virtual destructor; PropertyComponentAccessorY is not suitable as a base class.
141    */
142   ~PropertyComponentAccessorY() = default;
143
144   /**
145    * Query whether the accessor is set.
146    * @return True if set.
147    */
148   bool IsSet() const
149   {
150     return mProperty != nullptr;
151   }
152
153   /**
154    * Reset the property accessor
155    * @post Calling any other PropertyComponentAccessorY is invalid.
156    */
157   void Reset()
158   {
159     mProperty = nullptr;
160   }
161
162   /**
163    * @copydoc Dali::Internal::SceneGraph::PropertyBase::IsClean()
164    */
165   bool IsClean() const
166   {
167     return mProperty->IsClean();
168   }
169
170   /**
171    * Read access to the property.
172    * @param [in] bufferIndex The current update buffer index.
173    */
174   float Get( BufferIndex bufferIndex ) const
175   {
176     DALI_ASSERT_DEBUG( nullptr != mProperty && "PropertyComponentAccessorY::Get() mProperty was nullptr" );
177     return mProperty->Get( bufferIndex ).y; // Y Component only!
178   }
179
180   /**
181    * @copydoc SceneGraph::AnimatableProperty<float>::Set()
182    */
183   void Set( BufferIndex bufferIndex, float value ) const
184   {
185     DALI_ASSERT_DEBUG( nullptr != mProperty && "PropertyComponentAccessorY::Set() mProperty was nullptr" );
186     mProperty->SetY( bufferIndex, value );
187   }
188
189   /**
190    * @copydoc SceneGraph::AnimatableProperty<float>::Bake()
191    */
192   void Bake( BufferIndex bufferIndex, float value ) const
193   {
194     DALI_ASSERT_DEBUG( nullptr != mProperty && "PropertyComponentAccessorY::Bake() mProperty was nullptr" );
195     mProperty->BakeY( bufferIndex, value );
196   }
197
198 private:
199
200   // Undefined
201   PropertyComponentAccessorY() = delete;
202   PropertyComponentAccessorY(const PropertyComponentAccessorY& property) = delete;
203   PropertyComponentAccessorY& operator=(const PropertyComponentAccessorY& rhs) = delete;
204
205 private:
206
207   SceneGraph::AnimatableProperty<PropertyType>* mProperty; ///< The real property
208 };
209
210 /**
211  * A wrapper class for getting/setting a float component of another property.
212  * Animators use this instead of accessing properties directly.
213  */
214 template < typename PropertyType >
215 class PropertyComponentAccessorZ
216 {
217 public:
218
219   /**
220    * Create a property component.
221    * @param [in] property The property which holds a float component.
222    */
223   PropertyComponentAccessorZ( SceneGraph::PropertyBase* property )
224   : mProperty( static_cast< SceneGraph::AnimatableProperty<PropertyType>* >(property) ) // we know the type
225   {
226   }
227
228   /**
229    * Non-virtual destructor; PropertyComponentAccessorZ is not suitable as a base class.
230    */
231   ~PropertyComponentAccessorZ() = default;
232
233   /**
234    * Query whether the accessor is set.
235    * @return True if set.
236    */
237   bool IsSet() const
238   {
239     return mProperty != nullptr;
240   }
241
242   /**
243    * Reset the property accessor
244    * @post Calling any other PropertyComponentAccessorZ is invalid.
245    */
246   void Reset()
247   {
248     mProperty = nullptr;
249   }
250
251   /**
252    * @copydoc Dali::Internal::SceneGraph::PropertyBase::IsClean()
253    */
254   bool IsClean() const
255   {
256     return mProperty->IsClean();
257   }
258
259   /**
260    * Read access to the property.
261    * @param [in] bufferIndex The current update buffer index.
262    */
263   float Get( BufferIndex bufferIndex ) const
264   {
265     DALI_ASSERT_DEBUG( nullptr != mProperty && "PropertyComponentAccessorZ::Get() mProperty was nullptr" );
266     return mProperty->Get( bufferIndex ).z; // Z Component only!
267   }
268
269   /**
270    * @copydoc SceneGraph::AnimatableProperty<float>::Set()
271    */
272   void Set( BufferIndex bufferIndex, float value ) const
273   {
274     DALI_ASSERT_DEBUG( nullptr != mProperty && "PropertyComponentAccessorZ::Set() mProperty was nullptr" );
275     mProperty->SetZ( bufferIndex, value );
276   }
277
278   /**
279    * @copydoc SceneGraph::AnimatableProperty<float>::Bake()
280    */
281   void Bake( BufferIndex bufferIndex, float value ) const
282   {
283     DALI_ASSERT_DEBUG( nullptr != mProperty && "PropertyComponentAccessorZ::Bake() mProperty was nullptr" );
284     mProperty->BakeZ( bufferIndex, value );
285   }
286
287 private:
288
289   // Undefined
290   PropertyComponentAccessorZ() = delete;
291   PropertyComponentAccessorZ(const PropertyComponentAccessorZ& property) = delete;
292   PropertyComponentAccessorZ& operator=(const PropertyComponentAccessorZ& rhs) = delete;
293
294 private:
295
296   SceneGraph::AnimatableProperty<PropertyType>* mProperty; ///< The real property
297 };
298
299 /**
300  * A wrapper class for getting/setting a float component of another property.
301  * Animators use this instead of accessing properties directly.
302  */
303 template < typename PropertyType >
304 class PropertyComponentAccessorW
305 {
306 public:
307
308   /**
309    * Create a property component.
310    * @param [in] property The property which holds a float component.
311    */
312   PropertyComponentAccessorW( SceneGraph::PropertyBase* property )
313   : mProperty( static_cast< SceneGraph::AnimatableProperty<PropertyType>* >(property) ) // we know the type
314   {
315   }
316
317   /**
318    * Non-virtual destructor; PropertyComponentAccessorW is not suitable as a base class.
319    */
320   ~PropertyComponentAccessorW() = default;
321
322   /**
323    * Query whether the accessor is set.
324    * @return True if set.
325    */
326   bool IsSet() const
327   {
328     return mProperty != nullptr;
329   }
330
331   /**
332    * Reset the property accessor
333    * @post Calling any other PropertyComponentAccessorW is invalid.
334    */
335   void Reset()
336   {
337     mProperty = nullptr;
338   }
339
340   /**
341    * @copydoc Dali::Internal::SceneGraph::PropertyBase::IsClean()
342    */
343   bool IsClean() const
344   {
345     return mProperty->IsClean();
346   }
347
348   /**
349    * Read access to the property.
350    * @param [in] bufferIndex The current update buffer index.
351    */
352   float Get( BufferIndex bufferIndex ) const
353   {
354     DALI_ASSERT_DEBUG( nullptr != mProperty && "PropertyComponentAccessorW::Get() mProperty was nullptr" );
355     return mProperty->Get( bufferIndex ).w; // W Component only!
356   }
357
358   /**
359    * @copydoc SceneGraph::AnimatableProperty<float>::Set()
360    */
361   void Set( BufferIndex bufferIndex, float value ) const
362   {
363     DALI_ASSERT_DEBUG( nullptr != mProperty && "PropertyComponentAccessorW::Set() mProperty was nullptr" );
364     mProperty->SetW( bufferIndex, value );
365   }
366
367   /**
368    * @copydoc SceneGraph::AnimatableProperty<float>::Bake()
369    */
370   void Bake( BufferIndex bufferIndex, float value ) const
371   {
372     DALI_ASSERT_DEBUG( nullptr != mProperty && "PropertyComponentAccessorW::Bake() mProperty was nullptr" );
373     mProperty->BakeW( bufferIndex, value );
374   }
375
376 private:
377
378   // Undefined
379   PropertyComponentAccessorW() = delete;
380   PropertyComponentAccessorW(const PropertyComponentAccessorW& property) = delete;
381   PropertyComponentAccessorW& operator=(const PropertyComponentAccessorW& rhs) = delete;
382
383 private:
384
385   SceneGraph::AnimatableProperty<PropertyType>* mProperty; ///< The real property
386
387 };
388
389 } // namespace Internal
390
391 } // namespace Dali
392
393 #endif // DALI_INTERNAL_SCENE_GRAPH_PROPERTY_COMPONENT_ACCESSOR_H