-const TypeInfo* Object::GetTypeInfo() const
-{
- if ( !mTypeInfo )
- {
- // This uses a dynamic_cast so can be quite expensive so we only really want to do it once
- // especially as the type-info does not change during the life-time of an application
-
- Dali::TypeInfo typeInfoHandle = TypeRegistry::Get()->GetTypeInfo( this );
- if ( typeInfoHandle )
- {
- mTypeInfo = &GetImplementation( typeInfoHandle );
- }
- }
-
- return mTypeInfo;
-}
-
-void Object::ApplyConstraint( ConstraintBase& constraint )
-{
- if( !mConstraints )
- {
- mConstraints = new ConstraintContainer;
- }
- mConstraints->push_back( Dali::Constraint( &constraint ) );
-}
-
-void Object::RemoveConstraint( ConstraintBase& constraint )
-{
- // NULL if the Constraint sources are destroyed before Constraint::Apply()
- if( mConstraints )
- {
- ConstraintIter it( std::find( mConstraints->begin(), mConstraints->end(), Dali::Constraint( &constraint ) ) );
- if( it != mConstraints->end() )
- {
- mConstraints->erase( it );
- }
- }
-}
-
-void Object::RemoveConstraints()
-{
- // guard against constraint sending messages during core destruction
- if( mConstraints && Stage::IsInstalled() )
- {
- // If we have nothing in the scene-graph, just clear constraint containers
- const SceneGraph::PropertyOwner* propertyOwner = GetSceneObject();
- if ( NULL != propertyOwner )
- {
- const ConstraintConstIter endIter = mConstraints->end();
- for ( ConstraintIter iter = mConstraints->begin(); endIter != iter; ++iter )
- {
- GetImplementation( *iter ).RemoveInternal();
- }
- }
-
- delete mConstraints;
- mConstraints = NULL;
- }
-}
-
-void Object::RemoveConstraints( unsigned int tag )
-{
- // guard against constraint sending messages during core destruction
- if( mConstraints && Stage::IsInstalled() )
- {
- ConstraintIter iter( mConstraints->begin() );
- while(iter != mConstraints->end() )
- {
- ConstraintBase& constraint = GetImplementation( *iter );
- if( constraint.GetTag() == tag )
- {
- GetImplementation( *iter ).RemoveInternal();
- iter = mConstraints->erase( iter );
- }
- else
- {
- ++iter;
- }
- }
-
- if ( mConstraints->empty() )
- {
- delete mConstraints;
- mConstraints = NULL;
- }
- }
-}
-
-void Object::SetTypeInfo( const TypeInfo* typeInfo )
-{
- mTypeInfo = typeInfo;
-}
-
-Object::~Object()
-{
- // Notification for observers
- for( ConstObserverIter iter = mObservers.Begin(), endIter = mObservers.End(); iter != endIter; ++iter)
- {
- (*iter)->ObjectDestroyed(*this);
- }
-
- delete mConstraints;
- delete mPropertyNotifications;
-}
-
-CustomPropertyMetadata* Object::FindCustomProperty( Property::Index index ) const
-{
- CustomPropertyMetadata* property( NULL );
- int arrayIndex = index - PROPERTY_CUSTOM_START_INDEX;
- if( arrayIndex >= 0 )
- {
- if( arrayIndex < (int)mCustomProperties.Count() ) // we can only access the first 2 billion custom properties
- {
- property = static_cast<CustomPropertyMetadata*>(mCustomProperties[ arrayIndex ]);
- }
- }
- return property;
-}
-
-AnimatablePropertyMetadata* Object::FindAnimatableProperty( Property::Index index ) const
-{
- for ( int arrayIndex = 0; arrayIndex < (int)mAnimatableProperties.Count(); arrayIndex++ )
- {
- AnimatablePropertyMetadata* property = static_cast<AnimatablePropertyMetadata*>( mAnimatableProperties[ arrayIndex ] );
- if( property->index == index )
- {
- return property;
- }
- }
- return NULL;
-}
-
-AnimatablePropertyMetadata* Object::RegisterAnimatableProperty(Property::Index index) const
-{
- DALI_ASSERT_ALWAYS( (( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ))
- && "Property index is out of bounds" );
-
- // check whether the animatable property is registered already, if not then register one.
- AnimatablePropertyMetadata* animatableProperty = FindAnimatableProperty( index );
- if(!animatableProperty)
- {
- const TypeInfo* typeInfo( GetTypeInfo() );
- if (typeInfo)
- {
- Property::Index basePropertyIndex = typeInfo->GetBasePropertyIndex(index);
- if(basePropertyIndex == Property::INVALID_INDEX)
- {
- // If the property is not a component of a base property, register the whole property itself.
- index = RegisterSceneGraphProperty(typeInfo->GetPropertyName(index), index, Property::Value(typeInfo->GetPropertyType(index)));
- }
- else
- {
- // Since the property is a component of a base property, check whether the base property is regsitered.
- animatableProperty = FindAnimatableProperty( basePropertyIndex );
- if(!animatableProperty)
- {
- // If the base property is not registered yet, register the base property first.
- if(Property::INVALID_INDEX != RegisterSceneGraphProperty(typeInfo->GetPropertyName(basePropertyIndex), basePropertyIndex, Property::Value(typeInfo->GetPropertyType(basePropertyIndex))))
- {
- animatableProperty = static_cast<AnimatablePropertyMetadata*>(mAnimatableProperties[mAnimatableProperties.Size()-1]);
- }
- }
-
- if(animatableProperty)
- {
- // Create the metadata for the property component.
- mAnimatableProperties.PushBack( new AnimatablePropertyMetadata( index, typeInfo->GetComponentIndex(index), animatableProperty->type, animatableProperty->GetSceneGraphProperty() ) );
- }
- }
-
- // The metadata has just been added and therefore should be in the end of the vector.
- animatableProperty = static_cast<AnimatablePropertyMetadata*>(mAnimatableProperties[mAnimatableProperties.Size()-1]);
- }
- }
-
- return animatableProperty;
-}
-