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