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