00001 #ifndef TypedAttribute_H
00002 #define TypedAttribute_H
00003
00004 #include "OBTAbstractAttribute.h"
00005 #include "OBT_ASSERT.h"
00006
00007 namespace OBT
00008 {
00018 template< class TOwner, class TAttribute >
00019 class TypedAttribute : public AbstractAttribute
00020 {
00021 public:
00022
00023
00025 typedef const TAttribute& ( TOwner::*Getter )( ) const ;
00027 typedef void ( TOwner::*Setter )( const TAttribute& value ) ;
00028
00029 typedef const TAttribute& value_type ;
00030 typedef TOwner owner_type ;
00031
00038 TypedAttribute( const char* name, Getter getter, Setter setter ) ;
00039
00043 virtual ~TypedAttribute() ;
00044
00057 const TAttribute& getValue( const TOwner& owner ) const ;
00058
00068 void setValue( TOwner& owner, const TAttribute& value ) const ;
00069
00071
00072 bool isReadOnly() const ;
00073 virtual const RTTI& getOwnerRTTI() const ;
00074 virtual const RTTI& getRTTI() const ;
00076
00081 static const RTTI& getClassRTTI() ;
00082
00083 private:
00084
00086 Getter _getter ;
00087
00089 Setter _setter ;
00090 } ;
00091
00092
00093
00094
00095 template< class TOwner,class TAttribute >
00096 TypedAttribute< TOwner, TAttribute >::TypedAttribute( const char* name, Getter getter, Setter setter )
00097 :
00098 AbstractAttribute( name ),
00099 _getter( getter ),
00100 _setter( setter )
00101 {
00102 OBT_DBG_ASSERT( _getter != NULL ) ;
00103 }
00104
00105
00106
00107
00108 template< class TOwner,class TAttribute >
00109 TypedAttribute<TOwner, TAttribute>::~TypedAttribute( )
00110 {
00111
00112 }
00113
00114
00115
00116
00117 template< class TOwner,class TAttribute >
00118 bool
00119 TypedAttribute<TOwner, TAttribute>::isReadOnly() const
00120 {
00121 return ( _setter == NULL ) ;
00122 }
00123
00124
00125
00126
00127 template <class TOwner, class TAttribute>
00128 const TAttribute&
00129 TypedAttribute< TOwner, TAttribute >::getValue( const TOwner& owner ) const
00130 {
00131 return ( owner.*_getter )() ;
00132 }
00133
00134
00135
00136
00137 template <class TOwner, class TAttribute >
00138 void TypedAttribute< TOwner, TAttribute >::setValue( TOwner& owner, const TAttribute& value ) const
00139 {
00140
00141 OBT_DBG_ASSERT( isReadOnly( ) == false ) ;
00142 ( owner.*_setter )( value ) ;
00143 }
00144
00145
00146
00147
00148 template <class TOwner, class TAttribute >
00149 const OBT::RTTI&
00150 TypedAttribute< TOwner, TAttribute >::getOwnerRTTI( ) const
00151 {
00152 return TOwner::getClassRTTI() ;
00153 }
00154
00155
00156
00157
00158 template <class TOwner, class TAttribute >
00159 const RTTI&
00160 TypedAttribute< TOwner, TAttribute >::getRTTI( ) const
00161 {
00162 return TAttribute::getClassRTTI() ;
00163 }
00164
00165
00166
00167
00168 template <class TOwner, class TAttribute >
00169 const RTTI&
00170 TypedAttribute< TOwner, TAttribute >::getClassRTTI( )
00171 {
00172 return TAttribute::getClassRTTI() ;
00173 }
00174 }
00175 #endif //header