JSBSim Flight Dynamics Model 1.3.0 (09 Apr 2026)
An Open Source Flight Dynamics and Control Software Library in C++
Loading...
Searching...
No Matches
props.hxx
Go to the documentation of this file.
1
11#ifndef __PROPS_HXX
12#define __PROPS_HXX
13
14#ifndef PROPS_STANDALONE
15#define PROPS_STANDALONE 1
16#endif
17
18#include <vector>
19#include <string>
20#include <iostream>
21#include <sstream>
22#include <typeinfo>
23
24#include "simgear/compiler.h"
25#include "JSBSim_API.h"
26#if PROPS_STANDALONE
27
28// use this local implementation only if boost has not been included
29#if !defined(BOOST_UTILITY_ENABLE_IF_HPP) && !defined(BOOST_CORE_ENABLE_IF_HPP)
30// taken from: boost/utility/enable_if.hpp
31namespace boost {
32 template <bool B, class T = void>
33 struct enable_if_c {
34 typedef T type;
35 };
36
37 template <class T>
38 struct enable_if_c<false, T> {};
39
40 template <class Cond, class T = void>
41 struct enable_if : public enable_if_c<Cond::value, T> {};
42
43 template <bool B, class T = void>
44 struct disable_if_c {
45 typedef T type;
46 };
47
48 template <class T>
49 struct disable_if_c<true, T> {};
50
51 template <class Cond, class T = void>
52 struct disable_if : public disable_if_c<Cond::value, T> {};
53}
54#endif
55#else
56# include <boost/utility.hpp>
57# include <boost/type_traits/is_enum.hpp>
58
59# include <simgear/debug/logstream.hxx>
60# include <simgear/math/SGMathFwd.hxx>
61# include <simgear/math/sg_types.hxx>
62#endif
63#include <simgear/structure/SGReferenced.hxx>
64#include <simgear/structure/SGSharedPtr.hxx>
65
66// XXX This whole file should be in the simgear namespace, but I don't
67// have the guts yet...
68
69namespace simgear
70{
71
72 class PropertyInterpolationMgr;
73
74template<typename T>
75std::istream& readFrom(std::istream& stream, T& result)
76{
77 stream >> result;
78 return stream;
79}
80
89template<typename T>
90inline T parseString(const std::string& str)
91{
92 std::istringstream stream(str);
93 T result;
94 readFrom(stream, result);
95 return result;
96}
97
102#ifdef NONE
103#pragma warn A sloppy coder has defined NONE as a macro!
104#undef NONE
105#endif
106
107#ifdef ALIAS
108#pragma warn A sloppy coder has defined ALIAS as a macro!
109#undef ALIAS
110#endif
111
112#ifdef UNSPECIFIED
113#pragma warn A sloppy coder has defined UNSPECIFIED as a macro!
114#undef UNSPECIFIED
115#endif
116
117#ifdef BOOL
118#pragma warn A sloppy coder has defined BOOL as a macro!
119#undef BOOL
120#endif
121
122#ifdef INT
123#pragma warn A sloppy coder has defined INT as a macro!
124#undef INT
125#endif
126
127#ifdef LONG
128#pragma warn A sloppy coder has defined LONG as a macro!
129#undef LONG
130#endif
131
132#ifdef FLOAT
133#pragma warn A sloppy coder has defined FLOAT as a macro!
134#undef FLOAT
135#endif
136
137#ifdef DOUBLE
138#pragma warn A sloppy coder has defined DOUBLE as a macro!
139#undef DOUBLE
140#endif
141
142#ifdef STRING
143#pragma warn A sloppy coder has defined STRING as a macro!
144#undef STRING
145#endif
146
147namespace props
148{
153enum Type {
154 NONE = 0,
156 BOOL,
157 INT,
158 LONG,
159 FLOAT,
160 DOUBLE,
161 STRING,
162 UNSPECIFIED,
163 EXTENDED,
168 // Extended properties
169 VEC3D,
170 VEC4D
171};
172
173template<typename T> struct PropertyTraits;
174
175#define DEFINTERNALPROP(TYPE, PROP) \
176template<> \
177struct PropertyTraits<TYPE> \
178{ \
179 static const Type type_tag = PROP; \
180 enum { Internal = 1 }; \
181}
182
183DEFINTERNALPROP(bool, BOOL);
184DEFINTERNALPROP(int, INT);
185DEFINTERNALPROP(long, LONG);
186DEFINTERNALPROP(float, FLOAT);
187DEFINTERNALPROP(double, DOUBLE);
188DEFINTERNALPROP(const char *, STRING);
189DEFINTERNALPROP(const char[], STRING);
190#undef DEFINTERNALPROP
191
192}
193}
194
195
196
198// A raw value.
199//
200// This is the mechanism that information-providing routines can
201// use to link their own values to the property manager. Any
202// SGValue can be tied to a raw value and then untied again.
203//
204// Note: we are forced to use inlined methods here to ensure
205// that the templates will be instantiated. We're probably taking
206// a small performance hit for that.
208
214class SGRaw
215{
216public:
222 virtual simgear::props::Type getType() const = 0;
223 virtual ~SGRaw() {}
224
233 virtual SGRaw* clone() const = 0;
234
235};
236
237class SGRawExtended : public SGRaw
238{
239public:
247 virtual SGRawExtended* makeContainer() const = 0;
251 virtual std::ostream& printOn(std::ostream& stream) const = 0;
255 virtual std::istream& readFrom(std::istream& stream) = 0;
256};
257
258// Choose between different base classes based on whether the value is
259// stored internal to the property node. This frees us from defining
260// the virtual functions in the SGRawExtended interface where they
261// don't make sense, e.g. readFrom for the const char* type.
262template<typename T, int internal = simgear::props::PropertyTraits<T>::Internal>
264
265template<typename T>
266class SGRawBase<T, 1> : public SGRaw
267{
268};
269
270template<typename T>
271class SGRawBase<T, 0> : public SGRawExtended
272{
273 virtual SGRawExtended* makeContainer() const;
274 virtual std::ostream& printOn(std::ostream& stream) const;
275 virtual std::istream& readFrom(std::istream& stream);
276};
277
311template <class T>
312class SGRawValue : public SGRawBase<T>
313{
314public:
315
325 static T DefaultValue()
326 {
327 return T();
328 }
329
330
337
338
342 virtual ~SGRawValue () {}
343
344
351 virtual T getValue () const = 0;
352
353
366 virtual bool setValue (T value) = 0;
367
368
376};
377
378
379
381// Default values for every type.
383
384template<> inline bool SGRawValue<bool>::DefaultValue()
385{
386 return false;
387}
388
389template<> inline const char * SGRawValue<const char *>::DefaultValue()
390{
391 return "";
392}
393
404template <class T>
406{
407public:
408
418 SGRawValuePointer (T * ptr) : _ptr(ptr) {}
419
423 virtual ~SGRawValuePointer () {}
424
431 virtual T getValue () const { return *_ptr; }
432
439 virtual bool setValue (T value) { *_ptr = value; return true; }
440
446 virtual SGRaw* clone () const {
447 return new SGRawValuePointer(_ptr);
448 }
449
450private:
451 T * _ptr;
452};
453
454
461template <class T>
463{
464public:
465
469 typedef T (*getter_t)();
470
474 typedef void (*setter_t)(T);
475
486 SGRawValueFunctions (getter_t getter = 0, setter_t setter = 0)
487 : _getter(getter), _setter(setter) {}
488
493
501 virtual T getValue () const {
502 if (_getter) return (*_getter)();
503 else return SGRawValue<T>::DefaultValue();
504 }
505
513 virtual bool setValue (T value) {
514 if (_setter) { (*_setter)(value); return true; }
515 else return false;
516 }
517
521 virtual SGRaw* clone () const {
522 return new SGRawValueFunctions(_getter,_setter);
523 }
524
525private:
526 getter_t _getter;
527 setter_t _setter;
528};
529
530
541template <class T>
543{
544public:
545 typedef T (*getter_t)(int);
546 typedef void (*setter_t)(int,T);
547 SGRawValueFunctionsIndexed (int index, getter_t getter = 0, setter_t setter = 0)
548 : _index(index), _getter(getter), _setter(setter) {}
549 virtual ~SGRawValueFunctionsIndexed () {}
550 virtual T getValue () const {
551 if (_getter) return (*_getter)(_index);
552 else return SGRawValue<T>::DefaultValue();
553 }
554 virtual bool setValue (T value) {
555 if (_setter) { (*_setter)(_index, value); return true; }
556 else return false;
557 }
558 virtual SGRaw* clone () const {
559 return new SGRawValueFunctionsIndexed(_index, _getter, _setter);
560 }
561private:
562 int _index;
563 getter_t _getter;
564 setter_t _setter;
565};
566
567
574template <class C, class T>
576{
577public:
578 typedef T (C::*getter_t)() const;
579 typedef void (C::*setter_t)(T);
580 SGRawValueMethods (C &obj, getter_t getter = 0, setter_t setter = 0)
581 : _obj(obj), _getter(getter), _setter(setter) {}
582 virtual ~SGRawValueMethods () {}
583 virtual T getValue () const {
584 if (_getter) { return (_obj.*_getter)(); }
585 else { return SGRawValue<T>::DefaultValue(); }
586 }
587 virtual bool setValue (T value) {
588 if (_setter) { (_obj.*_setter)(value); return true; }
589 else return false;
590 }
591 virtual SGRaw* clone () const {
592 return new SGRawValueMethods(_obj, _getter, _setter);
593 }
594private:
595 C &_obj;
596 getter_t _getter;
597 setter_t _setter;
598};
599
600
607template <class C, class T>
609{
610public:
611 typedef T (C::*getter_t)(int) const;
612 typedef void (C::*setter_t)(int, T);
613 SGRawValueMethodsIndexed (C &obj, int index,
614 getter_t getter = 0, setter_t setter = 0)
615 : _obj(obj), _index(index), _getter(getter), _setter(setter) {}
616 virtual ~SGRawValueMethodsIndexed () {}
617 virtual T getValue () const {
618 if (_getter) { return (_obj.*_getter)(_index); }
619 else { return SGRawValue<T>::DefaultValue(); }
620 }
621 virtual bool setValue (T value) {
622 if (_setter) { (_obj.*_setter)(_index, value); return true; }
623 else return false;
624 }
625 virtual SGRaw* clone () const {
626 return new SGRawValueMethodsIndexed(_obj, _index, _getter, _setter);
627 }
628private:
629 C &_obj;
630 int _index;
631 getter_t _getter;
632 setter_t _setter;
633};
634
640template <class T>
642{
643public:
644
648 SGRawValueContainer(const T& obj) : _obj(obj) {}
649
654
658 virtual T getValue() const { return _obj; }
659
666 virtual bool setValue (T value) { _obj = value; return true; }
667
671 virtual SGRaw* clone () const {
672 return new SGRawValueContainer(_obj);
673 }
674
675private:
676 T _obj;
677};
678
679template<typename T>
681{
682 return new SGRawValueContainer<T>(static_cast<const SGRawValue<T>*>(this)
683 ->getValue());
684}
685
686template<typename T>
687std::ostream& SGRawBase<T, 0>::printOn(std::ostream& stream) const
688{
689 return stream << static_cast<SGRawValue<T>*>(this)->getValue();
690}
691
692template<typename T>
693std::istream& SGRawBase<T, 0>::readFrom(std::istream& stream)
694{
695 T value;
696 simgear::readFrom(stream, value);
697 static_cast<SGRawValue<T>*>(this)->setValue(value);
698 return stream;
699}
700
704class SGPropertyNode;
705typedef SGSharedPtr<SGPropertyNode> SGPropertyNode_ptr;
706typedef SGSharedPtr<const SGPropertyNode> SGConstPropertyNode_ptr;
707
708namespace simgear
709{
710typedef std::vector<SGPropertyNode_ptr> PropertyList;
711}
712
720{
721public:
722 virtual ~SGPropertyChangeListener ();
723
725 virtual void valueChanged(SGPropertyNode * node);
726
728 virtual void childAdded(SGPropertyNode * parent, SGPropertyNode * child);
729
731 virtual void childRemoved(SGPropertyNode * parent, SGPropertyNode * child);
732
733protected:
734 friend class SGPropertyNode;
735 virtual void register_property (SGPropertyNode * node);
736 virtual void unregister_property (SGPropertyNode * node);
737
738private:
739 std::vector<SGPropertyNode *> _properties;
740};
741
742
746class JSBSIM_API SGPropertyNode : public SGReferenced
747{
748public:
749
753 enum {
754 MAX_STRING_LEN = 1024
755 };
756
764 NO_ATTR = 0,
765 READ = 1,
766 WRITE = 2,
767 ARCHIVE = 4,
768 REMOVED = 8,
769 TRACE_READ = 16,
770 TRACE_WRITE = 32,
771 USERARCHIVE = 64,
772 PRESERVE = 128
773 // beware: if you add another attribute here,
774 // also update value of "LAST_USED_ATTRIBUTE".
775 };
776
777
782 static const int LAST_USED_ATTRIBUTE;
783
788
789
794
795
799 virtual ~SGPropertyNode ();
800
801
802
803 //
804 // Basic properties.
805 //
806
810 bool hasValue () const { return (_type != simgear::props::NONE); }
811
815 const std::string& getNameString () const { return _name; }
816
820 std::string getDisplayName (bool simplify = false) const;
821
822
826 int getIndex () const { return _index; }
827
828
832 SGPropertyNode * getParent () { return _parent; }
833
834
838 const SGPropertyNode * getParent () const { return _parent; }
839
840
841 //
842 // Children.
843 //
844
845
849 int nChildren () const { return (int)_children.size(); }
850
851
855 SGPropertyNode * getChild (int position);
856
857
861 const SGPropertyNode * getChild (int position) const;
862
863
867 bool hasChild (const char * name, int index = 0) const
868 {
869 return (getChild(name, index) != 0);
870 }
871
875 bool hasChild (const std::string& name, int index = 0) const
876 {
877 return (getChild(name, index) != 0);
878 }
879
887 SGPropertyNode * addChild ( const char* name,
888 int min_index = 0,
889 bool append = true );
890 SGPropertyNode * addChild ( const std::string& name,
891 int min_index = 0,
892 bool append = true )
893 { return addChild(name.c_str(), min_index, append); }
894
903 simgear::PropertyList addChildren ( const std::string& name,
904 size_t count,
905 int min_index = 0,
906 bool append = true );
907
911 SGPropertyNode * getChild (const char* name, int index = 0,
912 bool create = false);
913 SGPropertyNode * getChild (const std::string& name, int index = 0,
914 bool create = false);
918 const SGPropertyNode * getChild (const char * name, int index = 0) const;
919
923 const SGPropertyNode * getChild (const std::string& name, int index = 0) const
924 { return getChild(name.c_str(), index); }
925
926
930 simgear::PropertyList getChildren (const char * name) const;
931
935 simgear::PropertyList getChildren (const std::string& name) const
936 { return getChildren(name.c_str()); }
937
944
945 // TODO do we need the removeXXX methods to return the deleted nodes?
949 SGPropertyNode_ptr removeChild(int pos);
950
951
955 SGPropertyNode_ptr removeChild(const char * name, int index = 0);
956
960 SGPropertyNode_ptr removeChild(const std::string& name, int index = 0)
961 { return removeChild(name.c_str(), index); }
962
966 simgear::PropertyList removeChildren(const char * name);
967
971 simgear::PropertyList removeChildren(const std::string& name)
972 { return removeChildren(name.c_str()); }
973
978
979 //
980 // Alias support.
981 //
982
983
987 bool alias (SGPropertyNode * target);
988
989
993 bool alias (const char * path);
994
998 bool alias (const std::string& path)
999 { return alias(path.c_str()); }
1000
1001
1005 bool unalias ();
1006
1007
1011 bool isAlias () const { return (_type == simgear::props::ALIAS); }
1012
1013
1018
1019
1024
1025
1026 //
1027 // Path information.
1028 //
1029
1030
1034 std::string getPath (bool simplify = false) const;
1035
1036
1041
1042
1046 const SGPropertyNode * getRootNode () const;
1047
1048
1052 SGPropertyNode * getNode (const char * relative_path, bool create = false);
1053
1057 SGPropertyNode * getNode (const std::string& relative_path, bool create = false)
1058 { return getNode(relative_path.c_str(), create); }
1059
1070 SGPropertyNode * getNode (const char * relative_path, int index,
1071 bool create = false);
1072
1083 SGPropertyNode * getNode (const std::string& relative_path, int index,
1084 bool create = false)
1085 { return getNode(relative_path.c_str(), index, create); }
1086
1090 const SGPropertyNode * getNode (const char * relative_path) const;
1091
1095 const SGPropertyNode * getNode (const std::string& relative_path) const
1096 { return getNode(relative_path.c_str()); }
1097
1098
1105 const SGPropertyNode * getNode (const char * relative_path,
1106 int index) const;
1107
1114 const SGPropertyNode * getNode (const std::string& relative_path,
1115 int index) const
1116 { return getNode(relative_path.c_str(), index); }
1117
1118 //
1119 // Access Mode.
1120 //
1121
1125 bool getAttribute (Attribute attr) const { return ((_attr & attr) != 0); }
1126
1127
1131 void setAttribute (Attribute attr, bool state) {
1132 (state ? _attr |= attr : _attr &= ~attr);
1133 }
1134
1135
1139 int getAttributes () const { return _attr; }
1140
1141
1145 void setAttributes (int attr) { _attr = attr; }
1146
1147
1148 //
1149 // Leaf Value (primitive).
1150 //
1151
1152
1157
1158
1162 bool getBoolValue () const;
1163
1164
1168 int getIntValue () const;
1169
1170
1174 long getLongValue () const;
1175
1176
1180 float getFloatValue () const;
1181
1182
1186 double getDoubleValue () const;
1187
1188
1192 const char * getStringValue () const;
1193
1198 template<typename T>
1200 ::type* dummy = 0) const;
1201 // Getter for extended property
1202 template<typename T>
1204 ::type* dummy = 0) const;
1205
1209 template<typename T, typename T_get /* = T */> // TODO use C++11 or traits
1210 std::vector<T> getChildValues(const std::string& name) const;
1211
1215 template<typename T>
1216 std::vector<T> getChildValues(const std::string& name) const;
1217
1221 bool setBoolValue (bool value);
1222
1223
1227 bool setIntValue (int value);
1228
1229
1233 bool setLongValue (long value);
1234
1235
1239 bool setFloatValue (float value);
1240
1241
1245 bool setDoubleValue (double value);
1246
1247
1251 bool setStringValue (const char * value);
1252
1256 bool setStringValue (const std::string& value)
1257 { return setStringValue(value.c_str()); }
1258
1259
1263 bool setUnspecifiedValue (const char * value);
1264
1265 template<typename T>
1266 bool setValue(const T& val,
1268 ::type* dummy = 0);
1269
1270 template<typename T>
1271 bool setValue(const T& val,
1273 ::type* dummy = 0);
1274
1275 template<int N>
1276 bool setValue(const char (&val)[N])
1277 {
1278 return setValue(&val[0]);
1279 }
1280
1289 template<typename T>
1290 bool setValueReadOnly(const std::string& relative_path, const T& value)
1291 {
1292 SGPropertyNode* node = getNode(relative_path, true);
1293 bool ret = node->setValue(value);
1294 node->setAttributes(READ);
1295 return ret;
1296 }
1297
1298#if !PROPS_STANDALONE
1307 bool interpolate( const std::string& type,
1308 const SGPropertyNode& target,
1309 double duration = 0.6,
1310 const std::string& easing = "swing" );
1311
1320 bool interpolate( const std::string& type,
1321 const simgear::PropertyList& values,
1322 const double_list& deltas,
1323 const std::string& easing = "swing" );
1324
1328 static void setInterpolationMgr(simgear::PropertyInterpolationMgr* mgr);
1329
1333 static simgear::PropertyInterpolationMgr* getInterpolationMgr();
1334#endif
1335
1339 std::ostream& printOn(std::ostream& stream) const;
1340
1341 //
1342 // Data binding.
1343 //
1344
1345
1349 bool isTied () const { return _tied; }
1350
1354 template<typename T>
1355 bool tie(const SGRawValue<T> &rawValue, bool useDefault = true);
1356
1360 bool untie ();
1361
1362
1363 //
1364 // Convenience methods using paths.
1365 // TODO: add attribute methods
1366 //
1367
1368
1372 simgear::props::Type getType (const char * relative_path) const;
1373
1377 simgear::props::Type getType (const std::string& relative_path) const
1378 { return getType(relative_path.c_str()); }
1379
1383 bool hasValue (const char * relative_path) const;
1384
1388 bool hasValue (const std::string& relative_path) const
1389 { return hasValue(relative_path.c_str()); }
1390
1394 bool getBoolValue (const char * relative_path,
1395 bool defaultValue = false) const;
1396
1400 bool getBoolValue (const std::string& relative_path,
1401 bool defaultValue = false) const
1402 { return getBoolValue(relative_path.c_str(), defaultValue); }
1403
1407 int getIntValue (const char * relative_path,
1408 int defaultValue = 0) const;
1409
1413 int getIntValue (const std::string& relative_path,
1414 int defaultValue = 0) const
1415 { return getIntValue(relative_path.c_str(), defaultValue); }
1416
1417
1421 long getLongValue (const char * relative_path,
1422 long defaultValue = 0L) const;
1423
1427 long getLongValue (const std::string& relative_path,
1428 long defaultValue = 0L) const
1429 { return getLongValue(relative_path.c_str(), defaultValue); }
1430
1434 float getFloatValue (const char * relative_path,
1435 float defaultValue = 0.0f) const;
1436
1440 float getFloatValue (const std::string& relative_path,
1441 float defaultValue = 0.0f) const
1442 { return getFloatValue(relative_path.c_str(), defaultValue); }
1443
1444
1448 double getDoubleValue (const char * relative_path,
1449 double defaultValue = 0.0) const;
1450
1454 double getDoubleValue (const std::string& relative_path,
1455 double defaultValue = 0.0) const
1456 { return getDoubleValue(relative_path.c_str(), defaultValue); }
1457
1461 const char * getStringValue (const char * relative_path,
1462 const char * defaultValue = "") const;
1463
1464
1468 const char * getStringValue (const std::string& relative_path,
1469 const char * defaultValue = "") const
1470 { return getStringValue(relative_path.c_str(), defaultValue); }
1471
1472
1476 bool setBoolValue (const char * relative_path, bool value);
1477
1481 bool setBoolValue (const std::string& relative_path, bool value)
1482 { return setBoolValue(relative_path.c_str(), value); }
1483
1484
1488 bool setIntValue (const char * relative_path, int value);
1489
1493 bool setIntValue (const std::string& relative_path, int value)
1494 { return setIntValue(relative_path.c_str(), value); }
1495
1496
1500 bool setLongValue (const char * relative_path, long value);
1501
1505 bool setLongValue (const std::string& relative_path, long value)
1506 { return setLongValue(relative_path.c_str(), value); }
1507
1508
1512 bool setFloatValue (const char * relative_path, float value);
1513
1517 bool setFloatValue (const std::string& relative_path, float value)
1518 { return setFloatValue(relative_path.c_str(), value); }
1519
1520
1524 bool setDoubleValue (const char * relative_path, double value);
1525
1529 bool setDoubleValue (const std::string& relative_path, double value)
1530 { return setDoubleValue(relative_path.c_str(), value); }
1531
1532
1536 bool setStringValue (const char * relative_path, const char * value);
1537
1538 bool setStringValue(const char * relative_path, const std::string& value)
1539 { return setStringValue(relative_path, value.c_str()); }
1543 bool setStringValue (const std::string& relative_path, const char * value)
1544 { return setStringValue(relative_path.c_str(), value); }
1545
1546 bool setStringValue (const std::string& relative_path,
1547 const std::string& value)
1548 { return setStringValue(relative_path.c_str(), value.c_str()); }
1549
1553 bool setUnspecifiedValue (const char * relative_path, const char * value);
1554
1555
1559 bool isTied (const char * relative_path) const;
1560
1564 bool isTied (const std::string& relative_path) const
1565 { return isTied(relative_path.c_str()); }
1566
1570 bool tie (const char * relative_path, const SGRawValue<bool> &rawValue,
1571 bool useDefault = true);
1572
1576 bool tie (const std::string& relative_path, const SGRawValue<bool> &rawValue,
1577 bool useDefault = true)
1578 { return tie(relative_path.c_str(), rawValue, useDefault); }
1579
1580
1584 bool tie (const char * relative_path, const SGRawValue<int> &rawValue,
1585 bool useDefault = true);
1586
1590 bool tie (const std::string& relative_path, const SGRawValue<int> &rawValue,
1591 bool useDefault = true)
1592 { return tie(relative_path.c_str(), rawValue, useDefault); }
1593
1594
1598 bool tie (const char * relative_path, const SGRawValue<long> &rawValue,
1599 bool useDefault = true);
1600
1604 bool tie (const std::string& relative_path, const SGRawValue<long> &rawValue,
1605 bool useDefault = true)
1606 { return tie(relative_path.c_str(), rawValue, useDefault); }
1607
1608
1612 bool tie (const char * relative_path, const SGRawValue<float> &rawValue,
1613 bool useDefault = true);
1614
1618 bool tie (const std::string& relative_path, const SGRawValue<float> &rawValue,
1619 bool useDefault = true)
1620 { return tie(relative_path.c_str(), rawValue, useDefault); }
1621
1622
1626 bool tie (const char * relative_path, const SGRawValue<double> &rawValue,
1627 bool useDefault = true);
1628
1632 bool tie (const std::string& relative_path, const SGRawValue<double> &rawValue,
1633 bool useDefault = true)
1634 { return tie(relative_path.c_str(), rawValue, useDefault); }
1635
1636
1640 bool tie (const char * relative_path, const SGRawValue<const char *> &rawValue,
1641 bool useDefault = true);
1642
1646 bool tie (const std::string& relative_path, const SGRawValue<const char*> &rawValue,
1647 bool useDefault = true)
1648 { return tie(relative_path.c_str(), rawValue, useDefault); }
1649
1650
1654 bool untie (const char * relative_path);
1655
1659 bool untie (const std::string& relative_path)
1660 { return untie(relative_path.c_str()); }
1661
1662
1668 bool initial = false);
1669
1670
1675
1676
1680 int nListeners () const { return _listeners ? (int)_listeners->size() : 0; }
1681
1682
1687
1688
1693
1703 void fireCreatedRecursive(bool fire_self = false);
1704
1709
1718
1719
1723 void clearValue ();
1724
1734 static bool compare (const SGPropertyNode& lhs, const SGPropertyNode& rhs);
1735
1736protected:
1737
1738 void fireValueChanged (SGPropertyNode * node);
1739 void fireChildAdded (SGPropertyNode * parent, SGPropertyNode * child);
1740 void fireChildRemoved (SGPropertyNode * parent, SGPropertyNode * child);
1741
1742 SGPropertyNode_ptr eraseChild(simgear::PropertyList::iterator child);
1743
1747 SGPropertyNode (const std::string& name, int index, SGPropertyNode * parent);
1748 template<typename Itr>
1749 SGPropertyNode (Itr begin, Itr end, int index, SGPropertyNode * parent);
1750
1751 static simgear::PropertyInterpolationMgr* _interpolation_mgr;
1752
1753private:
1754
1755 // Get the raw value
1756 bool get_bool () const;
1757 int get_int () const;
1758 long get_long () const;
1759 float get_float () const;
1760 double get_double () const;
1761 const char * get_string () const;
1762
1763 // Set the raw value
1764 bool set_bool (bool value);
1765 bool set_int (int value);
1766 bool set_long (long value);
1767 bool set_float (float value);
1768 bool set_double (double value);
1769 bool set_string (const char * value);
1770
1771
1775 const char * make_string () const;
1776
1780 void trace_read () const;
1781
1782
1786 void trace_write () const;
1787
1788 int _index;
1789 std::string _name;
1792 SGPropertyNode * _parent;
1793 simgear::PropertyList _children;
1794 mutable std::string _buffer;
1796 bool _tied;
1797 int _attr;
1798
1799 // The right kind of pointer...
1800 union {
1801 SGPropertyNode * alias;
1802 SGRaw* val;
1803 } _value;
1804
1805 union {
1806 bool bool_val;
1807 int int_val;
1808 long long_val;
1809 float float_val;
1810 double double_val;
1811 char * string_val;
1812 } _local_val;
1813
1814 std::vector<SGPropertyChangeListener *> * _listeners;
1815
1816 // Pass name as a pair of iterators
1817 template<typename Itr>
1818 SGPropertyNode * getChildImpl (Itr begin, Itr end, int index = 0, bool create = false);
1819 // very internal method
1820 template<typename Itr>
1821 SGPropertyNode* getExistingChild (Itr begin, Itr end, int index);
1822 // very internal path parsing function
1823 template<typename SplitItr>
1824 friend SGPropertyNode* find_node_aux(SGPropertyNode * current, SplitItr& itr,
1825 bool create, int last_index);
1826 // For boost
1827 friend size_t hash_value(const SGPropertyNode& node);
1828};
1829
1830// Convenience functions for use in templates
1831template<typename T>
1832#if PROPS_STANDALONE
1833T
1834#else
1835typename boost::disable_if<boost::is_enum<T>, T>::type
1836#endif
1837getValue(const SGPropertyNode*);
1838
1839template<>
1840inline bool getValue<bool>(const SGPropertyNode* node) { return node->getBoolValue(); }
1841
1842template<>
1843inline int getValue<int>(const SGPropertyNode* node) { return node->getIntValue(); }
1844
1845template<>
1846inline long getValue<long>(const SGPropertyNode* node) { return node->getLongValue(); }
1847
1848template<>
1849inline float getValue<float>(const SGPropertyNode* node)
1850{
1851 return node->getFloatValue();
1852}
1853
1854template<>
1855inline double getValue<double>(const SGPropertyNode* node)
1856{
1857 return node->getDoubleValue();
1858}
1859
1860template<>
1861inline const char * getValue<const char*>(const SGPropertyNode* node)
1862{
1863 return node->getStringValue ();
1864}
1865
1866template<>
1867inline std::string getValue<std::string>(const SGPropertyNode* node)
1868{
1869 return node->getStringValue();
1870}
1871
1872inline bool setValue(SGPropertyNode* node, bool value)
1873{
1874 return node->setBoolValue(value);
1875}
1876
1877inline bool setValue(SGPropertyNode* node, int value)
1878{
1879 return node->setIntValue(value);
1880}
1881
1882inline bool setValue(SGPropertyNode* node, long value)
1883{
1884 return node->setLongValue(value);
1885}
1886
1887inline bool setValue(SGPropertyNode* node, float value)
1888{
1889 return node->setFloatValue(value);
1890}
1891
1892inline bool setValue(SGPropertyNode* node, double value)
1893{
1894 return node->setDoubleValue(value);
1895}
1896
1897inline bool setValue(SGPropertyNode* node, const char* value)
1898{
1899 return node->setStringValue(value);
1900}
1901
1902inline bool setValue (SGPropertyNode* node, const std::string& value)
1903{
1904 return node->setStringValue(value.c_str());
1905}
1906
1907template<typename T>
1908bool SGPropertyNode::tie(const SGRawValue<T> &rawValue, bool useDefault)
1909{
1910 using namespace simgear::props;
1911 if (_type == ALIAS || _tied)
1912 return false;
1913
1914 useDefault = useDefault && hasValue();
1915 T old_val = SGRawValue<T>::DefaultValue();
1916 if (useDefault)
1917 old_val = getValue<T>(this);
1918 clearValue();
1921 else
1922 _type = EXTENDED;
1923 _tied = true;
1924 _value.val = rawValue.clone();
1925 if (useDefault) {
1926 int save_attributes = getAttributes();
1927 setAttribute( WRITE, true );
1928 setValue(old_val);
1929 setAttributes( save_attributes );
1930 }
1931 return true;
1932}
1933
1934template<>
1935bool SGPropertyNode::tie (const SGRawValue<const char *> &rawValue,
1936 bool useDefault);
1937
1938template<typename T>
1940 ::PropertyTraits<T>::Internal>::type* dummy) const
1941{
1942 using namespace simgear::props;
1943 if (_attr == (READ|WRITE) && _type == EXTENDED
1944 && _value.val->getType() == PropertyTraits<T>::type_tag) {
1945 return static_cast<SGRawValue<T>*>(_value.val)->getValue();
1946 }
1947 if (getAttribute(TRACE_READ))
1948 trace_read();
1949 if (!getAttribute(READ))
1951 switch (_type) {
1952 case EXTENDED:
1953 if (_value.val->getType() == PropertyTraits<T>::type_tag)
1954 return static_cast<SGRawValue<T>*>(_value.val)->getValue();
1955 break;
1956 case STRING:
1957 case UNSPECIFIED:
1958 return simgear::parseString<T>(make_string());
1959 break;
1960 default: // avoid compiler warning
1961 break;
1962 }
1964}
1965
1966template<typename T>
1968 ::PropertyTraits<T>::Internal>::type* dummy) const
1969{
1970 return ::getValue<T>(this);
1971}
1972
1973template<typename T, typename T_get /* = T */> // TODO use C++11 or traits
1974std::vector<T> SGPropertyNode::getChildValues(const std::string& name) const
1975{
1976 const simgear::PropertyList& props = getChildren(name);
1977 std::vector<T> values( props.size() );
1978
1979 for( size_t i = 0; i < props.size(); ++i )
1980 values[i] = props[i]->getValue<T_get>();
1981
1982 return values;
1983}
1984
1985template<typename T>
1986inline
1987std::vector<T> SGPropertyNode::getChildValues(const std::string& name) const
1988{
1989 return getChildValues<T, T>(name);
1990}
1991
1992template<typename T>
1993bool SGPropertyNode::setValue(const T& val,
1995 ::PropertyTraits<T>::Internal>::type* dummy)
1996{
1997 using namespace simgear::props;
1998 if (_attr == (READ|WRITE) && _type == EXTENDED
1999 && _value.val->getType() == PropertyTraits<T>::type_tag) {
2000 static_cast<SGRawValue<T>*>(_value.val)->setValue(val);
2001 return true;
2002 }
2003 if (getAttribute(WRITE)
2004 && ((_type == EXTENDED
2005 && _value.val->getType() == PropertyTraits<T>::type_tag)
2006 || _type == NONE || _type == UNSPECIFIED)) {
2007 if (_type == NONE || _type == UNSPECIFIED) {
2008 clearValue();
2009 _type = EXTENDED;
2010 _value.val = new SGRawValueContainer<T>(val);
2011 } else {
2012 static_cast<SGRawValue<T>*>(_value.val)->setValue(val);
2013 }
2014 if (getAttribute(TRACE_WRITE))
2015 trace_write();
2016 return true;
2017 }
2018 return false;
2019}
2020
2021template<typename T>
2022inline bool SGPropertyNode::setValue(const T& val,
2024 ::PropertyTraits<T>::Internal>::type* dummy)
2025{
2026 return ::setValue(this, val);
2027}
2028
2032inline SGPropertyNode* makeChild(SGPropertyNode* parent, const char* name,
2033 int index = 0)
2034{
2035 return parent->getChild(name, index, true);
2036}
2037
2042namespace simgear
2043{
2044template<typename StringType>
2045inline SGPropertyNode* makeNode(SGPropertyNode* parent, const StringType& name)
2046{
2047 return parent->getNode(name, true);
2048}
2049}
2050
2051// For boost::hash
2052size_t hash_value(const SGPropertyNode& node);
2053
2054// Helper comparison and hash functions for common cases
2055
2056namespace simgear
2057{
2058namespace props
2059{
2061{
2062 bool operator()(const SGPropertyNode* lhs, const SGPropertyNode* rhs) const
2063 {
2064 return SGPropertyNode::compare(*lhs, *rhs);
2065 }
2066 bool operator()(SGPropertyNode_ptr lhs, const SGPropertyNode* rhs) const
2067 {
2068 return SGPropertyNode::compare(*lhs, *rhs);
2069 }
2070 bool operator()(const SGPropertyNode* lhs, SGPropertyNode_ptr rhs) const
2071 {
2072 return SGPropertyNode::compare(*lhs, *rhs);
2073 }
2074 bool operator()(SGPropertyNode_ptr lhs, SGPropertyNode_ptr rhs) const
2075 {
2076 return SGPropertyNode::compare(*lhs, *rhs);
2077 }
2078};
2079
2080struct Hash
2081{
2082 size_t operator()(const SGPropertyNode* node) const
2083 {
2084 return hash_value(*node);
2085 }
2086 size_t operator()(SGPropertyNode_ptr node) const
2087 {
2088 return hash_value(*node);
2089 }
2090};
2091}
2092}
2093
2098template<class T>
2101{
2102public:
2103 SGPropertyChangeCallback(T* obj, void (T::*method)(SGPropertyNode*),
2104 SGPropertyNode_ptr property,bool initial=false)
2105 : _obj(obj), _callback(method), _property(property)
2106 {
2107 _property->addChangeListener(this,initial);
2108 }
2109
2111 _obj(other._obj), _callback(other._callback), _property(other._property)
2112 {
2113 _property->addChangeListener(this,false);
2114 }
2115
2117 {
2118 _property->removeChangeListener(this);
2119 }
2121 {
2122 (_obj->*_callback)(node);
2123 }
2124private:
2125 T* _obj;
2126 void (T::*_callback)(SGPropertyNode*);
2127 SGPropertyNode_ptr _property;
2128};
2129
2130#endif // __PROPS_HXX
2131
2132// end of props.hxx
Convenience class for change listener callbacks without creating a derived class implementing a "valu...
Definition props.hxx:2101
void valueChanged(SGPropertyNode *node)
Called if value of node has changed.
Definition props.hxx:2120
The property change listener interface.
Definition props.hxx:720
virtual void childAdded(SGPropertyNode *parent, SGPropertyNode *child)
Called if child has been added to the given parent.
virtual void valueChanged(SGPropertyNode *node)
Called if value of node has changed.
virtual void childRemoved(SGPropertyNode *parent, SGPropertyNode *child)
Called if child has been removed from its parent.
A node in a property tree.
Definition props.hxx:747
void removeChangeListener(SGPropertyChangeListener *listener)
Remove a change listener from the property.
bool setUnspecifiedValue(const char *value)
Set a value of unspecified type for this node.
SGPropertyNode * getNode(const std::string &relative_path, int index, bool create=false)
Get a pointer to another node by relative path.
Definition props.hxx:1083
bool setDoubleValue(const std::string &relative_path, double value)
Set another node's value as a double.
Definition props.hxx:1529
bool hasChild(const char *name, int index=0) const
Test whether a named child exists.
Definition props.hxx:867
void fireChildRemoved(SGPropertyNode *child)
Fire a child-removed event to all listeners.
bool tie(const std::string &relative_path, const SGRawValue< long > &rawValue, bool useDefault=true)
Bind another node to an external long int source.
Definition props.hxx:1604
SGPropertyNode * getChild(const char *name, int index=0, bool create=false)
Get a child node by name and index.
SGPropertyNode_ptr removeChild(const std::string &name, int index=0)
Remove a child node.
Definition props.hxx:960
void fireChildrenRemovedRecursive()
Fire a child-removed event for every child of this node (Unlimited depth)
bool untie()
Unbind this node from any external data source.
bool unalias()
Remove any alias for this node.
simgear::props::Type getType() const
Get the type of leaf value, if any, for this node.
Attribute
Access mode attributes.
Definition props.hxx:763
int getIndex() const
Get the node's integer index.
Definition props.hxx:826
bool setValueReadOnly(const std::string &relative_path, const T &value)
Set relative node to given value and afterwards make read only.
Definition props.hxx:1290
std::ostream & printOn(std::ostream &stream) const
Print the value of the property to a stream.
simgear::PropertyList removeChildren(const std::string &name)
Remove all children with the specified name.
Definition props.hxx:971
bool setStringValue(const std::string &value)
Set a string value for this node.
Definition props.hxx:1256
bool getBoolValue(const char *relative_path, bool defaultValue=false) const
Get another node's value as a bool.
bool tie(const SGRawValue< T > &rawValue, bool useDefault=true)
Bind this node to an external source.
Definition props.hxx:1908
static const int LAST_USED_ATTRIBUTE
Last used attribute Update as needed when enum Attribute is changed.
Definition props.hxx:782
simgear::PropertyList getChildren(const std::string &name) const
Get a vector of all children with the specified name.
Definition props.hxx:935
bool hasValue(const char *relative_path) const
Test whether another node has a leaf value.
SGPropertyNode * getNode(const std::string &relative_path, bool create=false)
Get a pointer to another node by relative path.
Definition props.hxx:1057
bool tie(const char *relative_path, const SGRawValue< int > &rawValue, bool useDefault=true)
Bind another node to an external int source.
bool getBoolValue() const
Get a bool value for this node.
bool setStringValue(const std::string &relative_path, const char *value)
Set another node's value as a string.
Definition props.hxx:1543
bool getAttribute(Attribute attr) const
Check a single mode attribute for the property node.
Definition props.hxx:1125
const SGPropertyNode * getNode(const std::string &relative_path, int index) const
Get a const pointer to another node by relative path.
Definition props.hxx:1114
SGPropertyNode_ptr removeChild(const char *name, int index=0)
Remove a child node.
void setAttribute(Attribute attr, bool state)
Set a single mode attribute for the property node.
Definition props.hxx:1131
bool setStringValue(const char *relative_path, const char *value)
Set another node's value as a string.
simgear::props::Type getType(const std::string &relative_path) const
Get another node's type.
Definition props.hxx:1377
bool untie(const std::string &relative_path)
Unbind another node from any external data source.
Definition props.hxx:1659
static bool compare(const SGPropertyNode &lhs, const SGPropertyNode &rhs)
Compare two property trees.
const char * getStringValue(const std::string &relative_path, const char *defaultValue="") const
Get another node's value as a string.
Definition props.hxx:1468
bool isTied() const
Test whether this node is bound to an external data source.
Definition props.hxx:1349
double getDoubleValue() const
Get a double value for this node.
const SGPropertyNode * getNode(const char *relative_path, int index) const
Get a const pointer to another node by relative path.
const SGPropertyNode * getParent() const
Get a const pointer to the node's parent.
Definition props.hxx:838
bool tie(const char *relative_path, const SGRawValue< float > &rawValue, bool useDefault=true)
Bind another node to an external float source.
std::vector< T > getChildValues(const std::string &name) const
Get a list of values from all children with the given name.
Definition props.hxx:1974
long getLongValue() const
Get a long int value for this node.
void setAttributes(int attr)
Set all of the mode attributes for the property node.
Definition props.hxx:1145
bool setLongValue(long value)
Set a long int value for this node.
bool setFloatValue(const char *relative_path, float value)
Set another node's value as a float.
void addChangeListener(SGPropertyChangeListener *listener, bool initial=false)
Add a change listener to the property.
SGPropertyNode * getAliasTarget()
Get a non-const pointer to the current alias target, if any.
int getAttributes() const
Get all of the mode attributes for the property node.
Definition props.hxx:1139
bool setBoolValue(bool value)
Set a bool value for this node.
simgear::PropertyList removeChildren(const char *name)
Remove all children with the specified name.
bool setBoolValue(const char *relative_path, bool value)
Set another node's value as a bool.
std::string getPath(bool simplify=false) const
Get the path to this node from the root.
SGPropertyNode(const std::string &name, int index, SGPropertyNode *parent)
Protected constructor for making new nodes on demand.
int getIntValue() const
Get an int value for this node.
bool setFloatValue(const std::string &relative_path, float value)
Set another node's value as a float.
Definition props.hxx:1517
bool hasChild(const std::string &name, int index=0) const
Test whether a named child exists.
Definition props.hxx:875
const SGPropertyNode * getChild(const std::string &name, int index=0) const
Get a const child node by name and index.
Definition props.hxx:923
T getValue(typename boost::enable_if_c< simgear::props::PropertyTraits< T >::Internal > ::type *dummy=0) const
Get a value from a node.
void clearValue()
Clear any existing value and set the type to NONE.
const SGPropertyNode * getRootNode() const
Get a const pointer to the root node.
void removeAllChildren()
Remove all children (does not change the value of the node)
float getFloatValue(const char *relative_path, float defaultValue=0.0f) const
Get another node's value as a float.
SGPropertyNode * getNode(const char *relative_path, int index, bool create=false)
Get a pointer to another node by relative path.
bool setDoubleValue(double value)
Set a double value for this node.
bool setLongValue(const char *relative_path, long value)
Set another node's value as a long int.
simgear::props::Type getType(const char *relative_path) const
Get another node's type.
simgear::PropertyList getChildren(const char *name) const
Get a vector of all children with the specified name.
double getDoubleValue(const char *relative_path, double defaultValue=0.0) const
Get another node's value as a double.
bool hasValue(const std::string &relative_path) const
Test whether another node has a leaf value.
Definition props.hxx:1388
int nListeners() const
Get the number of listeners.
Definition props.hxx:1680
int getIntValue(const char *relative_path, int defaultValue=0) const
Get another node's value as an int.
float getFloatValue() const
Get a float value for this node.
SGPropertyNode * getParent()
Get a non-const pointer to the node's parent.
Definition props.hxx:832
void fireCreatedRecursive(bool fire_self=false)
Trigger a child-added and value-changed event for every child (Unlimited depth).
long getLongValue(const std::string &relative_path, long defaultValue=0L) const
Get another node's value as a long int.
Definition props.hxx:1427
bool setIntValue(int value)
Set an int value for this node.
bool tie(const std::string &relative_path, const SGRawValue< double > &rawValue, bool useDefault=true)
Bind another node to an external double source.
Definition props.hxx:1632
SGPropertyNode * getChild(int position)
Get a child node by position (NOT index).
bool setDoubleValue(const char *relative_path, double value)
Set another node's value as a double.
void fireChildAdded(SGPropertyNode *child)
Fire a child-added event to all listeners.
bool tie(const char *relative_path, const SGRawValue< const char * > &rawValue, bool useDefault=true)
Bind another node to an external string source.
bool alias(const char *path)
Alias this node's leaf value to another's by relative path.
int getIntValue(const std::string &relative_path, int defaultValue=0) const
Get another node's value as an int.
Definition props.hxx:1413
bool isAlias() const
Test whether the node's leaf value is aliased to another's.
Definition props.hxx:1011
float getFloatValue(const std::string &relative_path, float defaultValue=0.0f) const
Get another node's value as a float.
Definition props.hxx:1440
bool getBoolValue(const std::string &relative_path, bool defaultValue=false) const
Get another node's value as a bool.
Definition props.hxx:1400
bool setIntValue(const char *relative_path, int value)
Set another node's value as an int.
bool setBoolValue(const std::string &relative_path, bool value)
Set another node's value as a bool.
Definition props.hxx:1481
std::string getDisplayName(bool simplify=false) const
Get the node's pretty display name, with subscript when needed.
bool tie(const char *relative_path, const SGRawValue< bool > &rawValue, bool useDefault=true)
Bind another node to an external bool source.
SGPropertyNode(const SGPropertyNode &node)
Copy constructor.
bool tie(const std::string &relative_path, const SGRawValue< const char * > &rawValue, bool useDefault=true)
Bind another node to an external string source.
Definition props.hxx:1646
simgear::PropertyList addChildren(const std::string &name, size_t count, int min_index=0, bool append=true)
Create multiple child nodes with the given name an unused indices.
const SGPropertyNode * getNode(const char *relative_path) const
Get a const pointer to another node by relative path.
bool tie(const std::string &relative_path, const SGRawValue< int > &rawValue, bool useDefault=true)
Bind another node to an external int source.
Definition props.hxx:1590
const SGPropertyNode * getChild(int position) const
Get a const child node by position (NOT index).
bool alias(SGPropertyNode *target)
Alias this node's leaf value to another's.
long getLongValue(const char *relative_path, long defaultValue=0L) const
Get another node's value as a long int.
int nChildren() const
Get the number of child nodes.
Definition props.hxx:849
bool setStringValue(const char *value)
Set a string value for this node.
void fireValueChanged()
Fire a value change event to all listeners.
bool isTied(const std::string &relative_path) const
Test whether another node is bound to an external data source.
Definition props.hxx:1564
SGPropertyNode * getNode(const char *relative_path, bool create=false)
Get a pointer to another node by relative path.
bool tie(const std::string &relative_path, const SGRawValue< float > &rawValue, bool useDefault=true)
Bind another node to an external float source.
Definition props.hxx:1618
SGPropertyNode_ptr removeChild(int pos)
Remove child by position.
bool tie(const char *relative_path, const SGRawValue< double > &rawValue, bool useDefault=true)
Bind another node to an external double source.
const char * getStringValue(const char *relative_path, const char *defaultValue="") const
Get another node's value as a string.
bool setFloatValue(float value)
Set a float value for this node.
SGPropertyNode()
Default constructor.
bool removeChild(SGPropertyNode *node)
Remove child by pointer (if it is a child of this node).
bool isTied(const char *relative_path) const
Test whether another node is bound to an external data source.
const SGPropertyNode * getChild(const char *name, int index=0) const
Get a const child node by name and index.
const SGPropertyNode * getAliasTarget() const
Get a const pointer to the current alias target, if any.
bool tie(const std::string &relative_path, const SGRawValue< bool > &rawValue, bool useDefault=true)
Bind another node to an external bool source.
Definition props.hxx:1576
bool setIntValue(const std::string &relative_path, int value)
Set another node's value as an int.
Definition props.hxx:1493
const std::string & getNameString() const
Get the node's simple name as a string.
Definition props.hxx:815
bool setUnspecifiedValue(const char *relative_path, const char *value)
Set another node's value with no specified type.
bool tie(const char *relative_path, const SGRawValue< long > &rawValue, bool useDefault=true)
Bind another node to an external long int source.
bool hasValue() const
Test whether this node contains a primitive leaf value.
Definition props.hxx:810
SGPropertyNode * getRootNode()
Get a pointer to the root node.
const char * getStringValue() const
Get a string value for this node.
SGPropertyNode * addChild(const char *name, int min_index=0, bool append=true)
Create a new child node with the given name and an unused index.
const SGPropertyNode * getNode(const std::string &relative_path) const
Get a const pointer to another node by relative path.
Definition props.hxx:1095
double getDoubleValue(const std::string &relative_path, double defaultValue=0.0) const
Get another node's value as a double.
Definition props.hxx:1454
bool alias(const std::string &path)
Alias this node's leaf value to another's by relative path.
Definition props.hxx:998
virtual ~SGPropertyNode()
Destructor.
bool setLongValue(const std::string &relative_path, long value)
Set another node's value as a long int.
Definition props.hxx:1505
bool untie(const char *relative_path)
Unbind another node from any external data source.
virtual SGRawExtended * makeContainer() const =0
Make an SGRawValueContainer from the SGRawValue.
virtual std::ostream & printOn(std::ostream &stream) const =0
Write value out to a stream.
virtual std::istream & readFrom(std::istream &stream)=0
Read value from a stream and store it.
A raw value that contains its value.
Definition props.hxx:642
virtual bool setValue(T value)
Set the underlying value.
Definition props.hxx:666
virtual ~SGRawValueContainer()
Destructor.
Definition props.hxx:653
virtual SGRaw * clone() const
Create a copy of this raw value.
Definition props.hxx:671
virtual T getValue() const
Get the underlying value.
Definition props.hxx:658
SGRawValueContainer(const T &obj)
Explicit constructor.
Definition props.hxx:648
An indexed value bound to static functions.
Definition props.hxx:543
virtual bool setValue(T value)
Assign a new underlying value.
Definition props.hxx:554
virtual T getValue() const
Return the underlying value.
Definition props.hxx:550
A value managed through static functions.
Definition props.hxx:463
SGRawValueFunctions(getter_t getter=0, setter_t setter=0)
Explicit constructor.
Definition props.hxx:486
virtual bool setValue(T value)
Set the underlying value.
Definition props.hxx:513
virtual ~SGRawValueFunctions()
Destructor.
Definition props.hxx:492
T(* getter_t)()
The template type of a static getter function.
Definition props.hxx:469
void(* setter_t)(T)
The template type of a static setter function.
Definition props.hxx:474
virtual SGRaw * clone() const
Create a copy of this raw value, bound to the same functions.
Definition props.hxx:521
virtual T getValue() const
Get the underlying value.
Definition props.hxx:501
An indexed value managed through an object and access methods.
Definition props.hxx:609
virtual bool setValue(T value)
Assign a new underlying value.
Definition props.hxx:621
virtual T getValue() const
Return the underlying value.
Definition props.hxx:617
A value managed through an object and access methods.
Definition props.hxx:576
virtual bool setValue(T value)
Assign a new underlying value.
Definition props.hxx:587
virtual T getValue() const
Return the underlying value.
Definition props.hxx:583
A raw value bound to a pointer.
Definition props.hxx:406
virtual bool setValue(T value)
Set the underlying value.
Definition props.hxx:439
SGRawValuePointer(T *ptr)
Explicit pointer constructor.
Definition props.hxx:418
virtual SGRaw * clone() const
Create a copy of this raw value.
Definition props.hxx:446
virtual T getValue() const
Get the underlying value.
Definition props.hxx:431
virtual ~SGRawValuePointer()
Destructor.
Definition props.hxx:423
Abstract base class for a raw value.
Definition props.hxx:313
virtual simgear::props::Type getType() const
Return the type tag for this raw value type.
Definition props.hxx:372
SGRawValue()
Constructor.
Definition props.hxx:336
virtual ~SGRawValue()
Destructor.
Definition props.hxx:342
virtual T getValue() const =0
Return the underlying value.
virtual bool setValue(T value)=0
Assign a new underlying value.
static T DefaultValue()
The default underlying value for this type.
Definition props.hxx:325
Base class for SGRawValue classes that holds no type information.
Definition props.hxx:215
virtual SGRaw * clone() const =0
Create a new deep copy of this raw value.
virtual simgear::props::Type getType() const =0
Get the type enumeration for the raw value.
Property value types.
Definition props.hxx:148
Type
The possible types of an SGPropertyNode.
Definition props.hxx:153
@ ALIAS
The node "points" to another node.
Definition props.hxx:155
@ EXTENDED
The node's value is not stored in the property; the actual value and type is retrieved from an SGRawV...
Definition props.hxx:163
@ NONE
The node hasn't been assigned a value yet.
Definition props.hxx:154
Utility function for creation of a child property node using a relative path.
Definition props.hxx:70
T parseString(const std::string &str)
Parse a string as an object of a given type.
Definition props.hxx:90
SGPropertyNode * makeChild(SGPropertyNode *parent, const char *name, int index=0)
Utility function for creation of a child property node.
Definition props.hxx:2032