Merge "Klockwork fixes: Distance field iteration Checking for null...
[platform/core/uifw/dali-core.git] / dali / internal / event / animation / property-constraint.h
1 #ifndef __DALI_PROPERTY_CONSTRAINT_H__
2 #define __DALI_PROPERTY_CONSTRAINT_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 // INTERNAL INCLUDES
22 #include <dali/internal/event/animation/property-input-accessor.h>
23 #include <dali/internal/event/animation/property-input-indexer.h>
24 #include <dali/internal/event/common/property-input-impl.h>
25
26 namespace Dali
27 {
28
29 namespace Internal
30 {
31
32 /**
33  * A base class for connecting properties to a constraint function.
34  */
35 template < typename PropertyType >
36 class PropertyConstraintBase
37 {
38 public:
39
40   /**
41    * Create a property constraint.
42    */
43   PropertyConstraintBase()
44   : mInputsInitialized( false )
45   {
46   }
47
48   /**
49    * Virtual destructor.
50    */
51   virtual ~PropertyConstraintBase()
52   {
53   }
54
55   /**
56    * Clone a property constraint.
57    */
58   virtual PropertyConstraintBase< PropertyType >* Clone() = 0;
59
60   /**
61    * Clone a property constraint supporting component indices.
62    */
63   virtual PropertyConstraintBase< PropertyType >* CloneComponentFunc() = 0;
64
65   /**
66    * Set the input for one of the property constraint parameters.
67    * @param [in] index The parameter index.
68    * @param [in] input The interface for receiving a property value.
69    */
70   virtual void SetInput( unsigned int index, int componentIndex, const PropertyInputImpl& input ) = 0;
71
72   /**
73    * Retrieve the input for one of the property constraint parameters.
74    * @param [in] index The parameter index.
75    * @return The property input, or NULL if no input exists with this index.
76    */
77   virtual const PropertyInputImpl* GetInput( unsigned int index ) const = 0;
78
79   /**
80    * Query whether all of the inputs have been initialized.
81    * @return True if all of the inputs have been initialized.
82    */
83   bool InputsInitialized()
84   {
85     if ( !mInputsInitialized )
86     {
87       // Check whether the inputs are initialized yet
88       unsigned int index( 0u );
89       for ( const PropertyInputImpl* input = GetInput( index );
90             NULL != input;
91             input = GetInput( ++index ) )
92       {
93         if ( !input->InputInitialized() )
94         {
95           return false;
96         }
97       }
98
99       // All inputs are now initialized
100       mInputsInitialized = true;
101     }
102
103     return true;
104   }
105
106   /**
107    * Query whether any of the inputs have changed
108    * @return True if any of the inputs have changed.
109    */
110   bool InputsChanged()
111   {
112     unsigned int index( 0u );
113     for ( const PropertyInputImpl* input = GetInput( index );
114           NULL != input;
115           input = GetInput( ++index ) )
116     {
117       if ( input->InputChanged() )
118       {
119         // At least one of the inputs has changed
120         return true;
121       }
122     }
123
124     return false;
125   }
126
127   /**
128    * Apply the constraint.
129    * @param [in] bufferIndex The current update buffer index.
130    * @param [in] current The current property value.
131    * @return The constrained property value.
132    */
133   virtual PropertyType Apply( BufferIndex bufferIndex, const PropertyType& current ) = 0;
134
135 private:
136
137   bool mInputsInitialized;
138 };
139
140 /**
141  * Connects a constraint function with a target property & zero input properties.
142  */
143 template < typename PropertyType >
144 class PropertyConstraint0 : public PropertyConstraintBase< PropertyType >
145 {
146 public:
147
148   typedef boost::function< PropertyType (const PropertyType&)> ConstraintFunction;
149
150   /**
151    * Constructor.
152    * @param [in] func A constraint function.
153    */
154   PropertyConstraint0( const ConstraintFunction& func )
155   : mFunction( func )
156   {
157   }
158
159   /**
160    * Virtual destructor.
161    */
162   virtual ~PropertyConstraint0()
163   {
164   }
165
166   /**
167    * @copydoc PropertyConstraintBase::Clone()
168    */
169   virtual PropertyConstraintBase< PropertyType >* Clone()
170   {
171     return new PropertyConstraint0< PropertyType >( mFunction );
172   }
173
174   /**
175    * @copydoc PropertyConstraintBase::CloneComponentFunc()
176    */
177   virtual PropertyConstraintBase< PropertyType >* CloneComponentFunc()
178   {
179     DALI_ASSERT_ALWAYS( false && "PropertyConstraint0 does not support (property component) inputs" );
180     return NULL;
181   }
182
183   /**
184    * @copydoc PropertyConstraintBase::SetInput()
185    */
186   virtual void SetInput( unsigned int index, int componentIndex, const PropertyInputImpl& input )
187   {
188     DALI_ASSERT_ALWAYS( false && "PropertyConstraintBase::SetInput() needs overriding" ); // No additional inputs
189   }
190
191   /**
192    * @copydoc PropertyConstraintBase::GetInput()
193    */
194   virtual const PropertyInputImpl* GetInput( unsigned int index ) const
195   {
196     return NULL; // No additional inputs
197   }
198
199   /**
200    * @copydoc PropertyConstraintBase::Apply()
201    */
202   virtual PropertyType Apply( BufferIndex bufferIndex, const PropertyType& current )
203   {
204     return mFunction( current );
205   }
206
207 private:
208
209   // Undefined
210   PropertyConstraint0(const PropertyConstraint0&);
211
212   // Undefined
213   PropertyConstraint0& operator=(const PropertyConstraint0& rhs);
214
215 private:
216
217   ConstraintFunction mFunction;
218 };
219
220 /**
221  * Connects a constraint function with a target property & 1 input property.
222  */
223 template < typename PropertyType, typename PropertyInputAccessorType >
224 class PropertyConstraint1 : public PropertyConstraintBase< PropertyType >
225 {
226 public:
227
228   typedef boost::function< PropertyType (const PropertyType&, const PropertyInput&) > ConstraintFunction;
229
230   /**
231    * Constructor.
232    * @param [in] func A constraint function.
233    */
234   PropertyConstraint1( const ConstraintFunction& func )
235   : mFunction( func )
236   {
237   }
238
239   /**
240    * Constructor.
241    * @param [in] func A constraint function.
242    * @param [in] input1 A property input.
243    */
244   PropertyConstraint1( const ConstraintFunction& func,
245                        const PropertyInputAccessorType& input1 )
246   : mFunction( func ),
247     mInput1( input1 )
248   {
249   }
250
251   /**
252    * Virtual destructor.
253    */
254   virtual ~PropertyConstraint1()
255   {
256   }
257
258   /**
259    * @copydoc PropertyConstraintBase::Clone()
260    */
261   virtual PropertyConstraintBase< PropertyType >* Clone()
262   {
263     return new PropertyConstraint1< PropertyType, PropertyInputAccessorType >( mFunction, mInput1 );
264   }
265
266   /**
267    * @copydoc PropertyConstraintBase::CloneComponentFunc()
268    */
269   virtual PropertyConstraintBase< PropertyType >* CloneComponentFunc()
270   {
271     return new PropertyConstraint1< PropertyType, PropertyInputComponentAccessor >( mFunction, mInput1 );
272   }
273
274   /**
275    * @copydoc PropertyConstraintBase::SetInput()
276    */
277   virtual void SetInput( unsigned int index, int componentIndex, const PropertyInputImpl& input )
278   {
279     DALI_ASSERT_ALWAYS( 0u == index && "Constraint only has one input property" );
280
281     mInput1.SetInput( input, componentIndex );
282   }
283
284   /**
285    * @copydoc PropertyConstraintBase::GetInput()
286    */
287   virtual const PropertyInputImpl* GetInput( unsigned int index ) const
288   {
289     if ( 0u == index )
290     {
291       return mInput1.GetInput();
292     }
293
294     return NULL;
295   }
296
297   /**
298    * @copydoc PropertyConstraintBase::Apply()
299    */
300   virtual PropertyType Apply( BufferIndex bufferIndex, const PropertyType& current )
301   {
302     DALI_ASSERT_DEBUG( NULL != mInput1.GetInput() );
303
304     const PropertyInputIndexer< PropertyInputAccessorType > input1( bufferIndex, &mInput1 );
305
306     return mFunction( current, input1 );
307   }
308
309 private:
310
311   // Undefined
312   PropertyConstraint1(const PropertyConstraint1&);
313
314   // Undefined
315   PropertyConstraint1& operator=(const PropertyConstraint1& rhs);
316
317 private:
318
319   ConstraintFunction mFunction;
320
321   PropertyInputAccessorType mInput1;
322 };
323
324 /**
325  * Connects a constraint function with a target property & 2 input properties.
326  */
327 template < typename PropertyType, typename PropertyInputAccessorType >
328 class PropertyConstraint2 : public PropertyConstraintBase< PropertyType >
329 {
330 public:
331
332   typedef boost::function< PropertyType (const PropertyType&, const PropertyInput&, const PropertyInput&) > ConstraintFunction;
333
334   /**
335    * Constructor.
336    * @param [in] func A constraint function.
337    */
338   PropertyConstraint2( const ConstraintFunction& func )
339   : mFunction( func )
340   {
341   }
342
343   /**
344    * Constructor.
345    * @param [in] func A constraint function.
346    * @param [in] input1 A property input.
347    * @param [in] input2 A 2nd property input.
348    */
349   PropertyConstraint2( const ConstraintFunction& func,
350                        const PropertyInputAccessorType& input1,
351                        const PropertyInputAccessorType& input2 )
352   : mFunction( func ),
353     mInput1( input1 ),
354     mInput2( input2 )
355   {
356   }
357
358   /**
359    * Virtual destructor.
360    */
361   virtual ~PropertyConstraint2()
362   {
363   }
364
365   /**
366    * @copydoc PropertyConstraintBase::Clone()
367    */
368   virtual PropertyConstraintBase< PropertyType >* Clone()
369   {
370     return new PropertyConstraint2< PropertyType, PropertyInputAccessorType >( mFunction, mInput1, mInput2 );
371   }
372
373   /**
374    * @copydoc PropertyConstraintBase::CloneComponentFunc()
375    */
376   virtual PropertyConstraintBase< PropertyType >* CloneComponentFunc()
377   {
378     return new PropertyConstraint2< PropertyType, PropertyInputComponentAccessor >( mFunction, mInput1, mInput2 );
379   }
380
381   /**
382    * @copydoc PropertyConstraintBase::SetInput()
383    */
384   virtual void SetInput( unsigned int index, int componentIndex, const PropertyInputImpl& input )
385   {
386     DALI_ASSERT_ALWAYS( 2u > index && "Constraint only has 2 properties" );
387
388     if ( 0u == index )
389     {
390       mInput1.SetInput( input, componentIndex );
391     }
392     else
393     {
394       mInput2.SetInput( input, componentIndex );
395     }
396   }
397
398   /**
399    * @copydoc PropertyConstraintBase::GetInput()
400    */
401   virtual const PropertyInputImpl* GetInput( unsigned int index ) const
402   {
403     if ( 0u == index )
404     {
405       return mInput1.GetInput();
406     }
407     else if ( 1u == index )
408     {
409       return mInput2.GetInput();
410     }
411
412     return NULL;
413   }
414
415   /**
416    * @copydoc PropertyConstraintBase::Apply()
417    */
418   virtual PropertyType Apply( BufferIndex bufferIndex, const PropertyType& current )
419   {
420     DALI_ASSERT_DEBUG( NULL != mInput1.GetInput() );
421     DALI_ASSERT_DEBUG( NULL != mInput2.GetInput() );
422
423     const PropertyInputIndexer< PropertyInputAccessorType > input1( bufferIndex, &mInput1 );
424     const PropertyInputIndexer< PropertyInputAccessorType > input2( bufferIndex, &mInput2 );
425
426     return mFunction( current,
427                       input1,
428                       input2 );
429   }
430
431 private:
432
433   // Undefined
434   PropertyConstraint2(const PropertyConstraint2&);
435
436   // Undefined
437   PropertyConstraint2& operator=(const PropertyConstraint2& rhs);
438
439 private:
440
441   ConstraintFunction mFunction;
442
443   PropertyInputAccessorType mInput1;
444   PropertyInputAccessorType mInput2;
445 };
446
447 /**
448  * Connects a constraint function with a target property & 3 input properties.
449  */
450 template < class PropertyType, typename PropertyInputAccessorType >
451 class PropertyConstraint3 : public PropertyConstraintBase< PropertyType >
452 {
453 public:
454
455   typedef boost::function< PropertyType (const PropertyType&, const PropertyInput&, const PropertyInput&, const PropertyInput&)> ConstraintFunction;
456
457   /**
458    * Constructor.
459    * @param [in] func A constraint function.
460    */
461   PropertyConstraint3( const ConstraintFunction& func )
462   : mFunction( func )
463   {
464   }
465
466   /**
467    * Constructor.
468    * @param [in] func A constraint function.
469    * @param [in] input1 A property input.
470    * @param [in] input2 A 2nd property input.
471    * @param [in] input3 A 3rd property input.
472    */
473   PropertyConstraint3( const ConstraintFunction& func,
474                        const PropertyInputAccessorType& input1,
475                        const PropertyInputAccessorType& input2,
476                        const PropertyInputAccessorType& input3 )
477   : mFunction( func ),
478     mInput1( input1 ),
479     mInput2( input2 ),
480     mInput3( input3 )
481   {
482   }
483
484   /**
485    * Virtual destructor.
486    */
487   virtual ~PropertyConstraint3()
488   {
489   }
490
491   /**
492    * @copydoc PropertyConstraintBase::Clone()
493    */
494   virtual PropertyConstraintBase< PropertyType >* Clone()
495   {
496     return new PropertyConstraint3< PropertyType, PropertyInputAccessorType >( mFunction, mInput1, mInput2, mInput3 );
497   }
498
499   /**
500    * @copydoc PropertyConstraintBase::CloneComponentFunc()
501    */
502   virtual PropertyConstraintBase< PropertyType >* CloneComponentFunc()
503   {
504     return new PropertyConstraint3< PropertyType, PropertyInputComponentAccessor >( mFunction, mInput1, mInput2, mInput3 );
505   }
506
507   /**
508    * @copydoc PropertyConstraintBase::SetInput()
509    */
510   virtual void SetInput( unsigned int index, int componentIndex, const PropertyInputImpl& input )
511   {
512     DALI_ASSERT_ALWAYS( 3u > index && "Constraint only has 3 properties" );
513
514     if ( 0u == index )
515     {
516       mInput1.SetInput( input, componentIndex );
517     }
518     else if ( 1u == index )
519     {
520       mInput2.SetInput( input, componentIndex );
521     }
522     else
523     {
524       mInput3.SetInput( input, componentIndex );
525     }
526   }
527
528   /**
529    * @copydoc PropertyConstraintBase::GetInput()
530    */
531   virtual const PropertyInputImpl* GetInput( unsigned int index ) const
532   {
533     if ( 0u == index )
534     {
535       return mInput1.GetInput();
536     }
537     else if ( 1u == index )
538     {
539       return mInput2.GetInput();
540     }
541     else if ( 2u == index )
542     {
543       return mInput3.GetInput();
544     }
545
546     return NULL;
547   }
548
549   /**
550    * @copydoc PropertyConstraintBase::Apply()
551    */
552   virtual PropertyType Apply( BufferIndex bufferIndex, const PropertyType& current )
553   {
554     DALI_ASSERT_DEBUG( NULL != mInput1.GetInput() );
555     DALI_ASSERT_DEBUG( NULL != mInput2.GetInput() );
556     DALI_ASSERT_DEBUG( NULL != mInput3.GetInput() );
557
558     const PropertyInputIndexer< PropertyInputAccessorType > input1( bufferIndex, &mInput1 );
559     const PropertyInputIndexer< PropertyInputAccessorType > input2( bufferIndex, &mInput2 );
560     const PropertyInputIndexer< PropertyInputAccessorType > input3( bufferIndex, &mInput3 );
561
562     return mFunction( current,
563                       input1,
564                       input2,
565                       input3 );
566   }
567
568 private:
569
570   // Undefined
571   PropertyConstraint3(const PropertyConstraint3&);
572
573   // Undefined
574   PropertyConstraint3& operator=(const PropertyConstraint3& rhs);
575
576 private:
577
578   ConstraintFunction mFunction;
579
580   PropertyInputAccessorType mInput1;
581   PropertyInputAccessorType mInput2;
582   PropertyInputAccessorType mInput3;
583 };
584
585 /**
586  * Connects a constraint function with a target property & 4 input properties.
587  */
588 template < class PropertyType, typename PropertyInputAccessorType >
589 class PropertyConstraint4 : public PropertyConstraintBase< PropertyType >
590 {
591 public:
592
593   typedef boost::function< PropertyType (const PropertyType&, const PropertyInput&, const PropertyInput&, const PropertyInput&, const PropertyInput&) > ConstraintFunction;
594
595   /**
596    * Constructor.
597    * @param [in] func A constraint function.
598    */
599   PropertyConstraint4( const ConstraintFunction& func )
600   : mFunction( func )
601   {
602   }
603
604   /**
605    * Constructor.
606    * @param [in] func A constraint function.
607    * @param [in] input1 A property input.
608    * @param [in] input2 A 2nd property input.
609    * @param [in] input3 A 3rd property input.
610    * @param [in] input4 A 4th property input.
611    */
612   PropertyConstraint4( const ConstraintFunction& func,
613                        const PropertyInputAccessorType& input1,
614                        const PropertyInputAccessorType& input2,
615                        const PropertyInputAccessorType& input3,
616                        const PropertyInputAccessorType& input4 )
617   : mFunction( func ),
618     mInput1( input1 ),
619     mInput2( input2 ),
620     mInput3( input3 ),
621     mInput4( input4 )
622   {
623   }
624
625   /**
626    * Create a PropertyConstraint4 instance.
627    * @param [in] func A constraint function.
628    * @return A newly heap-allocated object.
629    */
630   static PropertyConstraintBase< PropertyType >* New( ConstraintFunction func )
631   {
632     return new PropertyConstraint4< PropertyType, PropertyInputAccessorType >( func );
633   }
634
635   /**
636    * Virtual destructor.
637    */
638   virtual ~PropertyConstraint4()
639   {
640   }
641
642   /**
643    * @copydoc PropertyConstraintBase::Clone()
644    */
645   virtual PropertyConstraintBase< PropertyType >* Clone()
646   {
647     return new PropertyConstraint4< PropertyType, PropertyInputAccessorType >( mFunction, mInput1, mInput2, mInput3, mInput4 );
648   }
649
650   /**
651    * @copydoc PropertyConstraintBase::CloneComponentFunc()
652    */
653   virtual PropertyConstraintBase< PropertyType >* CloneComponentFunc()
654   {
655     return new PropertyConstraint4< PropertyType, PropertyInputComponentAccessor >( mFunction, mInput1, mInput2, mInput3, mInput4 );
656   }
657
658   /**
659    * @copydoc PropertyConstraintBase::SetInput()
660    */
661   virtual void SetInput( unsigned int index, int componentIndex, const PropertyInputImpl& input )
662   {
663     DALI_ASSERT_ALWAYS( 4u > index && "Constraint only has 4 properties" );
664
665     if ( 0u == index )
666     {
667       mInput1.SetInput( input, componentIndex );
668     }
669     else if ( 1u == index )
670     {
671       mInput2.SetInput( input, componentIndex );
672     }
673     else if ( 2u == index )
674     {
675       mInput3.SetInput( input, componentIndex );
676     }
677     else
678     {
679       mInput4.SetInput( input, componentIndex );
680     }
681   }
682
683   /**
684    * @copydoc PropertyConstraintBase::GetInput()
685    */
686   virtual const PropertyInputImpl* GetInput( unsigned int index ) const
687   {
688     if ( 0u == index )
689     {
690       return mInput1.GetInput();
691     }
692     else if ( 1u == index )
693     {
694       return mInput2.GetInput();
695     }
696     else if ( 2u == index )
697     {
698       return mInput3.GetInput();
699     }
700     else if ( 3u == index )
701     {
702       return mInput4.GetInput();
703     }
704
705     return NULL;
706   }
707
708   /**
709    * @copydoc PropertyConstraintBase::Apply()
710    */
711   virtual PropertyType Apply( BufferIndex bufferIndex, const PropertyType& current )
712   {
713     DALI_ASSERT_DEBUG( NULL != mInput1.GetInput() );
714     DALI_ASSERT_DEBUG( NULL != mInput2.GetInput() );
715     DALI_ASSERT_DEBUG( NULL != mInput3.GetInput() );
716     DALI_ASSERT_DEBUG( NULL != mInput4.GetInput() );
717
718     const PropertyInputIndexer< PropertyInputAccessorType > input1( bufferIndex, &mInput1 );
719     const PropertyInputIndexer< PropertyInputAccessorType > input2( bufferIndex, &mInput2 );
720     const PropertyInputIndexer< PropertyInputAccessorType > input3( bufferIndex, &mInput3 );
721     const PropertyInputIndexer< PropertyInputAccessorType > input4( bufferIndex, &mInput4 );
722
723     return mFunction( current,
724                       input1,
725                       input2,
726                       input3,
727                       input4 );
728   }
729
730 private:
731
732   // Undefined
733   PropertyConstraint4(const PropertyConstraint4&);
734
735   // Undefined
736   PropertyConstraint4& operator=(const PropertyConstraint4& rhs);
737
738 private:
739
740   ConstraintFunction mFunction;
741
742   PropertyInputAccessorType mInput1;
743   PropertyInputAccessorType mInput2;
744   PropertyInputAccessorType mInput3;
745   PropertyInputAccessorType mInput4;
746 };
747
748 /**
749  * Connects a constraint function with a target property & 5 input properties.
750  */
751 template < class PropertyType, typename PropertyInputAccessorType >
752 class PropertyConstraint5 : public PropertyConstraintBase< PropertyType >
753 {
754 public:
755
756   typedef boost::function< PropertyType (const PropertyType&, const PropertyInput&, const PropertyInput&, const PropertyInput&, const PropertyInput&, const PropertyInput&) > ConstraintFunction;
757
758   /**
759    * Constructor.
760    * @param [in] func A constraint function.
761    */
762   PropertyConstraint5( const ConstraintFunction& func )
763   : mFunction( func )
764   {
765   }
766
767   /**
768    * Constructor.
769    * @param [in] func A constraint function.
770    * @param [in] input1 A property input.
771    * @param [in] input2 A 2nd property input.
772    * @param [in] input3 A 3rd property input.
773    * @param [in] input4 A 4th property input.
774    * @param [in] input5 A 5th property input.
775    */
776   PropertyConstraint5( const ConstraintFunction& func,
777                        const PropertyInputAccessorType& input1,
778                        const PropertyInputAccessorType& input2,
779                        const PropertyInputAccessorType& input3,
780                        const PropertyInputAccessorType& input4,
781                        const PropertyInputAccessorType& input5 )
782   : mFunction( func ),
783     mInput1( input1 ),
784     mInput2( input2 ),
785     mInput3( input3 ),
786     mInput4( input4 ),
787     mInput5( input5 )
788   {
789   }
790
791   /**
792    * Virtual destructor.
793    */
794   virtual ~PropertyConstraint5()
795   {
796   }
797
798   /**
799    * @copydoc PropertyConstraintBase::Clone()
800    */
801   virtual PropertyConstraintBase< PropertyType >* Clone()
802   {
803     return new PropertyConstraint5< PropertyType, PropertyInputAccessorType >( mFunction, mInput1, mInput2, mInput3, mInput4, mInput5 );
804   }
805
806   /**
807    * @copydoc PropertyConstraintBase::CloneComponentFunc()
808    */
809   virtual PropertyConstraintBase< PropertyType >* CloneComponentFunc()
810   {
811     return new PropertyConstraint5< PropertyType, PropertyInputComponentAccessor >( mFunction, mInput1, mInput2, mInput3, mInput4, mInput5 );
812   }
813
814   /**
815    * @copydoc PropertyConstraintBase::SetInput()
816    */
817   virtual void SetInput( unsigned int index, int componentIndex, const PropertyInputImpl& input )
818   {
819     DALI_ASSERT_ALWAYS( 5u > index && "Constraint only has 5 properties");
820
821     if ( 0u == index )
822     {
823       mInput1.SetInput( input, componentIndex );
824     }
825     else if ( 1u == index )
826     {
827       mInput2.SetInput( input, componentIndex );
828     }
829     else if ( 2u == index )
830     {
831       mInput3.SetInput( input, componentIndex );
832     }
833     else if ( 3u == index )
834     {
835       mInput4.SetInput( input, componentIndex );
836     }
837     else
838     {
839       mInput5.SetInput( input, componentIndex );
840     }
841   }
842
843   /**
844    * @copydoc PropertyConstraintBase::GetInput()
845    */
846   virtual const PropertyInputImpl* GetInput( unsigned int index ) const
847   {
848     if ( 0u == index )
849     {
850       return mInput1.GetInput();
851     }
852     else if ( 1u == index )
853     {
854       return mInput2.GetInput();
855     }
856     else if ( 2u == index )
857     {
858       return mInput3.GetInput();
859     }
860     else if ( 3u == index )
861     {
862       return mInput4.GetInput();
863     }
864     else if ( 4u == index )
865     {
866       return mInput5.GetInput();
867     }
868
869     return NULL;
870   }
871
872   /**
873    * @copydoc PropertyConstraintBase::Apply()
874    */
875   virtual PropertyType Apply( BufferIndex bufferIndex, const PropertyType& current )
876   {
877     DALI_ASSERT_DEBUG( NULL != mInput1.GetInput() );
878     DALI_ASSERT_DEBUG( NULL != mInput2.GetInput() );
879     DALI_ASSERT_DEBUG( NULL != mInput3.GetInput() );
880     DALI_ASSERT_DEBUG( NULL != mInput4.GetInput() );
881     DALI_ASSERT_DEBUG( NULL != mInput5.GetInput() );
882
883     const PropertyInputIndexer< PropertyInputAccessorType > input1( bufferIndex, &mInput1 );
884     const PropertyInputIndexer< PropertyInputAccessorType > input2( bufferIndex, &mInput2 );
885     const PropertyInputIndexer< PropertyInputAccessorType > input3( bufferIndex, &mInput3 );
886     const PropertyInputIndexer< PropertyInputAccessorType > input4( bufferIndex, &mInput4 );
887     const PropertyInputIndexer< PropertyInputAccessorType > input5( bufferIndex, &mInput5 );
888
889     return mFunction( current,
890                       input1,
891                       input2,
892                       input3,
893                       input4,
894                       input5 );
895   }
896
897 private:
898
899   // Undefined
900   PropertyConstraint5(const PropertyConstraint5&);
901
902   // Undefined
903   PropertyConstraint5& operator=(const PropertyConstraint5& rhs);
904
905 private:
906
907   ConstraintFunction mFunction;
908
909   PropertyInputAccessorType mInput1;
910   PropertyInputAccessorType mInput2;
911   PropertyInputAccessorType mInput3;
912   PropertyInputAccessorType mInput4;
913   PropertyInputAccessorType mInput5;
914 };
915
916 /**
917  * Connects a constraint function with a target property & 6 input properties.
918  */
919 template < class PropertyType, typename PropertyInputAccessorType >
920 class PropertyConstraint6 : public PropertyConstraintBase< PropertyType >
921 {
922 public:
923
924   typedef boost::function< PropertyType (const PropertyType&, const PropertyInput&, const PropertyInput&, const PropertyInput&, const PropertyInput&, const PropertyInput&, const PropertyInput&)> ConstraintFunction;
925
926   /**
927    * Constructor.
928    * @param [in] func A constraint function.
929    */
930   PropertyConstraint6( const ConstraintFunction& func )
931   : mFunction( func )
932   {
933   }
934
935   /**
936    * Constructor.
937    * @param [in] func A constraint function.
938    * @param [in] input1 A property input.
939    * @param [in] input2 A 2nd property input.
940    * @param [in] input3 A 3rd property input.
941    * @param [in] input4 A 4th property input.
942    * @param [in] input5 A 5th property input.
943    * @param [in] input6 A 6th property input.
944    */
945   PropertyConstraint6( const ConstraintFunction& func,
946                        const PropertyInputAccessorType& input1,
947                        const PropertyInputAccessorType& input2,
948                        const PropertyInputAccessorType& input3,
949                        const PropertyInputAccessorType& input4,
950                        const PropertyInputAccessorType& input5,
951                        const PropertyInputAccessorType& input6 )
952   : mFunction( func ),
953     mInput1( input1 ),
954     mInput2( input2 ),
955     mInput3( input3 ),
956     mInput4( input4 ),
957     mInput5( input5 ),
958     mInput6( input6 )
959   {
960   }
961
962   /**
963    * Virtual destructor.
964    */
965   virtual ~PropertyConstraint6()
966   {
967   }
968
969   /**
970    * @copydoc PropertyConstraintBase::Clone()
971    */
972   virtual PropertyConstraintBase< PropertyType >* Clone()
973   {
974     return new PropertyConstraint6< PropertyType, PropertyInputAccessorType >( mFunction, mInput1, mInput2, mInput3, mInput4, mInput5, mInput6 );
975   }
976
977   /**
978    * @copydoc PropertyConstraintBase::CloneComponentFunc()
979    */
980   virtual PropertyConstraintBase< PropertyType >* CloneComponentFunc()
981   {
982     return new PropertyConstraint6< PropertyType, PropertyInputComponentAccessor >( mFunction, mInput1, mInput2, mInput3, mInput4, mInput5, mInput6 );
983   }
984
985   /**
986    * @copydoc PropertyConstraintBase::SetInput()
987    */
988   virtual void SetInput( unsigned int index, int componentIndex, const PropertyInputImpl& input )
989   {
990     DALI_ASSERT_ALWAYS( 6u > index && "Constraint only has 6 properties" );
991
992     if ( 0u == index )
993     {
994       mInput1.SetInput( input, componentIndex );
995     }
996     else if ( 1u == index )
997     {
998       mInput2.SetInput( input, componentIndex );
999     }
1000     else if ( 2u == index )
1001     {
1002       mInput3.SetInput( input, componentIndex );
1003     }
1004     else if ( 3u == index )
1005     {
1006       mInput4.SetInput( input, componentIndex );
1007     }
1008     else if ( 4u == index )
1009     {
1010       mInput5.SetInput( input, componentIndex );
1011     }
1012     else
1013     {
1014       mInput6.SetInput( input, componentIndex );
1015     }
1016   }
1017
1018   /**
1019    * @copydoc PropertyConstraintBase::GetInput()
1020    */
1021   virtual const PropertyInputImpl* GetInput( unsigned int index ) const
1022   {
1023     if ( 0u == index )
1024     {
1025       return mInput1.GetInput();
1026     }
1027     else if ( 1u == index )
1028     {
1029       return mInput2.GetInput();
1030     }
1031     else if ( 2u == index )
1032     {
1033       return mInput3.GetInput();
1034     }
1035     else if ( 3u == index )
1036     {
1037       return mInput4.GetInput();
1038     }
1039     else if ( 4u == index )
1040     {
1041       return mInput5.GetInput();
1042     }
1043     else if ( 5u == index )
1044     {
1045       return mInput6.GetInput();
1046     }
1047
1048     return NULL;
1049   }
1050
1051   /**
1052    * @copydoc PropertyConstraintBase::Apply()
1053    */
1054   virtual PropertyType Apply( BufferIndex bufferIndex, const PropertyType& current )
1055   {
1056     DALI_ASSERT_DEBUG( NULL != mInput1.GetInput() );
1057     DALI_ASSERT_DEBUG( NULL != mInput2.GetInput() );
1058     DALI_ASSERT_DEBUG( NULL != mInput3.GetInput() );
1059     DALI_ASSERT_DEBUG( NULL != mInput4.GetInput() );
1060     DALI_ASSERT_DEBUG( NULL != mInput5.GetInput() );
1061     DALI_ASSERT_DEBUG( NULL != mInput6.GetInput() );
1062
1063     const PropertyInputIndexer< PropertyInputAccessorType > input1( bufferIndex, &mInput1 );
1064     const PropertyInputIndexer< PropertyInputAccessorType > input2( bufferIndex, &mInput2 );
1065     const PropertyInputIndexer< PropertyInputAccessorType > input3( bufferIndex, &mInput3 );
1066     const PropertyInputIndexer< PropertyInputAccessorType > input4( bufferIndex, &mInput4 );
1067     const PropertyInputIndexer< PropertyInputAccessorType > input5( bufferIndex, &mInput5 );
1068     const PropertyInputIndexer< PropertyInputAccessorType > input6( bufferIndex, &mInput6 );
1069
1070     return mFunction( current,
1071                       input1,
1072                       input2,
1073                       input3,
1074                       input4,
1075                       input5,
1076                       input6 );
1077   }
1078
1079 private:
1080
1081   // Undefined
1082   PropertyConstraint6(const PropertyConstraint6&);
1083
1084   // Undefined
1085   PropertyConstraint6& operator=(const PropertyConstraint6& rhs);
1086
1087 private:
1088
1089   ConstraintFunction mFunction;
1090
1091   PropertyInputAccessorType mInput1;
1092   PropertyInputAccessorType mInput2;
1093   PropertyInputAccessorType mInput3;
1094   PropertyInputAccessorType mInput4;
1095   PropertyInputAccessorType mInput5;
1096   PropertyInputAccessorType mInput6;
1097 };
1098
1099 } // namespace Internal
1100
1101 } // namespace Dali
1102
1103 #endif // __DALI_PROPERTY_CONSTRAINT_H__