]> git.mxchange.org Git - simgear.git/blob - simgear/misc/props.hxx
Patch from Tony Peden to remove unused variable and eliminate compiler
[simgear.git] / simgear / misc / 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 <map>
21
22 #if PROPS_STANDALONE
23
24 #include <string>
25 #include <iostream>
26
27 using std::string;
28 using std::vector;
29 using std::map;
30 using std::istream;
31 using std::ostream;
32
33 #else
34
35 #include <simgear/compiler.h>
36 #include <simgear/debug/logstream.hxx>
37 #include STL_STRING
38 #include STL_IOSTREAM
39 SG_USING_STD(string);
40 SG_USING_STD(vector);
41 SG_USING_STD(map);
42 #if !defined(SG_HAVE_NATIVE_SGI_COMPILERS)
43 SG_USING_STD(istream);
44 SG_USING_STD(ostream);
45 #endif
46
47 #endif
48
49
50 #ifdef NONE
51 #pragma warn A sloppy coder has defined NONE as a macro!
52 #undef NONE
53 #endif
54
55 #ifdef ALIAS
56 #pragma warn A sloppy coder has defined ALIAS as a macro!
57 #undef ALIAS
58 #endif
59
60 #ifdef UNSPECIFIED
61 #pragma warn A sloppy coder has defined UNSPECIFIED as a macro!
62 #undef UNSPECIFIED
63 #endif
64
65 #ifdef BOOL
66 #pragma warn A sloppy coder has defined BOOL as a macro!
67 #undef BOOL
68 #endif
69
70 #ifdef INT
71 #pragma warn A sloppy coder has defined INT as a macro!
72 #undef INT
73 #endif
74
75 #ifdef LONG
76 #pragma warn A sloppy coder has defined LONG as a macro!
77 #undef LONG
78 #endif
79
80 #ifdef FLOAT
81 #pragma warn A sloppy coder has defined FLOAT as a macro!
82 #undef FLOAT
83 #endif
84
85 #ifdef DOUBLE
86 #pragma warn A sloppy coder has defined DOUBLE as a macro!
87 #undef DOUBLE
88 #endif
89
90 #ifdef STRING
91 #pragma warn A sloppy coder has defined STRING as a macro!
92 #undef STRING
93 #endif
94
95
96 \f
97 ////////////////////////////////////////////////////////////////////////
98 // A raw value.
99 //
100 // This is the mechanism that information-providing routines can
101 // use to link their own values to the property manager.  Any
102 // SGValue can be tied to a raw value and then untied again.
103 //
104 // Note: we are forced to use inlined methods here to ensure
105 // that the templates will be instantiated.  We're probably taking
106 // a small performance hit for that.
107 ////////////////////////////////////////////////////////////////////////
108
109
110 /**
111  * Abstract base class for a raw value.
112  *
113  * <p>The property manager is implemented in two layers.  The {@link
114  * SGPropertyNode} is the highest and most abstract layer,
115  * representing an LValue/RValue pair: it records the position of the
116  * property in the property tree and contains facilities for
117  * navigation to other nodes.  It is guaranteed to be persistent: the
118  * {@link SGPropertyNode} will not change during a session, even if
119  * the property is bound and unbound multiple times.</p>
120  *
121  * <p>When the property value is not managed internally in the
122  * SGPropertyNode, the SGPropertyNode will contain a reference to an
123  * SGRawValue (this class), which provides an abstract way to get,
124  * set, and clone the underlying value.  The SGRawValue may change
125  * frequently during a session as a value is retyped or bound and
126  * unbound to various data source, but the abstract SGPropertyNode
127  * layer insulates the application from those changes.  The raw value
128  * contains no facilities for data binding or for type conversion: it
129  * is simply the abstraction of a primitive data type (or a compound
130  * data type, in the case of a string).</p>
131  *
132  * <p>The SGPropertyNode class always keeps a *copy* of a raw value,
133  * not the original one passed to it; if you override a derived class
134  * but do not replace the {@link #clone} method, strange things will
135  * happen.</p>
136  *
137  * <p>All derived SGRawValue classes must implement {@link #getValue},
138  * {@link #setValue}, and {@link #clone} for the appropriate type.</p>
139  *
140  * @see SGPropertyNode
141  * @see SGRawValuePointer
142  * @see SGRawValueFunctions
143  * @see SGRawValueFunctionsIndexed
144  * @see SGRawValueMethods
145  * @see SGRawValueMethodsIndexed
146  */
147 template <class T>
148 class SGRawValue
149 {
150 public:
151
152   /**
153    * The default underlying value for this type.
154    *
155    * Every raw value has a default; the default is false for a
156    * boolean, 0 for the various numeric values, and "" for a string.
157    * If additional types of raw values are added in the future, they
158    * may need different kinds of default values (such as epoch for a
159    * date type).  The default value is used when creating new values.
160    */
161   static const T DefaultValue;  // Default for this kind of raw value.
162
163
164   /**
165    * Constructor.
166    *
167    * Use the default value for this type.
168    */
169   SGRawValue () {}
170
171
172   /**
173    * Destructor.
174    */
175   virtual ~SGRawValue () {}
176
177
178   /**
179    * Return the underlying value.
180    *
181    * @return The actual value for the property.
182    * @see #setValue
183    */
184   virtual T getValue () const = 0;
185
186
187   /**
188    * Assign a new underlying value.
189    *
190    * If the new value cannot be set (because this is a read-only
191    * raw value, or because the new value is not acceptable for
192    * some reason) this method returns false and leaves the original
193    * value unchanged.
194    *
195    * @param value The actual value for the property.
196    * @return true if the value was set successfully, false otherwise.
197    * @see #getValue
198    */
199   virtual bool setValue (T value) = 0;
200
201
202   /**
203    * Create a new deep copy of this raw value.
204    *
205    * The copy will contain its own version of the underlying value
206    * as well.
207    *
208    * @return A deep copy of the current object.
209    */
210   virtual SGRawValue * clone () const = 0;
211 };
212
213
214 /**
215  * A raw value bound to a pointer.
216  *
217  * This is the most efficient way to tie an external value, but also
218  * the most dangerous, because there is no way for the supplier to
219  * perform bounds checking and derived calculations except by polling
220  * the variable to see if it has changed.  There is no default
221  * constructor, because this class would be meaningless without a
222  * pointer.
223  */
224 template <class T>
225 class SGRawValuePointer : public SGRawValue<T>
226 {
227 public:
228
229   /**
230    * Explicit pointer constructor.
231    *
232    * Create a new raw value bound to the value of the variable
233    * referenced by the pointer.
234    *
235    * @param ptr The pointer to the variable to which this raw value
236    * will be bound.
237    */
238   SGRawValuePointer (T * ptr) : _ptr(ptr) {}
239
240   /**
241    * Destructor.
242    */
243   virtual ~SGRawValuePointer () {}
244
245   /**
246    * Get the underlying value.
247    *
248    * This method will dereference the pointer and return the
249    * variable's value.
250    */
251   virtual T getValue () const { return *_ptr; }
252
253   /**
254    * Set the underlying value.
255    *
256    * This method will dereference the pointer and change the
257    * variable's value.
258    */
259   virtual bool setValue (T value) { *_ptr = value; return true; }
260
261   /**
262    * Create a copy of this raw value.
263    *
264    * The copy will use the same external pointer as the original.
265    */
266   virtual SGRawValue<T> * clone () const {
267     return new SGRawValuePointer<T>(_ptr);
268   }
269
270 private:
271   T * _ptr;
272 };
273
274
275 /**
276  * A value managed through static functions.
277  *
278  * A read-only value will not have a setter; a write-only value will
279  * not have a getter.
280  */
281 template <class T>
282 class SGRawValueFunctions : public SGRawValue<T>
283 {
284 public:
285
286   /**
287    * The template type of a static getter function.
288    */
289   typedef T (*getter_t)();
290
291   /**
292    * The template type of a static setter function.
293    */
294   typedef void (*setter_t)(T);
295
296   /**
297    * Explicit constructor.
298    *
299    * Create a new raw value bound to the getter and setter supplied.
300    *
301    * @param getter A static function for getting a value, or 0
302    * to read-disable the value.
303    * @param setter A static function for setting a value, or 0
304    * to write-disable the value.
305    */
306   SGRawValueFunctions (getter_t getter = 0, setter_t setter = 0)
307     : _getter(getter), _setter(setter) {}
308
309   /**
310    * Destructor.
311    */
312   virtual ~SGRawValueFunctions () {}
313
314   /**
315    * Get the underlying value.
316    *
317    * This method will invoke the getter function to get a value.
318    * If no getter function was supplied, this method will always
319    * return the default value for the type.
320    */
321   virtual T getValue () const {
322     if (_getter) return (*_getter)();
323     else return SGRawValue<T>::DefaultValue;
324   }
325
326   /**
327    * Set the underlying value.
328    *
329    * This method will invoke the setter function to change the
330    * underlying value.  If no setter function was supplied, this
331    * method will return false.
332    */
333   virtual bool setValue (T value) {
334     if (_setter) { (*_setter)(value); return true; }
335     else return false;
336   }
337
338   /**
339    * Create a copy of this raw value, bound to the same functions.
340    */
341   virtual SGRawValue<T> * clone () const {
342     return new SGRawValueFunctions<T>(_getter,_setter);
343   }
344
345 private:
346   getter_t _getter;
347   setter_t _setter;
348 };
349
350
351 /**
352  * An indexed value bound to static functions.
353  *
354  * A read-only value will not have a setter; a write-only value will
355  * not have a getter.  An indexed value is useful for binding one
356  * of a list of possible values (such as multiple engines for a
357  * plane).  The index is hard-coded at creation time.
358  *
359  * @see SGRawValue
360  */
361 template <class T>
362 class SGRawValueFunctionsIndexed : public SGRawValue<T>
363 {
364 public:
365   typedef T (*getter_t)(int);
366   typedef void (*setter_t)(int,T);
367   SGRawValueFunctionsIndexed (int index, getter_t getter = 0, setter_t setter = 0)
368     : _index(index), _getter(getter), _setter(setter) {}
369   virtual ~SGRawValueFunctionsIndexed () {}
370   virtual T getValue () const {
371     if (_getter) return (*_getter)(_index);
372     else return SGRawValue<T>::DefaultValue;
373   }
374   virtual bool setValue (T value) {
375     if (_setter) { (*_setter)(_index, value); return true; }
376     else return false;
377   }
378   virtual SGRawValue<T> * clone () const {
379     return new SGRawValueFunctionsIndexed<T>(_index, _getter, _setter);
380   }
381 private:
382   int _index;
383   getter_t _getter;
384   setter_t _setter;
385 };
386
387
388 /**
389  * A value managed through an object and access methods.
390  *
391  * A read-only value will not have a setter; a write-only value will
392  * not have a getter.
393  */
394 template <class C, class T>
395 class SGRawValueMethods : public SGRawValue<T>
396 {
397 public:
398   typedef T (C::*getter_t)() const;
399   typedef void (C::*setter_t)(T);
400   SGRawValueMethods (C &obj, getter_t getter = 0, setter_t setter = 0)
401     : _obj(obj), _getter(getter), _setter(setter) {}
402   virtual ~SGRawValueMethods () {}
403   virtual T getValue () const {
404     if (_getter) { return (_obj.*_getter)(); }
405     else { return SGRawValue<T>::DefaultValue; }
406   }
407   virtual bool setValue (T value) {
408     if (_setter) { (_obj.*_setter)(value); return true; }
409     else return false;
410   }
411   virtual SGRawValue<T> * clone () const {
412     return new SGRawValueMethods<C,T>(_obj, _getter, _setter);
413   }
414 private:
415   C &_obj;
416   getter_t _getter;
417   setter_t _setter;
418 };
419
420
421 /**
422  * An indexed value managed through an object and access methods.
423  *
424  * A read-only value will not have a setter; a write-only value will
425  * not have a getter.
426  */
427 template <class C, class T>
428 class SGRawValueMethodsIndexed : public SGRawValue<T>
429 {
430 public:
431   typedef T (C::*getter_t)(int) const;
432   typedef void (C::*setter_t)(int, T);
433   SGRawValueMethodsIndexed (C &obj, int index,
434                      getter_t getter = 0, setter_t setter = 0)
435     : _obj(obj), _index(index), _getter(getter), _setter(setter) {}
436   virtual ~SGRawValueMethodsIndexed () {}
437   virtual T getValue () const {
438     if (_getter) { return (_obj.*_getter)(_index); }
439     else { return SGRawValue<T>::DefaultValue; }
440   }
441   virtual bool setValue (T value) {
442     if (_setter) { (_obj.*_setter)(_index, value); return true; }
443     else return false;
444   }
445   virtual SGRawValue<T> * clone () const {
446     return new SGRawValueMethodsIndexed<C,T>(_obj, _index, _getter, _setter);
447   }
448 private:
449   C &_obj;
450   int _index;
451   getter_t _getter;
452   setter_t _setter;
453 };
454
455
456 \f
457 /**
458  * A node in a property tree.
459  */
460 class SGPropertyNode
461 {
462 public:
463
464   /**
465    * Public constants.
466    */
467   enum {
468     MAX_STRING_LEN = 1024
469   };
470
471   /**
472    * Property value types.
473    */
474   enum Type {
475     NONE,
476     ALIAS,
477     BOOL,
478     INT,
479     LONG,
480     FLOAT,
481     DOUBLE,
482     STRING,
483     UNSPECIFIED
484   };
485
486
487   /**
488    * Access mode attributes.
489    *
490    * <p>The ARCHIVE attribute is strictly advisory, and controls
491    * whether the property should normally be saved and restored.</p>
492    */
493   enum Attribute {
494     READ = 1,
495     WRITE = 2,
496     ARCHIVE = 4,
497     TRACE_READ = 8,
498     TRACE_WRITE = 16
499   };
500
501
502   /**
503    * Default constructor.
504    */
505   SGPropertyNode ();
506
507
508   /**
509    * Copy constructor.
510    */
511   SGPropertyNode (const SGPropertyNode &node);
512
513
514   /**
515    * Destructor.
516    */
517   virtual ~SGPropertyNode ();
518
519
520
521   //
522   // Basic properties.
523   //
524
525   /**
526    * Test whether this node contains a primitive leaf value.
527    */
528   bool hasValue () const { return (_type != NONE); }
529
530
531   /**
532    * Get the node's simple (XML) name.
533    */
534   const char * getName () const { return _name; }
535
536
537   /**
538    * Get the node's integer index.
539    */
540   const int getIndex () const { return _index; }
541
542
543   /**
544    * Get a non-const pointer to the node's parent.
545    */
546   SGPropertyNode * getParent () { return _parent; }
547
548
549   /**
550    * Get a const pointer to the node's parent.
551    */
552   const SGPropertyNode * getParent () const { return _parent; }
553
554
555   //
556   // Children.
557   //
558
559
560   /**
561    * Get the number of child nodes.
562    */
563   const int nChildren () const { return _children.size(); }
564
565
566   /**
567    * Get a child node by position (*NOT* index).
568    */
569   SGPropertyNode * getChild (int position);
570
571
572   /**
573    * Get a const child node by position (*NOT* index).
574    */
575   const SGPropertyNode * getChild (int position) const;
576
577
578   /**
579    * Get a child node by name and index.
580    */
581   SGPropertyNode * getChild (const char * name, int index = 0,
582                              bool create = false);
583
584
585   /**
586    * Get a const child node by name and index.
587    */
588   const SGPropertyNode * getChild (const char * name, int index = 0) const;
589
590
591   /**
592    * Get a vector of all children with the specified name.
593    */
594   vector<SGPropertyNode *> getChildren (const char * name);
595
596
597   /**
598    * Get a vector all all children (const) with the specified name.
599    */
600   vector<const SGPropertyNode *> getChildren (const char * name) const;
601
602
603   //
604   // Alias support.
605   //
606
607
608   /**
609    * Alias this node's leaf value to another's.
610    */
611   bool alias (SGPropertyNode * target);
612
613
614   /**
615    * Alias this node's leaf value to another's by relative path.
616    */
617   bool alias (const char * path);
618
619
620   /**
621    * Remove any alias for this node.
622    */
623   bool unalias ();
624
625
626   /**
627    * Test whether the node's leaf value is aliased to another's.
628    */
629   bool isAlias () const { return (_type == ALIAS); }
630
631
632   /**
633    * Get a non-const pointer to the current alias target, if any.
634    */
635   SGPropertyNode * getAliasTarget ();
636
637
638   /**
639    * Get a const pointer to the current alias target, if any.
640    */
641   const SGPropertyNode * getAliasTarget () const;
642
643
644   //
645   // Path information.
646   //
647
648
649   /**
650    * Get the path to this node from the root.
651    */
652   const char * getPath (bool simplify = false) const;
653
654
655   /**
656    * Get a pointer to the root node.
657    */
658   SGPropertyNode * getRootNode ();
659
660
661   /**
662    * Get a const pointer to the root node.
663    */
664   const SGPropertyNode * getRootNode () const;
665
666
667   /**
668    * Get a pointer to another node by relative path.
669    */
670   SGPropertyNode * getNode (const char * relative_path, bool create = false);
671
672
673   /**
674    * Get a pointer to another node by relative path.
675    *
676    * This method leaves the index off the last member of the path,
677    * so that the user can specify it separately (and save some
678    * string building).  For example, getNode("/bar[1]/foo", 3) is
679    * exactly equivalent to getNode("bar[1]/foo[3]").  The index
680    * provided overrides any given in the path itself for the last
681    * component.
682    */
683   SGPropertyNode * getNode (const char * relative_path, int index,
684                             bool create = false);
685
686
687   /**
688    * Get a const pointer to another node by relative path.
689    */
690   const SGPropertyNode * getNode (const char * relative_path) const;
691
692
693   /**
694    * Get a const pointer to another node by relative path.
695    *
696    * This method leaves the index off the last member of the path,
697    * so that the user can specify it separate.
698    */
699   const SGPropertyNode * getNode (const char * relative_path,
700                                   int index) const;
701
702
703   //
704   // Access Mode.
705   //
706
707   /**
708    * Check a single mode attribute for the property node.
709    */
710   bool getAttribute (Attribute attr) const { return ((_attr & attr) != 0); }
711
712
713   /**
714    * Set a single mode attribute for the property node.
715    */
716   void setAttribute (Attribute attr, bool state) {
717     (state ? _attr |= attr : _attr &= ~attr);
718   }
719
720
721   /**
722    * Get all of the mode attributes for the property node.
723    */
724   int getAttributes () const { return _attr; }
725
726
727   /**
728    * Set all of the mode attributes for the property node.
729    */
730   void setAttributes (int attr) { _attr = attr; }
731   
732
733   //
734   // Leaf Value (primitive).
735   //
736
737
738   /**
739    * Get the type of leaf value, if any, for this node.
740    */
741   Type getType () const;
742
743
744   /**
745    * Get a bool value for this node.
746    */
747   bool getBoolValue () const;
748
749
750   /**
751    * Get an int value for this node.
752    */
753   int getIntValue () const;
754
755
756   /**
757    * Get a long int value for this node.
758    */
759   long getLongValue () const;
760
761
762   /**
763    * Get a float value for this node.
764    */
765   float getFloatValue () const;
766
767
768   /**
769    * Get a double value for this node.
770    */
771   double getDoubleValue () const;
772
773
774   /**
775    * Get a string value for this node.
776    */
777   const char * getStringValue () const;
778
779
780
781   /**
782    * Set a bool value for this node.
783    */
784   bool setBoolValue (bool value);
785
786
787   /**
788    * Set an int value for this node.
789    */
790   bool setIntValue (int value);
791
792
793   /**
794    * Set a long int value for this node.
795    */
796   bool setLongValue (long value);
797
798
799   /**
800    * Set a float value for this node.
801    */
802   bool setFloatValue (float value);
803
804
805   /**
806    * Set a double value for this node.
807    */
808   bool setDoubleValue (double value);
809
810
811   /**
812    * Set a string value for this node.
813    */
814   bool setStringValue (const char * value);
815
816
817   /**
818    * Set a value of unspecified type for this node.
819    */
820   bool setUnspecifiedValue (const char * value);
821
822
823   //
824   // Data binding.
825   //
826
827
828   /**
829    * Test whether this node is bound to an external data source.
830    */
831   bool isTied () const { return _tied; }
832
833
834   /**
835    * Bind this node to an external bool source.
836    */
837   bool tie (const SGRawValue<bool> &rawValue, bool useDefault = true);
838
839
840   /**
841    * Bind this node to an external int source.
842    */
843   bool tie (const SGRawValue<int> &rawValue, bool useDefault = true);
844
845
846   /**
847    * Bind this node to an external long int source.
848    */
849   bool tie (const SGRawValue<long> &rawValue, bool useDefault = true);
850
851
852   /**
853    * Bind this node to an external float source.
854    */
855   bool tie (const SGRawValue<float> &rawValue, bool useDefault = true);
856
857
858   /**
859    * Bind this node to an external double source.
860    */
861   bool tie (const SGRawValue<double> &rawValue, bool useDefault = true);
862
863
864   /**
865    * Bind this node to an external string source.
866    */
867   bool tie (const SGRawValue<const char *> &rawValue, bool useDefault = true);
868
869
870   /**
871    * Unbind this node from any external data source.
872    */
873   bool untie ();
874
875
876   //
877   // Convenience methods using paths.
878   // TODO: add attribute methods
879   //
880
881
882   /**
883    * Get another node's type.
884    */
885   Type getType (const char * relative_path) const;
886
887
888   /**
889    * Test whether another node has a leaf value.
890    */
891   bool hasValue (const char * relative_path) const;
892
893
894   /**
895    * Get another node's value as a bool.
896    */
897   bool getBoolValue (const char * relative_path,
898                      bool defaultValue = false) const;
899
900
901   /**
902    * Get another node's value as an int.
903    */
904   int getIntValue (const char * relative_path,
905                    int defaultValue = 0) const;
906
907
908   /**
909    * Get another node's value as a long int.
910    */
911   long getLongValue (const char * relative_path,
912                      long defaultValue = 0L) const;
913
914
915   /**
916    * Get another node's value as a float.
917    */
918   float getFloatValue (const char * relative_path,
919                        float defaultValue = 0.0) const;
920
921
922   /**
923    * Get another node's value as a double.
924    */
925   double getDoubleValue (const char * relative_path,
926                          double defaultValue = 0.0L) const;
927
928
929   /**
930    * Get another node's value as a string.
931    */
932   const char * getStringValue (const char * relative_path,
933                                const char * defaultValue = "") const;
934
935
936   /**
937    * Set another node's value as a bool.
938    */
939   bool setBoolValue (const char * relative_path, bool value);
940
941
942   /**
943    * Set another node's value as an int.
944    */
945   bool setIntValue (const char * relative_path, int value);
946
947
948   /**
949    * Set another node's value as a long int.
950    */
951   bool setLongValue (const char * relative_path, long value);
952
953
954   /**
955    * Set another node's value as a float.
956    */
957   bool setFloatValue (const char * relative_path, float value);
958
959
960   /**
961    * Set another node's value as a double.
962    */
963   bool setDoubleValue (const char * relative_path, double value);
964
965
966   /**
967    * Set another node's value as a string.
968    */
969   bool setStringValue (const char * relative_path, const char * value);
970
971
972   /**
973    * Set another node's value with no specified type.
974    */
975   bool setUnspecifiedValue (const char * relative_path, const char * value);
976
977
978   /**
979    * Test whether another node is bound to an external data source.
980    */
981   bool isTied (const char * relative_path) const;
982
983
984   /**
985    * Bind another node to an external bool source.
986    */
987   bool tie (const char * relative_path, const SGRawValue<bool> &rawValue,
988             bool useDefault = true);
989
990
991   /**
992    * Bind another node to an external int source.
993    */
994   bool tie (const char * relative_path, const SGRawValue<int> &rawValue,
995             bool useDefault = true);
996
997
998   /**
999    * Bind another node to an external long int source.
1000    */
1001   bool tie (const char * relative_path, const SGRawValue<long> &rawValue,
1002             bool useDefault = true);
1003
1004
1005   /**
1006    * Bind another node to an external float source.
1007    */
1008   bool tie (const char * relative_path, const SGRawValue<float> &rawValue,
1009             bool useDefault = true);
1010
1011
1012   /**
1013    * Bind another node to an external double source.
1014    */
1015   bool tie (const char * relative_path, const SGRawValue<double> &rawValue,
1016             bool useDefault = true);
1017
1018
1019   /**
1020    * Bind another node to an external string source.
1021    */
1022   bool tie (const char * relative_path, const SGRawValue<const char *> &rawValue,
1023             bool useDefault = true);
1024
1025
1026   /**
1027    * Unbind another node from any external data source.
1028    */
1029   bool untie (const char * relative_path);
1030
1031
1032 protected:
1033
1034
1035   /**
1036    * Protected constructor for making new nodes on demand.
1037    */
1038   SGPropertyNode (const char * name, int index, SGPropertyNode * parent);
1039
1040
1041 private:
1042
1043                                 // Get the raw value
1044   bool get_bool () const;
1045   int get_int () const;
1046   long get_long () const;
1047   float get_float () const;
1048   double get_double () const;
1049   const char * get_string () const;
1050
1051                                 // Set the raw value
1052   bool set_bool (bool value);
1053   bool set_int (int value);
1054   bool set_long (long value);
1055   bool set_float (float value);
1056   bool set_double (double value);
1057   bool set_string (const char * value);
1058
1059
1060   /**
1061    * Clear any existing value and set the type to NONE.
1062    */
1063   void clear_value ();
1064
1065
1066   /**
1067    * Get the value as a string.
1068    */
1069   const char * make_string () const;
1070
1071
1072   /**
1073    * Trace a read access.
1074    */
1075   void trace_read () const;
1076
1077
1078   /**
1079    * Trace a write access.
1080    */
1081   void trace_write () const;
1082
1083   mutable char _buffer[MAX_STRING_LEN+1];
1084
1085   const char * _name;
1086   int _index;
1087   SGPropertyNode * _parent;
1088   vector<SGPropertyNode *> _children;
1089   typedef map<const string,SGPropertyNode *> cache_map;
1090   cache_map * _path_cache;
1091   Type _type;
1092   bool _tied;
1093   int _attr;
1094
1095                                 // The right kind of pointer...
1096   union {
1097     SGPropertyNode * alias;
1098     SGRawValue<bool> * bool_val;
1099     SGRawValue<int> * int_val;
1100     SGRawValue<long> * long_val;
1101     SGRawValue<float> * float_val;
1102     SGRawValue<double> * double_val;
1103     SGRawValue<const char *> * string_val;
1104   } _value;
1105
1106   union {
1107     bool bool_val;
1108     int int_val;
1109     long long_val;
1110     float float_val;
1111     double double_val;
1112     const char * string_val;
1113   } _local_val;
1114
1115
1116 };
1117
1118 #endif // __PROPS_HXX
1119
1120 // end of props.hxx