Purge underscored header file barriers
[platform/core/uifw/dali-core.git] / dali / internal / event / common / property-input-impl.h
1 #ifndef DALI_INTERNAL_PROPERTY_INPUT_IMPL_H
2 #define DALI_INTERNAL_PROPERTY_INPUT_IMPL_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 // EXTERNAL INCLUDES
22 #include <iostream>
23
24 // INTERNAL INCLUDES
25 #include <dali/public-api/object/property-input.h>
26 #include <dali/public-api/math/vector2.h>
27 #include <dali/public-api/math/vector3.h>
28 #include <dali/public-api/math/vector4.h>
29 #include <dali/public-api/math/quaternion.h>
30 #include <dali/public-api/math/matrix3.h>
31 #include <dali/public-api/math/matrix.h>
32 #include <dali/internal/common/buffer-index.h>
33
34 namespace Dali
35 {
36
37 namespace Internal
38 {
39
40 /**
41  * An abstract interface for receiving property values, and for querying whether
42  * a property value has changed i.e. whether a constraint needs to be reapplied.
43  */
44 class PropertyInputImpl
45 {
46 public:
47
48   /**
49    * Virtual destructor.
50    */
51   virtual ~PropertyInputImpl()
52   {
53   }
54
55   /**
56    * Query the type of property input.
57    * @return The property type.
58    */
59   virtual Property::Type GetType() const = 0;
60
61   /**
62    * Query the input value (for a constraint) has been initialized.
63    * @return True if initialized, otherwise the constraint should be skipped.
64    */
65   virtual bool InputInitialized() const = 0;
66
67   /**
68    * Query the input value (for a constraint) has changed.
69    * @return True if the input value has changed.
70    */
71   virtual bool InputChanged() const = 0;
72
73   /**
74    * Retrieve a boolean value.
75    * @pre GetType() returns Property::BOOLEAN.
76    * @param[in] bufferIndex The buffer to read from.
77    * @return The boolean value.
78    */
79   virtual const bool& GetBoolean( BufferIndex bufferIndex ) const
80   {
81     // the return will never be executed, it's just to keep the compiler happy
82     return reinterpret_cast<const bool&>(*this);
83   }
84
85   /**
86    * Retrieve an integer value.
87    * @pre GetType() returns Property::INTEGER.
88    * @param[in] bufferIndex The buffer to read from.
89    * @return The integer value.
90    */
91   virtual const int& GetInteger( BufferIndex bufferIndex ) const
92   {
93     // the return will never be executed, it's just to keep the compiler happy
94     return reinterpret_cast<const int&>(*this);
95   }
96
97   /**
98    * Retrieve a float value.
99    * @pre GetType() returns Property::FLOAT.
100    * @param[in] bufferIndex The buffer to read from.
101    * @return The float value.
102    */
103   virtual const float& GetFloat( BufferIndex bufferIndex ) const
104   {
105     // the return will never be executed, it's just to keep the compiler happy
106     return reinterpret_cast<const float&>(*this);
107   }
108
109   /**
110    * Retrieve a Vector2 value.
111    * @pre GetType() returns Property::VECTOR2.
112    * @param[in] bufferIndex The buffer to read from.
113    * @return The Vector2 value.
114    */
115   virtual const Vector2& GetVector2( BufferIndex bufferIndex ) const
116   {
117     // the return will never be executed, it's just to keep the compiler happy
118     return reinterpret_cast<const Vector2&>(*this);
119   }
120
121   /**
122    * Retrieve a Vector3 value.
123    * @pre GetType() returns Property::VECTOR3.
124    * @param[in] bufferIndex The buffer to read from.
125    * @return The Vector3 value.
126    */
127   virtual const Vector3& GetVector3( BufferIndex bufferIndex ) const
128   {
129     // the return will never be executed, it's just to keep the compiler happy
130     return reinterpret_cast<const Vector3&>(*this);
131   }
132
133   /**
134    * Retrieve a Vector4 value.
135    * @pre GetType() returns Property::VECTOR4.
136    * @param[in] bufferIndex The buffer to read from.
137    * @return The Vector4 value.
138    */
139   virtual const Vector4& GetVector4( BufferIndex bufferIndex ) const
140   {
141     // the return will never be executed, it's just to keep the compiler happy
142     return reinterpret_cast<const Vector4&>(*this);
143   }
144
145   /**
146    * Retrieve a Quaternion value.
147    * @pre GetType() returns Property::Quaternion.
148    * @param[in] bufferIndex The buffer to read from.
149    * @return The Quaternion value.
150    */
151   virtual const Quaternion& GetQuaternion( BufferIndex bufferIndex ) const
152   {
153     // the return will never be executed, it's just to keep the compiler happy
154     return reinterpret_cast<const Quaternion&>(*this);
155   }
156
157   /**
158    * Retrieve a Matrix value.
159    * @pre GetType() returns Property::Matrix.
160    * @param[in] bufferIndex The buffer to read from.
161    * @return The Matrix value.
162    */
163   virtual const Matrix3& GetMatrix3( BufferIndex bufferIndex ) const
164   {
165     // the return will never be executed, it's just to keep the compiler happy
166     return reinterpret_cast<const Matrix3&>(*this);
167   }
168
169   /**
170    * Retrieve a Matrix value.
171    * @pre GetType() returns Property::Matrix.
172    * @param[in] bufferIndex The buffer to read from.
173    * @return The Matrix value.
174    */
175   virtual const Matrix& GetMatrix( BufferIndex bufferIndex ) const
176   {
177     // the return will never be executed, it's just to keep the compiler happy
178     return reinterpret_cast<const Matrix&>(*this);
179   }
180
181   // Accessors for Constraint functions
182
183   /**
184    * Retrieve a boolean input for a constraint function.
185    * @note For inherited properties, this method should be overriden to return the value
186    * from the previous frame i.e. not from the current update buffer.
187    * @pre GetType() returns Property::BOOLEAN.
188    * @param[in] updateBufferIndex The current update buffer index.
189    * @return The boolean value.
190    */
191   virtual const bool& GetConstraintInputBoolean( BufferIndex updateBufferIndex ) const
192   {
193     return GetBoolean( updateBufferIndex );
194   }
195
196   /**
197    * Retrieve an integer input for a constraint function.
198    * @note For inherited properties, this method should be overriden to return the value
199    * from the previous frame i.e. not from the current update buffer.
200    * @pre GetType() returns Property::INTEGER.
201    * @param[in] updateBufferIndex The current update buffer index.
202    * @return The integer value.
203    */
204   virtual const int& GetConstraintInputInteger( BufferIndex updateBufferIndex ) const
205   {
206     return GetInteger( updateBufferIndex );
207   }
208
209   /**
210    * Retrieve a float input for a constraint function.
211    * @note For inherited properties, this method should be overriden to return the value
212    * from the previous frame i.e. not from the current update buffer.
213    * @pre GetType() returns Property::FLOAT.
214    * @param[in] updateBufferIndex The current update buffer index.
215    * @return The float value.
216    */
217   virtual const float& GetConstraintInputFloat( BufferIndex updateBufferIndex ) const
218   {
219     return GetFloat( updateBufferIndex );
220   }
221
222   /**
223    * Retrieve a Vector2 input for a constraint function.
224    * @note For inherited properties, this method should be overriden to return the value
225    * from the previous frame i.e. not from the current update buffer.
226    * @pre GetType() returns Property::VECTOR2.
227    * @param[in] updateBufferIndex The buffer to read from.
228    * @return The Vector2 value.
229    */
230   virtual const Vector2& GetConstraintInputVector2( BufferIndex updateBufferIndex ) const
231   {
232     return GetVector2( updateBufferIndex );
233   }
234
235   /**
236    * Retrieve a Vector3 input for a constraint function.
237    * @note For inherited properties, this method should be overriden to return the value
238    * from the previous frame i.e. not from the current update buffer.
239    * @pre GetType() returns Property::VECTOR3.
240    * @param[in] updateBufferIndex The buffer to read from.
241    * @return The Vector3 value.
242    */
243   virtual const Vector3& GetConstraintInputVector3( BufferIndex updateBufferIndex ) const
244   {
245     return GetVector3( updateBufferIndex );
246   }
247
248   /**
249    * Retrieve a Vector4 input for a constraint function.
250    * @note For inherited properties, this method should be overriden to return the value
251    * from the previous frame i.e. not from the current update buffer.
252    * @pre GetType() returns Property::VECTOR4.
253    * @param[in] updateBufferIndex The buffer to read from.
254    * @return The Vector4 value.
255    */
256   virtual const Vector4& GetConstraintInputVector4( BufferIndex updateBufferIndex ) const
257   {
258     return GetVector4( updateBufferIndex );
259   }
260
261   /**
262    * Retrieve a Quaternion input for a constraint function.
263    * @note For inherited properties, this method should be overriden to return the value
264    * from the previous frame i.e. not from the current update buffer.
265    * @pre GetType() returns Property::Quaternion.
266    * @param[in] updateBufferIndex The buffer to read from.
267    * @return The Quaternion value.
268    */
269   virtual const Quaternion& GetConstraintInputQuaternion( BufferIndex updateBufferIndex ) const
270   {
271     return GetQuaternion( updateBufferIndex );
272   }
273
274   /**
275    * Retrieve a Matrix3 input for a constraint function.
276    * @note For inherited properties, this method should be overriden to return the value
277    * from the previous frame i.e. not from the current update buffer.
278    * @pre GetType() returns Property::Matrix.
279    * @param[in] updateBufferIndex The buffer to read from.
280    * @return The Matrix value.
281    */
282   virtual const Matrix3& GetConstraintInputMatrix3( BufferIndex updateBufferIndex ) const
283   {
284     return GetMatrix3( updateBufferIndex );
285   }
286
287   /**
288    * Retrieve a Matrix input for a constraint function.
289    * @note For inherited properties, this method should be overriden to return the value
290    * from the previous frame i.e. not from the current update buffer.
291    * @pre GetType() returns Property::Matrix.
292    * @param[in] updateBufferIndex The buffer to read from.
293    * @return The Matrix value.
294    */
295   virtual const Matrix& GetConstraintInputMatrix( BufferIndex updateBufferIndex ) const
296   {
297     return GetMatrix( updateBufferIndex );
298   }
299
300   /**
301    * Query whether the property belongs to the
302    * transform manager or not.
303    * @return True if it is a transform manager property, false otherwise
304    */
305   virtual bool IsTransformManagerProperty() const
306   {
307     return false;
308   }
309
310   /**
311    * Print the property value using a stream.
312    * @param[in] debugStream The output stream.
313    * @param[in] bufferIndex The buffer to read from.
314    * @todo Place this far-too-large-to-be-inlined function in a cpp and remove <iostream> header dependency from this file.
315    */
316   void DebugPrint( std::ostream& debugStream, BufferIndex bufferIndex ) const
317   {
318     switch ( GetType() )
319     {
320       case Property::BOOLEAN:
321       {
322         debugStream << GetBoolean( bufferIndex );
323         break;
324       }
325
326       case Property::INTEGER:
327       {
328         debugStream << GetInteger( bufferIndex );
329         break;
330       }
331
332       case Property::FLOAT:
333       {
334         debugStream << GetFloat( bufferIndex );
335         break;
336       }
337
338       case Property::VECTOR2:
339       {
340         debugStream << GetVector2( bufferIndex );
341         break;
342       }
343
344       case Property::VECTOR3:
345       {
346         debugStream << GetVector3( bufferIndex );
347         break;
348       }
349
350       case Property::VECTOR4:
351       {
352         debugStream << GetVector4( bufferIndex );
353         break;
354       }
355
356       case Property::ROTATION:
357       {
358         debugStream << GetQuaternion( bufferIndex );
359         break;
360       }
361
362       case Property::MATRIX:
363       {
364         debugStream << GetMatrix( bufferIndex );
365         break;
366       }
367
368       case Property::MATRIX3:
369       {
370         debugStream << GetMatrix3( bufferIndex );
371         break;
372       }
373
374       default:
375         break; // print nothing
376     }
377   }
378 };
379
380 } // namespace Internal
381
382 } // namespace Dali
383
384 #endif // DALI_INTERNAL_PROPERTY_INPUT_IMPL_H