00001 #ifndef RENDERGROUPPROXY_H 00002 #define RENDERGROUPPROXY_H 00003 00004 #include "Types.h" 00005 #include "PointerProperty.h" 00006 #include "Rendergroup.h" 00007 #include "BindingInterface.h" 00008 00009 namespace RenderTools { 00010 00011 template < class T > 00012 class PropertyProxy : public BindingInterface, public PointerProperty< T > { 00013 public: 00014 00015 PropertyProxy( void ): 00016 PointerProperty< T >( shared_ptr< T >() ){ 00017 } 00018 00019 virtual const string getTypeName( bool ofComponent = false ) const { 00020 T t; 00021 if( ofComponent ){ 00022 return( RenderTools::getTypeName( t ) ); 00023 } 00024 return( RenderTools::getTypeName( t ) + "Proxy" ); 00025 } 00026 00027 virtual void onInitialize( void ){ 00028 if( ! m_pointer ){ 00029 PropertyPtr p = find( this->getValue() ); 00030 if( p ){ 00031 m_pointer = dynamic_pointer_cast< T >( p ); 00032 } 00033 } 00034 } 00035 00036 virtual void onBind( int unit = -1 ){ 00037 onInitialize(); 00038 } 00039 00040 virtual void onUnbind( int unit = -1 ){ 00041 m_pointer.reset(); 00042 } 00043 00044 virtual const string getValue( int vectorElement = -1 ) const { 00045 return( m_proxyName ); 00046 } 00047 00048 virtual bool setValue( const string value, int vectorElement = -1 ){ 00049 string prevName = m_name; 00050 m_proxyName = value; 00051 return( m_proxyName != prevName ); 00052 } 00053 00054 virtual void setPointer( const shared_ptr< T > p ){ 00055 if( p ){ 00056 m_proxyName = p->getPath(); 00057 m_pointer = dynamic_pointer_cast< T >( p ); 00058 sendPropertyEvent( PropertyEvent( PropertyEvent::CHANGED, getSharedPtr< AbstractProperty >() ) ); 00059 } 00060 } 00061 00062 protected: 00063 string m_proxyName; 00064 }; 00065 00066 template< class T > 00067 inline ostream & operator << ( ostream & os, const shared_ptr< PropertyProxy< T > > rhs ){ 00068 return( os ); 00069 } 00070 00071 template< class T > 00072 inline const istream & operator >> ( const istream & is, shared_ptr< PropertyProxy< T > > rhs ){ 00073 return( is ); 00074 } 00075 00076 }; // namespace RenderTools 00077 00078 #endif
1.5.8