00001
00002
00003
00004
00005
00006
00007
00008
00009
00023 #ifndef _FIELD_ELEMENT_FINFO_H
00024 #define _FIELD_ELEMENT_FINFO_H
00025
00026 class FieldElementFinfoBase: public Finfo
00027 {
00028 public:
00029 FieldElementFinfoBase(
00030 const string& name,
00031 const string& doc,
00032 const Cinfo* fieldCinfo,
00033 bool deferCreate
00034 )
00035 : Finfo( name, doc),
00036 setNum_( 0 ),
00037 getNum_( 0 ),
00038 fieldCinfo_( fieldCinfo ),
00039 deferCreate_( deferCreate )
00040 {;}
00041
00042 virtual ~FieldElementFinfoBase() {
00043 if ( setNum_ )
00044 delete setNum_;
00045 if ( getNum_ )
00046 delete getNum_;
00047 }
00048
00049 void registerFinfo( Cinfo* c ) {
00050 c->registerFinfo( setNum_ );
00051 c->registerFinfo( getNum_ );
00052 c->registerPostCreationFinfo( this );
00053 }
00054
00055 bool strSet( const Eref& tgt, const string& field,
00056 const string& arg ) const {
00057 return 0;
00058 }
00059
00060 bool strGet( const Eref& tgt, const string& field,
00061 string& returnValue ) const {
00062 return 0;
00063 }
00064
00068 void postCreationFunc( Id parent, Element* parentElm ) const;
00069
00075 virtual char* lookupField( char* parent,
00076 unsigned int fieldIndex ) const = 0;
00077
00079 virtual void setNumField( char* parent, unsigned int num )
00080 const = 0;
00081
00083 virtual unsigned int getNumField( const char* parent )
00084 const = 0;
00085
00086
00087
00088
00089
00090 protected:
00091 DestFinfo* setNum_;
00092 DestFinfo* getNum_;
00093 const Cinfo* fieldCinfo_;
00094 bool deferCreate_;
00095 };
00096
00097 template < class T, class F > class FieldElementFinfo: public FieldElementFinfoBase
00098 {
00099 public:
00100 FieldElementFinfo(
00101 const string& name,
00102 const string& doc,
00103 const Cinfo* fieldCinfo,
00104 F* ( T::*lookupField )( unsigned int ),
00105 void( T::*setNumField )( unsigned int num ),
00106 unsigned int ( T::*getNumField )() const,
00107 bool deferCreate = 0
00108 )
00109 : FieldElementFinfoBase( name, doc, fieldCinfo, deferCreate ),
00110 lookupField_( lookupField ),
00111 setNumField_( setNumField ),
00112 getNumField_( getNumField )
00113 {
00114 string setname = "setNum" + name;
00115 setname[6] = toupper( setname[6] );
00116
00117
00118
00119
00120
00121 setNum_ = new DestFinfo(
00122 setname,
00123 "Assigns number of field entries in field array.",
00124 new OpFunc1< T, unsigned int >( setNumField ) );
00125
00126 string getname = "getNum" + name;
00127 getname[6] = toupper( getname[6] );
00128 getNum_ = new DestFinfo(
00129 getname,
00130 "Requests number of field entries in field array."
00131 "The requesting Element must "
00132 "provide a handler for the returned value.",
00133 new GetOpFunc< T, unsigned int >( getNumField ) );
00134 }
00135
00141 char* lookupField( char* parent, unsigned int fieldIndex ) const
00142 {
00143 T* pa = reinterpret_cast< T* >( parent );
00144 if ( fieldIndex < ( pa->*getNumField_ )() ) {
00145 F* self = ( pa->*lookupField_ )( fieldIndex );
00146 return reinterpret_cast< char* >( self );
00147 }
00148 return 0;
00149 }
00150
00152 void setNumField( char* parent, unsigned int num ) const
00153 {
00154 T* pa = reinterpret_cast< T* >( parent );
00155 ( pa->*setNumField_ )( num );
00156 }
00157
00159 unsigned int getNumField( const char* parent ) const
00160 {
00161 const T* pa = reinterpret_cast< const T* >( parent );
00162 return ( pa->*getNumField_ )();
00163 }
00164
00165
00166
00168 string rttiType() const {
00169 return Conv<F>::rttiType();
00170 }
00171
00172 private:
00173 F* ( T::*lookupField_ )( unsigned int );
00174 void( T::*setNumField_ )( unsigned int num );
00175 unsigned int ( T::*getNumField_ )() const;
00176 };
00177
00178 #endif // _FIELD_ELEMENT_FINFO_H