wxArt2D
id.inl
Go to the documentation of this file.
1 /*! \file wx/general/id.inl
2  \author Michael S�trop
3  \date Created 12/12/2003
4 
5  Copyright: 2003-2004 (c) Michael S�trop
6 
7  Licence: wxWidgets Licence
8 
9  RCS-ID: $Id: id.inl,v 1.14 2008/10/30 23:18:09 titato Exp $
10 */
11 
12 #ifndef __ID_INL__
13 #define __ID_INL__
14 
15 #include "wx/general/gen.h"
16 
17 //--------------------------------------------------------------------
18 // a2dPropertyId
19 //--------------------------------------------------------------------
20 
22 {
23  return obj->DoIgnoreIfNotMember( this );
24 }
25 
27 {
28  prop->m_id = id;
29 }
30 
31 //--------------------------------------------------------------------
32 // a2dPropertyIdProp
33 //--------------------------------------------------------------------
34 
35 template<class proptype>
36 void a2dPropertyIdProp<proptype>::SetPropertyToObject( a2dObject *obj, const proptype &value ) const
37 {
38  obj->SetProperty( value.Clone( a2dObject::clone_flat ) );
39 }
40 
41 template<class proptype>
42 void a2dPropertyIdProp<proptype>::SetPropertyToObject( a2dObject *obj, proptype* property ) const
43 {
44  // and assign it
45  if( property->GetId() == this )
46  {
47  if ( obj->HasPropertyId( this ) )
48  {
49  //dynamic property id->IsOnlyMember();
50  if( !IsOnlyMember() )
51  {
52  // check if the property already exists
53  a2dNamedProperty* existprop = 0;
54 
55  // If the property can be set more than once, ignore existing one
56 
57  if( ! CheckFlags( a2dPropertyId::flag_multiple ) )
58  {
59  existprop = obj->FindProperty( this );
60  }
61 
62  if ( existprop )
63  {
64  // does exist, so assign the new value
65  existprop->Assign( *property );
66  obj->OnPropertyChanged( this );
67  }
68  else
69  {
70  // does not exist, so add it
71  // we know that it doesn't exist, so we do not need to remove it
72  // or we want to add it more than once
73  obj->AddProperty( property->Clone( a2dObject::clone_flat ) );
74  obj->OnPropertyChanged( this );
75  }
76  }
77  }
78  else
79  {
80  wxString warn;
81  warn.Printf( wxT("object with name %s does not have propertyId with name: %s"), obj->GetName().c_str(), GetName().c_str() );
82  wxLogWarning( warn );
83  }
84  }
85  else
86  {
87  wxString warn;
88  warn.Printf( wxT("a2dNamedProperty Id with name %s does not fit propertyId to set with name: %s"), property->GetName().c_str(), GetName().c_str() );
89  wxLogWarning( warn );
90  }
91 
92 }
93 
94 template<class proptype>
96 {
97  proptype *castprop = wxStaticCastTmpl( nprop, proptype );
98  if ( castprop )
99  SetPropertyToObject( obj, castprop );
100 }
101 
102 template<class proptype>
104 {
105  return GetPropertyClone( obj );
106 }
107 
108 template<class proptype>
110 {
111  const a2dNamedProperty* prop = obj->FindProperty( this );
112  if ( prop )
113  {
114  proptype *prop2 = wxStaticCastTmpl( prop->Clone( a2dObject::clone_deep ), proptype );
115  return prop2;
116  }
117  return NULL;
118 }
119 
120 template<class proptype>
122 {
123  a2dNamedProperty* prop = obj->FindProperty( this );
124  if ( prop )
125  {
126  proptype *prop2 = wxStaticCastTmpl( prop, proptype );
127  return prop2;
128  }
129 
130  return 0;
131 }
132 
133 template<class proptype>
134 const proptype *a2dPropertyIdProp<proptype>::GetProperty( const a2dObject *obj ) const
135 {
136  const a2dNamedProperty* prop = obj->FindProperty( this );
137  if ( prop )
138  {
139  const proptype *prop2 = wxStaticCastTmpl( prop, proptype );
140  return prop2;
141  }
142 
143  return 0;
144 }
145 
146 
147 //--------------------------------------------------------------------
148 // a2dPropertyIdTyped
149 //--------------------------------------------------------------------
150 
151 template<class basetype, class proptype>
152 a2dPropertyIdTyped<basetype,proptype>::a2dPropertyIdTyped( const wxString& name, Flags flags, const basetype &defaultvalue )
153 : a2dPropertyId( name, flags )
154 {
155  m_defaultvalue = defaultvalue;
156  m_get = NULL;
157  m_set = NULL;
158  m_constset = NULL;
159  m_constget = NULL;
160  m_ptm = NULL;
161 }
162 
163 template<class basetype, class proptype>
164 a2dPropertyIdTyped<basetype,proptype>::a2dPropertyIdTyped( const wxString& name, basetype defaultvalue, Flags flags )
165 : a2dPropertyId( name, flags )
166 {
167  m_defaultvalue = defaultvalue;
168  m_get = NULL;
169  m_set = NULL;
170  m_constset = NULL;
171  m_constget = NULL;
172  m_ptm = NULL;
173 }
174 
175 template<class basetype, class proptype >
176 a2dPropertyIdTyped<basetype, proptype >::a2dPropertyIdTyped( const wxString& name, Flags flags, const basetype &defaultvalue, Get getFunc, Set setFunc )
177 : a2dPropertyId( name, flags )
178 {
179  //m_defaultvalue = defaultvalue;
180  m_get = getFunc;
181  m_set = setFunc;
182  m_constget = NULL;
183  m_constset = NULL;
184  m_ptm = NULL;
185 }
186 
187 template<class basetype, class proptype >
188 a2dPropertyIdTyped<basetype, proptype >::a2dPropertyIdTyped( const wxString& name, Flags flags, const basetype &defaultvalue, Get getFunc, ConstSet setFunc )
189 : a2dPropertyId( name, flags )
190 {
191  //m_defaultvalue = defaultvalue;
192  m_get = getFunc;
193  m_set = NULL;
194  m_constset = setFunc;
195  m_constget = NULL;
196  m_ptm = NULL;
197 }
198 
199 template<class basetype, class proptype >
200 a2dPropertyIdTyped<basetype, proptype >::a2dPropertyIdTyped( const wxString& name, Flags flags, const basetype &defaultvalue, ConstGet getFunc, ConstSet setFunc )
201 : a2dPropertyId( name, flags )
202 {
203  //m_defaultvalue = defaultvalue;
204  m_get = NULL;
205  m_set = NULL;
206  m_constget = getFunc;
207  m_constset = setFunc;
208  m_ptm = NULL;
209 }
210 
211 template<class basetype, class proptype >
212 a2dPropertyIdTyped<basetype, proptype >::a2dPropertyIdTyped( const wxString& name, Flags flags, const basetype &defaultvalue, basetype wxObject::* ptm )
213 : a2dPropertyId( name, flags )
214 {
215  //m_defaultvalue = defaultvalue;
216  m_get = NULL;
217  m_set = NULL;
218  m_constget = NULL;
219  m_constset = NULL;
220  m_ptm = ptm;
221 }
222 
223 template<class basetype, class proptype>
225 {
226  proptype *castprop = wxStaticCastTmpl( nprop, proptype );
227  if ( castprop )
228  SetPropertyToObject( obj, castprop, a2dPropertyId::set_none );
229 }
230 
231 template<class basetype, class proptype>
233 {
234  return GetPropertyClone( obj );
235 }
236 
237 template<class basetype, class proptype>
238 void a2dPropertyIdTyped<basetype,proptype>::SetPropertyToObject( a2dObject *obj, const basetype &value, SetFlags setflags ) const
239 {
240  // create a property object
241  proptype prop( this, value );
242  SetPropertyToObject( obj, &prop, setflags );
243 }
244 
245 template<class basetype, class proptype>
246 void a2dPropertyIdTyped<basetype,proptype>::SetPropertyToObject( a2dObject *obj, proptype* property, SetFlags setflags ) const
247 {
248  if( property->GetId() == this )
249  {
250  if ( obj->HasPropertyId( this ) )
251  {
252  if( setflags & a2dPropertyId::set_remove_property )
253  {
254  obj->RemoveProperty( this, true );
255  }
256 
257  proptype *castprop = wxStaticCastTmpl( property, proptype );
258  if ( m_ptm )
259  {
260  obj->*m_ptm = castprop->GetValue();
261  obj->OnPropertyChanged( castprop->GetId() );
262  }
263  else if (m_set)
264  {
265  (obj->*m_set)( castprop->GetValue() );
266  obj->OnPropertyChanged( castprop->GetId() );
267  }
268  else if (m_constset)
269  {
270  (obj->*m_constset)( castprop->GetValue() );
271  obj->OnPropertyChanged( castprop->GetId() );
272  }
273  //dynamic property id->IsOnlyMember();
274  else if( !IsOnlyMember() && !(setflags & a2dPropertyId::set_onlymember) )
275  {
276  // check if the property already exists
277  a2dNamedProperty* existprop = 0;
278 
279  // If the property can be set more than once, ignore existing one
280 
281  if( ! CheckFlags( a2dPropertyId::flag_multiple ) )
282  {
283  existprop = obj->FindProperty( this );
284  }
285 
286  if ( existprop )
287  {
288  // does exist, so assign the new value
289  existprop->Assign( *property );
290  obj->OnPropertyChanged( this );
291  }
292  else
293  {
294  // does not exist, so add it
295  // we know that it doesn't exist, so we do not need to remove it
296  // or we want to add it more than once
297  obj->AddProperty( property->Clone( a2dObject::clone_flat ) );
298  obj->OnPropertyChanged( this );
299  }
300  }
301  }
302  else
303  {
304  wxString warn;
305  warn.Printf( wxT("object with name %s does not have propertyId with name: %s"), obj->GetName().c_str(), GetName().c_str() );
306  wxLogWarning( warn );
307  }
308  }
309  else
310  {
311  wxString warn;
312  warn.Printf( wxT("a2dNamedProperty Id with name %s does not fit propertyId to set with name: %s"), property->GetName().c_str(), GetName().c_str() );
313  wxLogWarning( warn );
314  }
315 }
316 
317 template<class basetype, class proptype>
319 {
320  const a2dNamedProperty *prop = obj->FindProperty( this );
321  return wxStaticCastNullTmpl( prop, proptype );
322 }
323 
324 template<class basetype, class proptype>
326 {
327  //first try the pointer, since they have priority
328  if ( m_ptm )
329  return obj->*m_ptm;
330  if (m_get)
331  return (obj->*m_get)();
332  if (m_constget)
333  return (obj->*m_constget)();
334 
335  const a2dNamedProperty* prop = obj->FindProperty( this );
336  if ( prop )
337  {
338  proptype *prop2 = wxStaticCastTmpl( prop, proptype );
339  return prop2->GetValue();
340  }
341  return GetDefaultValue();
342 }
343 
344 template<class basetype, class proptype>
345 basetype a2dPropertyIdTyped<basetype,proptype>::GetPropertyValue( const a2dObject *obj, const basetype &defaultvalue ) const
346 {
347  //first try the pointer, since they have priority
348  if ( m_ptm )
349  return obj->*m_ptm;
350  if (m_get)
351  return (obj->*m_get)();
352  if (m_constget)
353  return (obj->*m_constget)();
354 
355  // now assemble properties with this id, which is normally just one.
356  const a2dNamedProperty* prop = obj->FindProperty( this );
357  if ( prop )
358  {
359  proptype *prop2 = wxStaticCastTmpl( prop, proptype );
360  return prop2->GetValue();
361  }
362  return defaultvalue;
363 }
364 
365 template<class basetype, class proptype>
367 {
368  // Note: this is not yet supported for properties implemented as members
369  a2dNamedProperty* prop = obj->FindProperty( this );
370  if ( prop )
371  {
372  proptype *prop2 = wxStaticCastTmpl( prop, proptype );
373  return prop2->GetValuePtr();
374  }
375  else
376  {
377  return 0;
378  }
379 }
380 
381 template<class basetype, class proptype>
383 {
384  return proptype::CreatePropertyFromString( this, value );
385 }
386 
387 
388 template<class basetype, class proptype>
390 {
391  static a2dPropertyIdTyped<basetype,proptype> dummy( wxT("__dummy__"), a2dPropertyId::flag_none, basetype() );
392  return &dummy;
393 }
394 
395 template<class basetype, class proptype>
397 {
398  if ( m_ptm )
399  {
400  return new proptype( this, obj->*m_ptm );
401  }
402  if (m_get)
403  {
404  basetype val = (obj->*m_get)();
405  return new proptype( this, val );
406  }
407  if (m_get)
408  {
409  basetype val = (obj->*m_constget)();
410  return new proptype( this, val );
411  }
412 
413  const a2dNamedProperty* prop = obj->FindProperty( this );
414  if ( prop )
415  {
416  proptype *prop2 = wxStaticCastTmpl( prop->Clone( a2dObject::clone_deep ), proptype );
417  return prop2;
418  }
419  return NULL;
420 }
421 
422 //--------------------------------------------------------------------
423 // a2dPropertyIdGetSet
424 //--------------------------------------------------------------------
425 
426 template<class basetype, class proptype >
427 a2dPropertyIdGetSet<basetype, proptype >::a2dPropertyIdGetSet( const wxString& name, a2dPropertyId::Flags flags, const basetype &defaultvalue, Get getFunc, Set setFunc )
428  : a2dPropertyIdTyped<basetype, proptype>( name, flags, defaultvalue, getFunc, setFunc )
429 {
430 }
431 
432 template<class basetype, class proptype >
433 a2dPropertyIdGetSet<basetype, proptype >::a2dPropertyIdGetSet( const wxString& name, a2dPropertyId::Flags flags, const basetype &defaultvalue, Get getFunc, ConstSet setFunc )
434  : a2dPropertyIdTyped<basetype, proptype>( name, flags, defaultvalue, getFunc, setFunc )
435 {
436 }
437 
438 template<class basetype, class proptype >
440 {
445  return true;
446 }
447 
448 template<class basetype, class proptype >
450 {
456 }
457 
458 template<class basetype, class proptype >
459 basetype a2dPropertyIdGetSet<basetype, proptype >::GetPropertyValue( const a2dObject *obj, const basetype &defaultvalue ) const
460 {
465  return defaultvalue;
466 }
467 
468 template<class basetype, class proptype >
470 {
471  basetype val;
476  return new proptype( *this, val );
477 }
478 
479 template<class basetype, class proptype >
481 {
482  return GetPropertyClone( obj );
483 }
484 
485 
486 //--------------------------------------------------------------------
487 // a2dMemberDclrTyped
488 //--------------------------------------------------------------------
489 
490 template<class basetype, class proptype>
491 bool a2dMemberDclrTyped<basetype,proptype>::SetPropertyToObject( a2dObject *obj, const basetype &value ) const
492 {
493  // dynamically check obj type
494  obj->*m_ptm = value;
495  return true;
496 }
497 
498 template<class basetype, class proptype >
500 {
501  if ( m_ptm )
502  return obj->*m_ptm;
504 }
505 
506 template<class basetype, class proptype >
507 basetype a2dMemberDclrTyped<basetype, proptype>::GetPropertyValue( const a2dObject *obj, const basetype &defaultvalue ) const
508 {
509  if ( m_ptm )
510  return obj->*m_ptm;
511  return defaultvalue;
512 }
513 
514 template<class basetype, class proptype>
516 {
517  return new proptype( *this, obj->*m_ptm );
518 }
519 
520 
521 #endif
522 
virtual void Assign(const a2dNamedProperty &other)=0
Virtual assignment operator.
proptype * GetPropertyClone(const a2dObject *obj) const
retrieve in form of a a2dNamedProperty the value of the property identified with this id ...
Definition: id.inl:396
(In) Visible property that can be added to Docview Objects.
Definition: gen.h:1785
set the property also to all childs
Definition: id.h:228
virtual wxString GetName() const
Returns the name of this object, if no name is given the internal id will be returned.
Definition: gen.cpp:1310
bool SetPropertyToObject(a2dObject *obj, const basetype &value) const
Set the property value in obj.
Definition: id.inl:439
fundamental classes used by all other modules.
basetype GetPropertyValue(const a2dObject *obj) const
Get the property value in obj.
Definition: id.inl:499
a2dNamedProperty * CreatePropertyFromString(const wxString &value) const
Create a new property object from a value string.
Definition: id.inl:382
a2dPropertyIdGetSet(const wxString &name, a2dPropertyId::Flags flags, const basetype &defaultvalue, Get getFunc, Set setFunc)
constructor
Definition: id.inl:427
static a2dPropertyIdTyped< basetype, proptype > * GetDummy()
returns a dummy property id of this type, that can be used in non-id applications ...
Definition: id.inl:389
const a2dPropertyId * m_id
The property id object identifying this property.
Definition: gen.h:1945
void SetPropertyToObject(a2dObject *obj, const proptype &value) const
Set the property in obj to value (cloning value)
Definition: id.inl:36
Ref Counted base object.
Definition: gen.h:1045
proptype * GetPropertyListOnly(const a2dObject *obj) const
Get the property from the list in obj ( no members, not cloned )
Definition: id.inl:318
Flags
Flags for property ids.
Definition: id.h:158
basetype * GetPropertyValuePtr(a2dObject *obj) const
Get a pointer to the property value in obj.
Definition: id.inl:366
proptype * GetProperty(a2dObject *obj) const
Get the property in obj (not cloned)
Definition: id.inl:121
proptype * GetPropertyClone(const a2dObject *obj) const
Get the property in obj (cloned)
Definition: id.inl:469
void SetNamedPropertyToObject(a2dObject *obj, a2dNamedProperty *nprop, SetFlags setflags=set_none) const
Set the property in obj to value (not cloning value)
Definition: id.inl:95
no special flags set
Definition: id.h:161
void SetProperty(a2dNamedProperty *propertyHolder, a2dPropertyId::SetFlags flags=a2dPropertyId::set_none)
Set the property to the this object.
Definition: gen.cpp:1605
virtual void OnPropertyChanged(const a2dPropertyId *id)
This function is called after a property changed.
Definition: gen.cpp:1635
SetFlags
Flags used for manipulating the way a property is set to a2dObject.
Definition: id.h:219
const basetype & GetDefaultValue() const
Get the default value for this property.
Definition: id.h:573
basetype GetPropertyValue(const a2dObject *obj) const
Get the property value in obj.
Definition: id.inl:449
a2dNamedProperty * GetPropertyAsNamedProperty(const a2dObject *obj) const
retrieve in form of a a2dNamedProperty the property identified with this id
Definition: id.inl:103
no special flags set
Definition: id.h:222
void SetPropertyToObject(a2dObject *obj, const basetype &value, SetFlags setflags=set_none) const
Set the property in obj to value.
Definition: id.inl:238
a2dNamedProperty * Clone(a2dObject::CloneOptions options, a2dRefMap *refs=NULL) const
Virtual copy constructor.
Definition: gen.cpp:1820
static void DoSetPropertyId(a2dNamedProperty *prop, a2dPropertyId *id)
this is called by derived classes to change an id in a property
Definition: id.inl:26
remove the property, don&#39;t set it as member
Definition: id.h:234
void SetNamedPropertyToObject(a2dObject *obj, a2dNamedProperty *nprop, SetFlags setflags=set_none) const
Set the property in obj to value (not cloning value)
Definition: id.inl:224
a2dPropertyIdTyped()
this constructor is only for property ids referencing other property ids
Definition: id.h:603
virtual bool DoIgnoreIfNotMember(const a2dPropertyId *id) const
used to decide if a property shall be ignored, if it is not a member
Definition: gen.h:1393
virtual bool AddProperty(a2dNamedProperty *property)
This function is called by a2dPropertyId to add a property to the list.
Definition: gen.cpp:1541
This is the base class for all kinds of property id&#39;s for a2dObject.
Definition: id.h:154
proptype * GetPropertyClone(const a2dObject *obj) const
retrieve in form of a a2dNamedProperty the value of the property identified with this id ...
Definition: id.inl:109
basetype m_defaultvalue
this is the value returned if e.g. a property is not found
Definition: id.h:613
Allow adding a specific property with ID more than once to a list.
Definition: id.h:188
virtual bool RemoveProperty(const a2dPropertyId *id, bool all=true)
This function is called by a2dPropertyId to remove a property from the list.
Definition: gen.cpp:1573
bool DoIgnoreIfNotMember(a2dObject *obj) const
this is called by derived to check if a property should be added as non-member
Definition: id.inl:21
basetype GetPropertyValue(const a2dObject *obj) const
Get the property value in obj.
Definition: id.inl:325
virtual a2dNamedProperty * FindProperty(const a2dPropertyId *id, a2dPropertyId::Flags flags=a2dPropertyId::flag_none)
Find a dynamic property with given id in the property list.
Definition: gen.cpp:1547
This template class is for property ids with a known data type.
Definition: id.h:477
Like a2dPropertyIdTyped, but always references a certain member in a certain class.
Definition: id.h:786
id.inl Source File -- Sun Oct 12 2014 17:04:21 -- Sun Oct 12 2014 -- 1.8.5 -- wxArt2D -- . -- Main Page Reference Documentation