00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00020 #ifndef flc_proptable_H
00021 #define flc_proptable_H
00022
00023 #include <falcon/setup.h>
00024 #include <falcon/types.h>
00025 #include <falcon/string.h>
00026 #include <falcon/item.h>
00027 #include <falcon/basealloc.h>
00028 #include <falcon/reflectfunc.h>
00029
00030
00031 namespace Falcon
00032 {
00033
00034 class CoreObject;
00035
00040 struct PropEntry
00041 {
00042 enum {
00043 NO_OFFSET = 0xFFFFFFFF
00044 };
00045
00047 const String *m_name;
00048
00050 bool m_bReadOnly;
00051
00060 bool isWriteOnly() const {
00061 return m_eReflectMode == e_reflectSetGet && m_reflection.gs.m_getterId == NO_OFFSET;
00062 }
00063
00065 t_reflection m_eReflectMode;
00066
00068 void *reflect_data;
00069
00071 Item m_value;
00072
00073 union {
00074 uint32 offset;
00075 struct {
00076 reflectionFunc to;
00077 reflectionFunc from;
00078 } rfunc;
00079
00080 struct {
00081 uint32 m_getterId;
00082 uint32 m_setterId;
00083 } gs;
00084 } m_reflection;
00085
00089 void reflectTo( CoreObject *instance, void *user_data, const Item &prop ) const;
00090
00094 void reflectFrom( CoreObject *instance, void *user_data, Item &prop ) const;
00095 };
00096
00097
00126 class FALCON_DYN_CLASS PropertyTable: public BaseAlloc
00127 {
00128 public:
00129 uint32 m_size;
00130 uint32 m_added;
00131 bool m_bReflective;
00132 bool m_bStatic;
00133 PropEntry *m_entries;
00134
00135 public:
00136
00137 PropertyTable( uint32 size );
00138 PropertyTable( const PropertyTable & );
00139 ~PropertyTable();
00140
00141 uint32 size() const { return m_size; }
00142 uint32 added() const { return m_added; }
00143
00144 bool isReflective() const { return m_bReflective; }
00145 bool isStatic() const { return m_bStatic; }
00146
00148 void checkProperties();
00149
00150 bool findKey( const String &key, uint32 &pos ) const;
00151
00152 PropEntry &getEntry( uint32 pos ) { return m_entries[pos]; }
00153 const PropEntry &getEntry( uint32 pos ) const { return m_entries[pos]; }
00154
00155 const Item *getValue( const String &key ) const
00156 {
00157 uint32 pos;
00158 if( findKey( key, pos ) )
00159 return getValue( pos );
00160 return 0;
00161 }
00162
00163 Item *getValue( uint32 pos ) { return &m_entries[ pos ].m_value; }
00164 const Item *getValue( uint32 pos ) const { return &m_entries[ pos ].m_value; }
00165 const String *getKey( uint32 pos ) const { return m_entries[pos].m_name; }
00166
00167 PropEntry &append( const String *name );
00168
00169 bool append( const String *key, const Item &itm, bool bReadOnly = false )
00170 {
00171 if ( m_added <= m_size ) {
00172 PropEntry e = append( key );
00173 e.m_value = itm;
00174 e.m_bReadOnly = bReadOnly;
00175 e.m_eReflectMode = e_reflectNone;
00176 return true;
00177 }
00178
00179 return false;
00180 }
00181
00182 bool append( const String *key, const Item &itm, t_reflection mode, uint32 offset, bool bReadOnly = false )
00183 {
00184 if ( m_added <= m_size ) {
00185 PropEntry e = append( key );
00186 e.m_value = itm;
00187 e.m_bReadOnly = bReadOnly;
00188 e.m_eReflectMode = mode;
00189 e.m_reflection.offset = offset;
00190 return true;
00191 }
00192
00193 return false;
00194 }
00195
00196 bool append( const String *key, const Item &itm, reflectionFunc func_from, reflectionFunc func_to = 0 )
00197 {
00198 if ( m_added <= m_size ) {
00199 PropEntry e = append( key );
00200 e.m_value = itm;
00201 e.m_bReadOnly = func_to == 0;
00202 e.m_eReflectMode = e_reflectFunc;
00203 e.m_reflection.rfunc.from = func_from;
00204 e.m_reflection.rfunc.to = func_to;
00205 return true;
00206 }
00207
00208 return false;
00209 }
00210
00211
00212 PropEntry &appendSafe( const String *key )
00213 {
00214 m_entries[m_added].m_name = key;
00215 PropEntry *ret = m_entries + m_added;
00216 m_added++;
00217 return *ret;
00218 }
00219
00220 void appendSafe( const String *key, const Item &itm, bool bReadOnly = false )
00221 {
00222 m_entries[m_added].m_name = key;
00223 m_entries[m_added].m_value = itm;
00224 m_entries[m_added].m_bReadOnly = bReadOnly;
00225 m_entries[m_added].m_eReflectMode = e_reflectNone;
00226 m_added++;
00227 }
00228
00229 void appendSafe( const String *key, const Item &itm, t_reflection mode, uint32 offset, bool bReadOnly = false )
00230 {
00231 m_entries[m_added].m_name = key;
00232 m_entries[m_added].m_value = itm;
00233 m_entries[m_added].m_bReadOnly = bReadOnly;
00234 m_entries[m_added].m_eReflectMode = mode;
00235 m_entries[m_added].m_reflection.offset = offset;
00236 m_added++;
00237 }
00238
00239 void appendSafe( const String *key, const Item &itm, reflectionFunc func_from, reflectionFunc func_to = 0 )
00240 {
00241 m_entries[m_added].m_name = key;
00242 m_entries[m_added].m_value = itm;
00243 m_entries[m_added].m_bReadOnly = func_to == 0;
00244 m_entries[m_added].m_eReflectMode = e_reflectFunc;
00245 m_entries[m_added].m_reflection.rfunc.from = func_from;
00246 m_entries[m_added].m_reflection.rfunc.to = func_to;
00247 m_added++;
00248 }
00249 };
00250
00251 }
00252
00253 #endif
00254
00255