00001 #ifndef OBTPrimitiveAttribute_H
00002 #define OBTPrimitiveAttribute_H
00003
00004 #include "OBTRTTI.h"
00005
00006 namespace OBT
00007 {
00020 template< class TOwner, class TAttribute, unsigned long typeID >
00021 class PrimitiveAttribute : public AbstractAttribute
00022 {
00023 public:
00024
00026 typedef TAttribute ( TOwner::*Getter )( ) const ;
00028 typedef void ( TOwner::*Setter )( TAttribute value );
00029
00030 typedef TAttribute value_type ;
00031 typedef TOwner owner_type ;
00032
00040 PrimitiveAttribute( const char* name, Getter getter, Setter setter ) ;
00041
00045 virtual ~PrimitiveAttribute() ;
00046
00059 TAttribute getValue( const TOwner& owner ) const ;
00060
00073 void setValue( TOwner& owner, TAttribute value ) const ;
00074
00076
00077 bool isReadOnly() const ;
00078 virtual const RTTI& getOwnerRTTI() const ;
00079 virtual const RTTI& getRTTI() const ;
00081
00086 static const RTTI& getClassRTTI() ;
00087
00088 private:
00089
00091 Getter _getter ;
00092
00094 Setter _setter ;
00095
00097 static const RTTI _rtti ;
00098 } ;
00099
00100
00101 template < class TOwner, class TAttribute, unsigned long typeID >
00102 const RTTI PrimitiveAttribute< TOwner, TAttribute, typeID >::_rtti( typeID, typeid( PrimitiveAttribute< TOwner, TAttribute, typeID > ).name(), NULL, 1,
00103 &( AbstractAttribute::getClassRTTI() ) ) ;
00104
00105
00106
00107
00108 template < class TOwner, class TAttribute, unsigned long typeID >
00109 PrimitiveAttribute< TOwner, TAttribute, typeID >::PrimitiveAttribute( const char* name, Getter getter, Setter setter )
00110 :
00111 AbstractAttribute( name ),
00112 _getter( getter ),
00113 _setter( setter )
00114 {
00115 OBT_DBG_ASSERT( _getter != NULL ) ;
00116 }
00117
00118
00119
00120
00121 template < class TOwner, class TAttribute, unsigned long typeID >
00122 PrimitiveAttribute< TOwner, TAttribute, typeID >::~PrimitiveAttribute( )
00123 {
00124 }
00125
00126
00127
00128
00129 template < class TOwner, class TAttribute, unsigned long typeID >
00130 bool
00131 PrimitiveAttribute< TOwner, TAttribute, typeID >::isReadOnly() const
00132 {
00133 return ( _setter == NULL ) ;
00134 }
00135
00136
00137
00138
00139 template < class TOwner, class TAttribute, unsigned long typeID >
00140 TAttribute
00141 PrimitiveAttribute< TOwner, TAttribute, typeID >::getValue( const TOwner& owner ) const
00142 {
00143 return ( owner.*_getter )() ;
00144 }
00145
00146
00147
00148
00149 template < class TOwner, class TAttribute, unsigned long typeID >
00150 void
00151 PrimitiveAttribute< TOwner, TAttribute, typeID >::setValue( TOwner& owner, TAttribute value ) const
00152 {
00153
00154 OBT_DBG_ASSERT( isReadOnly( ) == false ) ;
00155 ( owner.*_setter )( value ) ;
00156 }
00157
00158
00159
00160
00161 template < class TOwner, class TAttribute, unsigned long typeID >
00162 const RTTI&
00163 PrimitiveAttribute< TOwner, TAttribute, typeID >::getOwnerRTTI() const
00164 {
00165 return TOwner::getClassRTTI() ;
00166 }
00167
00168
00169
00170
00171 template < class TOwner, class TAttribute, unsigned long typeID >
00172 const RTTI&
00173 PrimitiveAttribute< TOwner, TAttribute, typeID >::getRTTI ( ) const
00174 {
00175 return _rtti ;
00176 }
00177
00178
00179
00180
00181 template < class TOwner, class TAttribute, unsigned long typeID >
00182 const RTTI&
00183 PrimitiveAttribute< TOwner, TAttribute, typeID >::getClassRTTI( )
00184 {
00185 return _rtti ;
00186 }
00187
00188 template < class TOwner >
00189 class BoolAttribute : public PrimitiveAttribute< TOwner, bool, 1991421614 >
00190 {
00191 public :
00192
00193 BoolAttribute( const char* name, Getter getter, Setter setter )
00194 :
00195 PrimitiveAttribute< TOwner, bool, 1991421614 >( name, getter, setter )
00196 {}
00197 } ;
00198
00199 template < class TOwner >
00200 class ShortAttribute : public PrimitiveAttribute< TOwner, short, 1933918052 >
00201 {
00202 public :
00203
00204 ShortAttribute( const char* name, Getter getter, Setter setter )
00205 :
00206 PrimitiveAttribute< TOwner, short, 1933918052 >( name, getter, setter )
00207 {}
00208 } ;
00209
00210 template < class TOwner >
00211 class UnsignedShortAttribute : public PrimitiveAttribute< TOwner, unsigned short, 2009635584 >
00212 {
00213 public :
00214
00215 UnsignedShortAttribute( const char* name, Getter getter, Setter setter )
00216 :
00217 PrimitiveAttribute< TOwner, unsigned short, 2009635584 >( name, getter, setter )
00218 {}
00219 } ;
00220
00221 template < class TOwner >
00222 class IntAttribute : public PrimitiveAttribute< TOwner, int, 2240172011 >
00223 {
00224 public :
00225
00226 IntAttribute( const char* name, Getter getter, Setter setter )
00227 :
00228 PrimitiveAttribute< TOwner, int, 2240172011 >( name, getter, setter )
00229 {}
00230 } ;
00231
00232 template < class TOwner >
00233 class UnsignedIntAttribute : public PrimitiveAttribute< TOwner, unsigned int, 1543155168 >
00234 {
00235 public :
00236
00237 UnsignedIntAttribute( const char* name, Getter getter, Setter setter )
00238 :
00239 PrimitiveAttribute< TOwner, unsigned int, 1543155168 >( name, getter, setter )
00240 {}
00241 } ;
00242
00243 template < class TOwner >
00244 class LongAttribute : public PrimitiveAttribute< TOwner, long, 1468120404 >
00245 {
00246 public :
00247
00248 LongAttribute( const char* name, Getter getter, Setter setter )
00249 :
00250 PrimitiveAttribute< TOwner, long, 1468120404 >( name, getter, setter )
00251 {}
00252 } ;
00253
00254 template < class TOwner >
00255 class UnsignedLongAttribute : public PrimitiveAttribute< TOwner, unsigned long, 3266407847 >
00256 {
00257 public :
00258
00259 UnsignedLongAttribute( const char* name, Getter getter, Setter setter )
00260 :
00261 PrimitiveAttribute< TOwner, unsigned long, 3266407847 >( name, getter, setter )
00262 {}
00263 } ;
00264
00265 template < class TOwner >
00266 class FloatAttribute : public PrimitiveAttribute< TOwner, float, 1498253751 >
00267 {
00268 public :
00269
00270 FloatAttribute( const char* name, Getter getter, Setter setter )
00271 :
00272 PrimitiveAttribute< TOwner, float, 1498253751 >( name, getter, setter )
00273 {}
00274 } ;
00275
00276 template < class TOwner >
00277 class DoubleAttribute : public PrimitiveAttribute< TOwner, double, 1608088171 >
00278 {
00279 public :
00280
00281 DoubleAttribute( const char* name, Getter getter, Setter setter )
00282 :
00283 PrimitiveAttribute< TOwner, double, 1608088171 >( name, getter, setter )
00284 {}
00285 } ;
00286
00287 template < class TOwner >
00288 class StringAttribute : public PrimitiveAttribute< TOwner, const char*, 1135290523 >
00289 {
00290 public :
00291
00292 StringAttribute( const char* name, Getter getter, Setter setter )
00293 :
00294 PrimitiveAttribute< TOwner, const char*, 1135290523 >( name, getter, setter )
00295 {}
00296 } ;
00297 }
00298 #endif //header