]> git.mxchange.org Git - simgear.git/blob - simgear/props/props.hxx
960d2aeac631535f22c085c156f401a857837e38
[simgear.git] / simgear / props / props.hxx
1 /**
2  * \file props.hxx
3  * Interface definition for a property list.
4  * Started Fall 2000 by David Megginson, david@megginson.com
5  * This code is released into the Public Domain.
6  *
7  * See props.html for documentation [replace with URL when available].
8  *
9  * $Id$
10  */
11
12 #ifndef __PROPS_HXX
13 #define __PROPS_HXX
14
15 #ifndef PROPS_STANDALONE
16 #define PROPS_STANDALONE 0
17 #endif
18
19 #include <vector>
20 #include <string>
21 #include <iostream>
22 #include <sstream>
23
24 #include <boost/utility.hpp>
25
26 #if PROPS_STANDALONE
27 #else
28 #include <simgear/compiler.h>
29 #include <simgear/debug/logstream.hxx>
30 #endif
31
32
33
34 #include <simgear/structure/SGReferenced.hxx>
35 #include <simgear/structure/SGSharedPtr.hxx>
36
37 // XXX This whole file should be in the simgear namespace, but I don't
38 // have the guts yet...
39
40 namespace simgear
41 {
42 template<typename T>
43 std::istream& readFrom(std::istream& stream, T& result)
44 {
45     stream >> result;
46     return stream;
47 }
48
49 /**
50  * Parse a string as an object of a given type.
51  * XXX no error behavior yet.
52  *
53  * @tparam T the return type
54  * @param str the string
55  * @return the object.
56  */
57 template<typename T>
58 inline T parseString(const std::string& str)
59 {
60     std::istringstream stream(str);
61     T result;
62     readFrom(stream, result);
63     return result;
64 }
65
66 /**
67  * Property value types.
68  */
69
70 #ifdef NONE
71 #pragma warn A sloppy coder has defined NONE as a macro!
72 #undef NONE
73 #endif
74
75 #ifdef ALIAS
76 #pragma warn A sloppy coder has defined ALIAS as a macro!
77 #undef ALIAS
78 #endif
79
80 #ifdef UNSPECIFIED
81 #pragma warn A sloppy coder has defined UNSPECIFIED as a macro!
82 #undef UNSPECIFIED
83 #endif
84
85 #ifdef BOOL
86 #pragma warn A sloppy coder has defined BOOL as a macro!
87 #undef BOOL
88 #endif
89
90 #ifdef INT
91 #pragma warn A sloppy coder has defined INT as a macro!
92 #undef INT
93 #endif
94
95 #ifdef LONG
96 #pragma warn A sloppy coder has defined LONG as a macro!
97 #undef LONG
98 #endif
99
100 #ifdef FLOAT
101 #pragma warn A sloppy coder has defined FLOAT as a macro!
102 #undef FLOAT
103 #endif
104
105 #ifdef DOUBLE
106 #pragma warn A sloppy coder has defined DOUBLE as a macro!
107 #undef DOUBLE
108 #endif
109
110 #ifdef STRING
111 #pragma warn A sloppy coder has defined STRING as a macro!
112 #undef STRING
113 #endif
114
115 namespace props
116 {
117 /**
118  * The possible types of an SGPropertyNode. Types that appear after
119  * EXTENDED are not stored in the SGPropertyNode itself.
120  */
121 enum Type {
122     NONE = 0, /**< The node hasn't been assigned a value yet. */
123     ALIAS, /**< The node "points" to another node. */
124     BOOL,
125     INT,
126     LONG,
127     FLOAT,
128     DOUBLE,
129     STRING,
130     UNSPECIFIED,
131     EXTENDED  /**< The node's value is not stored in the property;
132                * the actual value and type is retrieved from an
133                * SGRawValue node. This type is never returned by @see
134                * SGPropertyNode::getType.
135                */
136 };
137
138 template<typename T> struct PropertyTraits;
139
140 #define DEFINTERNALPROP(TYPE, PROP) \
141 template<> \
142 struct PropertyTraits<TYPE> \
143 { \
144     static const Type type_tag = PROP; \
145     enum  { Internal = 1 }; \
146 }
147
148 DEFINTERNALPROP(bool, BOOL);
149 DEFINTERNALPROP(int, INT);
150 DEFINTERNALPROP(long, LONG);
151 DEFINTERNALPROP(float, FLOAT);
152 DEFINTERNALPROP(double, DOUBLE);
153 DEFINTERNALPROP(const char *, STRING);
154 #undef DEFINTERNALPROP
155
156 }
157 }
158
159
160
161 \f
162 ////////////////////////////////////////////////////////////////////////
163 // A raw value.
164 //
165 // This is the mechanism that information-providing routines can
166 // use to link their own values to the property manager.  Any
167 // SGValue can be tied to a raw value and then untied again.
168 //
169 // Note: we are forced to use inlined methods here to ensure
170 // that the templates will be instantiated.  We're probably taking
171 // a small performance hit for that.
172 ////////////////////////////////////////////////////////////////////////
173
174 /**
175  * Base class for SGRawValue classes that holds no type
176  * information. This allows some generic manipulation of the
177  * SGRawValue object.
178  */
179 class SGRaw
180 {
181 public:
182     /**
183      * Get the type enumeration for the raw value.
184      *
185      * @return the type.
186      */
187     virtual simgear::props::Type getType() const = 0;
188     virtual ~SGRaw() {}
189     
190     /**
191      * Create a new deep copy of this raw value.
192      *
193      * The copy will contain its own version of the underlying value
194      * as well, and will be the same type.
195      *
196      * @return A deep copy of the current object.
197      */
198     virtual SGRaw* clone() const = 0;
199
200 };
201
202 class SGRawExtended : public SGRaw
203 {
204 public:
205     /**    
206      * Make an SGRawValueContainer from the SGRawValue.
207      *
208      * This is a virtual function of SGRawExtended so that
209      * SGPropertyNode::untie doesn't need to know the type of an
210      * extended property.
211      */
212     virtual SGRawExtended* makeContainer() const = 0;
213     /**
214      * Write value out to a stream
215      */
216     virtual std::ostream& printOn(std::ostream& stream) const = 0;
217     /**
218      * Read value from a stream and store it.
219      */
220     virtual std::istream& readFrom(std::istream& stream) = 0;
221 };
222
223 // Choose between different base classes based on whether the value is
224 // stored internal to the property node. This frees us from defining
225 // the virtual functions in the SGRawExtended interface where they
226 // don't make sense, e.g. readFrom for the const char* type.
227 template<typename T, int internal = simgear::props::PropertyTraits<T>::Internal>
228 class SGRawBase;
229
230 template<typename T>
231 class SGRawBase<T, 1> : public SGRaw
232 {
233 };
234
235 template<typename T>
236 class SGRawBase<T, 0> : public SGRawExtended
237 {
238     virtual SGRawExtended* makeContainer() const;
239     virtual std::ostream& printOn(std::ostream& stream) const;
240     virtual std::istream& readFrom(std::istream& stream);
241 };
242
243 /**
244  * Abstract base class for a raw value.
245  *
246  * <p>The property manager is implemented in two layers.  The {@link
247  * SGPropertyNode} is the highest and most abstract layer,
248  * representing an LValue/RValue pair: it records the position of the
249  * property in the property tree and contains facilities for
250  * navigation to other nodes.  It is guaranteed to be persistent: the
251  * {@link SGPropertyNode} will not change during a session, even if
252  * the property is bound and unbound multiple times.</p>
253  *
254  * <p>When the property value is not managed internally in the
255  * SGPropertyNode, the SGPropertyNode will contain a reference to an
256  * SGRawValue (this class), which provides an abstract way to get,
257  * set, and clone the underlying value.  The SGRawValue may change
258  * frequently during a session as a value is retyped or bound and
259  * unbound to various data source, but the abstract SGPropertyNode
260  * layer insulates the application from those changes.
261  *
262  * <p>The SGPropertyNode class always keeps a *copy* of a raw value,
263  * not the original one passed to it; if you override a derived class
264  * but do not replace the {@link #clone} method, strange things will
265  * happen.</p>
266  *
267  * <p>All derived SGRawValue classes must implement {@link #getValue},
268  * {@link #setValue}, and {@link #clone} for the appropriate type.</p>
269  *
270  * @see SGPropertyNode
271  * @see SGRawValuePointer
272  * @see SGRawValueFunctions
273  * @see SGRawValueFunctionsIndexed
274  * @see SGRawValueMethods
275  * @see SGRawValueMethodsIndexed
276  * @see SGRawValueContainer
277  */
278 template <class T>
279 class SGRawValue : public SGRawBase<T>
280 {
281 public:
282
283   /**
284    * The default underlying value for this type.
285    *
286    * Every raw value has a default; the default is false for a
287    * boolean, 0 for the various numeric values, and "" for a string.
288    * If additional types of raw values are added in the future, they
289    * may need different kinds of default values (such as epoch for a
290    * date type).  The default value is used when creating new values.
291    */
292   static const T DefaultValue;  // Default for this kind of raw value.
293
294
295   /**
296    * Constructor.
297    *
298    * Use the default value for this type.
299    */
300   SGRawValue () {}
301
302
303   /**
304    * Destructor.
305    */
306   virtual ~SGRawValue () {}
307
308
309   /**
310    * Return the underlying value.
311    *
312    * @return The actual value for the property.
313    * @see #setValue
314    */
315   virtual T getValue () const = 0;
316
317
318   /**
319    * Assign a new underlying value.
320    *
321    * If the new value cannot be set (because this is a read-only
322    * raw value, or because the new value is not acceptable for
323    * some reason) this method returns false and leaves the original
324    * value unchanged.
325    *
326    * @param value The actual value for the property.
327    * @return true if the value was set successfully, false otherwise.
328    * @see #getValue
329    */
330   virtual bool setValue (T value) = 0;
331
332
333   /**
334    * Return the type tag for this raw value type.
335    */
336   virtual simgear::props::Type getType() const
337   {
338     return simgear::props::PropertyTraits<T>::type_tag;
339   }
340 };
341
342
343
344 ////////////////////////////////////////////////////////////////////////
345 // Default values for every type.
346 ////////////////////////////////////////////////////////////////////////
347
348 template<> const bool SGRawValue<bool>::DefaultValue;
349 template<> const int SGRawValue<int>::DefaultValue;
350 template<> const long SGRawValue<long>::DefaultValue;
351 template<> const float SGRawValue<float>::DefaultValue;
352 template<> const double SGRawValue<double>::DefaultValue;
353 template<> const char * const SGRawValue<const char *>::DefaultValue;
354
355 /**
356  * A raw value bound to a pointer.
357  *
358  * This is the most efficient way to tie an external value, but also
359  * the most dangerous, because there is no way for the supplier to
360  * perform bounds checking and derived calculations except by polling
361  * the variable to see if it has changed.  There is no default
362  * constructor, because this class would be meaningless without a
363  * pointer.
364  */
365 template <class T>
366 class SGRawValuePointer : public SGRawValue<T>
367 {
368 public:
369
370   /**
371    * Explicit pointer constructor.
372    *
373    * Create a new raw value bound to the value of the variable
374    * referenced by the pointer.
375    *
376    * @param ptr The pointer to the variable to which this raw value
377    * will be bound.
378    */
379   SGRawValuePointer (T * ptr) : _ptr(ptr) {}
380
381   /**
382    * Destructor.
383    */
384   virtual ~SGRawValuePointer () {}
385
386   /**
387    * Get the underlying value.
388    *
389    * This method will dereference the pointer and return the
390    * variable's value.
391    */
392   virtual T getValue () const { return *_ptr; }
393
394   /**
395    * Set the underlying value.
396    *
397    * This method will dereference the pointer and change the
398    * variable's value.
399    */
400   virtual bool setValue (T value) { *_ptr = value; return true; }
401
402   /**
403    * Create a copy of this raw value.
404    *
405    * The copy will use the same external pointer as the original.
406    */
407   virtual SGRaw* clone () const {
408     return new SGRawValuePointer(_ptr);
409   }
410
411 private:
412   T * _ptr;
413 };
414
415
416 /**
417  * A value managed through static functions.
418  *
419  * A read-only value will not have a setter; a write-only value will
420  * not have a getter.
421  */
422 template <class T>
423 class SGRawValueFunctions : public SGRawValue<T>
424 {
425 public:
426
427   /**
428    * The template type of a static getter function.
429    */
430   typedef T (*getter_t)();
431
432   /**
433    * The template type of a static setter function.
434    */
435   typedef void (*setter_t)(T);
436
437   /**
438    * Explicit constructor.
439    *
440    * Create a new raw value bound to the getter and setter supplied.
441    *
442    * @param getter A static function for getting a value, or 0
443    * to read-disable the value.
444    * @param setter A static function for setting a value, or 0
445    * to write-disable the value.
446    */
447   SGRawValueFunctions (getter_t getter = 0, setter_t setter = 0)
448     : _getter(getter), _setter(setter) {}
449
450   /**
451    * Destructor.
452    */
453   virtual ~SGRawValueFunctions () {}
454
455   /**
456    * Get the underlying value.
457    *
458    * This method will invoke the getter function to get a value.
459    * If no getter function was supplied, this method will always
460    * return the default value for the type.
461    */
462   virtual T getValue () const {
463     if (_getter) return (*_getter)();
464     else return SGRawValue<T>::DefaultValue;
465   }
466
467   /**
468    * Set the underlying value.
469    *
470    * This method will invoke the setter function to change the
471    * underlying value.  If no setter function was supplied, this
472    * method will return false.
473    */
474   virtual bool setValue (T value) {
475     if (_setter) { (*_setter)(value); return true; }
476     else return false;
477   }
478
479   /**
480    * Create a copy of this raw value, bound to the same functions.
481    */
482   virtual SGRaw* clone () const {
483     return new SGRawValueFunctions(_getter,_setter);
484   }
485
486 private:
487   getter_t _getter;
488   setter_t _setter;
489 };
490
491
492 /**
493  * An indexed value bound to static functions.
494  *
495  * A read-only value will not have a setter; a write-only value will
496  * not have a getter.  An indexed value is useful for binding one
497  * of a list of possible values (such as multiple engines for a
498  * plane).  The index is hard-coded at creation time.
499  *
500  * @see SGRawValue
501  */
502 template <class T>
503 class SGRawValueFunctionsIndexed : public SGRawValue<T>
504 {
505 public:
506   typedef T (*getter_t)(int);
507   typedef void (*setter_t)(int,T);
508   SGRawValueFunctionsIndexed (int index, getter_t getter = 0, setter_t setter = 0)
509     : _index(index), _getter(getter), _setter(setter) {}
510   virtual ~SGRawValueFunctionsIndexed () {}
511   virtual T getValue () const {
512     if (_getter) return (*_getter)(_index);
513     else return SGRawValue<T>::DefaultValue;
514   }
515   virtual bool setValue (T value) {
516     if (_setter) { (*_setter)(_index, value); return true; }
517     else return false;
518   }
519   virtual SGRaw* clone () const {
520     return new SGRawValueFunctionsIndexed(_index, _getter, _setter);
521   }
522 private:
523   int _index;
524   getter_t _getter;
525   setter_t _setter;
526 };
527
528
529 /**
530  * A value managed through an object and access methods.
531  *
532  * A read-only value will not have a setter; a write-only value will
533  * not have a getter.
534  */
535 template <class C, class T>
536 class SGRawValueMethods : public SGRawValue<T>
537 {
538 public:
539   typedef T (C::*getter_t)() const;
540   typedef void (C::*setter_t)(T);
541   SGRawValueMethods (C &obj, getter_t getter = 0, setter_t setter = 0)
542     : _obj(obj), _getter(getter), _setter(setter) {}
543   virtual ~SGRawValueMethods () {}
544   virtual T getValue () const {
545     if (_getter) { return (_obj.*_getter)(); }
546     else { return SGRawValue<T>::DefaultValue; }
547   }
548   virtual bool setValue (T value) {
549     if (_setter) { (_obj.*_setter)(value); return true; }
550     else return false;
551   }
552   virtual SGRaw* clone () const {
553     return new SGRawValueMethods(_obj, _getter, _setter);
554   }
555 private:
556   C &_obj;
557   getter_t _getter;
558   setter_t _setter;
559 };
560
561
562 /**
563  * An indexed value managed through an object and access methods.
564  *
565  * A read-only value will not have a setter; a write-only value will
566  * not have a getter.
567  */
568 template <class C, class T>
569 class SGRawValueMethodsIndexed : public SGRawValue<T>
570 {
571 public:
572   typedef T (C::*getter_t)(int) const;
573   typedef void (C::*setter_t)(int, T);
574   SGRawValueMethodsIndexed (C &obj, int index,
575                      getter_t getter = 0, setter_t setter = 0)
576     : _obj(obj), _index(index), _getter(getter), _setter(setter) {}
577   virtual ~SGRawValueMethodsIndexed () {}
578   virtual T getValue () const {
579     if (_getter) { return (_obj.*_getter)(_index); }
580     else { return SGRawValue<T>::DefaultValue; }
581   }
582   virtual bool setValue (T value) {
583     if (_setter) { (_obj.*_setter)(_index, value); return true; }
584     else return false;
585   }
586   virtual SGRaw* clone () const {
587     return new SGRawValueMethodsIndexed(_obj, _index, _getter, _setter);
588   }
589 private:
590   C &_obj;
591   int _index;
592   getter_t _getter;
593   setter_t _setter;
594 };
595
596 /**
597  * A raw value that contains its value. This provides a way for
598  * property nodes to contain values that shouldn't be stored in the
599  * property node itself.
600  */
601 template <class T>
602 class SGRawValueContainer : public SGRawValue<T>
603 {
604 public:
605
606     /**
607      * Explicit constructor.
608      */
609     SGRawValueContainer(const T& obj) : _obj(obj) {}
610
611     /**
612      * Destructor.
613      */
614     virtual ~SGRawValueContainer() {}
615
616     /**
617      * Get the underlying value.
618      */
619     virtual T getValue() const { return _obj; }
620
621     /**
622      * Set the underlying value.
623      *
624      * This method will dereference the pointer and change the
625      * variable's value.
626      */
627     virtual bool setValue (T value) { _obj = value; return true; }
628
629     /**
630      * Create a copy of this raw value.
631      */
632     virtual SGRaw* clone () const {
633         return new SGRawValueContainer(_obj);
634     }
635
636 private:
637     T _obj;
638 };
639
640 template<typename T>
641 SGRawExtended* SGRawBase<T, 0>::makeContainer() const
642 {
643     return new SGRawValueContainer<T>(static_cast<const SGRawValue<T>*>(this)
644                                       ->getValue());
645 }
646
647 template<typename T>
648 std::ostream& SGRawBase<T, 0>::printOn(std::ostream& stream) const
649 {
650     return stream << static_cast<SGRawValue<T>*>(this)->getValue();
651 }
652
653 template<typename T>
654 std::istream& SGRawBase<T, 0>::readFrom(std::istream& stream)
655 {
656     T value;
657     simgear::readFrom(stream, value);
658     static_cast<SGRawValue<T>*>(this)->setValue(value);
659     return stream;
660 }
661 \f
662 /**
663  * The smart pointer that manage reference counting
664  */
665 class SGPropertyNode;
666 typedef SGSharedPtr<SGPropertyNode> SGPropertyNode_ptr;
667 typedef SGSharedPtr<const SGPropertyNode> SGConstPropertyNode_ptr;
668
669 \f
670 /**
671  * The property change listener interface.
672  *
673  * <p>Any class that needs to listen for property changes must implement
674  * this interface.</p>
675  */
676 class SGPropertyChangeListener
677 {
678 public:
679   virtual ~SGPropertyChangeListener ();
680   virtual void valueChanged (SGPropertyNode * node);
681   virtual void childAdded (SGPropertyNode * parent, SGPropertyNode * child);
682   virtual void childRemoved (SGPropertyNode * parent, SGPropertyNode * child);
683
684 protected:
685   friend class SGPropertyNode;
686   virtual void register_property (SGPropertyNode * node);
687   virtual void unregister_property (SGPropertyNode * node);
688
689 private:
690   std::vector<SGPropertyNode *> _properties;
691 };
692
693
694 \f
695 /**
696  * A node in a property tree.
697  */
698 class SGPropertyNode : public SGReferenced
699 {
700 public:
701
702   /**
703    * Public constants.
704    */
705   enum {
706     MAX_STRING_LEN = 1024
707   };
708
709   /**
710    * Access mode attributes.
711    *
712    * <p>The ARCHIVE attribute is strictly advisory, and controls
713    * whether the property should normally be saved and restored.</p>
714    */
715   enum Attribute {
716     READ = 1,
717     WRITE = 2,
718     ARCHIVE = 4,
719     REMOVED = 8,
720     TRACE_READ = 16,
721     TRACE_WRITE = 32,
722     USERARCHIVE = 64
723   };
724
725
726   /**
727    * Last used attribute
728    * Update as needed when enum Attribute is changed
729    */
730   static const int LAST_USED_ATTRIBUTE;
731
732
733   /**
734    * Default constructor.
735    */
736   SGPropertyNode ();
737
738
739   /**
740    * Copy constructor.
741    */
742   SGPropertyNode (const SGPropertyNode &node);
743
744
745   /**
746    * Destructor.
747    */
748   virtual ~SGPropertyNode ();
749
750
751
752   //
753   // Basic properties.
754   //
755
756   /**
757    * Test whether this node contains a primitive leaf value.
758    */
759     bool hasValue () const { return (_type != simgear::props::NONE); }
760
761
762   /**
763    * Get the node's simple (XML) name.
764    */
765   const char * getName () const { return _name.c_str(); }
766
767
768   /**
769    * Get the node's pretty display name, with subscript when needed.
770    */
771   const char * getDisplayName (bool simplify = false) const;
772
773
774   /**
775    * Get the node's integer index.
776    */
777   int getIndex () const { return _index; }
778
779
780   /**
781    * Get a non-const pointer to the node's parent.
782    */
783   SGPropertyNode * getParent () { return _parent; }
784
785
786   /**
787    * Get a const pointer to the node's parent.
788    */
789   const SGPropertyNode * getParent () const { return _parent; }
790
791
792   //
793   // Children.
794   //
795
796
797   /**
798    * Get the number of child nodes.
799    */
800   int nChildren () const { return _children.size(); }
801
802
803   /**
804    * Get a child node by position (*NOT* index).
805    */
806   SGPropertyNode * getChild (int position);
807
808
809   /**
810    * Get a const child node by position (*NOT* index).
811    */
812   const SGPropertyNode * getChild (int position) const;
813
814
815   /**
816    * Test whether a named child exists.
817    */
818   bool hasChild (const char * name, int index = 0) const
819   {
820     return (getChild(name, index) != 0);
821   }
822
823   /**
824    * Test whether a named child exists.
825    */
826   bool hasChild (const std::string& name, int index = 0) const
827   {
828     return (getChild(name, index) != 0);
829   }
830
831   /**
832    * Create a child node after the last node with the same name.
833    */
834   SGPropertyNode * addChild (const char * name);
835
836   /**
837    * Get a child node by name and index.
838    */
839   SGPropertyNode * getChild (const char * name, int index = 0,
840                              bool create = false);
841
842   /**
843    * Get a child node by name and index.
844    */
845   SGPropertyNode * getChild (const std::string& name, int index = 0,
846                              bool create = false)
847   { return getChild(name.c_str(), index, create); }
848
849
850   /**
851    * Get a const child node by name and index.
852    */
853   const SGPropertyNode * getChild (const char * name, int index = 0) const;
854
855   /**
856    * Get a const child node by name and index.
857    */
858   const SGPropertyNode * getChild (const std::string& name, int index = 0) const
859   { return getChild(name.c_str(), index); }
860
861
862   /**
863    * Get a vector of all children with the specified name.
864    */
865   std::vector<SGPropertyNode_ptr> getChildren (const char * name) const;
866
867   /**
868    * Get a vector of all children with the specified name.
869    */
870   std::vector<SGPropertyNode_ptr> getChildren (const std::string& name) const
871   { return getChildren(name.c_str()); }
872
873   /**
874    * Remove child by position.
875    */
876   SGPropertyNode_ptr removeChild (int pos, bool keep = true);
877
878
879   /**
880    * Remove a child node
881    */
882   SGPropertyNode_ptr removeChild (const char * name, int index = 0,
883                                   bool keep = true);
884
885   /**
886    * Remove a child node
887    */
888   SGPropertyNode_ptr removeChild (const std::string& name, int index = 0,
889                                   bool keep = true)
890   { return removeChild(name.c_str(), index, keep); }
891
892   /**
893    * Remove all children with the specified name.
894    */
895   std::vector<SGPropertyNode_ptr> removeChildren (const char * name,
896                                              bool keep = true);
897
898
899   /**
900    * Remove all children with the specified name.
901    */
902   std::vector<SGPropertyNode_ptr> removeChildren (const std::string& name,
903                                              bool keep = true)
904   { return removeChildren(name.c_str(), keep); }
905
906   //
907   // Alias support.
908   //
909
910
911   /**
912    * Alias this node's leaf value to another's.
913    */
914   bool alias (SGPropertyNode * target);
915
916
917   /**
918    * Alias this node's leaf value to another's by relative path.
919    */
920   bool alias (const char * path);
921
922   /**
923    * Alias this node's leaf value to another's by relative path.
924    */
925   bool alias (const std::string& path)
926   { return alias(path.c_str()); }
927
928
929   /**
930    * Remove any alias for this node.
931    */
932   bool unalias ();
933
934
935   /**
936    * Test whether the node's leaf value is aliased to another's.
937    */
938   bool isAlias () const { return (_type == simgear::props::ALIAS); }
939
940
941   /**
942    * Get a non-const pointer to the current alias target, if any.
943    */
944   SGPropertyNode * getAliasTarget ();
945
946
947   /**
948    * Get a const pointer to the current alias target, if any.
949    */
950   const SGPropertyNode * getAliasTarget () const;
951
952
953   //
954   // Path information.
955   //
956
957
958   /**
959    * Get the path to this node from the root.
960    */
961   const char * getPath (bool simplify = false) const;
962
963
964   /**
965    * Get a pointer to the root node.
966    */
967   SGPropertyNode * getRootNode ();
968
969
970   /**
971    * Get a const pointer to the root node.
972    */
973   const SGPropertyNode * getRootNode () const;
974
975
976   /**
977    * Get a pointer to another node by relative path.
978    */
979   SGPropertyNode * getNode (const char * relative_path, bool create = false);
980
981   /**
982    * Get a pointer to another node by relative path.
983    */
984   SGPropertyNode * getNode (const std::string& relative_path, bool create = false)
985   { return getNode(relative_path.c_str(), create); }
986
987   /**
988    * Get a pointer to another node by relative path.
989    *
990    * This method leaves the index off the last member of the path,
991    * so that the user can specify it separately (and save some
992    * string building).  For example, getNode("/bar[1]/foo", 3) is
993    * exactly equivalent to getNode("bar[1]/foo[3]").  The index
994    * provided overrides any given in the path itself for the last
995    * component.
996    */
997   SGPropertyNode * getNode (const char * relative_path, int index,
998                             bool create = false);
999
1000   /**
1001    * Get a pointer to another node by relative path.
1002    *
1003    * This method leaves the index off the last member of the path,
1004    * so that the user can specify it separately (and save some
1005    * string building).  For example, getNode("/bar[1]/foo", 3) is
1006    * exactly equivalent to getNode("bar[1]/foo[3]").  The index
1007    * provided overrides any given in the path itself for the last
1008    * component.
1009    */
1010   SGPropertyNode * getNode (const std::string& relative_path, int index,
1011                             bool create = false)
1012   { return getNode(relative_path.c_str(), index, create); }
1013
1014   /**
1015    * Get a const pointer to another node by relative path.
1016    */
1017   const SGPropertyNode * getNode (const char * relative_path) const;
1018
1019   /**
1020    * Get a const pointer to another node by relative path.
1021    */
1022   const SGPropertyNode * getNode (const std::string& relative_path) const
1023   { return getNode(relative_path.c_str()); }
1024
1025
1026   /**
1027    * Get a const pointer to another node by relative path.
1028    *
1029    * This method leaves the index off the last member of the path,
1030    * so that the user can specify it separate.
1031    */
1032   const SGPropertyNode * getNode (const char * relative_path,
1033                                   int index) const;
1034
1035   /**
1036    * Get a const pointer to another node by relative path.
1037    *
1038    * This method leaves the index off the last member of the path,
1039    * so that the user can specify it separate.
1040    */
1041   const SGPropertyNode * getNode (const std::string& relative_path,
1042                                   int index) const
1043   { return getNode(relative_path.c_str(), index); }
1044
1045   //
1046   // Access Mode.
1047   //
1048
1049   /**
1050    * Check a single mode attribute for the property node.
1051    */
1052   bool getAttribute (Attribute attr) const { return ((_attr & attr) != 0); }
1053
1054
1055   /**
1056    * Set a single mode attribute for the property node.
1057    */
1058   void setAttribute (Attribute attr, bool state) {
1059     (state ? _attr |= attr : _attr &= ~attr);
1060   }
1061
1062
1063   /**
1064    * Get all of the mode attributes for the property node.
1065    */
1066   int getAttributes () const { return _attr; }
1067
1068
1069   /**
1070    * Set all of the mode attributes for the property node.
1071    */
1072   void setAttributes (int attr) { _attr = attr; }
1073   
1074
1075   //
1076   // Leaf Value (primitive).
1077   //
1078
1079
1080   /**
1081    * Get the type of leaf value, if any, for this node.
1082    */
1083   simgear::props::Type getType () const;
1084
1085
1086   /**
1087    * Get a bool value for this node.
1088    */
1089   bool getBoolValue () const;
1090
1091
1092   /**
1093    * Get an int value for this node.
1094    */
1095   int getIntValue () const;
1096
1097
1098   /**
1099    * Get a long int value for this node.
1100    */
1101   long getLongValue () const;
1102
1103
1104   /**
1105    * Get a float value for this node.
1106    */
1107   float getFloatValue () const;
1108
1109
1110   /**
1111    * Get a double value for this node.
1112    */
1113   double getDoubleValue () const;
1114
1115
1116   /**
1117    * Get a string value for this node.
1118    */
1119   const char * getStringValue () const;
1120
1121   /**
1122    * Get a value from a node. If the actual type of the node doesn't
1123    * match the desired type, a conversion isn't guaranteed.
1124    */
1125   template<typename T>
1126   T getValue(typename boost::enable_if_c<simgear::props::PropertyTraits<T>::Internal>
1127              ::type* dummy = 0) const;
1128   // Getter for extended property
1129   template<typename T>
1130   T getValue(typename boost::disable_if_c<simgear::props::PropertyTraits<T>::Internal>
1131              ::type* dummy = 0) const;
1132
1133   /**
1134    * Set a bool value for this node.
1135    */
1136   bool setBoolValue (bool value);
1137
1138
1139   /**
1140    * Set an int value for this node.
1141    */
1142   bool setIntValue (int value);
1143
1144
1145   /**
1146    * Set a long int value for this node.
1147    */
1148   bool setLongValue (long value);
1149
1150
1151   /**
1152    * Set a float value for this node.
1153    */
1154   bool setFloatValue (float value);
1155
1156
1157   /**
1158    * Set a double value for this node.
1159    */
1160   bool setDoubleValue (double value);
1161
1162
1163   /**
1164    * Set a string value for this node.
1165    */
1166   bool setStringValue (const char * value);
1167
1168   /**
1169    * Set a string value for this node.
1170    */
1171   bool setStringValue (const std::string& value)
1172   { return setStringValue(value.c_str()); }
1173
1174
1175   /**
1176    * Set a value of unspecified type for this node.
1177    */
1178   bool setUnspecifiedValue (const char * value);
1179
1180   template<typename T>
1181   bool setValue(const T& val,
1182                 typename boost::enable_if_c<simgear::props::PropertyTraits<T>::Internal>
1183                 ::type* dummy = 0);
1184
1185   template<typename T>
1186   bool setValue(const T& val,
1187                 typename boost::disable_if_c<simgear::props::PropertyTraits<T>::Internal>
1188                 ::type* dummy = 0);
1189   
1190   /**
1191    * Print the value of the property to a stream.
1192    */
1193   std::ostream& printOn(std::ostream& stream) const;
1194   
1195   //
1196   // Data binding.
1197   //
1198
1199
1200   /**
1201    * Test whether this node is bound to an external data source.
1202    */
1203   bool isTied () const { return _tied; }
1204
1205     /**
1206      * Bind this node to an external source.
1207      */
1208     template<typename T>
1209     bool tie(const SGRawValue<T> &rawValue, bool useDefault = true);
1210
1211   /**
1212    * Unbind this node from any external data source.
1213    */
1214   bool untie ();
1215
1216
1217   //
1218   // Convenience methods using paths.
1219   // TODO: add attribute methods
1220   //
1221
1222
1223   /**
1224    * Get another node's type.
1225    */
1226   simgear::props::Type getType (const char * relative_path) const;
1227
1228   /**
1229    * Get another node's type.
1230    */
1231   simgear::props::Type getType (const std::string& relative_path) const
1232   { return getType(relative_path.c_str()); }
1233
1234   /**
1235    * Test whether another node has a leaf value.
1236    */
1237   bool hasValue (const char * relative_path) const;
1238
1239   /**
1240    * Test whether another node has a leaf value.
1241    */
1242   bool hasValue (const std::string& relative_path) const
1243   { return hasValue(relative_path.c_str()); }
1244
1245   /**
1246    * Get another node's value as a bool.
1247    */
1248   bool getBoolValue (const char * relative_path,
1249                      bool defaultValue = false) const;
1250
1251   /**
1252    * Get another node's value as a bool.
1253    */
1254   bool getBoolValue (const std::string& relative_path,
1255                      bool defaultValue = false) const
1256   { return getBoolValue(relative_path.c_str(), defaultValue); }
1257
1258   /**
1259    * Get another node's value as an int.
1260    */
1261   int getIntValue (const char * relative_path,
1262                    int defaultValue = 0) const;
1263
1264   /**
1265    * Get another node's value as an int.
1266    */
1267   int getIntValue (const std::string& relative_path,
1268                    int defaultValue = 0) const
1269   { return getIntValue(relative_path.c_str(), defaultValue); }
1270
1271
1272   /**
1273    * Get another node's value as a long int.
1274    */
1275   long getLongValue (const char * relative_path,
1276                      long defaultValue = 0L) const;
1277
1278   /**
1279    * Get another node's value as a long int.
1280    */
1281   long getLongValue (const std::string& relative_path,
1282                      long defaultValue = 0L) const
1283   { return getLongValue(relative_path.c_str(), defaultValue); }
1284
1285   /**
1286    * Get another node's value as a float.
1287    */
1288   float getFloatValue (const char * relative_path,
1289                        float defaultValue = 0.0f) const;
1290
1291   /**
1292    * Get another node's value as a float.
1293    */
1294   float getFloatValue (const std::string& relative_path,
1295                        float defaultValue = 0.0f) const
1296   { return getFloatValue(relative_path.c_str(), defaultValue); }
1297
1298
1299   /**
1300    * Get another node's value as a double.
1301    */
1302   double getDoubleValue (const char * relative_path,
1303                          double defaultValue = 0.0) const;
1304
1305   /**
1306    * Get another node's value as a double.
1307    */
1308   double getDoubleValue (const std::string& relative_path,
1309                          double defaultValue = 0.0) const
1310   { return getDoubleValue(relative_path.c_str(), defaultValue); }
1311
1312   /**
1313    * Get another node's value as a string.
1314    */
1315   const char * getStringValue (const char * relative_path,
1316                                const char * defaultValue = "") const;
1317
1318
1319   /**
1320    * Get another node's value as a string.
1321    */
1322   const char * getStringValue (const std::string& relative_path,
1323                                const char * defaultValue = "") const
1324   { return getStringValue(relative_path.c_str(), defaultValue); }
1325
1326
1327   /**
1328    * Set another node's value as a bool.
1329    */
1330   bool setBoolValue (const char * relative_path, bool value);
1331
1332   /**
1333    * Set another node's value as a bool.
1334    */
1335   bool setBoolValue (const std::string& relative_path, bool value)
1336   { return setBoolValue(relative_path.c_str(), value); }
1337
1338
1339   /**
1340    * Set another node's value as an int.
1341    */
1342   bool setIntValue (const char * relative_path, int value);
1343
1344   /**
1345    * Set another node's value as an int.
1346    */
1347   bool setIntValue (const std::string& relative_path, int value)
1348   { return setIntValue(relative_path.c_str(), value); }
1349
1350
1351   /**
1352    * Set another node's value as a long int.
1353    */
1354   bool setLongValue (const char * relative_path, long value);
1355
1356   /**
1357    * Set another node's value as a long int.
1358    */
1359   bool setLongValue (const std::string& relative_path, long value)
1360   { return setLongValue(relative_path.c_str(), value); }
1361
1362
1363   /**
1364    * Set another node's value as a float.
1365    */
1366   bool setFloatValue (const char * relative_path, float value);
1367
1368   /**
1369    * Set another node's value as a float.
1370    */
1371   bool setFloatValue (const std::string& relative_path, float value)
1372   { return setFloatValue(relative_path.c_str(), value); }
1373
1374
1375   /**
1376    * Set another node's value as a double.
1377    */
1378   bool setDoubleValue (const char * relative_path, double value);
1379
1380   /**
1381    * Set another node's value as a double.
1382    */
1383   bool setDoubleValue (const std::string& relative_path, double value)
1384   { return setDoubleValue(relative_path.c_str(), value); }
1385
1386
1387   /**
1388    * Set another node's value as a string.
1389    */
1390   bool setStringValue (const char * relative_path, const char * value);
1391
1392   /**
1393    * Set another node's value as a string.
1394    */
1395   bool setStringValue (const std::string& relative_path, const char * value)
1396   { return setStringValue(relative_path.c_str(), value); }
1397
1398
1399   /**
1400    * Set another node's value with no specified type.
1401    */
1402   bool setUnspecifiedValue (const char * relative_path, const char * value);
1403
1404
1405   /**
1406    * Test whether another node is bound to an external data source.
1407    */
1408   bool isTied (const char * relative_path) const;
1409
1410   /**
1411    * Test whether another node is bound to an external data source.
1412    */
1413   bool isTied (const std::string& relative_path) const
1414   { return isTied(relative_path.c_str()); }
1415
1416   /**
1417    * Bind another node to an external bool source.
1418    */
1419   bool tie (const char * relative_path, const SGRawValue<bool> &rawValue,
1420             bool useDefault = true);
1421
1422   /**
1423    * Bind another node to an external bool source.
1424    */
1425   bool tie (const std::string& relative_path, const SGRawValue<bool> &rawValue,
1426             bool useDefault = true)
1427   { return tie(relative_path.c_str(), rawValue, useDefault); }
1428
1429
1430   /**
1431    * Bind another node to an external int source.
1432    */
1433   bool tie (const char * relative_path, const SGRawValue<int> &rawValue,
1434             bool useDefault = true);
1435
1436   /**
1437    * Bind another node to an external int source.
1438    */
1439   bool tie (const std::string& relative_path, const SGRawValue<int> &rawValue,
1440             bool useDefault = true)
1441   { return tie(relative_path.c_str(), rawValue, useDefault); }
1442
1443
1444   /**
1445    * Bind another node to an external long int source.
1446    */
1447   bool tie (const char * relative_path, const SGRawValue<long> &rawValue,
1448             bool useDefault = true);
1449
1450   /**
1451    * Bind another node to an external long int source.
1452    */
1453   bool tie (const std::string& relative_path, const SGRawValue<long> &rawValue,
1454             bool useDefault = true)
1455   { return tie(relative_path.c_str(), rawValue, useDefault); }
1456
1457
1458   /**
1459    * Bind another node to an external float source.
1460    */
1461   bool tie (const char * relative_path, const SGRawValue<float> &rawValue,
1462             bool useDefault = true);
1463
1464   /**
1465    * Bind another node to an external float source.
1466    */
1467   bool tie (const std::string& relative_path, const SGRawValue<float> &rawValue,
1468             bool useDefault = true)
1469   { return tie(relative_path.c_str(), rawValue, useDefault); }
1470
1471
1472   /**
1473    * Bind another node to an external double source.
1474    */
1475   bool tie (const char * relative_path, const SGRawValue<double> &rawValue,
1476             bool useDefault = true);
1477
1478   /**
1479    * Bind another node to an external double source.
1480    */
1481   bool tie (const std::string& relative_path, const SGRawValue<double> &rawValue,
1482             bool useDefault = true)
1483   { return tie(relative_path.c_str(), rawValue, useDefault); }
1484
1485
1486   /**
1487    * Bind another node to an external string source.
1488    */
1489   bool tie (const char * relative_path, const SGRawValue<const char *> &rawValue,
1490             bool useDefault = true);
1491
1492   /**
1493    * Bind another node to an external string source.
1494    */
1495   bool tie (const std::string& relative_path, const SGRawValue<const char*> &rawValue,
1496             bool useDefault = true)
1497   { return tie(relative_path.c_str(), rawValue, useDefault); }
1498
1499
1500   /**
1501    * Unbind another node from any external data source.
1502    */
1503   bool untie (const char * relative_path);
1504
1505   /**
1506    * Unbind another node from any external data source.
1507    */
1508   bool untie (const std::string& relative_path)
1509   { return untie(relative_path.c_str()); }
1510
1511
1512   /**
1513    * Add a change listener to the property. If "initial" is set call the
1514    * listener initially.
1515    */
1516   void addChangeListener (SGPropertyChangeListener * listener,
1517                           bool initial = false);
1518
1519
1520   /**
1521    * Remove a change listener from the property.
1522    */
1523   void removeChangeListener (SGPropertyChangeListener * listener);
1524
1525
1526   /**
1527    * Get the number of listeners.
1528    */
1529   int nListeners () const { return _listeners ? _listeners->size() : 0; }
1530
1531
1532   /**
1533    * Fire a value change event to all listeners.
1534    */
1535   void fireValueChanged ();
1536
1537
1538   /**
1539    * Fire a child-added event to all listeners.
1540    */
1541   void fireChildAdded (SGPropertyNode * child);
1542
1543
1544   /**
1545    * Fire a child-removed event to all listeners.
1546    */
1547   void fireChildRemoved (SGPropertyNode * child);
1548
1549
1550   /**
1551    * Clear any existing value and set the type to NONE.
1552    */
1553   void clearValue ();
1554
1555
1556 protected:
1557
1558   void fireValueChanged (SGPropertyNode * node);
1559   void fireChildAdded (SGPropertyNode * parent, SGPropertyNode * child);
1560   void fireChildRemoved (SGPropertyNode * parent, SGPropertyNode * child);
1561
1562   /**
1563    * Protected constructor for making new nodes on demand.
1564    */
1565   SGPropertyNode (const char * name, int index, SGPropertyNode * parent);
1566
1567
1568 private:
1569
1570                                 // Get the raw value
1571   bool get_bool () const;
1572   int get_int () const;
1573   long get_long () const;
1574   float get_float () const;
1575   double get_double () const;
1576   const char * get_string () const;
1577
1578                                 // Set the raw value
1579   bool set_bool (bool value);
1580   bool set_int (int value);
1581   bool set_long (long value);
1582   bool set_float (float value);
1583   bool set_double (double value);
1584   bool set_string (const char * value);
1585
1586
1587   /**
1588    * Get the value as a string.
1589    */
1590   const char * make_string () const;
1591
1592   /**
1593    * Trace a read access.
1594    */
1595   void trace_read () const;
1596
1597
1598   /**
1599    * Trace a write access.
1600    */
1601   void trace_write () const;
1602
1603
1604   /**
1605    * Remove this node from all nodes that link to it in their path cache.
1606    */
1607   void remove_from_path_caches();
1608
1609
1610   class hash_table;
1611
1612   int _index;
1613   std::string _name;
1614   mutable std::string _display_name;
1615   /// To avoid cyclic reference counting loops this shall not be a reference
1616   /// counted pointer
1617   SGPropertyNode * _parent;
1618   std::vector<SGPropertyNode_ptr> _children;
1619   std::vector<SGPropertyNode_ptr> _removedChildren;
1620   std::vector<hash_table *> _linkedNodes;
1621   mutable std::string _path;
1622   mutable std::string _buffer;
1623   hash_table * _path_cache;
1624   simgear::props::Type _type;
1625   bool _tied;
1626   int _attr;
1627
1628                                 // The right kind of pointer...
1629   union {
1630     SGPropertyNode * alias;
1631     SGRaw* val;
1632   } _value;
1633
1634   union {
1635     bool bool_val;
1636     int int_val;
1637     long long_val;
1638     float float_val;
1639     double double_val;
1640     char * string_val;
1641   } _local_val;
1642
1643   std::vector<SGPropertyChangeListener *> * _listeners;
1644
1645
1646   /**
1647     * Register/unregister node that links to this node in its path cache.
1648     */
1649   void add_linked_node (hash_table * node) { _linkedNodes.push_back(node); }
1650   bool remove_linked_node (hash_table * node);
1651
1652
1653 \f
1654   /**
1655    * A very simple hash table.
1656    */
1657   class hash_table {
1658   public:
1659
1660     /**
1661      * An entry in a bucket in a hash table.
1662      */
1663     class entry {
1664     public:
1665       entry ();
1666       ~entry ();
1667       const char * get_key () { return _key.c_str(); }
1668       void set_key (const char * key);
1669       SGPropertyNode * get_value () { return _value; }
1670       void set_value (SGPropertyNode * value);
1671     private:
1672       std::string _key;
1673       SGSharedPtr<SGPropertyNode> _value;
1674     };
1675
1676
1677     /**
1678      * A bucket in a hash table.
1679      */
1680     class bucket {
1681     public:
1682       bucket ();
1683       ~bucket ();
1684       entry * get_entry (const char * key, bool create = false);
1685       bool erase (SGPropertyNode * node);
1686       void clear (hash_table * owner);
1687     private:
1688       int _length;
1689       entry ** _entries;
1690     };
1691
1692     friend class bucket;
1693
1694     hash_table ();
1695     ~hash_table ();
1696     SGPropertyNode * get (const char * key);
1697     void put (const char * key, SGPropertyNode * value);
1698     bool erase (SGPropertyNode * node);
1699
1700   private:
1701     unsigned int hashcode (const char * key);
1702     unsigned int _data_length;
1703     bucket ** _data;
1704   };
1705
1706 };
1707
1708 // Convenience functions for use in templates
1709 template<typename T>
1710 T getValue(const SGPropertyNode*);
1711
1712 template<>
1713 inline bool getValue<bool>(const SGPropertyNode* node) { return node->getBoolValue(); }
1714
1715 template<>
1716 inline int getValue<int>(const SGPropertyNode* node) { return node->getIntValue(); }
1717
1718 template<>
1719 inline long getValue<long>(const SGPropertyNode* node) { return node->getLongValue(); }
1720
1721 template<>
1722 inline float getValue<float>(const SGPropertyNode* node)
1723 {
1724     return node->getFloatValue();
1725 }
1726
1727 template<>
1728 inline double getValue<double>(const SGPropertyNode* node)
1729 {
1730     return node->getDoubleValue();
1731 }
1732
1733 template<>
1734 inline const char * getValue<const char*>(const SGPropertyNode* node)
1735 {
1736     return node->getStringValue ();
1737 }
1738
1739 inline bool setValue(SGPropertyNode* node, bool value)
1740 {
1741     return node->setBoolValue(value);
1742 }
1743
1744 inline bool setValue(SGPropertyNode* node, int value)
1745 {
1746     return node->setIntValue(value);
1747 }
1748
1749 inline bool setValue(SGPropertyNode* node, long value)
1750 {
1751     return node->setLongValue(value);
1752 }
1753
1754 inline bool setValue(SGPropertyNode* node, float value)
1755 {
1756     return node->setFloatValue(value);
1757 }
1758
1759 inline bool setValue(SGPropertyNode* node, double value)
1760 {
1761     return node->setDoubleValue(value);
1762 }
1763
1764 inline bool setValue(SGPropertyNode* node, const char* value)
1765 {
1766     return node->setStringValue(value);
1767 }
1768
1769 inline bool setValue (SGPropertyNode* node, const std::string& value)
1770 {
1771     return node->setStringValue(value.c_str());
1772 }
1773
1774 template<typename T>
1775 bool SGPropertyNode::tie(const SGRawValue<T> &rawValue, bool useDefault)
1776 {
1777     using namespace simgear::props;
1778     if (_type == ALIAS || _tied)
1779         return false;
1780
1781     useDefault = useDefault && hasValue();
1782     T old_val = SGRawValue<T>::DefaultValue;
1783     if (useDefault)
1784         old_val = getValue<T>(this);
1785     clearValue();
1786     if (PropertyTraits<T>::Internal)
1787         _type = PropertyTraits<T>::type_tag;
1788     else
1789         _type = EXTENDED;
1790     _tied = true;
1791     _value.val = rawValue.clone();
1792     if (useDefault)
1793         setValue(old_val);
1794     return true;
1795 }
1796
1797 template<>
1798 bool SGPropertyNode::tie (const SGRawValue<const char *> &rawValue,
1799                           bool useDefault);
1800
1801 template<typename T>
1802 T SGPropertyNode::getValue(typename boost::disable_if_c<simgear::props
1803                            ::PropertyTraits<T>::Internal>::type* dummy) const
1804 {
1805     using namespace simgear::props;
1806     if (_attr == (READ|WRITE) && _type == EXTENDED
1807         && _value.val->getType() == PropertyTraits<T>::type_tag) {
1808         return static_cast<SGRawValue<T>*>(_value.val)->getValue();
1809     }
1810     if (getAttribute(TRACE_READ))
1811         trace_read();
1812     if (!getAttribute(READ))
1813         return SGRawValue<T>::DefaultValue;
1814     switch (_type) {
1815     case EXTENDED:
1816         if (_value.val->getType() == PropertyTraits<T>::type_tag)
1817             return static_cast<SGRawValue<T>*>(_value.val)->getValue();
1818         break;
1819     case STRING:
1820     case UNSPECIFIED:
1821         return simgear::parseString<T>(make_string());
1822         break;
1823     }
1824     return SGRawValue<T>::DefaultValue;
1825 }
1826
1827 template<typename T>
1828 inline T SGPropertyNode::getValue(typename boost::enable_if_c<simgear::props
1829                                   ::PropertyTraits<T>::Internal>::type* dummy) const
1830 {
1831   return ::getValue<T>(this);
1832 }
1833
1834 template<typename T>
1835 bool SGPropertyNode::setValue(const T& val,
1836                               typename boost::disable_if_c<simgear::props
1837                               ::PropertyTraits<T>::Internal>::type* dummy)
1838 {
1839     using namespace simgear::props;
1840     if (_attr == (READ|WRITE) && _type == EXTENDED
1841         && _value.val->getType() == PropertyTraits<T>::type_tag) {
1842         static_cast<SGRawValue<T>*>(_value.val)->setValue(val);
1843         return true;
1844     }
1845     if (getAttribute(WRITE)
1846         && ((_type == EXTENDED
1847             && _value.val->getType() == PropertyTraits<T>::type_tag)
1848             || _type == NONE || _type == UNSPECIFIED)) {
1849         if (_type == NONE || _type == UNSPECIFIED) {
1850             clearValue();
1851             _type = EXTENDED;
1852             _value.val = new SGRawValueContainer<T>(val);
1853         } else {
1854             static_cast<SGRawValue<T>*>(_value.val)->setValue(val);
1855         }
1856         if (getAttribute(TRACE_WRITE))
1857             trace_write();
1858         return true;
1859     }
1860     return false;
1861 }
1862
1863 template<typename T>
1864 inline bool SGPropertyNode::setValue(const T& val,
1865                                      typename boost::enable_if_c<simgear::props
1866                                      ::PropertyTraits<T>::Internal>::type* dummy)
1867 {
1868   return ::setValue(this, val);
1869 }
1870 #endif // __PROPS_HXX
1871
1872 // end of props.hxx