OMKDuplicatedAttributeExtension.inl

Go to the documentation of this file.
00001 #ifndef OMK_DUPLICATEDATTRIBUTEEXTENSION_INL
00002 #define OMK_DUPLICATEDATTRIBUTEEXTENSION_INL
00003 
00004 #include "OMKDuplicatedAttributeExtension.h"
00005 #include "OMKExtensibleSimulatedObject.inl"
00006 #include "OMKParametersAccessor.inl"
00007 //-------------------------------------------------------------------------
00008 namespace OMK
00009 {
00010 //-------------------------------------------------------------------------
00011 // The creator for DuplicatedAttributeExtension
00012 template< typename AttributType, typename Type >
00013 class DuplicatedAttributeExtensionCreatorT : public ExtensionCreator
00014 {
00015 public:
00016         Extension* operator()( ExtensibleSimulatedObject* owner, const Name& id ) const
00017         {
00018                 return new DuplicatedAttributeExtension< AttributType, Type >( owner, id ) ;
00019         }
00020 } ;
00021 #define STRINGIFY_IN_DUPLICATED_ATTRIBUTE_EXTENSION(x) #x
00022 #define REGISTER_DUPLICATED_ATTRIBUTE_EXTENSION_FACTORY( AttributType, Type )\
00023   /* Factory */ \
00024   template <> Name OMK::DuplicatedAttributeExtension< AttributType, Type >::OMK_CLASS_ID( std::string( STRINGIFY_IN_DUPLICATED_ATTRIBUTE_EXTENSION( DuplicatedAttribute_ ## AttributType ## _SeeAsA_ ## Type ) ) ) ; \
00025   template <> const bool OMK::DuplicatedAttributeExtension< AttributType, Type >::REGISTERED_IN_EXTENSION_FACTORY( \
00026       OMK::ExtensionFactory::getInstance(). \
00027       registerCreator< OMK::DuplicatedAttributeExtensionCreatorT< AttributType, Type > > \
00028       ( OMK::DuplicatedAttributeExtension< AttributType, Type >::OMK_CLASS_ID ) )
00029 //-------------------------------------------------------------------------
00030 template< typename AttributType, typename Type >
00031 DuplicatedAttributeExtension< AttributType, Type >::DuplicatedAttributeExtension( ExtensibleSimulatedObject* owner, const Name& id )
00032 : OMK::ExtensionT< ExtensibleSimulatedObject >( owner, id ),
00033   _duplicatedAttribute( 0 )
00034 {
00035 }
00036 //-------------------------------------------------------------------------
00037 template< typename AttributType, typename Type >
00038 DuplicatedAttributeExtension< AttributType, Type >::~DuplicatedAttributeExtension()
00039 {
00040   _owner->removeAttribute( _duplicatedAttribute->getId() ) ;
00041   delete _duplicatedAttribute ;
00042   _duplicatedAttribute = 0 ;
00043 }
00044 //-------------------------------------------------------------------------
00045 template< typename AttributType, typename Type >
00046 bool DuplicatedAttributeExtension< AttributType, Type >::loadExtensionParameters( const ConfigurationParameterDescriptor * node )
00047 {
00048         // Retrieve the visual objects
00049   bool ok = true ;
00050   // Attribute to offset
00051   std::string attributeName ;
00052   ok = ok && ParametersAccessor::get( node, "Attribute", attributeName, _owner ) ;
00053   if( ok )
00054   {
00055     Name id( attributeName + "_duplicated_" + typeid( Type ).name() ) ;
00056     ParametersAccessor::get( node, "Id", id ) ;
00057     IAccessorT< AttributType >* accessor = _owner->getBaseAttribute< AttributType >( Name( attributeName ) ) ;
00058     ok = accessor != 0 ;
00059     _duplicatedAttribute = new AttributeAccT< Type, AttributType >( id, accessor );
00060     _owner->addAttribute( *_duplicatedAttribute ) ;
00061   }
00062   return ok ;
00063 }
00064 
00065 } 
00066 
00067 #endif // OMK_DUPLICATEDATTRIBUTEEXTENSION_INL

logo OpenMask

Documentation generated on Mon Jun 9 11:45:56 2008

Generated with doxygen by Dimitri van Heesch ,   1997-2007