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