00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef __ID_INL__
00013 #define __ID_INL__
00014
00015 #include "wx/general/gen.h"
00016
00017
00018
00019
00020
00021 bool a2dPropertyId::DoIgnoreIfNotMember( a2dObject *obj ) const
00022 {
00023 return obj->DoIgnoreIfNotMember( this );
00024 }
00025
00026 void a2dPropertyId::DoSetPropertyId( a2dNamedProperty *prop, a2dPropertyId *id )
00027 {
00028 prop->m_id = id;
00029 }
00030
00031
00032
00033
00034
00035 template<class proptype>
00036 void a2dPropertyIdProp<proptype>::SetPropertyToObject( a2dObject *obj, const proptype &value ) const
00037 {
00038 obj->SetProperty( value.Clone( a2dObject::clone_flat ) );
00039 }
00040
00041 template<class proptype>
00042 void a2dPropertyIdProp<proptype>::SetPropertyToObject( a2dObject *obj, proptype *value ) const
00043 {
00044
00045 obj->SetProperty( value );
00046 }
00047
00048 template<class proptype>
00049 void a2dPropertyIdProp<proptype>::SetNamedPropertyToObject( a2dObject* obj, a2dNamedProperty* nprop, SetFlags setflags ) const
00050 {
00051 proptype *castprop = wxStaticCastTmpl( nprop, proptype );
00052 if ( castprop )
00053 SetPropertyToObject( obj, castprop );
00054 }
00055
00056 template<class proptype>
00057 a2dNamedProperty* a2dPropertyIdProp<proptype>::GetPropertyAsNamedProperty( const a2dObject *obj ) const
00058 {
00059 return GetPropertyClone( obj );
00060 }
00061
00062 template<class proptype>
00063 proptype *a2dPropertyIdProp<proptype>::GetPropertyClone( const a2dObject *obj ) const
00064 {
00065 const a2dNamedProperty* prop = obj->FindProperty( this );
00066 if ( prop )
00067 {
00068 proptype *prop2 = wxStaticCastTmpl( prop->Clone( a2dObject::clone_deep ), proptype );
00069 return prop2;
00070 }
00071 return NULL;
00072 }
00073
00074 template<class proptype>
00075 proptype *a2dPropertyIdProp<proptype>::GetProperty( a2dObject *obj ) const
00076 {
00077 a2dNamedProperty* prop = obj->FindProperty( this );
00078 if ( prop )
00079 {
00080 proptype *prop2 = wxStaticCastTmpl( prop, proptype );
00081 return prop2;
00082 }
00083
00084 return 0;
00085 }
00086
00087 template<class proptype>
00088 const proptype *a2dPropertyIdProp<proptype>::GetProperty( const a2dObject *obj ) const
00089 {
00090 const a2dNamedProperty* prop = obj->FindProperty( this );
00091 if ( prop )
00092 {
00093 const proptype *prop2 = wxStaticCastTmpl( prop, proptype );
00094 return prop2;
00095 }
00096
00097 return 0;
00098 }
00099
00100
00101
00102
00103
00104
00105 template<class basetype, class proptype>
00106 a2dPropertyIdTyped<basetype,proptype>::a2dPropertyIdTyped( const wxString& name, Flags flags, const basetype &defaultvalue )
00107 : a2dPropertyId( name, flags )
00108 {
00109 m_defaultvalue = defaultvalue;
00110 m_get = NULL;
00111 m_set = NULL;
00112 m_constset = NULL;
00113 m_constget = NULL;
00114 m_ptm = NULL;
00115 }
00116
00117 template<class basetype, class proptype>
00118 a2dPropertyIdTyped<basetype,proptype>::a2dPropertyIdTyped( const wxString& name, basetype defaultvalue, Flags flags )
00119 : a2dPropertyId( name, flags )
00120 {
00121 m_defaultvalue = defaultvalue;
00122 m_get = NULL;
00123 m_set = NULL;
00124 m_constset = NULL;
00125 m_constget = NULL;
00126 m_ptm = NULL;
00127 }
00128
00129 template<class basetype, class proptype >
00130 a2dPropertyIdTyped<basetype, proptype >::a2dPropertyIdTyped( const wxString& name, Flags flags, const basetype &defaultvalue, Get getFunc, Set setFunc )
00131 : a2dPropertyId( name, flags )
00132 {
00133
00134 m_get = getFunc;
00135 m_set = setFunc;
00136 m_constget = NULL;
00137 m_constset = NULL;
00138 m_ptm = NULL;
00139 }
00140
00141 template<class basetype, class proptype >
00142 a2dPropertyIdTyped<basetype, proptype >::a2dPropertyIdTyped( const wxString& name, Flags flags, const basetype &defaultvalue, Get getFunc, ConstSet setFunc )
00143 : a2dPropertyId( name, flags )
00144 {
00145
00146 m_get = getFunc;
00147 m_set = NULL;
00148 m_constset = setFunc;
00149 m_constget = NULL;
00150 m_ptm = NULL;
00151 }
00152
00153 template<class basetype, class proptype >
00154 a2dPropertyIdTyped<basetype, proptype >::a2dPropertyIdTyped( const wxString& name, Flags flags, const basetype &defaultvalue, ConstGet getFunc, ConstSet setFunc )
00155 : a2dPropertyId( name, flags )
00156 {
00157
00158 m_get = NULL;
00159 m_set = NULL;
00160 m_constget = getFunc;
00161 m_constset = setFunc;
00162 m_ptm = NULL;
00163 }
00164
00165 template<class basetype, class proptype >
00166 a2dPropertyIdTyped<basetype, proptype >::a2dPropertyIdTyped( const wxString& name, Flags flags, const basetype &defaultvalue, basetype wxObject::* ptm )
00167 : a2dPropertyId( name, flags )
00168 {
00169
00170 m_get = NULL;
00171 m_set = NULL;
00172 m_constget = NULL;
00173 m_constset = NULL;
00174 m_ptm = ptm;
00175 }
00176
00177 template<class basetype, class proptype>
00178 void a2dPropertyIdTyped<basetype,proptype>::SetNamedPropertyToObject( a2dObject* obj, a2dNamedProperty* nprop, SetFlags setflags ) const
00179 {
00180 proptype *castprop = wxStaticCastTmpl( nprop, proptype );
00181 if ( castprop )
00182 SetPropertyToObject( obj, castprop, a2dPropertyId::set_none );
00183 }
00184
00185 template<class basetype, class proptype>
00186 a2dNamedProperty* a2dPropertyIdTyped<basetype,proptype>::GetPropertyAsNamedProperty( const a2dObject *obj ) const
00187 {
00188 return GetPropertyClone( obj );
00189 }
00190
00191 template<class basetype, class proptype>
00192 void a2dPropertyIdTyped<basetype,proptype>::SetPropertyToObject( a2dObject *obj, const basetype &value, SetFlags setflags ) const
00193 {
00194
00195 proptype prop( this, value );
00196 SetPropertyToObject( obj, &prop, setflags );
00197 }
00198
00199 template<class basetype, class proptype>
00200 void a2dPropertyIdTyped<basetype,proptype>::SetPropertyToObject( a2dObject *obj, proptype* property, SetFlags setflags ) const
00201 {
00202 if( property->GetId() == this )
00203 {
00204 if ( obj->HasPropertyId( this ) )
00205 {
00206 if( setflags & a2dPropertyId::set_remove_property )
00207 {
00208 obj->RemoveProperty( this, true );
00209 }
00210
00211 proptype *castprop = wxStaticCastTmpl( property, proptype );
00212 if ( m_ptm )
00213 {
00214 obj->*m_ptm = castprop->GetValue();
00215 obj->OnPropertyChanged( castprop->GetId() );
00216 }
00217 else if (m_set)
00218 {
00219 (obj->*m_set)( castprop->GetValue() );
00220 obj->OnPropertyChanged( castprop->GetId() );
00221 }
00222 else if (m_constset)
00223 {
00224 (obj->*m_constset)( castprop->GetValue() );
00225 obj->OnPropertyChanged( castprop->GetId() );
00226 }
00227
00228 else if( !IsOnlyMember() && !(setflags & a2dPropertyId::set_onlymember) )
00229 {
00230
00231 a2dNamedProperty* existprop = 0;
00232
00233
00234
00235 if( ! CheckFlags( a2dPropertyId::flag_multiple ) )
00236 {
00237 existprop = obj->FindProperty( this );
00238 }
00239
00240 if ( existprop )
00241 {
00242
00243 existprop->Assign( *property );
00244 obj->OnPropertyChanged( this );
00245 }
00246 else
00247 {
00248
00249
00250
00251 obj->AddProperty( property->Clone( a2dObject::clone_flat ) );
00252 obj->OnPropertyChanged( this );
00253 }
00254 }
00255 }
00256 else
00257 {
00258 wxString warn;
00259 warn.Printf( wxT("object with name %s does not have propertyId with name: %s"), obj->GetName().c_str(), GetName().c_str() );
00260 wxLogWarning( warn );
00261 }
00262 }
00263 else
00264 {
00265 wxString warn;
00266 warn.Printf( wxT("a2dNamedProperty Id with name %s does not fit propertyId to set with name: %s"), property->GetName().c_str(), GetName().c_str() );
00267 wxLogWarning( warn );
00268 }
00269 }
00270
00271 template<class basetype, class proptype>
00272 proptype *a2dPropertyIdTyped<basetype,proptype>::GetPropertyListOnly( const a2dObject *obj ) const
00273 {
00274 const a2dNamedProperty *prop = obj->FindProperty( this );
00275 return wxStaticCastNullTmpl( prop, proptype );
00276 }
00277
00278 template<class basetype, class proptype>
00279 basetype a2dPropertyIdTyped<basetype,proptype>::GetPropertyValue( const a2dObject *obj ) const
00280 {
00281
00282 if ( m_ptm )
00283 return obj->*m_ptm;
00284 if (m_get)
00285 return (obj->*m_get)();
00286
00287 const a2dNamedProperty* prop = obj->FindProperty( this );
00288 if ( prop )
00289 {
00290 proptype *prop2 = wxStaticCastTmpl( prop, proptype );
00291 return prop2->GetValue();
00292 }
00293 return GetDefaultValue();
00294 }
00295
00296 template<class basetype, class proptype>
00297 basetype a2dPropertyIdTyped<basetype,proptype>::GetPropertyValue( const a2dObject *obj, const basetype &defaultvalue ) const
00298 {
00299
00300 if ( m_ptm )
00301 return obj->*m_ptm;
00302 if (m_get)
00303 return (obj->*m_get)();
00304
00305
00306 const a2dNamedProperty* prop = obj->FindProperty( this );
00307 if ( prop )
00308 {
00309 proptype *prop2 = wxStaticCastTmpl( prop, proptype );
00310 return prop2->GetValue();
00311 }
00312 return defaultvalue;
00313 }
00314
00315 template<class basetype, class proptype>
00316 basetype *a2dPropertyIdTyped<basetype,proptype>::GetPropertyValuePtr( a2dObject *obj ) const
00317 {
00318
00319 a2dNamedProperty* prop = obj->FindProperty( this );
00320 if ( prop )
00321 {
00322 proptype *prop2 = wxStaticCastTmpl( prop, proptype );
00323 return prop2->GetValuePtr();
00324 }
00325 else
00326 {
00327 return 0;
00328 }
00329 }
00330
00331 template<class basetype, class proptype>
00332 inline a2dNamedProperty *a2dPropertyIdTyped<basetype,proptype>::CreatePropertyFromString( const wxString &value ) const
00333 {
00334 return proptype::CreatePropertyFromString( this, value );
00335 }
00336
00337
00338 template<class basetype, class proptype>
00339 a2dPropertyIdTyped<basetype,proptype>* a2dPropertyIdTyped<basetype, proptype>::GetDummy()
00340 {
00341 static a2dPropertyIdTyped<basetype,proptype> dummy( wxT("__dummy__"), a2dPropertyId::flag_none, basetype() );
00342 return &dummy;
00343 }
00344
00345 template<class basetype, class proptype>
00346 proptype *a2dPropertyIdTyped<basetype,proptype>::GetPropertyClone( const a2dObject *obj ) const
00347 {
00348 if ( m_ptm )
00349 {
00350 return new proptype( this, obj->*m_ptm );
00351 }
00352
00353 if (m_get)
00354 {
00355 basetype val = (obj->*m_get)();
00356 return new proptype( this, val );
00357 }
00358
00359 const a2dNamedProperty* prop = obj->FindProperty( this );
00360 if ( prop )
00361 {
00362 proptype *prop2 = wxStaticCastTmpl( prop->Clone( a2dObject::clone_deep ), proptype );
00363 return prop2;
00364 }
00365 return NULL;
00366 }
00367
00368
00369
00370
00371
00372 template<class basetype, class proptype >
00373 a2dPropertyIdGetSet<basetype, proptype >::a2dPropertyIdGetSet( const wxString& name, a2dPropertyId::Flags flags, const basetype &defaultvalue, Get getFunc, Set setFunc )
00374 : a2dPropertyIdTyped<basetype, proptype>( name, flags, defaultvalue, getFunc, setFunc )
00375 {
00376 }
00377
00378 template<class basetype, class proptype >
00379 a2dPropertyIdGetSet<basetype, proptype >::a2dPropertyIdGetSet( const wxString& name, a2dPropertyId::Flags flags, const basetype &defaultvalue, Get getFunc, ConstSet setFunc )
00380 : a2dPropertyIdTyped<basetype, proptype>( name, flags, defaultvalue, getFunc, setFunc )
00381 {
00382 }
00383
00384 template<class basetype, class proptype >
00385 bool a2dPropertyIdGetSet<basetype, proptype >::SetPropertyToObject( a2dObject *obj, const basetype &value ) const
00386 {
00387 if (a2dPropertyIdTyped<basetype, proptype>::m_set)
00388 (obj->*a2dPropertyIdTyped<basetype, proptype>::m_set)( value );
00389 if (a2dPropertyIdTyped<basetype, proptype>::m_constset)
00390 (obj->*a2dPropertyIdTyped<basetype, proptype>::m_constset)( value );
00391 return true;
00392 }
00393
00394 template<class basetype, class proptype >
00395 basetype a2dPropertyIdGetSet<basetype, proptype >::GetPropertyValue( const a2dObject *obj ) const
00396 {
00397 if (a2dPropertyIdTyped<basetype, proptype>::m_get)
00398 return (obj->*a2dPropertyIdTyped<basetype, proptype>::m_get)();
00399 if (a2dPropertyIdTyped<basetype, proptype>::m_constget)
00400 return (obj->*a2dPropertyIdTyped<basetype, proptype>::m_constget)();
00401 return a2dPropertyIdTyped<basetype, proptype>::GetDefaultValue();
00402 }
00403
00404 template<class basetype, class proptype >
00405 basetype a2dPropertyIdGetSet<basetype, proptype >::GetPropertyValue( const a2dObject *obj, const basetype &defaultvalue ) const
00406 {
00407 if (a2dPropertyIdTyped<basetype, proptype>::m_get)
00408 return (obj->*a2dPropertyIdTyped<basetype, proptype>::m_get)();
00409 if (a2dPropertyIdTyped<basetype, proptype>::m_constget)
00410 return (obj->*a2dPropertyIdTyped<basetype, proptype>::m_constget)();
00411 return defaultvalue;
00412 }
00413
00414 template<class basetype, class proptype >
00415 proptype* a2dPropertyIdGetSet<basetype, proptype >::GetPropertyClone( const a2dObject *obj ) const
00416 {
00417 basetype val;
00418 if (a2dPropertyIdTyped<basetype, proptype>::m_get)
00419 val = (obj->*a2dPropertyIdTyped<basetype, proptype>::m_get)();
00420 if (a2dPropertyIdTyped<basetype, proptype>::m_constget)
00421 val = (obj->*a2dPropertyIdTyped<basetype, proptype>::m_constget)();
00422 return new proptype( *this, val );
00423 }
00424
00425 template<class basetype, class proptype >
00426 a2dNamedProperty* a2dPropertyIdGetSet<basetype, proptype >::GetPropertyAsNamedProperty( const a2dObject *obj ) const
00427 {
00428 return GetPropertyClone( obj );
00429 }
00430
00431
00432
00433
00434
00435
00436 template<class basetype, class proptype>
00437 bool a2dMemberDclrTyped<basetype,proptype>::SetPropertyToObject( a2dObject *obj, const basetype &value ) const
00438 {
00439
00440 obj->*m_ptm = value;
00441 return true;
00442 }
00443
00444 template<class basetype, class proptype >
00445 basetype a2dMemberDclrTyped<basetype, proptype>::GetPropertyValue( const a2dObject *obj ) const
00446 {
00447 if ( m_ptm )
00448 return obj->*m_ptm;
00449 return a2dPropertyIdTyped<basetype, proptype>::GetDefaultValue();
00450 }
00451
00452 template<class basetype, class proptype >
00453 basetype a2dMemberDclrTyped<basetype, proptype>::GetPropertyValue( const a2dObject *obj, const basetype &defaultvalue ) const
00454 {
00455 if ( m_ptm )
00456 return obj->*m_ptm;
00457 return defaultvalue;
00458 }
00459
00460 template<class basetype, class proptype>
00461 proptype *a2dMemberDclrTyped<basetype,proptype>::GetPropertyClone( const a2dObject *obj ) const
00462 {
00463 return new proptype( *this, obj->*m_ptm );
00464 }
00465
00466
00467 #endif
00468