Klocwork fixes.
[platform/core/uifw/dali-core.git] / dali / internal / event / animation / property-input-accessor.h
1 #ifndef __DALI_PROPERTY_INPUT_ACCESSOR_H__
2 #define __DALI_PROPERTY_INPUT_ACCESSOR_H__
3
4 //
5 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
6 //
7 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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 // INTERNAL INCLUDES
21 #include <dali/public-api/object/property-types.h>
22 #include <dali/internal/event/common/property-input-impl.h>
23
24 namespace Dali
25 {
26
27 namespace Internal
28 {
29
30 class PropertyInputAccessor
31 {
32 public:
33
34   /**
35    * Create the PropertyInputAccessor.
36    */
37   PropertyInputAccessor()
38   : mInput( NULL )
39   {
40   }
41
42   /**
43    * Create the PropertyInputAccessor.
44    */
45   PropertyInputAccessor( const PropertyInputImpl* input, int /*componentIndex*/ )
46   : mInput( input )
47   {
48   }
49
50   /**
51    * Copy from a PropertyInputAccessor
52    */
53   PropertyInputAccessor( const PropertyInputAccessor& accessor )
54   : mInput( accessor.mInput )
55   {
56   }
57
58   /**
59    * Copy from a PropertyInputAccessor
60    */
61   PropertyInputAccessor& operator=(const PropertyInputAccessor& accessor)
62   {
63     mInput = accessor.mInput;
64
65     return *this;
66   }
67
68   /**
69    * Set the property input.
70    */
71   void SetInput( const PropertyInputImpl& input, int componentIndex )
72   {
73     DALI_ASSERT_DEBUG( componentIndex < 0 && "Did not expect a valid component index" );
74     mInput = &input;
75   }
76
77   /**
78    * Retrieve the property input.
79    */
80   const PropertyInputImpl* GetInput() const
81   {
82     return mInput;
83   }
84
85   /**
86    * @copydoc Dali::Internal::PropertyInputImpl::GetType()
87    */
88   Property::Type GetType() const
89   {
90     return mInput->GetType();
91   }
92
93   /**
94    * @copydoc Dali::Internal::PropertyInputImpl::GetConstraintInputBoolean()
95    */
96   const bool& GetConstraintInputBoolean( BufferIndex updateBufferIndex ) const
97   {
98     return mInput->GetConstraintInputBoolean( updateBufferIndex );
99   }
100
101   /**
102    * @copydoc Dali::Internal::PropertyInputImpl::GetConstraintInputFloat()
103    */
104   const float& GetConstraintInputFloat( BufferIndex updateBufferIndex ) const
105   {
106     return mInput->GetConstraintInputFloat( updateBufferIndex );
107   }
108
109   /**
110    * @copydoc Dali::Internal::PropertyInputImpl::GetConstraintInputVector2()
111    */
112   const Vector2& GetConstraintInputVector2( BufferIndex updateBufferIndex ) const
113   {
114     return mInput->GetConstraintInputVector2( updateBufferIndex );
115   }
116
117   /**
118    * @copydoc Dali::Internal::PropertyInputImpl::GetConstraintInputVector3()
119    */
120   const Vector3& GetConstraintInputVector3( BufferIndex updateBufferIndex ) const
121   {
122     return mInput->GetConstraintInputVector3( updateBufferIndex );
123   }
124
125   /**
126    * @copydoc Dali::Internal::PropertyInputImpl::GetConstraintInputVector4()
127    */
128   const Vector4& GetConstraintInputVector4( BufferIndex updateBufferIndex ) const
129   {
130     return mInput->GetConstraintInputVector4( updateBufferIndex );
131   }
132
133   /**
134    * @copydoc Dali::Internal::PropertyInputImpl::GetConstraintInputQuaternion()
135    */
136   const Quaternion& GetConstraintInputQuaternion( BufferIndex updateBufferIndex ) const
137   {
138     return mInput->GetConstraintInputQuaternion( updateBufferIndex );
139   }
140
141   /**
142    * @copydoc Dali::Internal::PropertyInputImpl::GetConstraintInputMatrix3()
143    */
144   const Matrix3& GetConstraintInputMatrix3( BufferIndex updateBufferIndex ) const
145   {
146     return mInput->GetConstraintInputMatrix3( updateBufferIndex );
147   }
148
149   /**
150    * @copydoc Dali::Internal::PropertyInputImpl::GetConstraintInputMatrix()
151    */
152   const Matrix& GetConstraintInputMatrix( BufferIndex updateBufferIndex ) const
153   {
154     return mInput->GetConstraintInputMatrix( updateBufferIndex );
155   }
156
157 public:
158
159   const PropertyInputImpl* mInput;
160 };
161
162 class PropertyInputComponentAccessor
163 {
164 public:
165
166   /**
167    * Create the PropertyInputComponentAccessor.
168    */
169   PropertyInputComponentAccessor()
170   : mInput( NULL ),
171     mComponentIndex( 0 )
172   {
173   }
174
175   /**
176    * Create the PropertyInputComponentAccessor.
177    */
178   PropertyInputComponentAccessor( const PropertyInputImpl* input, int componentIndex )
179   : mInput( input ),
180     mComponentIndex( componentIndex )
181   {
182   }
183
184   /**
185    * Copy from a PropertyInputAccessor
186    */
187   PropertyInputComponentAccessor( const PropertyInputAccessor& accessor )
188   : mInput( accessor.mInput ),
189     mComponentIndex( -1 )
190   {
191   }
192
193   /**
194    * Copy from a PropertyInputComponentAccessor
195    */
196   PropertyInputComponentAccessor( const PropertyInputComponentAccessor& accessor )
197   : mInput( accessor.mInput ),
198     mComponentIndex( accessor.mComponentIndex )
199   {
200   }
201
202   /**
203    * Assign from a PropertyInputComponentAccessor
204    */
205   PropertyInputComponentAccessor& operator=(const PropertyInputComponentAccessor& accessor)
206   {
207     mInput = accessor.mInput;
208     mComponentIndex = accessor.mComponentIndex;
209     return *this;
210   }
211
212   /**
213    * Set the property input.
214    */
215   void SetInput( const PropertyInputImpl& input, int componentIndex )
216   {
217     mInput = &input;
218     mComponentIndex = componentIndex;
219   }
220
221   /**
222    * Retrieve the property input.
223    */
224   const PropertyInputImpl* GetInput() const
225   {
226     return mInput;
227   }
228
229   /**
230    * @copydoc Dali::Internal::PropertyInputImpl::GetType()
231    */
232   Property::Type GetType() const
233   {
234     return mInput->GetType();
235   }
236
237   /**
238    * @copydoc Dali::Internal::PropertyInputImpl::GetConstraintInputBoolean()
239    */
240   const bool& GetConstraintInputBoolean( BufferIndex updateBufferIndex ) const
241   {
242     DALI_ASSERT_DEBUG( mComponentIndex < 0 && "Did not expect valid component index" );
243
244     return mInput->GetConstraintInputBoolean( updateBufferIndex );
245   }
246
247   /**
248    * @copydoc Dali::Internal::PropertyInputImpl::GetConstraintInputFloat()
249    */
250   const float& GetConstraintInputFloat( BufferIndex updateBufferIndex ) const
251   {
252     // Invalid index is ok
253     if ( mComponentIndex < 0 )
254     {
255       // Not a Vector3 or Vector4 component, expecting float type
256       return mInput->GetConstraintInputFloat( updateBufferIndex );
257     }
258     else if ( PropertyTypes::Get< Vector3 >() == mInput->GetType() )
259     {
260       if ( 0 == mComponentIndex )
261       {
262         return mInput->GetConstraintInputVector3( updateBufferIndex ).x;
263       }
264       else if ( 1 == mComponentIndex )
265       {
266         return mInput->GetConstraintInputVector3( updateBufferIndex ).y;
267       }
268
269       DALI_ASSERT_DEBUG( 2 == mComponentIndex && "Invalid Vector3 component index" );
270       return mInput->GetConstraintInputVector3( updateBufferIndex ).z;
271     }
272
273     // Expecting Vector4
274     if ( 0 == mComponentIndex )
275     {
276       return mInput->GetConstraintInputVector4( updateBufferIndex ).x;
277     }
278     else if ( 1 == mComponentIndex )
279     {
280       return mInput->GetConstraintInputVector4( updateBufferIndex ).y;
281     }
282     else if ( 2 == mComponentIndex )
283     {
284       return mInput->GetConstraintInputVector4( updateBufferIndex ).y;
285     }
286
287     DALI_ASSERT_DEBUG( 3 == mComponentIndex && "Invalid Vector4 component index" );
288     return mInput->GetConstraintInputVector4( updateBufferIndex ).w;
289   }
290
291   /**
292    * @copydoc Dali::Internal::PropertyInputImpl::GetConstraintInputVector2()
293    */
294   const Vector2& GetConstraintInputVector2( BufferIndex updateBufferIndex ) const
295   {
296     DALI_ASSERT_DEBUG( mComponentIndex < 0 && "Did not expect valid component index" );
297
298     return mInput->GetConstraintInputVector2( updateBufferIndex );
299   }
300
301   /**
302    * @copydoc Dali::Internal::PropertyInputImpl::GetConstraintInputVector3()
303    */
304   const Vector3& GetConstraintInputVector3( BufferIndex updateBufferIndex ) const
305   {
306     DALI_ASSERT_DEBUG( mComponentIndex < 0 && "Did not expect valid component index" );
307
308     return mInput->GetConstraintInputVector3( updateBufferIndex );
309   }
310
311   /**
312    * @copydoc Dali::Internal::PropertyInputImpl::GetConstraintInputVector4()
313    */
314   const Vector4& GetConstraintInputVector4( BufferIndex updateBufferIndex ) const
315   {
316     DALI_ASSERT_DEBUG( mComponentIndex < 0 && "Did not expect valid component index" );
317
318     return mInput->GetConstraintInputVector4( updateBufferIndex );
319   }
320
321   /**
322    * @copydoc Dali::Internal::PropertyInputImpl::GetConstraintInputQuaternion()
323    */
324   const Quaternion& GetConstraintInputQuaternion( BufferIndex updateBufferIndex ) const
325   {
326     DALI_ASSERT_DEBUG( mComponentIndex < 0 && "Did not expect valid component index" );
327
328     return mInput->GetConstraintInputQuaternion( updateBufferIndex );
329   }
330
331   /**
332    * @copydoc Dali::Internal::PropertyInputImpl::GetConstraintInputMatrix3()
333    */
334   const Matrix3& GetConstraintInputMatrix3( BufferIndex updateBufferIndex ) const
335   {
336     DALI_ASSERT_DEBUG( mComponentIndex < 0 && "Did not expect valid component index" );
337
338     return mInput->GetConstraintInputMatrix3( updateBufferIndex );
339   }
340
341   /**
342    * @copydoc Dali::Internal::PropertyInputImpl::GetConstraintInputMatrix()
343    */
344   const Matrix& GetConstraintInputMatrix( BufferIndex updateBufferIndex ) const
345   {
346     DALI_ASSERT_DEBUG( mComponentIndex < 0 && "Did not expect valid component index" );
347
348     return mInput->GetConstraintInputMatrix( updateBufferIndex );
349   }
350
351 public:
352
353   const PropertyInputImpl* mInput;
354   int mComponentIndex;
355 };
356
357 } // namespace Internal
358
359 } // namespace Dali
360
361 #endif // __DALI_PROPERTY_INPUT_ACCESSOR_H__