Follow the include-order coding conventions
[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) 2014 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  * These dummy values are used to handle PropertyInputImpl errors
42  */
43 static const bool DUMMY_BOOLEAN_VALUE( false );
44 static const float DUMMY_FLOAT_VALUE( 0.0f );
45 static const int DUMMY_INTEGER_VALUE( 0 );
46 static const Vector2 DUMMY_VECTOR2_VALUE( 0.0f, 0.0f );
47 static const Vector3 DUMMY_VECTOR3_VALUE( 0.0f, 0.0f, 0.0f );
48 static const Vector4 DUMMY_VECTOR4_VALUE( 0.0f, 0.0f, 0.0f, 0.0f );
49 static const Matrix3 DUMMY_MATRIX3_VALUE;
50 static const Matrix DUMMY_MATRIX_VALUE;
51 static const Quaternion DUMMY_QUATERNION_VALUE( 1.0f, 0.0f, 0.0f, 0.0f );
52
53 /**
54  * An abstract interface for receiving property values, and for querying whether
55  * a property value has changed i.e. whether a constraint needs to be reapplied.
56  */
57 class PropertyInputImpl
58 {
59 public:
60
61   /**
62    * Virtual destructor.
63    */
64   virtual ~PropertyInputImpl()
65   {
66   }
67
68   /**
69    * Query the type of property input.
70    * @return The property type.
71    */
72   virtual Property::Type GetType() const = 0;
73
74   /**
75    * Query the input value (for a constraint) has been initialized.
76    * @return True if initialized, otherwise the constraint should be skipped.
77    */
78   virtual bool InputInitialized() const = 0;
79
80   /**
81    * Query the input value (for a constraint) has changed.
82    * @return True if the input value has changed.
83    */
84   virtual bool InputChanged() const = 0;
85
86   /**
87    * Retrieve a boolean value.
88    * @pre GetType() returns Property::BOOLEAN.
89    * @param[in] bufferIndex The buffer to read from.
90    * @return The boolean value.
91    */
92   virtual const bool& GetBoolean( BufferIndex bufferIndex ) const
93   {
94     DALI_ASSERT_ALWAYS( false && "Property type mismatch" );
95     return DUMMY_BOOLEAN_VALUE;
96   }
97
98   /**
99    * Retrieve a float value.
100    * @pre GetType() returns Property::FLOAT.
101    * @param[in] bufferIndex The buffer to read from.
102    * @return The float value.
103    */
104   virtual const float& GetFloat( BufferIndex bufferIndex ) const
105   {
106     DALI_ASSERT_ALWAYS( false && "Property type mismatch" );
107     return DUMMY_FLOAT_VALUE;
108   }
109
110   /**
111    * Retrieve an integer value.
112    * @pre GetType() returns Property::INTEGER.
113    * @param[in] bufferIndex The buffer to read from.
114    * @return The integer value.
115    */
116   virtual const int& GetInteger( BufferIndex bufferIndex ) const
117   {
118     DALI_ASSERT_ALWAYS( false && "Property type mismatch" );
119     return DUMMY_INTEGER_VALUE;
120   }
121
122   /**
123    * Retrieve a Vector2 value.
124    * @pre GetType() returns Property::VECTOR2.
125    * @param[in] bufferIndex The buffer to read from.
126    * @return The Vector2 value.
127    */
128   virtual const Vector2& GetVector2( BufferIndex bufferIndex ) const
129   {
130     DALI_ASSERT_ALWAYS( false && "Property type mismatch" );
131     return DUMMY_VECTOR2_VALUE;
132   }
133
134   /**
135    * Retrieve a Vector3 value.
136    * @pre GetType() returns Property::VECTOR3.
137    * @param[in] bufferIndex The buffer to read from.
138    * @return The Vector3 value.
139    */
140   virtual const Vector3& GetVector3( BufferIndex bufferIndex ) const
141   {
142     DALI_ASSERT_ALWAYS( false && "Property type mismatch" );
143     return DUMMY_VECTOR3_VALUE;
144   }
145
146   /**
147    * Retrieve a Vector4 value.
148    * @pre GetType() returns Property::VECTOR4.
149    * @param[in] bufferIndex The buffer to read from.
150    * @return The Vector4 value.
151    */
152   virtual const Vector4& GetVector4( BufferIndex bufferIndex ) const
153   {
154     DALI_ASSERT_ALWAYS( false && "Property type mismatch" );
155     return DUMMY_VECTOR4_VALUE;
156   }
157
158   /**
159    * Retrieve a Quaternion value.
160    * @pre GetType() returns Property::Quaternion.
161    * @param[in] bufferIndex The buffer to read from.
162    * @return The Quaternion value.
163    */
164   virtual const Quaternion& GetQuaternion( BufferIndex bufferIndex ) const
165   {
166     DALI_ASSERT_ALWAYS( false && "Property type mismatch" );
167     return DUMMY_QUATERNION_VALUE;
168   }
169
170   /**
171    * Retrieve a Matrix value.
172    * @pre GetType() returns Property::Matrix.
173    * @param[in] bufferIndex The buffer to read from.
174    * @return The Matrix value.
175    */
176   virtual const Matrix3& GetMatrix3( BufferIndex bufferIndex ) const
177   {
178     DALI_ASSERT_ALWAYS( false && "Property type mismatch" );
179     return DUMMY_MATRIX3_VALUE;
180   }
181
182   /**
183    * Retrieve a Matrix value.
184    * @pre GetType() returns Property::Matrix.
185    * @param[in] bufferIndex The buffer to read from.
186    * @return The Matrix value.
187    */
188   virtual const Matrix& GetMatrix( BufferIndex bufferIndex ) const
189   {
190     DALI_ASSERT_ALWAYS( false && "Property type mismatch" );
191     return DUMMY_MATRIX_VALUE;
192   }
193
194   // Accessors for Constraint functions
195
196   /**
197    * Retrieve a boolean 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::BOOLEAN.
201    * @param[in] updateBufferIndex The current update buffer index.
202    * @return The boolean value.
203    */
204   virtual const bool& GetConstraintInputBoolean( BufferIndex updateBufferIndex ) const
205   {
206     return GetBoolean( 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 an integer 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::INTEGER.
227    * @param[in] updateBufferIndex The current update buffer index.
228    * @return The integer value.
229    */
230   virtual const int& GetConstraintInputInteger( BufferIndex updateBufferIndex ) const
231   {
232     return GetInteger( updateBufferIndex );
233   }
234
235   /**
236    * Retrieve a Vector2 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::VECTOR2.
240    * @param[in] updateBufferIndex The buffer to read from.
241    * @return The Vector2 value.
242    */
243   virtual const Vector2& GetConstraintInputVector2( BufferIndex updateBufferIndex ) const
244   {
245     return GetVector2( updateBufferIndex );
246   }
247
248   /**
249    * Retrieve a Vector3 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::VECTOR3.
253    * @param[in] updateBufferIndex The buffer to read from.
254    * @return The Vector3 value.
255    */
256   virtual const Vector3& GetConstraintInputVector3( BufferIndex updateBufferIndex ) const
257   {
258     return GetVector3( updateBufferIndex );
259   }
260
261   /**
262    * Retrieve a Vector4 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::VECTOR4.
266    * @param[in] updateBufferIndex The buffer to read from.
267    * @return The Vector4 value.
268    */
269   virtual const Vector4& GetConstraintInputVector4( BufferIndex updateBufferIndex ) const
270   {
271     return GetVector4( updateBufferIndex );
272   }
273
274   /**
275    * Retrieve a Quaternion 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::Quaternion.
279    * @param[in] updateBufferIndex The buffer to read from.
280    * @return The Quaternion value.
281    */
282   virtual const Quaternion& GetConstraintInputQuaternion( BufferIndex updateBufferIndex ) const
283   {
284     return GetQuaternion( updateBufferIndex );
285   }
286
287   /**
288    * Retrieve a Matrix3 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 Matrix3& GetConstraintInputMatrix3( BufferIndex updateBufferIndex ) const
296   {
297     return GetMatrix3( updateBufferIndex );
298   }
299
300   /**
301    * Retrieve a Matrix input for a constraint function.
302    * @note For inherited properties, this method should be overriden to return the value
303    * from the previous frame i.e. not from the current update buffer.
304    * @pre GetType() returns Property::Matrix.
305    * @param[in] updateBufferIndex The buffer to read from.
306    * @return The Matrix value.
307    */
308   virtual const Matrix& GetConstraintInputMatrix( BufferIndex updateBufferIndex ) const
309   {
310     return GetMatrix( updateBufferIndex );
311   }
312
313   /**
314    * Print the property value using a stream.
315    * @param[in] debugStream The output stream.
316    * @param[in] bufferIndex The buffer to read from.
317    * @todo Place this far-too-large-to-be-inlined function in a cpp and remove <iostream> header dependency from this file.
318    */
319   void DebugPrint( std::ostream& debugStream, BufferIndex bufferIndex ) const
320   {
321     switch ( GetType() )
322     {
323       case Property::BOOLEAN:
324       {
325         debugStream << GetBoolean( bufferIndex );
326         break;
327       }
328
329       case Property::FLOAT:
330       {
331         debugStream << GetFloat( bufferIndex );
332         break;
333       }
334
335       case Property::INTEGER:
336       {
337         debugStream << GetInteger( bufferIndex );
338         break;
339       }
340
341       case Property::VECTOR2:
342       {
343         debugStream << GetVector2( bufferIndex );
344         break;
345       }
346
347       case Property::VECTOR3:
348       {
349         debugStream << GetVector3( bufferIndex );
350         break;
351       }
352
353       case Property::VECTOR4:
354       {
355         debugStream << GetVector4( bufferIndex );
356         break;
357       }
358
359       case Property::ROTATION:
360       {
361         debugStream << GetQuaternion( bufferIndex );
362         break;
363       }
364
365       case Property::MATRIX:
366       {
367         debugStream << GetMatrix( bufferIndex );
368         break;
369       }
370
371       case Property::MATRIX3:
372       {
373         debugStream << GetMatrix3( bufferIndex );
374         break;
375       }
376
377       default:
378         break; // print nothing
379     }
380   }
381 };
382
383 } // namespace Internal
384
385 } // namespace Dali
386
387 #endif // __DALI_INTERNAL_PROPERTY_INPUT_IMPL_H__