00001 #ifndef PROPERTY_H
00002 #define PROPERTY_H
00003
00004 #include "Types.h"
00005 #include "AbstractProperty.h"
00006 #include "StringProperty.h"
00007 #include "PointerProperty.h"
00008 #include "VectorProperty.h"
00009 #include "EnumProperty.h"
00010 #include "PropertyProxy.h"
00011 #include "PropertyProxyContainer.h"
00012 #include "Factory.h"
00013
00014 namespace RenderTools {
00015
00018 template< typename T >
00019 inline PropertyPtr createProperty( AbstractPropertyContainer * owner, const string name, T & value, const EnumList enums, AbstractProperty::SemanticMask semantic = AbstractProperty::NONE ){
00020 if( owner && owner->isProperty( name ) ){
00021 owner->removeProperty( owner->findProperty( name ), true );
00022 }
00023 shared_ptr< EnumProperty< T > >p( new EnumProperty<T>( shared_ptr< T >( new T( value ) ) ) );
00024 p->setEnums( enums );
00025 p->createProperties();
00026 p->setName( name );
00027 p->setSemantic( semantic );
00028 AbstractPropertyContainer::addPropertyToOwner( owner, p );
00029 return( p );
00030 }
00031
00034 template< typename T >
00035 inline PropertyPtr createProperty( AbstractPropertyContainer * owner, const string name, T & value, AbstractProperty::SemanticMask semantic = AbstractProperty::NONE ){
00036 if( owner && owner->isProperty( name ) ){
00037 owner->removeProperty( owner->findProperty( name ), true );
00038 }
00039 PropertyPtr p( new PointerProperty<T>( shared_ptr< T >( new T( value ) ) ) );
00040 p->createProperties();
00041 p->setName( name );
00042 p->setSemantic( semantic );
00043 AbstractPropertyContainer::addPropertyToOwner( owner, p );
00044 return( p );
00045 }
00046
00049 inline PropertyPtr createProperty( AbstractPropertyContainer * owner, const string name, string * value, AbstractProperty::SemanticMask semantic = AbstractProperty::NONE ){
00050 if( owner && owner->isProperty( name ) ){
00051 owner->removeProperty( owner->findProperty( name ), true );
00052 }
00053 PropertyPtr p( new StringProperty( shared_ptr< string >( value, AbstractProperty::NullDeleter() ) ) );
00054 p->createProperties();
00055 p->setName( name );
00056 p->setSemantic( semantic );
00057 AbstractPropertyContainer::addPropertyToOwner( owner, p );
00058 return( p );
00059 }
00060
00063 inline PropertyPtr createProperty( AbstractPropertyContainer * owner, const string name, const char * value, AbstractProperty::SemanticMask semantic = AbstractProperty::NONE ){
00064 if( owner && owner->isProperty( name ) ){
00065 owner->removeProperty( owner->findProperty( name ), true );
00066 }
00067 PropertyPtr p( new StringProperty( shared_ptr< string > ( new string( value ) ) ) );
00068 p->createProperties();
00069 p->setName( name );
00070 p->setSemantic( semantic );
00071 AbstractPropertyContainer::addPropertyToOwner( owner, p );
00072 return( p );
00073 }
00074
00075 inline PropertyPtr createProperty( AbstractPropertyContainer * owner, const string name, const string * value, AbstractProperty::SemanticMask semantic = AbstractProperty::NONE ){
00076 return( createProperty( owner, name, const_cast< string * >( value ), semantic ) );
00077 }
00078
00079 inline PropertyPtr createProperty( AbstractPropertyContainer * owner, const string name, string & value, AbstractProperty::SemanticMask semantic = AbstractProperty::NONE ){
00080 return( createProperty( owner, name, value.c_str(), semantic ) );
00081 }
00082
00083 inline PropertyPtr createProperty( AbstractPropertyContainer * owner, const string name, const string & value, AbstractProperty::SemanticMask semantic = AbstractProperty::NONE ){
00084 return( createProperty( owner, name, const_cast< string & >( value ), semantic ) );
00085 }
00086
00087 inline PropertyPtr createProperty( AbstractPropertyContainer * owner, const string name, string value, AbstractProperty::SemanticMask semantic = AbstractProperty::NONE ){
00088 return( createProperty( owner, name, value.c_str(), semantic ) );
00089 }
00090
00093 template< typename T >
00094 inline PropertyPtr createProperty( AbstractPropertyContainer * owner, const string name, T * value, AbstractProperty::SemanticMask semantic = AbstractProperty::NONE ){
00095 if( owner && owner->isProperty( name ) ){
00096 owner->removeProperty( owner->findProperty( name ), true );
00097 }
00098 PropertyPtr p( new PointerProperty<T>( shared_ptr< T >( value, AbstractProperty::NullDeleter() ) ) );
00099 p->createProperties();
00100 p->setName( name );
00101 p->setSemantic( semantic );
00102 AbstractPropertyContainer::addPropertyToOwner( owner, p );
00103 return( p );
00104 }
00105
00108 template< typename T >
00109 inline PropertyPtr createProperty( AbstractPropertyContainer * owner, const string name, vector<T> * value, AbstractProperty::SemanticMask semantic = AbstractProperty::NONE ){
00110 if( owner && owner->isProperty( name ) ){
00111 owner->removeProperty( owner->findProperty( name ), true );
00112 }
00113 PropertyPtr p( new VectorProperty<T>( shared_ptr< vector< T > >( value, AbstractProperty::NullDeleter() ) ) );
00114 p->createProperties();
00115 p->setName( name );
00116 p->setSemantic( semantic );
00117 AbstractPropertyContainer::addPropertyToOwner( owner, p );
00118 return( p );
00119 }
00120
00123 template< typename T >
00124 inline PropertyPtr createProperty( AbstractPropertyContainer * owner, const string name, shared_ptr< T > * pointer ){
00125 if( owner && owner->isProperty( name ) ){
00126 owner->removeProperty( owner->findProperty( name ), true );
00127 }
00128 * pointer = shared_ptr< T >( new T() );
00129 ( * pointer )->createProperties();
00130 ( * pointer )->setName( name );
00131 AbstractPropertyContainer::addPropertyToOwner( owner, * pointer );
00132 return( * pointer );
00133
00134 }
00135
00136 template< class T >
00137 inline shared_ptr< PropertyProxy< T > > createProperty( shared_ptr< PropertyProxyContainer< T > > & owner, string name ){
00138 if( owner && owner->isProperty( name ) ){
00139 owner->removeProperty( owner->findProperty( name ), true );
00140 }
00141 shared_ptr< PropertyProxy< T > > pointer( new PropertyProxy< T >() );
00142 pointer->createProperties();
00143 pointer->setName( name );
00144 AbstractPropertyContainer::addPropertyToOwner( owner.get(), pointer );
00145 return( pointer );
00146 }
00147
00148 };
00149
00150 #endif