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.
7 * See props.html for documentation [replace with URL when available].
15 #ifndef PROPS_STANDALONE
16 #define PROPS_STANDALONE 0
33 #include <simgear/compiler.h>
34 #include <simgear/debug/logstream.hxx>
39 SG_USING_STD(istream);
40 SG_USING_STD(ostream);
44 #include <simgear/structure/SGReferenced.hxx>
45 #include <simgear/structure/SGSharedPtr.hxx>
49 #pragma warn A sloppy coder has defined NONE as a macro!
54 #pragma warn A sloppy coder has defined ALIAS as a macro!
59 #pragma warn A sloppy coder has defined UNSPECIFIED as a macro!
64 #pragma warn A sloppy coder has defined BOOL as a macro!
69 #pragma warn A sloppy coder has defined INT as a macro!
74 #pragma warn A sloppy coder has defined LONG as a macro!
79 #pragma warn A sloppy coder has defined FLOAT as a macro!
84 #pragma warn A sloppy coder has defined DOUBLE as a macro!
89 #pragma warn A sloppy coder has defined STRING as a macro!
95 ////////////////////////////////////////////////////////////////////////
98 // This is the mechanism that information-providing routines can
99 // use to link their own values to the property manager. Any
100 // SGValue can be tied to a raw value and then untied again.
102 // Note: we are forced to use inlined methods here to ensure
103 // that the templates will be instantiated. We're probably taking
104 // a small performance hit for that.
105 ////////////////////////////////////////////////////////////////////////
109 * Abstract base class for a raw value.
111 * <p>The property manager is implemented in two layers. The {@link
112 * SGPropertyNode} is the highest and most abstract layer,
113 * representing an LValue/RValue pair: it records the position of the
114 * property in the property tree and contains facilities for
115 * navigation to other nodes. It is guaranteed to be persistent: the
116 * {@link SGPropertyNode} will not change during a session, even if
117 * the property is bound and unbound multiple times.</p>
119 * <p>When the property value is not managed internally in the
120 * SGPropertyNode, the SGPropertyNode will contain a reference to an
121 * SGRawValue (this class), which provides an abstract way to get,
122 * set, and clone the underlying value. The SGRawValue may change
123 * frequently during a session as a value is retyped or bound and
124 * unbound to various data source, but the abstract SGPropertyNode
125 * layer insulates the application from those changes. The raw value
126 * contains no facilities for data binding or for type conversion: it
127 * is simply the abstraction of a primitive data type (or a compound
128 * data type, in the case of a string).</p>
130 * <p>The SGPropertyNode class always keeps a *copy* of a raw value,
131 * not the original one passed to it; if you override a derived class
132 * but do not replace the {@link #clone} method, strange things will
135 * <p>All derived SGRawValue classes must implement {@link #getValue},
136 * {@link #setValue}, and {@link #clone} for the appropriate type.</p>
138 * @see SGPropertyNode
139 * @see SGRawValuePointer
140 * @see SGRawValueFunctions
141 * @see SGRawValueFunctionsIndexed
142 * @see SGRawValueMethods
143 * @see SGRawValueMethodsIndexed
151 * The default underlying value for this type.
153 * Every raw value has a default; the default is false for a
154 * boolean, 0 for the various numeric values, and "" for a string.
155 * If additional types of raw values are added in the future, they
156 * may need different kinds of default values (such as epoch for a
157 * date type). The default value is used when creating new values.
159 static const T DefaultValue; // Default for this kind of raw value.
165 * Use the default value for this type.
173 virtual ~SGRawValue () {}
177 * Return the underlying value.
179 * @return The actual value for the property.
182 virtual T getValue () const = 0;
186 * Assign a new underlying value.
188 * If the new value cannot be set (because this is a read-only
189 * raw value, or because the new value is not acceptable for
190 * some reason) this method returns false and leaves the original
193 * @param value The actual value for the property.
194 * @return true if the value was set successfully, false otherwise.
197 virtual bool setValue (T value) = 0;
201 * Create a new deep copy of this raw value.
203 * The copy will contain its own version of the underlying value
206 * @return A deep copy of the current object.
208 virtual SGRawValue * clone () const = 0;
213 * A raw value bound to a pointer.
215 * This is the most efficient way to tie an external value, but also
216 * the most dangerous, because there is no way for the supplier to
217 * perform bounds checking and derived calculations except by polling
218 * the variable to see if it has changed. There is no default
219 * constructor, because this class would be meaningless without a
223 class SGRawValuePointer : public SGRawValue<T>
228 * Explicit pointer constructor.
230 * Create a new raw value bound to the value of the variable
231 * referenced by the pointer.
233 * @param ptr The pointer to the variable to which this raw value
236 SGRawValuePointer (T * ptr) : _ptr(ptr) {}
241 virtual ~SGRawValuePointer () {}
244 * Get the underlying value.
246 * This method will dereference the pointer and return the
249 virtual T getValue () const { return *_ptr; }
252 * Set the underlying value.
254 * This method will dereference the pointer and change the
257 virtual bool setValue (T value) { *_ptr = value; return true; }
260 * Create a copy of this raw value.
262 * The copy will use the same external pointer as the original.
264 virtual SGRawValue<T> * clone () const {
265 return new SGRawValuePointer<T>(_ptr);
274 * A value managed through static functions.
276 * A read-only value will not have a setter; a write-only value will
280 class SGRawValueFunctions : public SGRawValue<T>
285 * The template type of a static getter function.
287 typedef T (*getter_t)();
290 * The template type of a static setter function.
292 typedef void (*setter_t)(T);
295 * Explicit constructor.
297 * Create a new raw value bound to the getter and setter supplied.
299 * @param getter A static function for getting a value, or 0
300 * to read-disable the value.
301 * @param setter A static function for setting a value, or 0
302 * to write-disable the value.
304 SGRawValueFunctions (getter_t getter = 0, setter_t setter = 0)
305 : _getter(getter), _setter(setter) {}
310 virtual ~SGRawValueFunctions () {}
313 * Get the underlying value.
315 * This method will invoke the getter function to get a value.
316 * If no getter function was supplied, this method will always
317 * return the default value for the type.
319 virtual T getValue () const {
320 if (_getter) return (*_getter)();
321 else return SGRawValue<T>::DefaultValue;
325 * Set the underlying value.
327 * This method will invoke the setter function to change the
328 * underlying value. If no setter function was supplied, this
329 * method will return false.
331 virtual bool setValue (T value) {
332 if (_setter) { (*_setter)(value); return true; }
337 * Create a copy of this raw value, bound to the same functions.
339 virtual SGRawValue<T> * clone () const {
340 return new SGRawValueFunctions<T>(_getter,_setter);
350 * An indexed value bound to static functions.
352 * A read-only value will not have a setter; a write-only value will
353 * not have a getter. An indexed value is useful for binding one
354 * of a list of possible values (such as multiple engines for a
355 * plane). The index is hard-coded at creation time.
360 class SGRawValueFunctionsIndexed : public SGRawValue<T>
363 typedef T (*getter_t)(int);
364 typedef void (*setter_t)(int,T);
365 SGRawValueFunctionsIndexed (int index, getter_t getter = 0, setter_t setter = 0)
366 : _index(index), _getter(getter), _setter(setter) {}
367 virtual ~SGRawValueFunctionsIndexed () {}
368 virtual T getValue () const {
369 if (_getter) return (*_getter)(_index);
370 else return SGRawValue<T>::DefaultValue;
372 virtual bool setValue (T value) {
373 if (_setter) { (*_setter)(_index, value); return true; }
376 virtual SGRawValue<T> * clone () const {
377 return new SGRawValueFunctionsIndexed<T>(_index, _getter, _setter);
387 * A value managed through an object and access methods.
389 * A read-only value will not have a setter; a write-only value will
392 template <class C, class T>
393 class SGRawValueMethods : public SGRawValue<T>
396 typedef T (C::*getter_t)() const;
397 typedef void (C::*setter_t)(T);
398 SGRawValueMethods (C &obj, getter_t getter = 0, setter_t setter = 0)
399 : _obj(obj), _getter(getter), _setter(setter) {}
400 virtual ~SGRawValueMethods () {}
401 virtual T getValue () const {
402 if (_getter) { return (_obj.*_getter)(); }
403 else { return SGRawValue<T>::DefaultValue; }
405 virtual bool setValue (T value) {
406 if (_setter) { (_obj.*_setter)(value); return true; }
409 virtual SGRawValue<T> * clone () const {
410 return new SGRawValueMethods<C,T>(_obj, _getter, _setter);
420 * An indexed value managed through an object and access methods.
422 * A read-only value will not have a setter; a write-only value will
425 template <class C, class T>
426 class SGRawValueMethodsIndexed : public SGRawValue<T>
429 typedef T (C::*getter_t)(int) const;
430 typedef void (C::*setter_t)(int, T);
431 SGRawValueMethodsIndexed (C &obj, int index,
432 getter_t getter = 0, setter_t setter = 0)
433 : _obj(obj), _index(index), _getter(getter), _setter(setter) {}
434 virtual ~SGRawValueMethodsIndexed () {}
435 virtual T getValue () const {
436 if (_getter) { return (_obj.*_getter)(_index); }
437 else { return SGRawValue<T>::DefaultValue; }
439 virtual bool setValue (T value) {
440 if (_setter) { (_obj.*_setter)(_index, value); return true; }
443 virtual SGRawValue<T> * clone () const {
444 return new SGRawValueMethodsIndexed<C,T>(_obj, _index, _getter, _setter);
455 * The smart pointer that manage reference counting
457 class SGPropertyNode;
458 typedef SGSharedPtr<SGPropertyNode> SGPropertyNode_ptr;
459 typedef SGSharedPtr<const SGPropertyNode> SGConstPropertyNode_ptr;
463 * The property change listener interface.
465 * <p>Any class that needs to listen for property changes must implement
466 * this interface.</p>
468 class SGPropertyChangeListener
471 virtual ~SGPropertyChangeListener ();
472 virtual void valueChanged (SGPropertyNode * node);
473 virtual void childAdded (SGPropertyNode * parent, SGPropertyNode * child);
474 virtual void childRemoved (SGPropertyNode * parent, SGPropertyNode * child);
477 friend class SGPropertyNode;
478 virtual void register_property (SGPropertyNode * node);
479 virtual void unregister_property (SGPropertyNode * node);
482 vector<SGPropertyNode *> _properties;
488 * A node in a property tree.
490 class SGPropertyNode : public SGReferenced
498 MAX_STRING_LEN = 1024
502 * Property value types.
518 * Access mode attributes.
520 * <p>The ARCHIVE attribute is strictly advisory, and controls
521 * whether the property should normally be saved and restored.</p>
535 * Last used attribute
536 * Update as needed when enum Attribute is changed
538 static const int LAST_USED_ATTRIBUTE;
542 * Default constructor.
550 SGPropertyNode (const SGPropertyNode &node);
556 virtual ~SGPropertyNode ();
565 * Test whether this node contains a primitive leaf value.
567 bool hasValue () const { return (_type != NONE); }
571 * Get the node's simple (XML) name.
573 const char * getName () const { return _name.c_str(); }
577 * Get the node's pretty display name, with subscript when needed.
579 const char * getDisplayName (bool simplify = false) const;
583 * Get the node's integer index.
585 int getIndex () const { return _index; }
589 * Get a non-const pointer to the node's parent.
591 SGPropertyNode * getParent () { return _parent; }
595 * Get a const pointer to the node's parent.
597 const SGPropertyNode * getParent () const { return _parent; }
606 * Get the number of child nodes.
608 int nChildren () const { return _children.size(); }
612 * Get a child node by position (*NOT* index).
614 SGPropertyNode * getChild (int position);
618 * Get a const child node by position (*NOT* index).
620 const SGPropertyNode * getChild (int position) const;
624 * Test whether a named child exists.
626 bool hasChild (const char * name, int index = 0) const
628 return (getChild(name, index) != 0);
632 * Test whether a named child exists.
634 bool hasChild (const std::string& name, int index = 0) const
636 return (getChild(name, index) != 0);
641 * Get a child node by name and index.
643 SGPropertyNode * getChild (const char * name, int index = 0,
644 bool create = false);
647 * Get a child node by name and index.
649 SGPropertyNode * getChild (const std::string& name, int index = 0,
651 { return getChild(name.c_str(), index, create); }
655 * Get a const child node by name and index.
657 const SGPropertyNode * getChild (const char * name, int index = 0) const;
660 * Get a const child node by name and index.
662 const SGPropertyNode * getChild (const std::string& name, int index = 0) const
663 { return getChild(name.c_str(), index); }
667 * Get a vector of all children with the specified name.
669 vector<SGPropertyNode_ptr> getChildren (const char * name) const;
672 * Get a vector of all children with the specified name.
674 vector<SGPropertyNode_ptr> getChildren (const std::string& name) const
675 { return getChildren(name.c_str()); }
678 * Remove child by position.
680 SGPropertyNode_ptr removeChild (int pos, bool keep = true);
684 * Remove a child node
686 SGPropertyNode_ptr removeChild (const char * name, int index = 0,
690 * Remove a child node
692 SGPropertyNode_ptr removeChild (const std::string& name, int index = 0,
694 { return removeChild(name.c_str(), index, keep); }
697 * Remove all children with the specified name.
699 vector<SGPropertyNode_ptr> removeChildren (const char * name,
704 * Remove all children with the specified name.
706 vector<SGPropertyNode_ptr> removeChildren (const std::string& name,
708 { return removeChildren(name.c_str(), keep); }
716 * Alias this node's leaf value to another's.
718 bool alias (SGPropertyNode * target);
722 * Alias this node's leaf value to another's by relative path.
724 bool alias (const char * path);
727 * Alias this node's leaf value to another's by relative path.
729 bool alias (const std::string& path)
730 { return alias(path.c_str()); }
734 * Remove any alias for this node.
740 * Test whether the node's leaf value is aliased to another's.
742 bool isAlias () const { return (_type == ALIAS); }
746 * Get a non-const pointer to the current alias target, if any.
748 SGPropertyNode * getAliasTarget ();
752 * Get a const pointer to the current alias target, if any.
754 const SGPropertyNode * getAliasTarget () const;
763 * Get the path to this node from the root.
765 const char * getPath (bool simplify = false) const;
769 * Get a pointer to the root node.
771 SGPropertyNode * getRootNode ();
775 * Get a const pointer to the root node.
777 const SGPropertyNode * getRootNode () const;
781 * Get a pointer to another node by relative path.
783 SGPropertyNode * getNode (const char * relative_path, bool create = false);
786 * Get a pointer to another node by relative path.
788 SGPropertyNode * getNode (const std::string& relative_path, bool create = false)
789 { return getNode(relative_path.c_str(), create); }
792 * Get a pointer to another node by relative path.
794 * This method leaves the index off the last member of the path,
795 * so that the user can specify it separately (and save some
796 * string building). For example, getNode("/bar[1]/foo", 3) is
797 * exactly equivalent to getNode("bar[1]/foo[3]"). The index
798 * provided overrides any given in the path itself for the last
801 SGPropertyNode * getNode (const char * relative_path, int index,
802 bool create = false);
805 * Get a pointer to another node by relative path.
807 * This method leaves the index off the last member of the path,
808 * so that the user can specify it separately (and save some
809 * string building). For example, getNode("/bar[1]/foo", 3) is
810 * exactly equivalent to getNode("bar[1]/foo[3]"). The index
811 * provided overrides any given in the path itself for the last
814 SGPropertyNode * getNode (const std::string& relative_path, int index,
816 { return getNode(relative_path.c_str(), index, create); }
819 * Get a const pointer to another node by relative path.
821 const SGPropertyNode * getNode (const char * relative_path) const;
824 * Get a const pointer to another node by relative path.
826 const SGPropertyNode * getNode (const std::string& relative_path) const
827 { return getNode(relative_path.c_str()); }
831 * Get a const pointer to another node by relative path.
833 * This method leaves the index off the last member of the path,
834 * so that the user can specify it separate.
836 const SGPropertyNode * getNode (const char * relative_path,
840 * Get a const pointer to another node by relative path.
842 * This method leaves the index off the last member of the path,
843 * so that the user can specify it separate.
845 const SGPropertyNode * getNode (const std::string& relative_path,
847 { return getNode(relative_path.c_str(), index); }
854 * Check a single mode attribute for the property node.
856 bool getAttribute (Attribute attr) const { return ((_attr & attr) != 0); }
860 * Set a single mode attribute for the property node.
862 void setAttribute (Attribute attr, bool state) {
863 (state ? _attr |= attr : _attr &= ~attr);
868 * Get all of the mode attributes for the property node.
870 int getAttributes () const { return _attr; }
874 * Set all of the mode attributes for the property node.
876 void setAttributes (int attr) { _attr = attr; }
880 // Leaf Value (primitive).
885 * Get the type of leaf value, if any, for this node.
887 Type getType () const;
891 * Get a bool value for this node.
893 bool getBoolValue () const;
897 * Get an int value for this node.
899 int getIntValue () const;
903 * Get a long int value for this node.
905 long getLongValue () const;
909 * Get a float value for this node.
911 float getFloatValue () const;
915 * Get a double value for this node.
917 double getDoubleValue () const;
921 * Get a string value for this node.
923 const char * getStringValue () const;
928 * Set a bool value for this node.
930 bool setBoolValue (bool value);
934 * Set an int value for this node.
936 bool setIntValue (int value);
940 * Set a long int value for this node.
942 bool setLongValue (long value);
946 * Set a float value for this node.
948 bool setFloatValue (float value);
952 * Set a double value for this node.
954 bool setDoubleValue (double value);
958 * Set a string value for this node.
960 bool setStringValue (const char * value);
963 * Set a string value for this node.
965 bool setStringValue (const std::string& value)
966 { return setStringValue(value.c_str()); }
970 * Set a value of unspecified type for this node.
972 bool setUnspecifiedValue (const char * value);
981 * Test whether this node is bound to an external data source.
983 bool isTied () const { return _tied; }
987 * Bind this node to an external bool source.
989 bool tie (const SGRawValue<bool> &rawValue, bool useDefault = true);
993 * Bind this node to an external int source.
995 bool tie (const SGRawValue<int> &rawValue, bool useDefault = true);
999 * Bind this node to an external long int source.
1001 bool tie (const SGRawValue<long> &rawValue, bool useDefault = true);
1005 * Bind this node to an external float source.
1007 bool tie (const SGRawValue<float> &rawValue, bool useDefault = true);
1011 * Bind this node to an external double source.
1013 bool tie (const SGRawValue<double> &rawValue, bool useDefault = true);
1017 * Bind this node to an external string source.
1019 bool tie (const SGRawValue<const char *> &rawValue, bool useDefault = true);
1023 * Unbind this node from any external data source.
1029 // Convenience methods using paths.
1030 // TODO: add attribute methods
1035 * Get another node's type.
1037 Type getType (const char * relative_path) const;
1040 * Get another node's type.
1042 Type getType (const std::string& relative_path) const
1043 { return getType(relative_path.c_str()); }
1046 * Test whether another node has a leaf value.
1048 bool hasValue (const char * relative_path) const;
1051 * Test whether another node has a leaf value.
1053 bool hasValue (const std::string& relative_path) const
1054 { return hasValue(relative_path.c_str()); }
1057 * Get another node's value as a bool.
1059 bool getBoolValue (const char * relative_path,
1060 bool defaultValue = false) const;
1063 * Get another node's value as a bool.
1065 bool getBoolValue (const std::string& relative_path,
1066 bool defaultValue = false) const
1067 { return getBoolValue(relative_path.c_str(), defaultValue); }
1070 * Get another node's value as an int.
1072 int getIntValue (const char * relative_path,
1073 int defaultValue = 0) const;
1076 * Get another node's value as an int.
1078 int getIntValue (const std::string& relative_path,
1079 int defaultValue = 0) const
1080 { return getIntValue(relative_path.c_str(), defaultValue); }
1084 * Get another node's value as a long int.
1086 long getLongValue (const char * relative_path,
1087 long defaultValue = 0L) const;
1090 * Get another node's value as a long int.
1092 long getLongValue (const std::string& relative_path,
1093 long defaultValue = 0L) const
1094 { return getLongValue(relative_path.c_str(), defaultValue); }
1097 * Get another node's value as a float.
1099 float getFloatValue (const char * relative_path,
1100 float defaultValue = 0.0f) const;
1103 * Get another node's value as a float.
1105 float getFloatValue (const std::string& relative_path,
1106 float defaultValue = 0.0f) const
1107 { return getFloatValue(relative_path.c_str(), defaultValue); }
1111 * Get another node's value as a double.
1113 double getDoubleValue (const char * relative_path,
1114 double defaultValue = 0.0) const;
1117 * Get another node's value as a double.
1119 double getDoubleValue (const std::string& relative_path,
1120 double defaultValue = 0.0) const
1121 { return getDoubleValue(relative_path.c_str(), defaultValue); }
1124 * Get another node's value as a string.
1126 const char * getStringValue (const char * relative_path,
1127 const char * defaultValue = "") const;
1131 * Get another node's value as a string.
1133 const char * getStringValue (const std::string& relative_path,
1134 const char * defaultValue = "") const
1135 { return getStringValue(relative_path.c_str(), defaultValue); }
1139 * Set another node's value as a bool.
1141 bool setBoolValue (const char * relative_path, bool value);
1144 * Set another node's value as a bool.
1146 bool setBoolValue (const std::string& relative_path, bool value)
1147 { return setBoolValue(relative_path.c_str(), value); }
1151 * Set another node's value as an int.
1153 bool setIntValue (const char * relative_path, int value);
1156 * Set another node's value as an int.
1158 bool setIntValue (const std::string& relative_path, int value)
1159 { return setIntValue(relative_path.c_str(), value); }
1163 * Set another node's value as a long int.
1165 bool setLongValue (const char * relative_path, long value);
1168 * Set another node's value as a long int.
1170 bool setLongValue (const std::string& relative_path, long value)
1171 { return setLongValue(relative_path.c_str(), value); }
1175 * Set another node's value as a float.
1177 bool setFloatValue (const char * relative_path, float value);
1180 * Set another node's value as a float.
1182 bool setFloatValue (const std::string& relative_path, float value)
1183 { return setFloatValue(relative_path.c_str(), value); }
1187 * Set another node's value as a double.
1189 bool setDoubleValue (const char * relative_path, double value);
1192 * Set another node's value as a double.
1194 bool setDoubleValue (const std::string& relative_path, double value)
1195 { return setDoubleValue(relative_path.c_str(), value); }
1199 * Set another node's value as a string.
1201 bool setStringValue (const char * relative_path, const char * value);
1204 * Set another node's value as a string.
1206 bool setStringValue (const std::string& relative_path, const char * value)
1207 { return setStringValue(relative_path.c_str(), value); }
1211 * Set another node's value with no specified type.
1213 bool setUnspecifiedValue (const char * relative_path, const char * value);
1217 * Test whether another node is bound to an external data source.
1219 bool isTied (const char * relative_path) const;
1222 * Test whether another node is bound to an external data source.
1224 bool isTied (const std::string& relative_path) const
1225 { return isTied(relative_path.c_str()); }
1228 * Bind another node to an external bool source.
1230 bool tie (const char * relative_path, const SGRawValue<bool> &rawValue,
1231 bool useDefault = true);
1234 * Bind another node to an external bool source.
1236 bool tie (const std::string& relative_path, const SGRawValue<bool> &rawValue,
1237 bool useDefault = true)
1238 { return tie(relative_path.c_str(), rawValue, useDefault); }
1242 * Bind another node to an external int source.
1244 bool tie (const char * relative_path, const SGRawValue<int> &rawValue,
1245 bool useDefault = true);
1248 * Bind another node to an external int source.
1250 bool tie (const std::string& relative_path, const SGRawValue<int> &rawValue,
1251 bool useDefault = true)
1252 { return tie(relative_path.c_str(), rawValue, useDefault); }
1256 * Bind another node to an external long int source.
1258 bool tie (const char * relative_path, const SGRawValue<long> &rawValue,
1259 bool useDefault = true);
1262 * Bind another node to an external long int source.
1264 bool tie (const std::string& relative_path, const SGRawValue<long> &rawValue,
1265 bool useDefault = true)
1266 { return tie(relative_path.c_str(), rawValue, useDefault); }
1270 * Bind another node to an external float source.
1272 bool tie (const char * relative_path, const SGRawValue<float> &rawValue,
1273 bool useDefault = true);
1276 * Bind another node to an external float source.
1278 bool tie (const std::string& relative_path, const SGRawValue<float> &rawValue,
1279 bool useDefault = true)
1280 { return tie(relative_path.c_str(), rawValue, useDefault); }
1284 * Bind another node to an external double source.
1286 bool tie (const char * relative_path, const SGRawValue<double> &rawValue,
1287 bool useDefault = true);
1290 * Bind another node to an external double source.
1292 bool tie (const std::string& relative_path, const SGRawValue<double> &rawValue,
1293 bool useDefault = true)
1294 { return tie(relative_path.c_str(), rawValue, useDefault); }
1298 * Bind another node to an external string source.
1300 bool tie (const char * relative_path, const SGRawValue<const char *> &rawValue,
1301 bool useDefault = true);
1304 * Bind another node to an external string source.
1306 bool tie (const std::string& relative_path, const SGRawValue<const char*> &rawValue,
1307 bool useDefault = true)
1308 { return tie(relative_path.c_str(), rawValue, useDefault); }
1312 * Unbind another node from any external data source.
1314 bool untie (const char * relative_path);
1317 * Unbind another node from any external data source.
1319 bool untie (const std::string& relative_path)
1320 { return untie(relative_path.c_str()); }
1324 * Add a change listener to the property. If "initial" is set call the
1325 * listener initially.
1327 void addChangeListener (SGPropertyChangeListener * listener,
1328 bool initial = false);
1332 * Remove a change listener from the property.
1334 void removeChangeListener (SGPropertyChangeListener * listener);
1338 * Get the number of listeners.
1340 int nListeners () const { return _listeners ? _listeners->size() : 0; }
1344 * Fire a value change event to all listeners.
1346 void fireValueChanged ();
1350 * Fire a child-added event to all listeners.
1352 void fireChildAdded (SGPropertyNode * child);
1356 * Fire a child-removed event to all listeners.
1358 void fireChildRemoved (SGPropertyNode * child);
1362 * Clear any existing value and set the type to NONE.
1369 void fireValueChanged (SGPropertyNode * node);
1370 void fireChildAdded (SGPropertyNode * parent, SGPropertyNode * child);
1371 void fireChildRemoved (SGPropertyNode * parent, SGPropertyNode * child);
1374 * Protected constructor for making new nodes on demand.
1376 SGPropertyNode (const char * name, int index, SGPropertyNode * parent);
1381 // Get the raw value
1382 bool get_bool () const;
1383 int get_int () const;
1384 long get_long () const;
1385 float get_float () const;
1386 double get_double () const;
1387 const char * get_string () const;
1389 // Set the raw value
1390 bool set_bool (bool value);
1391 bool set_int (int value);
1392 bool set_long (long value);
1393 bool set_float (float value);
1394 bool set_double (double value);
1395 bool set_string (const char * value);
1399 * Get the value as a string.
1401 const char * make_string () const;
1405 * Trace a read access.
1407 void trace_read () const;
1411 * Trace a write access.
1413 void trace_write () const;
1417 * Remove this node from all nodes that link to it in their path cache.
1419 void remove_from_path_caches();
1426 mutable string _display_name;
1427 /// To avoid cyclic reference counting loops this shall not be a reference
1429 SGPropertyNode * _parent;
1430 vector<SGPropertyNode_ptr> _children;
1431 vector<SGPropertyNode_ptr> _removedChildren;
1432 vector<hash_table *> _linkedNodes;
1433 mutable string _path;
1434 mutable string _buffer;
1435 hash_table * _path_cache;
1440 // The right kind of pointer...
1442 SGPropertyNode * alias;
1443 SGRawValue<bool> * bool_val;
1444 SGRawValue<int> * int_val;
1445 SGRawValue<long> * long_val;
1446 SGRawValue<float> * float_val;
1447 SGRawValue<double> * double_val;
1448 SGRawValue<const char *> * string_val;
1460 vector <SGPropertyChangeListener *> * _listeners;
1464 * Register/unregister node that links to this node in its path cache.
1466 void add_linked_node (hash_table * node) { _linkedNodes.push_back(node); }
1467 bool remove_linked_node (hash_table * node);
1472 * A very simple hash table.
1478 * An entry in a bucket in a hash table.
1484 const char * get_key () { return _key.c_str(); }
1485 void set_key (const char * key);
1486 SGPropertyNode * get_value () { return _value; }
1487 void set_value (SGPropertyNode * value);
1490 SGSharedPtr<SGPropertyNode> _value;
1495 * A bucket in a hash table.
1501 entry * get_entry (const char * key, bool create = false);
1502 bool erase (SGPropertyNode * node);
1503 void clear (hash_table * owner);
1509 friend class bucket;
1513 SGPropertyNode * get (const char * key);
1514 void put (const char * key, SGPropertyNode * value);
1515 bool erase (SGPropertyNode * node);
1518 unsigned int hashcode (const char * key);
1519 unsigned int _data_length;
1525 #endif // __PROPS_HXX