Optimize type-info-impl and type-registry-impl
[platform/core/uifw/dali-core.git] / dali / internal / event / common / type-info-impl.cpp
1 /*
2  * Copyright (c) 2018 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali/internal/event/common/type-info-impl.h>
20
21 // EXTERNAL INCLUDES
22 #include <algorithm> // std::find_if
23 #include <string>
24
25 // INTERNAL INCLUDES
26 #include <dali/integration-api/debug.h>
27 #include <dali/internal/event/common/type-registry-impl.h>
28 #include <dali/internal/event/common/object-impl.h>
29
30 using std::find_if;
31
32 namespace Dali
33 {
34
35 namespace Internal
36 {
37
38 namespace
39 {
40
41 /*
42  * Functor to find by given type for vector of pairs
43  */
44 template <typename S, typename T>
45 struct PairFinder
46 {
47   PairFinder(const S& find)
48   : mFind(find)
49   {
50   }
51
52   bool operator()(const T& p) const
53   {
54     return p.first == mFind;
55   }
56
57 private:
58
59   const S& mFind;
60 };
61
62 /**
63  * Functor to find a matching property name
64  */
65 template <typename T>
66 struct PropertyNameFinder
67 {
68   PropertyNameFinder( const std::string& find )
69   : mFind( find )
70   {
71   }
72
73   bool operator()(const T &p) const
74   {
75     return p.second.name == mFind;
76   }
77
78 private:
79
80   const std::string& mFind;
81 };
82
83 /**
84  * Functor to find a matching property component index
85  */
86 template <typename T>
87 struct PropertyComponentFinder
88 {
89   PropertyComponentFinder( Property::Index basePropertyIndex, const int find )
90   : mBasePropertyIndex( basePropertyIndex ),
91     mFind( find )
92   {
93   }
94
95   bool operator()(const T &p) const
96   {
97     return ( p.second.basePropertyIndex == mBasePropertyIndex && p.second.componentIndex == mFind );
98   }
99
100 private:
101
102   Property::Index mBasePropertyIndex;
103   const int mFind;
104 };
105
106 /**
107  * Helper function to find the right default property with given index and return the desired detail of it
108  */
109 template< typename Parameter, typename Member >
110 inline bool GetDefaultPropertyField( const Dali::PropertyDetails* propertyTable, Property::Index count, Property::Index index, Member member, Parameter& parameter )
111 {
112   bool found = false;
113   // is index inside this table (bigger than first index but smaller than first + count)
114   if( ( index >= propertyTable->enumIndex ) && ( index < ( propertyTable->enumIndex + count ) ) )
115   {
116     // return the match. we're assuming here that there is no gaps between the indices in a table
117     parameter = propertyTable[ index - propertyTable->enumIndex ].*member;
118     found = true;
119   }
120   // should never really get here
121   return found;
122 }
123
124 // static pointer value to mark that a base class address has not been resolved
125 // 0x01 is not a valid pointer but used here to differentiate from nullptr
126 // unfortunately it cannot be constexpr as C++ does not allow them to be initialised with reinterpret_cast
127 Internal::TypeInfo* const UNRESOLVED = reinterpret_cast<Internal::TypeInfo*>( 0x1 );
128
129 /**
130  * Helper function to resolve and return the pointer to the base type info
131  * Not a member function to avoid having to #include additional headers and to make sure this gets inlined inside this cpp
132  * @param[in/out] baseType pointer to resolve and set
133  * @param[in] typeRegistry reference to the type registry
134  * @param[in] baseTypeName string name of the base type
135  * @return true is base type exists
136  */
137 inline bool GetBaseType( Internal::TypeInfo*& baseType, TypeRegistry& typeRegistry, const std::string& baseTypeName )
138 {
139   // if greater than unresolved means we have a base type, null means no base
140   bool baseExists = ( baseType > UNRESOLVED );
141   // base only needs to be resolved once
142   if( UNRESOLVED == baseType )
143   {
144     TypeRegistry::TypeInfoPointer base = typeRegistry.GetTypeInfo( baseTypeName );
145     if( base )
146     {
147       baseType = base.Get(); // dont pass ownership, just return raw pointer
148       baseExists = true;
149     }
150     else
151     {
152       // no type info found so assuming no base as all type registration is done in startup for now
153       baseType = nullptr;
154     }
155   }
156   return baseExists;
157 }
158
159 } // unnamed namespace
160
161 TypeInfo::TypeInfo( const std::string &name, const std::string &baseTypeName, Dali::TypeInfo::CreateFunction creator,
162                     const Dali::PropertyDetails* defaultProperties, Property::Index defaultPropertyCount )
163 : mTypeRegistry( *TypeRegistry::Get() ), mBaseType( UNRESOLVED ),
164   mTypeName( name ), mBaseTypeName( baseTypeName ), mCreate( creator ), mDefaultProperties( defaultProperties ),
165   mDefaultPropertyCount( defaultPropertyCount ), mCSharpType( false )
166 {
167   DALI_ASSERT_ALWAYS(!name.empty() && "Type info construction must have a name");
168   DALI_ASSERT_ALWAYS(!baseTypeName.empty() && "Type info construction must have a base type name");
169 }
170
171 TypeInfo::TypeInfo(const std::string &name, const std::string &baseTypeName, Dali::CSharpTypeInfo::CreateFunction creator)
172 : mTypeRegistry( *TypeRegistry::Get() ), mBaseType( UNRESOLVED ),
173   mTypeName( name ), mBaseTypeName( baseTypeName ), mCSharpCreate( creator ), mCSharpType( true )
174 {
175   DALI_ASSERT_ALWAYS(!name.empty() && "Type info construction must have a name");
176   DALI_ASSERT_ALWAYS(!baseTypeName.empty() && "Type info construction must have a base type name");
177 }
178
179 TypeInfo::~TypeInfo()
180 {
181 }
182
183 BaseHandle TypeInfo::CreateInstance() const
184 {
185   BaseHandle ret;
186
187   if(mCreate)
188   {
189     if ( mCSharpType )
190     {
191       // CSharp currently only registers one create function for all custom controls
192       // it uses the type name to decide which one to create
193       ret = *mCSharpCreate( mTypeName.c_str() );
194     }
195     else
196     {
197       ret = mCreate();
198     }
199
200     if ( ret )
201     {
202       BaseObject& handle = ret.GetBaseObject();
203       Object *object = dynamic_cast<Internal::Object*>(&handle);
204
205       if ( object )
206       {
207         object->SetTypeInfo( this );
208       }
209     }
210   }
211   return ret;
212 }
213
214 bool TypeInfo::DoActionTo(BaseObject *object, const std::string &actionName, const Property::Map &properties)
215 {
216   bool done = false;
217
218   ActionContainer::iterator iter = find_if(mActions.begin(), mActions.end(), PairFinder<std::string, ActionPair>(actionName));
219
220   if( iter != mActions.end() )
221   {
222     done = (iter->second)(object, actionName, properties);
223   }
224
225   if( !done )
226   {
227     if( GetBaseType( mBaseType, mTypeRegistry, mBaseTypeName ) )
228     {
229       // call base type recursively
230       done = mBaseType->DoActionTo( object, actionName, properties );
231     }
232   }
233
234   return done;
235 }
236
237 bool TypeInfo::ConnectSignal( BaseObject* object, ConnectionTrackerInterface* connectionTracker, const std::string& signalName, FunctorDelegate* functor )
238 {
239   bool connected( false );
240
241   ConnectorContainer::iterator iter = find_if( mSignalConnectors.begin(), mSignalConnectors.end(),
242                                                  PairFinder<std::string, ConnectionPair>(signalName) );
243
244   if( iter != mSignalConnectors.end() )
245   {
246     connected = (iter->second)( object, connectionTracker, signalName, functor );
247   }
248
249   if( !connected )
250   {
251     if( GetBaseType( mBaseType, mTypeRegistry, mBaseTypeName ) )
252     {
253       // call base type recursively
254       connected = mBaseType->ConnectSignal( object, connectionTracker, signalName, functor );
255     }
256   }
257
258   return connected;
259 }
260
261 const std::string& TypeInfo::GetName() const
262 {
263   return mTypeName;
264 }
265
266 const std::string& TypeInfo::GetBaseName() const
267 {
268   return mBaseTypeName;
269 }
270
271 Dali::TypeInfo::CreateFunction TypeInfo::GetCreator() const
272 {
273   return mCreate;
274 }
275
276 size_t TypeInfo::GetActionCount() const
277 {
278   size_t count = mActions.size();
279
280   if( GetBaseType( mBaseType, mTypeRegistry, mBaseTypeName ) )
281   {
282     // call base type recursively
283     count += mBaseType->GetActionCount();
284   }
285
286   return count;
287 }
288
289 std::string TypeInfo::GetActionName(size_t index) const
290 {
291   std::string name;
292   const size_t count = mActions.size();
293
294   if( index < count )
295   {
296     name = mActions[index].first;
297   }
298   else
299   {
300     if( GetBaseType( mBaseType, mTypeRegistry, mBaseTypeName ) )
301     {
302       // call base type recursively
303       return mBaseType->GetActionName( index - count );
304     }
305   }
306
307   return name;
308 }
309
310 size_t TypeInfo::GetSignalCount() const
311 {
312   size_t count = mSignalConnectors.size();
313
314   if( GetBaseType( mBaseType, mTypeRegistry, mBaseTypeName ) )
315   {
316     // call base type recursively
317     count += mBaseType->GetSignalCount();
318   }
319
320   return count;
321 }
322
323 std::string TypeInfo::GetSignalName(size_t index) const
324 {
325   std::string name;
326   const size_t count = mSignalConnectors.size();
327
328   if( index < count )
329   {
330     name = mSignalConnectors[index].first;
331   }
332   else
333   {
334     if( GetBaseType( mBaseType, mTypeRegistry, mBaseTypeName ) )
335     {
336       // call base type recursively
337       return mBaseType->GetSignalName( index - count );
338     }
339   }
340
341   return name;
342 }
343
344 void TypeInfo::GetPropertyIndices( Property::IndexContainer& indices ) const
345 {
346   // Default Properties
347   if( mDefaultProperties )
348   {
349     indices.Reserve( indices.Size() + mDefaultPropertyCount );
350     for( Property::Index index = 0; index < mDefaultPropertyCount; ++index )
351     {
352       indices.PushBack( mDefaultProperties[ index ].enumIndex );
353     }
354   }
355
356   if( GetBaseType( mBaseType, mTypeRegistry, mBaseTypeName ) )
357   {
358     // call base type recursively
359     mBaseType->GetPropertyIndices( indices );
360   }
361
362   AppendProperties( indices, mRegisteredProperties );
363 }
364
365 void TypeInfo::GetChildPropertyIndices( Property::IndexContainer& indices ) const
366 {
367   if( GetBaseType( mBaseType, mTypeRegistry, mBaseTypeName ) )
368   {
369     // call base type recursively
370     mBaseType->GetChildPropertyIndices( indices );
371   }
372
373   AppendProperties( indices, mRegisteredChildProperties );
374 }
375
376 /**
377  * Append the indices in RegisteredProperties to the given index container.
378  */
379 void TypeInfo::AppendProperties( Dali::Property::IndexContainer& indices,
380                                  const TypeInfo::RegisteredPropertyContainer& registeredProperties ) const
381 {
382   if ( ! registeredProperties.empty() )
383   {
384     indices.Reserve( indices.Size() + registeredProperties.size() );
385
386     for( auto&& elem : registeredProperties )
387     {
388       indices.PushBack( elem.first );
389     }
390   }
391 }
392
393 const std::string& TypeInfo::GetRegisteredPropertyName( Property::Index index ) const
394 {
395   RegisteredPropertyContainer::const_iterator iter = find_if( mRegisteredProperties.begin(), mRegisteredProperties.end(),
396                                                           PairFinder< Property::Index, RegisteredPropertyPair >( index ) );
397   if ( iter != mRegisteredProperties.end() )
398   {
399     return iter->second.name;
400   }
401   if( GetBaseType( mBaseType, mTypeRegistry, mBaseTypeName ) )
402   {
403     // call base type recursively
404     return mBaseType->GetRegisteredPropertyName( index );
405   }
406   static std::string empty;
407   return empty;
408 }
409
410 std::string TypeInfo::GetPropertyName( Property::Index index ) const
411 {
412   std::string propertyName;
413   // default or custom
414   if ( mDefaultProperties && ( index < DEFAULT_PROPERTY_MAX_COUNT ) )
415   {
416     const char* name = nullptr;
417     if( GetDefaultPropertyField( mDefaultProperties, mDefaultPropertyCount,index, &Dali::PropertyDetails::name, name ) )
418     {
419       propertyName = name;
420     }
421   }
422   else
423   {
424     RegisteredPropertyContainer::const_iterator iter = find_if( mRegisteredProperties.begin(), mRegisteredProperties.end(),
425                                                             PairFinder< Property::Index, RegisteredPropertyPair >( index ) );
426     if ( iter != mRegisteredProperties.end() )
427     {
428       return iter->second.name;
429     }
430   }
431   // if not our property, go to parent
432   if( propertyName.empty() )
433   {
434     if( GetBaseType( mBaseType, mTypeRegistry, mBaseTypeName ) )
435     {
436       // call base type recursively
437       return mBaseType->GetPropertyName( index );
438     }
439   }
440
441   return propertyName;
442 }
443
444 void TypeInfo::AddActionFunction( const std::string &actionName, Dali::TypeInfo::ActionFunction function )
445 {
446   if( NULL == function)
447   {
448     DALI_LOG_WARNING("Action function is empty\n");
449   }
450   else
451   {
452     ActionContainer::iterator iter = std::find_if(mActions.begin(), mActions.end(),
453                                                   PairFinder<std::string, ActionPair>(actionName));
454
455     if( iter == mActions.end() )
456     {
457       mActions.push_back( ActionPair( actionName, function ) );
458     }
459     else
460     {
461       DALI_LOG_WARNING("Action already exists in TypeRegistry Type\n", actionName.c_str());
462     }
463   }
464 }
465
466 void TypeInfo::AddConnectorFunction( const std::string& signalName, Dali::TypeInfo::SignalConnectorFunction function )
467 {
468   if( NULL == function)
469   {
470     DALI_LOG_WARNING("Connector function is empty\n");
471   }
472   else
473   {
474     ConnectorContainer::iterator iter = find_if( mSignalConnectors.begin(), mSignalConnectors.end(),
475                                                    PairFinder<std::string, ConnectionPair>(signalName) );
476
477     if( iter == mSignalConnectors.end() )
478     {
479       mSignalConnectors.push_back( ConnectionPair( signalName, function ) );
480     }
481     else
482     {
483       DALI_LOG_WARNING("Signal name already exists in TypeRegistry Type for signal connector function\n", signalName.c_str());
484     }
485   }
486 }
487
488 void TypeInfo::AddProperty( const std::string& name, Property::Index index, Property::Type type, Dali::TypeInfo::SetPropertyFunction setFunc, Dali::TypeInfo::GetPropertyFunction getFunc )
489 {
490   // The setter can be empty as a property can be read-only.
491
492   if ( NULL == getFunc )
493   {
494     DALI_ASSERT_ALWAYS( ! "GetProperty Function is empty" );
495   }
496   else
497   {
498     RegisteredPropertyContainer::iterator iter = find_if( mRegisteredProperties.begin(), mRegisteredProperties.end(),
499                                                           PairFinder< Property::Index, RegisteredPropertyPair>(index) );
500
501     if ( iter == mRegisteredProperties.end() )
502     {
503       mRegisteredProperties.push_back( RegisteredPropertyPair( index, RegisteredProperty( type, setFunc, getFunc, name, Property::INVALID_INDEX, Property::INVALID_COMPONENT_INDEX ) ) );
504     }
505     else
506     {
507       DALI_ASSERT_ALWAYS( ! "Property index already added to Type" );
508     }
509   }
510 }
511
512 void TypeInfo::AddProperty( const std::string& name, Property::Index index, Property::Type type, Dali::CSharpTypeInfo::SetPropertyFunction setFunc, Dali::CSharpTypeInfo::GetPropertyFunction getFunc)
513 {
514
515   // The setter can be empty as a property can be read-only.
516
517   if ( NULL == getFunc )
518   {
519     DALI_ASSERT_ALWAYS( ! "GetProperty Function is empty" );
520   }
521   else
522   {
523     RegisteredPropertyContainer::iterator iter = find_if( mRegisteredProperties.begin(), mRegisteredProperties.end(),
524                                                           PairFinder< Property::Index, RegisteredPropertyPair>(index) );
525
526     if ( iter == mRegisteredProperties.end() )
527     {
528       mRegisteredProperties.push_back( RegisteredPropertyPair( index, RegisteredProperty( type, setFunc, getFunc, name, Property::INVALID_INDEX, Property::INVALID_COMPONENT_INDEX ) ) );
529     }
530     else
531     {
532       DALI_ASSERT_ALWAYS( ! "Property index already added to Type" );
533     }
534   }
535
536 }
537
538
539 void TypeInfo::AddAnimatableProperty( const std::string& name, Property::Index index, Property::Type type )
540 {
541   RegisteredPropertyContainer::iterator iter = find_if( mRegisteredProperties.begin(), mRegisteredProperties.end(),
542                                                         PairFinder< Property::Index, RegisteredPropertyPair>(index) );
543
544   if ( iter == mRegisteredProperties.end() )
545   {
546     mRegisteredProperties.push_back( RegisteredPropertyPair( index, RegisteredProperty( type, name, Property::INVALID_INDEX, Property::INVALID_COMPONENT_INDEX ) ) );
547   }
548   else
549   {
550     DALI_ASSERT_ALWAYS( ! "Property index already added to Type" );
551   }
552 }
553
554 void TypeInfo::AddAnimatableProperty( const std::string& name, Property::Index index, const Property::Value& defaultValue )
555 {
556   RegisteredPropertyContainer::iterator iter = find_if( mRegisteredProperties.begin(), mRegisteredProperties.end(),
557                                                         PairFinder< Property::Index, RegisteredPropertyPair>(index) );
558
559   if ( iter == mRegisteredProperties.end() )
560   {
561     mRegisteredProperties.push_back( RegisteredPropertyPair( index, RegisteredProperty( defaultValue.GetType(), name, Property::INVALID_INDEX, Property::INVALID_COMPONENT_INDEX ) ) );
562     mPropertyDefaultValues.push_back( PropertyDefaultValuePair( index, defaultValue ) );
563   }
564   else
565   {
566     DALI_ASSERT_ALWAYS( ! "Property index already added to Type" );
567   }
568 }
569
570 void TypeInfo::AddAnimatablePropertyComponent( const std::string& name, Property::Index index, Property::Index baseIndex, uint32_t componentIndex )
571 {
572   Property::Type type = GetPropertyType( baseIndex );
573   DALI_ASSERT_ALWAYS( ( type == Property::VECTOR2 || type == Property::VECTOR3 || type == Property::VECTOR4 ) && "Base property does not support component" );
574
575   bool success = false;
576
577   RegisteredPropertyContainer::iterator iter = find_if( mRegisteredProperties.begin(), mRegisteredProperties.end(),
578                                                         PairFinder< Property::Index, RegisteredPropertyPair>(index) );
579
580   if ( iter == mRegisteredProperties.end() )
581   {
582     iter = find_if( mRegisteredProperties.begin(), mRegisteredProperties.end(),
583                     PropertyComponentFinder< RegisteredPropertyPair >( baseIndex, componentIndex ) );
584
585     if ( iter == mRegisteredProperties.end() )
586     {
587       mRegisteredProperties.push_back( RegisteredPropertyPair( index, RegisteredProperty( type, name, baseIndex, componentIndex ) ) );
588       success = true;
589     }
590   }
591
592   DALI_ASSERT_ALWAYS( success && "Property component already registered" );
593 }
594
595 void TypeInfo::AddChildProperty( const std::string& name, Property::Index index, Property::Type type )
596 {
597   RegisteredPropertyContainer::iterator iter = find_if( mRegisteredChildProperties.begin(), mRegisteredChildProperties.end(),
598                                                         PairFinder< Property::Index, RegisteredPropertyPair>(index) );
599
600   if ( iter == mRegisteredChildProperties.end() )
601   {
602     mRegisteredChildProperties.push_back( RegisteredPropertyPair( index, RegisteredProperty( type, name, Property::INVALID_INDEX, Property::INVALID_COMPONENT_INDEX ) ) );
603   }
604   else
605   {
606     DALI_ASSERT_ALWAYS( ! "Property index already added to Type" );
607   }
608 }
609
610 uint32_t TypeInfo::GetPropertyCount() const
611 {
612   uint32_t count = mDefaultPropertyCount + static_cast<uint32_t>( mRegisteredProperties.size() );
613
614   if( GetBaseType( mBaseType, mTypeRegistry, mBaseTypeName ) )
615   {
616     // call base type recursively
617     count += mBaseType->GetPropertyCount();
618   }
619
620   return count;
621 }
622
623 Property::Index TypeInfo::GetPropertyIndex( const std::string& name ) const
624 {
625   Property::Index index = Property::INVALID_INDEX;
626   bool found = false;
627
628   // check default properties
629   if( mDefaultProperties )
630   {
631     for( Property::Index tableIndex = 0; tableIndex < mDefaultPropertyCount; ++tableIndex )
632     {
633       if( 0 == name.compare( mDefaultProperties[ tableIndex ].name ) )
634       {
635         index = mDefaultProperties[ tableIndex ].enumIndex;
636         found = true;
637         break;
638       }
639     }
640   }
641   if( !found )
642   {
643     // Slow but should not be done that often
644     RegisteredPropertyContainer::const_iterator iter = find_if( mRegisteredProperties.begin(), mRegisteredProperties.end(),
645                                                             PropertyNameFinder< RegisteredPropertyPair >( name ) );
646     if ( iter != mRegisteredProperties.end() )
647     {
648       index = iter->first;
649     }
650     else if( GetBaseType( mBaseType, mTypeRegistry, mBaseTypeName ) )
651     {
652       // call base type recursively
653       index = mBaseType->GetPropertyIndex( name );
654     }
655   }
656
657   return index;
658 }
659
660 Property::Index TypeInfo::GetBasePropertyIndex( Property::Index index ) const
661 {
662   Property::Index basePropertyIndex = Property::INVALID_INDEX;
663
664   RegisteredPropertyContainer::const_iterator iter = find_if( mRegisteredProperties.begin(), mRegisteredProperties.end(),
665                                                           PairFinder< Property::Index, RegisteredPropertyPair >( index ) );
666
667   if ( iter != mRegisteredProperties.end() )
668   {
669     basePropertyIndex = iter->second.basePropertyIndex;
670   }
671   else if( GetBaseType( mBaseType, mTypeRegistry, mBaseTypeName ) )
672   {
673     // call base type recursively
674     basePropertyIndex = mBaseType->GetBasePropertyIndex( index );
675   }
676
677   return basePropertyIndex;
678 }
679
680 int TypeInfo::GetComponentIndex( Property::Index index ) const
681 {
682   int componentIndex = Property::INVALID_COMPONENT_INDEX;
683
684   RegisteredPropertyContainer::const_iterator iter = find_if( mRegisteredProperties.begin(), mRegisteredProperties.end(),
685                                                           PairFinder< Property::Index, RegisteredPropertyPair >( index ) );
686
687   if ( iter != mRegisteredProperties.end() )
688   {
689     componentIndex = iter->second.componentIndex;
690   }
691   else if( GetBaseType( mBaseType, mTypeRegistry, mBaseTypeName ) )
692   {
693     // call base type recursively
694     componentIndex = mBaseType->GetComponentIndex( index );
695   }
696
697   return componentIndex;
698 }
699
700 Property::Index TypeInfo::GetChildPropertyIndex( const std::string& name ) const
701 {
702   Property::Index index = Property::INVALID_INDEX;
703
704   // Slow but should not be done that often
705   RegisteredPropertyContainer::const_iterator iter = find_if( mRegisteredChildProperties.begin(), mRegisteredChildProperties.end(),
706                                                           PropertyNameFinder< RegisteredPropertyPair >( name ) );
707
708   if ( iter != mRegisteredChildProperties.end() )
709   {
710     index = iter->first;
711   }
712   else if( GetBaseType( mBaseType, mTypeRegistry, mBaseTypeName ) )
713   {
714     // call base type recursively
715     index = mBaseType->GetChildPropertyIndex( name );
716   }
717
718   return index;
719 }
720
721 const std::string& TypeInfo::GetChildPropertyName( Property::Index index ) const
722 {
723   RegisteredPropertyContainer::const_iterator iter = find_if( mRegisteredChildProperties.begin(), mRegisteredChildProperties.end(),
724                                                           PairFinder< Property::Index, RegisteredPropertyPair >( index ) );
725
726   if ( iter != mRegisteredChildProperties.end() )
727   {
728     return iter->second.name;
729   }
730
731   if( GetBaseType( mBaseType, mTypeRegistry, mBaseTypeName ) )
732   {
733     // call base type recursively
734     return mBaseType->GetChildPropertyName( index );
735   }
736
737   DALI_LOG_ERROR( "Property index %d not found\n", index );
738
739   static std::string empty;
740   return empty;
741 }
742
743 Property::Type TypeInfo::GetChildPropertyType( Property::Index index ) const
744 {
745   Property::Type type( Property::NONE );
746
747   RegisteredPropertyContainer::const_iterator iter = find_if( mRegisteredChildProperties.begin(), mRegisteredChildProperties.end(),
748                                                           PairFinder< Property::Index, RegisteredPropertyPair >( index ) );
749
750   if ( iter != mRegisteredChildProperties.end() )
751   {
752     type = iter->second.type;
753   }
754   else if( GetBaseType( mBaseType, mTypeRegistry, mBaseTypeName ) )
755   {
756     // call base type recursively
757     type = mBaseType->GetChildPropertyType( index );
758   }
759   else
760   {
761     DALI_LOG_ERROR( "Property index %d not found\n", index );
762   }
763
764   return type;
765 }
766
767 bool TypeInfo::IsPropertyWritable( Property::Index index ) const
768 {
769   bool writable = false;
770   bool found = false;
771
772   // default property?
773   if ( ( index < DEFAULT_PROPERTY_MAX_COUNT ) && mDefaultProperties )
774   {
775     found = GetDefaultPropertyField( mDefaultProperties, mDefaultPropertyCount,index, &Dali::PropertyDetails::writable, writable );
776   }
777   else if( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) )
778   {
779     writable = true; // animatable property is writable
780     found = true;
781   }
782   else
783   {
784     RegisteredPropertyContainer::const_iterator iter = find_if( mRegisteredProperties.begin(), mRegisteredProperties.end(),
785                                                             PairFinder< Property::Index, RegisteredPropertyPair >( index ) );
786     if ( iter != mRegisteredProperties.end() )
787     {
788       writable = iter->second.setFunc ? true : false;
789       found = true;
790     }
791   }
792
793   // if not found, continue to base
794   if( !found )
795   {
796     if( GetBaseType( mBaseType, mTypeRegistry, mBaseTypeName ) )
797     {
798       // call base type recursively
799       writable = mBaseType->IsPropertyWritable( index );
800     }
801     else
802     {
803       DALI_LOG_ERROR( "Property index %d not found\n", index );
804     }
805   }
806
807   return writable;
808 }
809
810 bool TypeInfo::IsPropertyAnimatable( Property::Index index ) const
811 {
812   bool animatable = false;
813   bool found = false;
814
815   // default property?
816   if ( ( index < DEFAULT_PROPERTY_MAX_COUNT ) && mDefaultProperties )
817   {
818     found = GetDefaultPropertyField( mDefaultProperties, mDefaultPropertyCount,index, &Dali::PropertyDetails::animatable, animatable );
819   }
820   else if ( ( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX ) )
821   {
822     // Type Registry event-thread only properties are not animatable.
823     animatable = false;
824     found = true;
825   }
826   else if( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) )
827   {
828     animatable = true;
829     found = true;
830   }
831
832   // if not found, continue to base
833   if( !found )
834   {
835     if( GetBaseType( mBaseType, mTypeRegistry, mBaseTypeName ) )
836     {
837       // call base type recursively
838       animatable = mBaseType->IsPropertyAnimatable( index );
839     }
840     else
841     {
842       DALI_LOG_ERROR( "Property index %d not found\n", index );
843     }
844   }
845
846   return animatable;
847 }
848
849 bool TypeInfo::IsPropertyAConstraintInput( Property::Index index ) const
850 {
851   bool constraintInput = false;
852   bool found = false;
853
854   // default property?
855   if ( ( index < DEFAULT_PROPERTY_MAX_COUNT ) && mDefaultProperties )
856   {
857     found = GetDefaultPropertyField( mDefaultProperties, mDefaultPropertyCount,index, &Dali::PropertyDetails::constraintInput, constraintInput );
858   }
859   else if ( ( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX ) )
860   {
861     // Type Registry event-thread only properties cannot be used as constraint input
862     constraintInput = false;
863     found = true;
864   }
865   else if( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) )
866   {
867     constraintInput = true;
868     found = true;
869   }
870
871   // if not found, continue to base
872   if( !found )
873   {
874     if( GetBaseType( mBaseType, mTypeRegistry, mBaseTypeName ) )
875     {
876       // call base type recursively
877       constraintInput = mBaseType->IsPropertyAConstraintInput( index );
878     }
879     else
880     {
881       DALI_LOG_ERROR( "Property index %d not found\n", index );
882     }
883   }
884
885   return constraintInput;
886 }
887
888
889 Property::Type TypeInfo::GetPropertyType( Property::Index index ) const
890 {
891   Property::Type type( Property::NONE );
892   bool found = false;
893
894   // default property?
895   if ( ( index < DEFAULT_PROPERTY_MAX_COUNT ) && mDefaultProperties )
896   {
897     found = GetDefaultPropertyField( mDefaultProperties, mDefaultPropertyCount,index, &Dali::PropertyDetails::type, type );
898   }
899   else
900   {
901     RegisteredPropertyContainer::const_iterator iter = find_if( mRegisteredProperties.begin(), mRegisteredProperties.end(),
902                                                             PairFinder< Property::Index, RegisteredPropertyPair >( index ) );
903
904     if ( iter != mRegisteredProperties.end() )
905     {
906       if( iter->second.componentIndex == Property::INVALID_COMPONENT_INDEX )
907       {
908         type = iter->second.type;
909         found = true;
910       }
911       else
912       {
913         // If component index is set, then we should return FLOAT
914         type = Property::FLOAT;
915         found = true;
916       }
917     }
918   }
919
920   if( !found )
921   {
922     if( GetBaseType( mBaseType, mTypeRegistry, mBaseTypeName ) )
923     {
924       // call base type recursively
925       type = mBaseType->GetPropertyType( index );
926     }
927     else
928     {
929       DALI_LOG_ERROR( "Property index %d not found\n", index );
930     }
931   }
932
933   return type;
934 }
935
936 Property::Value TypeInfo::GetPropertyDefaultValue( Property::Index index ) const
937 {
938   PropertyDefaultValueContainer::const_iterator iter = find_if( mPropertyDefaultValues.begin(), mPropertyDefaultValues.end(),
939                                                     PairFinder< Property::Index, PropertyDefaultValuePair >( index ) );
940   if( iter != mPropertyDefaultValues.end() )
941   {
942     return iter->second;
943   }
944   else
945   {
946     return Property::Value( GetPropertyType( index ) );
947   }
948 }
949
950 void TypeInfo::SetProperty( BaseObject *object, Property::Index index, const Property::Value& value ) const
951 {
952   RegisteredPropertyContainer::const_iterator iter = find_if( mRegisteredProperties.begin(), mRegisteredProperties.end(),
953                                                               PairFinder< Property::Index, RegisteredPropertyPair >( index ) );
954   if ( iter != mRegisteredProperties.end() )
955   {
956     if( iter->second.setFunc )
957     {
958       if( mCSharpType )
959       {
960         // CSharp wants a property name not an index
961         const std::string& name = (iter->second).name;
962
963         iter->second.cSharpSetFunc( object,name.c_str(), const_cast< Property::Value* >(&value) );
964       }
965       else
966       {
967         iter->second.setFunc( object, index, value );
968       }
969     }
970   }
971   else if( GetBaseType( mBaseType, mTypeRegistry, mBaseTypeName ) )
972   {
973     // call base type recursively
974     mBaseType->SetProperty( object, index, value );
975   }
976   else
977   {
978     DALI_LOG_ERROR( "Property index %d not found\n", index );
979   }
980 }
981
982 void TypeInfo::SetProperty( BaseObject *object, const std::string& name, const Property::Value& value ) const
983 {
984   RegisteredPropertyContainer::const_iterator iter = find_if( mRegisteredProperties.begin(), mRegisteredProperties.end(),
985                                                               PropertyNameFinder< RegisteredPropertyPair >( name ) );
986   if ( iter != mRegisteredProperties.end() )
987   {
988     DALI_ASSERT_ALWAYS( iter->second.setFunc && "Trying to write to a read-only property" );
989
990     if( mCSharpType )
991     {
992       // CSharp wants a property name not an index
993       iter->second.cSharpSetFunc( object,name.c_str(), const_cast< Property::Value* >(&value ));
994     }
995     else
996     {
997       iter->second.setFunc( object, iter->first, value );
998     }
999   }
1000   else if( GetBaseType( mBaseType, mTypeRegistry, mBaseTypeName ) )
1001   {
1002     // call base type recursively
1003     mBaseType->SetProperty( object, name, value );
1004   }
1005   else
1006   {
1007     DALI_LOG_ERROR( "Property %s not found", name.c_str() );
1008   }
1009 }
1010
1011 Property::Value TypeInfo::GetProperty( const BaseObject *object, Property::Index index ) const
1012 {
1013   RegisteredPropertyContainer::const_iterator iter = find_if( mRegisteredProperties.begin(), mRegisteredProperties.end(),
1014                                                           PairFinder< Property::Index, RegisteredPropertyPair >( index ) );
1015   if( iter != mRegisteredProperties.end() )
1016   {
1017     if( mCSharpType ) // using csharp property get which returns a pointer to a Property::Value
1018     {
1019       // CSharp wants a property name not an index
1020       // CSharp callback can't return an object by value, it can only return a pointer
1021       // CSharp has ownership of the pointer contents, which is fine because we are returning by from this function by value
1022       const std::string& name = (iter->second).name;
1023
1024       return *( iter->second.cSharpGetFunc( const_cast< BaseObject* >( object ), name.c_str()) );
1025
1026     }
1027     else
1028     {
1029       // Need to remove the constness here as CustomActor will not be able to call Downcast with a const pointer to the object
1030       return iter->second.getFunc( const_cast< BaseObject* >( object ), index );
1031     }
1032   }
1033
1034   if( GetBaseType( mBaseType, mTypeRegistry, mBaseTypeName ) )
1035   {
1036     // call base type recursively
1037     return mBaseType->GetProperty( object, index );
1038   }
1039
1040   DALI_LOG_ERROR( "Property index %d not found\n", index );
1041   return Property::Value();
1042 }
1043
1044 Property::Value TypeInfo::GetProperty( const BaseObject *object, const std::string& name ) const
1045 {
1046   RegisteredPropertyContainer::const_iterator iter = find_if( mRegisteredProperties.begin(), mRegisteredProperties.end(),
1047                                                             PropertyNameFinder< RegisteredPropertyPair >( name ) );
1048
1049
1050
1051   if( iter != mRegisteredProperties.end() )
1052   {
1053     if( mCSharpType ) // using csharp property get which returns a pointer to a Property::Value
1054     {
1055        // CSharp wants a property name not an index
1056        // CSharp callback can't return an object by value, it can only return a pointer
1057        // CSharp has ownership of the pointer contents, which is fine because we are returning by from this function by value
1058        return *( iter->second.cSharpGetFunc( const_cast< BaseObject* >( object ), name.c_str() ));
1059
1060     }
1061     else
1062     {
1063       // Need to remove the constness here as CustomActor will not be able to call Downcast with a const pointer to the object
1064       return iter->second.getFunc( const_cast< BaseObject* >( object ), iter->first );
1065     }
1066   }
1067
1068   if( GetBaseType( mBaseType, mTypeRegistry, mBaseTypeName ) )
1069   {
1070     // call base type recursively
1071     return mBaseType->GetProperty( object, name );
1072   }
1073
1074   DALI_LOG_ERROR( "Property %s not found", name.c_str() );
1075   return Property::Value();
1076 }
1077
1078 } // namespace Internal
1079
1080 } // namespace Dali