00001 #ifndef VECTORPROPERTY_H 00002 #define VECTORPROPERTY_H 00003 00004 #include "Types.h" 00005 #include "Util.h" 00006 #include "AbstractProperty.h" 00007 #include "AbstractPropertyContainer.h" 00008 00009 namespace RenderTools { 00010 00011 template< class T > 00012 class VectorProperty : public AbstractProperty { 00013 public: 00014 00015 VectorProperty( const shared_ptr< vector<T> > & value ): 00016 AbstractProperty(), 00017 m_vector( value ){ 00018 } 00019 00020 virtual void onInitialize( void ){ 00021 00022 } 00023 00024 virtual const string getTypeName( bool ofComponent ) const { 00025 T t; 00026 return( RenderTools::getTypeName( t, ofComponent ) ); 00027 } 00028 00029 virtual bool isVector( void ) const { 00030 return( true ); 00031 } 00032 00033 virtual unsigned int getNumVectorElements( void ) const { 00034 return( m_vector.get()->size() ); 00035 } 00036 00037 virtual bool setValue( const string toValue, int element = -1 ){ 00038 string value = toValue; 00039 if( toValue == "" ){ 00040 value = string( " " ); 00041 } 00042 stringstream s( AbstractPropertyContainer::interpret( value ) ); 00043 string prevValue = getValue(); 00044 if( element >= 0 ){ 00045 s >> m_vector.get()[ element ]; 00046 } 00047 else { 00048 for( unsigned int i = 0; i < m_vector->size(); i++ ){ 00049 s >> m_vector.get()[ i ]; 00050 } 00051 } 00052 return( getValue() != prevValue ); 00053 } 00054 00055 virtual const string getValue( int element = -1 ) const { 00056 stringstream s; 00057 if( element >= 0 ){ 00058 s << m_vector.get()[ element ] << string( " " ); 00059 } 00060 else { 00061 for( unsigned int i = 0; i < m_vector->size(); i++ ){ 00062 s << m_vector.get()[ i ] << string( " " ); 00063 } 00064 } 00065 return( trim( s.str() ) ); 00066 } 00067 00068 virtual const void * getDataPointer( unsigned int offset ) const { 00069 return( ( void * ) & m_vector.get()[ offset ] ); 00070 } 00071 protected: 00072 shared_ptr< vector< T > > m_vector; 00073 }; 00074 00075 }; // namespace RenderTools 00076 00077 00078 #endif
1.5.8