JSBSim Flight Dynamics Model 1.2.3 (07 Jun 2025)
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#ifndef SG_LOG
29# define SG_GENERAL 0
30# define SG_ALERT 0
31# define SG_WARN 1
32# define SG_LOG(type, level, message) (type) ? (std::cerr <<message << endl) : (std::cout <<message << endl)
33#endif
34
35// use this local implementation only if boost has not been included
36#if !defined(BOOST_UTILITY_ENABLE_IF_HPP) && !defined(BOOST_CORE_ENABLE_IF_HPP)
37// taken from: boost/utility/enable_if.hpp
38namespace boost {
39 template <bool B, class T = void>
40 struct enable_if_c {
41 typedef T type;
42 };
43
44 template <class T>
45 struct enable_if_c<false, T> {};
46
47 template <class Cond, class T = void>
48 struct enable_if : public enable_if_c<Cond::value, T> {};
49
50 template <bool B, class T = void>
51 struct disable_if_c {
52 typedef T type;
53 };
54
55 template <class T>
56 struct disable_if_c<true, T> {};
57
58 template <class Cond, class T = void>
59 struct disable_if : public disable_if_c<Cond::value, T> {};
60}
61#endif
62#else
63# include <boost/utility.hpp>
64# include <boost/type_traits/is_enum.hpp>
65
66# include <simgear/debug/logstream.hxx>
67# include <simgear/math/SGMathFwd.hxx>
68# include <simgear/math/sg_types.hxx>
69#endif
70#include <simgear/structure/SGReferenced.hxx>
71#include <simgear/structure/SGSharedPtr.hxx>
72
73// XXX This whole file should be in the simgear namespace, but I don't
74// have the guts yet...
75
76namespace simgear
77{
78
79 class PropertyInterpolationMgr;
80
81template<typename T>
82std::istream& readFrom(std::istream& stream, T& result)
83{
84 stream >> result;
85 return stream;
86}
87
96template<typename T>
97inline T parseString(const std::string& str)
98{
99 std::istringstream stream(str);
100 T result;
101 readFrom(stream, result);
102 return result;
103}
104
109#ifdef NONE
110#pragma warn A sloppy coder has defined NONE as a macro!
111#undef NONE
112#endif
113
114#ifdef ALIAS
115#pragma warn A sloppy coder has defined ALIAS as a macro!
116#undef ALIAS
117#endif
118
119#ifdef UNSPECIFIED
120#pragma warn A sloppy coder has defined UNSPECIFIED as a macro!
121#undef UNSPECIFIED
122#endif
123
124#ifdef BOOL
125#pragma warn A sloppy coder has defined BOOL as a macro!
126#undef BOOL
127#endif
128
129#ifdef INT
130#pragma warn A sloppy coder has defined INT as a macro!
131#undef INT
132#endif
133
134#ifdef LONG
135#pragma warn A sloppy coder has defined LONG as a macro!
136#undef LONG
137#endif
138
139#ifdef FLOAT
140#pragma warn A sloppy coder has defined FLOAT as a macro!
141#undef FLOAT
142#endif
143
144#ifdef DOUBLE
145#pragma warn A sloppy coder has defined DOUBLE as a macro!
146#undef DOUBLE
147#endif
148
149#ifdef STRING
150#pragma warn A sloppy coder has defined STRING as a macro!
151#undef STRING
152#endif
153
154namespace props
155{
160enum Type {
161 NONE = 0,
163 BOOL,
164 INT,
165 LONG,
166 FLOAT,
167 DOUBLE,
168 STRING,
169 UNSPECIFIED,
170 EXTENDED,
175 // Extended properties
176 VEC3D,
177 VEC4D
178};
179
180template<typename T> struct PropertyTraits;
181
182#define DEFINTERNALPROP(TYPE, PROP) \
183template<> \
184struct PropertyTraits<TYPE> \
185{ \
186 static const Type type_tag = PROP; \
187 enum { Internal = 1 }; \
188}
189
190DEFINTERNALPROP(bool, BOOL);
191DEFINTERNALPROP(int, INT);
192DEFINTERNALPROP(long, LONG);
193DEFINTERNALPROP(float, FLOAT);
194DEFINTERNALPROP(double, DOUBLE);
195DEFINTERNALPROP(const char *, STRING);
196DEFINTERNALPROP(const char[], STRING);
197#undef DEFINTERNALPROP
198
199}
200}
201
202
203
205// A raw value.
206//
207// This is the mechanism that information-providing routines can
208// use to link their own values to the property manager. Any
209// SGValue can be tied to a raw value and then untied again.
210//
211// Note: we are forced to use inlined methods here to ensure
212// that the templates will be instantiated. We're probably taking
213// a small performance hit for that.
215
221class SGRaw
222{
223public:
229 virtual simgear::props::Type getType() const = 0;
230 virtual ~SGRaw() {}
231
240 virtual SGRaw* clone() const = 0;
241
242};
243
244class SGRawExtended : public SGRaw
245{
246public:
254 virtual SGRawExtended* makeContainer() const = 0;
258 virtual std::ostream& printOn(std::ostream& stream) const = 0;
262 virtual std::istream& readFrom(std::istream& stream) = 0;
263};
264
265// Choose between different base classes based on whether the value is
266// stored internal to the property node. This frees us from defining
267// the virtual functions in the SGRawExtended interface where they
268// don't make sense, e.g. readFrom for the const char* type.
269template<typename T, int internal = simgear::props::PropertyTraits<T>::Internal>
271
272template<typename T>
273class SGRawBase<T, 1> : public SGRaw
274{
275};
276
277template<typename T>
278class SGRawBase<T, 0> : public SGRawExtended
279{
280 virtual SGRawExtended* makeContainer() const;
281 virtual std::ostream& printOn(std::ostream& stream) const;
282 virtual std::istream& readFrom(std::istream& stream);
283};
284
318template <class T>
319class SGRawValue : public SGRawBase<T>
320{
321public:
322
332 static T DefaultValue()
333 {
334 return T();
335 }
336
337
344
345
349 virtual ~SGRawValue () {}
350
351
358 virtual T getValue () const = 0;
359
360
373 virtual bool setValue (T value) = 0;
374
375
383};
384
385
386
388// Default values for every type.
390
391template<> inline bool SGRawValue<bool>::DefaultValue()
392{
393 return false;
394}
395
396template<> inline const char * SGRawValue<const char *>::DefaultValue()
397{
398 return "";
399}
400
411template <class T>
413{
414public:
415
425 SGRawValuePointer (T * ptr) : _ptr(ptr) {}
426
430 virtual ~SGRawValuePointer () {}
431
438 virtual T getValue () const { return *_ptr; }
439
446 virtual bool setValue (T value) { *_ptr = value; return true; }
447
453 virtual SGRaw* clone () const {
454 return new SGRawValuePointer(_ptr);
455 }
456
457private:
458 T * _ptr;
459};
460
461
468template <class T>
470{
471public:
472
476 typedef T (*getter_t)();
477
481 typedef void (*setter_t)(T);
482
493 SGRawValueFunctions (getter_t getter = 0, setter_t setter = 0)
494 : _getter(getter), _setter(setter) {}
495
500
508 virtual T getValue () const {
509 if (_getter) return (*_getter)();
510 else return SGRawValue<T>::DefaultValue();
511 }
512
520 virtual bool setValue (T value) {
521 if (_setter) { (*_setter)(value); return true; }
522 else return false;
523 }
524
528 virtual SGRaw* clone () const {
529 return new SGRawValueFunctions(_getter,_setter);
530 }
531
532private:
533 getter_t _getter;
534 setter_t _setter;
535};
536
537
548template <class T>
550{
551public:
552 typedef T (*getter_t)(int);
553 typedef void (*setter_t)(int,T);
554 SGRawValueFunctionsIndexed (int index, getter_t getter = 0, setter_t setter = 0)
555 : _index(index), _getter(getter), _setter(setter) {}
556 virtual ~SGRawValueFunctionsIndexed () {}
557 virtual T getValue () const {
558 if (_getter) return (*_getter)(_index);
559 else return SGRawValue<T>::DefaultValue();
560 }
561 virtual bool setValue (T value) {
562 if (_setter) { (*_setter)(_index, value); return true; }
563 else return false;
564 }
565 virtual SGRaw* clone () const {
566 return new SGRawValueFunctionsIndexed(_index, _getter, _setter);
567 }
568private:
569 int _index;
570 getter_t _getter;
571 setter_t _setter;
572};
573
574
581template <class C, class T>
583{
584public:
585 typedef T (C::*getter_t)() const;
586 typedef void (C::*setter_t)(T);
587 SGRawValueMethods (C &obj, getter_t getter = 0, setter_t setter = 0)
588 : _obj(obj), _getter(getter), _setter(setter) {}
589 virtual ~SGRawValueMethods () {}
590 virtual T getValue () const {
591 if (_getter) { return (_obj.*_getter)(); }
592 else { return SGRawValue<T>::DefaultValue(); }
593 }
594 virtual bool setValue (T value) {
595 if (_setter) { (_obj.*_setter)(value); return true; }
596 else return false;
597 }
598 virtual SGRaw* clone () const {
599 return new SGRawValueMethods(_obj, _getter, _setter);
600 }
601private:
602 C &_obj;
603 getter_t _getter;
604 setter_t _setter;
605};
606
607
614template <class C, class T>
616{
617public:
618 typedef T (C::*getter_t)(int) const;
619 typedef void (C::*setter_t)(int, T);
620 SGRawValueMethodsIndexed (C &obj, int index,
621 getter_t getter = 0, setter_t setter = 0)
622 : _obj(obj), _index(index), _getter(getter), _setter(setter) {}
623 virtual ~SGRawValueMethodsIndexed () {}
624 virtual T getValue () const {
625 if (_getter) { return (_obj.*_getter)(_index); }
626 else { return SGRawValue<T>::DefaultValue(); }
627 }
628 virtual bool setValue (T value) {
629 if (_setter) { (_obj.*_setter)(_index, value); return true; }
630 else return false;
631 }
632 virtual SGRaw* clone () const {
633 return new SGRawValueMethodsIndexed(_obj, _index, _getter, _setter);
634 }
635private:
636 C &_obj;
637 int _index;
638 getter_t _getter;
639 setter_t _setter;
640};
641
647template <class T>
649{
650public:
651
655 SGRawValueContainer(const T& obj) : _obj(obj) {}
656
661
665 virtual T getValue() const { return _obj; }
666
673 virtual bool setValue (T value) { _obj = value; return true; }
674
678 virtual SGRaw* clone () const {
679 return new SGRawValueContainer(_obj);
680 }
681
682private:
683 T _obj;
684};
685
686template<typename T>
688{
689 return new SGRawValueContainer<T>(static_cast<const SGRawValue<T>*>(this)
690 ->getValue());
691}
692
693template<typename T>
694std::ostream& SGRawBase<T, 0>::printOn(std::ostream& stream) const
695{
696 return stream << static_cast<SGRawValue<T>*>(this)->getValue();
697}
698
699template<typename T>
700std::istream& SGRawBase<T, 0>::readFrom(std::istream& stream)
701{
702 T value;
703 simgear::readFrom(stream, value);
704 static_cast<SGRawValue<T>*>(this)->setValue(value);
705 return stream;
706}
707
711class SGPropertyNode;
712typedef SGSharedPtr<SGPropertyNode> SGPropertyNode_ptr;
713typedef SGSharedPtr<const SGPropertyNode> SGConstPropertyNode_ptr;
714
715namespace simgear
716{
717typedef std::vector<SGPropertyNode_ptr> PropertyList;
718}
719
727{
728public:
729 virtual ~SGPropertyChangeListener ();
730
732 virtual void valueChanged(SGPropertyNode * node);
733
735 virtual void childAdded(SGPropertyNode * parent, SGPropertyNode * child);
736
738 virtual void childRemoved(SGPropertyNode * parent, SGPropertyNode * child);
739
740protected:
741 friend class SGPropertyNode;
742 virtual void register_property (SGPropertyNode * node);
743 virtual void unregister_property (SGPropertyNode * node);
744
745private:
746 std::vector<SGPropertyNode *> _properties;
747};
748
749
753class JSBSIM_API SGPropertyNode : public SGReferenced
754{
755public:
756
760 enum {
761 MAX_STRING_LEN = 1024
762 };
763
771 NO_ATTR = 0,
772 READ = 1,
773 WRITE = 2,
774 ARCHIVE = 4,
775 REMOVED = 8,
776 TRACE_READ = 16,
777 TRACE_WRITE = 32,
778 USERARCHIVE = 64,
779 PRESERVE = 128
780 // beware: if you add another attribute here,
781 // also update value of "LAST_USED_ATTRIBUTE".
782 };
783
784
789 static const int LAST_USED_ATTRIBUTE;
790
795
796
801
802
806 virtual ~SGPropertyNode ();
807
808
809
810 //
811 // Basic properties.
812 //
813
817 bool hasValue () const { return (_type != simgear::props::NONE); }
818
822 const std::string& getNameString () const { return _name; }
823
827 std::string getDisplayName (bool simplify = false) const;
828
829
833 int getIndex () const { return _index; }
834
835
839 SGPropertyNode * getParent () { return _parent; }
840
841
845 const SGPropertyNode * getParent () const { return _parent; }
846
847
848 //
849 // Children.
850 //
851
852
856 int nChildren () const { return (int)_children.size(); }
857
858
862 SGPropertyNode * getChild (int position);
863
864
868 const SGPropertyNode * getChild (int position) const;
869
870
874 bool hasChild (const char * name, int index = 0) const
875 {
876 return (getChild(name, index) != 0);
877 }
878
882 bool hasChild (const std::string& name, int index = 0) const
883 {
884 return (getChild(name, index) != 0);
885 }
886
894 SGPropertyNode * addChild ( const char* name,
895 int min_index = 0,
896 bool append = true );
897 SGPropertyNode * addChild ( const std::string& name,
898 int min_index = 0,
899 bool append = true )
900 { return addChild(name.c_str(), min_index, append); }
901
910 simgear::PropertyList addChildren ( const std::string& name,
911 size_t count,
912 int min_index = 0,
913 bool append = true );
914
918 SGPropertyNode * getChild (const char* name, int index = 0,
919 bool create = false);
920 SGPropertyNode * getChild (const std::string& name, int index = 0,
921 bool create = false);
925 const SGPropertyNode * getChild (const char * name, int index = 0) const;
926
930 const SGPropertyNode * getChild (const std::string& name, int index = 0) const
931 { return getChild(name.c_str(), index); }
932
933
937 simgear::PropertyList getChildren (const char * name) const;
938
942 simgear::PropertyList getChildren (const std::string& name) const
943 { return getChildren(name.c_str()); }
944
951
952 // TODO do we need the removeXXX methods to return the deleted nodes?
956 SGPropertyNode_ptr removeChild(int pos);
957
958
962 SGPropertyNode_ptr removeChild(const char * name, int index = 0);
963
967 SGPropertyNode_ptr removeChild(const std::string& name, int index = 0)
968 { return removeChild(name.c_str(), index); }
969
973 simgear::PropertyList removeChildren(const char * name);
974
978 simgear::PropertyList removeChildren(const std::string& name)
979 { return removeChildren(name.c_str()); }
980
985
986 //
987 // Alias support.
988 //
989
990
994 bool alias (SGPropertyNode * target);
995
996
1000 bool alias (const char * path);
1001
1005 bool alias (const std::string& path)
1006 { return alias(path.c_str()); }
1007
1008
1012 bool unalias ();
1013
1014
1018 bool isAlias () const { return (_type == simgear::props::ALIAS); }
1019
1020
1025
1026
1031
1032
1033 //
1034 // Path information.
1035 //
1036
1037
1041 std::string getPath (bool simplify = false) const;
1042
1043
1048
1049
1053 const SGPropertyNode * getRootNode () const;
1054
1055
1059 SGPropertyNode * getNode (const char * relative_path, bool create = false);
1060
1064 SGPropertyNode * getNode (const std::string& relative_path, bool create = false)
1065 { return getNode(relative_path.c_str(), create); }
1066
1077 SGPropertyNode * getNode (const char * relative_path, int index,
1078 bool create = false);
1079
1090 SGPropertyNode * getNode (const std::string& relative_path, int index,
1091 bool create = false)
1092 { return getNode(relative_path.c_str(), index, create); }
1093
1097 const SGPropertyNode * getNode (const char * relative_path) const;
1098
1102 const SGPropertyNode * getNode (const std::string& relative_path) const
1103 { return getNode(relative_path.c_str()); }
1104
1105
1112 const SGPropertyNode * getNode (const char * relative_path,
1113 int index) const;
1114
1121 const SGPropertyNode * getNode (const std::string& relative_path,
1122 int index) const
1123 { return getNode(relative_path.c_str(), index); }
1124
1125 //
1126 // Access Mode.
1127 //
1128
1132 bool getAttribute (Attribute attr) const { return ((_attr & attr) != 0); }
1133
1134
1138 void setAttribute (Attribute attr, bool state) {
1139 (state ? _attr |= attr : _attr &= ~attr);
1140 }
1141
1142
1146 int getAttributes () const { return _attr; }
1147
1148
1152 void setAttributes (int attr) { _attr = attr; }
1153
1154
1155 //
1156 // Leaf Value (primitive).
1157 //
1158
1159
1164
1165
1169 bool getBoolValue () const;
1170
1171
1175 int getIntValue () const;
1176
1177
1181 long getLongValue () const;
1182
1183
1187 float getFloatValue () const;
1188
1189
1193 double getDoubleValue () const;
1194
1195
1199 const char * getStringValue () const;
1200
1205 template<typename T>
1207 ::type* dummy = 0) const;
1208 // Getter for extended property
1209 template<typename T>
1211 ::type* dummy = 0) const;
1212
1216 template<typename T, typename T_get /* = T */> // TODO use C++11 or traits
1217 std::vector<T> getChildValues(const std::string& name) const;
1218
1222 template<typename T>
1223 std::vector<T> getChildValues(const std::string& name) const;
1224
1228 bool setBoolValue (bool value);
1229
1230
1234 bool setIntValue (int value);
1235
1236
1240 bool setLongValue (long value);
1241
1242
1246 bool setFloatValue (float value);
1247
1248
1252 bool setDoubleValue (double value);
1253
1254
1258 bool setStringValue (const char * value);
1259
1263 bool setStringValue (const std::string& value)
1264 { return setStringValue(value.c_str()); }
1265
1266
1270 bool setUnspecifiedValue (const char * value);
1271
1272 template<typename T>
1273 bool setValue(const T& val,
1275 ::type* dummy = 0);
1276
1277 template<typename T>
1278 bool setValue(const T& val,
1280 ::type* dummy = 0);
1281
1282 template<int N>
1283 bool setValue(const char (&val)[N])
1284 {
1285 return setValue(&val[0]);
1286 }
1287
1296 template<typename T>
1297 bool setValueReadOnly(const std::string& relative_path, const T& value)
1298 {
1299 SGPropertyNode* node = getNode(relative_path, true);
1300 bool ret = node->setValue(value);
1301 node->setAttributes(READ);
1302 return ret;
1303 }
1304
1305#if !PROPS_STANDALONE
1314 bool interpolate( const std::string& type,
1315 const SGPropertyNode& target,
1316 double duration = 0.6,
1317 const std::string& easing = "swing" );
1318
1327 bool interpolate( const std::string& type,
1328 const simgear::PropertyList& values,
1329 const double_list& deltas,
1330 const std::string& easing = "swing" );
1331
1335 static void setInterpolationMgr(simgear::PropertyInterpolationMgr* mgr);
1336
1340 static simgear::PropertyInterpolationMgr* getInterpolationMgr();
1341#endif
1342
1346 std::ostream& printOn(std::ostream& stream) const;
1347
1348 //
1349 // Data binding.
1350 //
1351
1352
1356 bool isTied () const { return _tied; }
1357
1361 template<typename T>
1362 bool tie(const SGRawValue<T> &rawValue, bool useDefault = true);
1363
1367 bool untie ();
1368
1369
1370 //
1371 // Convenience methods using paths.
1372 // TODO: add attribute methods
1373 //
1374
1375
1379 simgear::props::Type getType (const char * relative_path) const;
1380
1384 simgear::props::Type getType (const std::string& relative_path) const
1385 { return getType(relative_path.c_str()); }
1386
1390 bool hasValue (const char * relative_path) const;
1391
1395 bool hasValue (const std::string& relative_path) const
1396 { return hasValue(relative_path.c_str()); }
1397
1401 bool getBoolValue (const char * relative_path,
1402 bool defaultValue = false) const;
1403
1407 bool getBoolValue (const std::string& relative_path,
1408 bool defaultValue = false) const
1409 { return getBoolValue(relative_path.c_str(), defaultValue); }
1410
1414 int getIntValue (const char * relative_path,
1415 int defaultValue = 0) const;
1416
1420 int getIntValue (const std::string& relative_path,
1421 int defaultValue = 0) const
1422 { return getIntValue(relative_path.c_str(), defaultValue); }
1423
1424
1428 long getLongValue (const char * relative_path,
1429 long defaultValue = 0L) const;
1430
1434 long getLongValue (const std::string& relative_path,
1435 long defaultValue = 0L) const
1436 { return getLongValue(relative_path.c_str(), defaultValue); }
1437
1441 float getFloatValue (const char * relative_path,
1442 float defaultValue = 0.0f) const;
1443
1447 float getFloatValue (const std::string& relative_path,
1448 float defaultValue = 0.0f) const
1449 { return getFloatValue(relative_path.c_str(), defaultValue); }
1450
1451
1455 double getDoubleValue (const char * relative_path,
1456 double defaultValue = 0.0) const;
1457
1461 double getDoubleValue (const std::string& relative_path,
1462 double defaultValue = 0.0) const
1463 { return getDoubleValue(relative_path.c_str(), defaultValue); }
1464
1468 const char * getStringValue (const char * relative_path,
1469 const char * defaultValue = "") const;
1470
1471
1475 const char * getStringValue (const std::string& relative_path,
1476 const char * defaultValue = "") const
1477 { return getStringValue(relative_path.c_str(), defaultValue); }
1478
1479
1483 bool setBoolValue (const char * relative_path, bool value);
1484
1488 bool setBoolValue (const std::string& relative_path, bool value)
1489 { return setBoolValue(relative_path.c_str(), value); }
1490
1491
1495 bool setIntValue (const char * relative_path, int value);
1496
1500 bool setIntValue (const std::string& relative_path, int value)
1501 { return setIntValue(relative_path.c_str(), value); }
1502
1503
1507 bool setLongValue (const char * relative_path, long value);
1508
1512 bool setLongValue (const std::string& relative_path, long value)
1513 { return setLongValue(relative_path.c_str(), value); }
1514
1515
1519 bool setFloatValue (const char * relative_path, float value);
1520
1524 bool setFloatValue (const std::string& relative_path, float value)
1525 { return setFloatValue(relative_path.c_str(), value); }
1526
1527
1531 bool setDoubleValue (const char * relative_path, double value);
1532
1536 bool setDoubleValue (const std::string& relative_path, double value)
1537 { return setDoubleValue(relative_path.c_str(), value); }
1538
1539
1543 bool setStringValue (const char * relative_path, const char * value);
1544
1545 bool setStringValue(const char * relative_path, const std::string& value)
1546 { return setStringValue(relative_path, value.c_str()); }
1550 bool setStringValue (const std::string& relative_path, const char * value)
1551 { return setStringValue(relative_path.c_str(), value); }
1552
1553 bool setStringValue (const std::string& relative_path,
1554 const std::string& value)
1555 { return setStringValue(relative_path.c_str(), value.c_str()); }
1556
1560 bool setUnspecifiedValue (const char * relative_path, const char * value);
1561
1562
1566 bool isTied (const char * relative_path) const;
1567
1571 bool isTied (const std::string& relative_path) const
1572 { return isTied(relative_path.c_str()); }
1573
1577 bool tie (const char * relative_path, const SGRawValue<bool> &rawValue,
1578 bool useDefault = true);
1579
1583 bool tie (const std::string& relative_path, const SGRawValue<bool> &rawValue,
1584 bool useDefault = true)
1585 { return tie(relative_path.c_str(), rawValue, useDefault); }
1586
1587
1591 bool tie (const char * relative_path, const SGRawValue<int> &rawValue,
1592 bool useDefault = true);
1593
1597 bool tie (const std::string& relative_path, const SGRawValue<int> &rawValue,
1598 bool useDefault = true)
1599 { return tie(relative_path.c_str(), rawValue, useDefault); }
1600
1601
1605 bool tie (const char * relative_path, const SGRawValue<long> &rawValue,
1606 bool useDefault = true);
1607
1611 bool tie (const std::string& relative_path, const SGRawValue<long> &rawValue,
1612 bool useDefault = true)
1613 { return tie(relative_path.c_str(), rawValue, useDefault); }
1614
1615
1619 bool tie (const char * relative_path, const SGRawValue<float> &rawValue,
1620 bool useDefault = true);
1621
1625 bool tie (const std::string& relative_path, const SGRawValue<float> &rawValue,
1626 bool useDefault = true)
1627 { return tie(relative_path.c_str(), rawValue, useDefault); }
1628
1629
1633 bool tie (const char * relative_path, const SGRawValue<double> &rawValue,
1634 bool useDefault = true);
1635
1639 bool tie (const std::string& relative_path, const SGRawValue<double> &rawValue,
1640 bool useDefault = true)
1641 { return tie(relative_path.c_str(), rawValue, useDefault); }
1642
1643
1647 bool tie (const char * relative_path, const SGRawValue<const char *> &rawValue,
1648 bool useDefault = true);
1649
1653 bool tie (const std::string& relative_path, const SGRawValue<const char*> &rawValue,
1654 bool useDefault = true)
1655 { return tie(relative_path.c_str(), rawValue, useDefault); }
1656
1657
1661 bool untie (const char * relative_path);
1662
1666 bool untie (const std::string& relative_path)
1667 { return untie(relative_path.c_str()); }
1668
1669
1675 bool initial = false);
1676
1677
1682
1683
1687 int nListeners () const { return _listeners ? (int)_listeners->size() : 0; }
1688
1689
1694
1695
1700
1710 void fireCreatedRecursive(bool fire_self = false);
1711
1716
1725
1726
1730 void clearValue ();
1731
1741 static bool compare (const SGPropertyNode& lhs, const SGPropertyNode& rhs);
1742
1743protected:
1744
1745 void fireValueChanged (SGPropertyNode * node);
1746 void fireChildAdded (SGPropertyNode * parent, SGPropertyNode * child);
1747 void fireChildRemoved (SGPropertyNode * parent, SGPropertyNode * child);
1748
1749 SGPropertyNode_ptr eraseChild(simgear::PropertyList::iterator child);
1750
1754 SGPropertyNode (const std::string& name, int index, SGPropertyNode * parent);
1755 template<typename Itr>
1756 SGPropertyNode (Itr begin, Itr end, int index, SGPropertyNode * parent);
1757
1758 static simgear::PropertyInterpolationMgr* _interpolation_mgr;
1759
1760private:
1761
1762 // Get the raw value
1763 bool get_bool () const;
1764 int get_int () const;
1765 long get_long () const;
1766 float get_float () const;
1767 double get_double () const;
1768 const char * get_string () const;
1769
1770 // Set the raw value
1771 bool set_bool (bool value);
1772 bool set_int (int value);
1773 bool set_long (long value);
1774 bool set_float (float value);
1775 bool set_double (double value);
1776 bool set_string (const char * value);
1777
1778
1782 const char * make_string () const;
1783
1787 void trace_read () const;
1788
1789
1793 void trace_write () const;
1794
1795 int _index;
1796 std::string _name;
1799 SGPropertyNode * _parent;
1800 simgear::PropertyList _children;
1801 mutable std::string _buffer;
1803 bool _tied;
1804 int _attr;
1805
1806 // The right kind of pointer...
1807 union {
1808 SGPropertyNode * alias;
1809 SGRaw* val;
1810 } _value;
1811
1812 union {
1813 bool bool_val;
1814 int int_val;
1815 long long_val;
1816 float float_val;
1817 double double_val;
1818 char * string_val;
1819 } _local_val;
1820
1821 std::vector<SGPropertyChangeListener *> * _listeners;
1822
1823 // Pass name as a pair of iterators
1824 template<typename Itr>
1825 SGPropertyNode * getChildImpl (Itr begin, Itr end, int index = 0, bool create = false);
1826 // very internal method
1827 template<typename Itr>
1828 SGPropertyNode* getExistingChild (Itr begin, Itr end, int index);
1829 // very internal path parsing function
1830 template<typename SplitItr>
1831 friend SGPropertyNode* find_node_aux(SGPropertyNode * current, SplitItr& itr,
1832 bool create, int last_index);
1833 // For boost
1834 friend size_t hash_value(const SGPropertyNode& node);
1835};
1836
1837// Convenience functions for use in templates
1838template<typename T>
1839#if PROPS_STANDALONE
1840T
1841#else
1842typename boost::disable_if<boost::is_enum<T>, T>::type
1843#endif
1844getValue(const SGPropertyNode*);
1845
1846template<>
1847inline bool getValue<bool>(const SGPropertyNode* node) { return node->getBoolValue(); }
1848
1849template<>
1850inline int getValue<int>(const SGPropertyNode* node) { return node->getIntValue(); }
1851
1852template<>
1853inline long getValue<long>(const SGPropertyNode* node) { return node->getLongValue(); }
1854
1855template<>
1856inline float getValue<float>(const SGPropertyNode* node)
1857{
1858 return node->getFloatValue();
1859}
1860
1861template<>
1862inline double getValue<double>(const SGPropertyNode* node)
1863{
1864 return node->getDoubleValue();
1865}
1866
1867template<>
1868inline const char * getValue<const char*>(const SGPropertyNode* node)
1869{
1870 return node->getStringValue ();
1871}
1872
1873template<>
1874inline std::string getValue<std::string>(const SGPropertyNode* node)
1875{
1876 return node->getStringValue();
1877}
1878
1879inline bool setValue(SGPropertyNode* node, bool value)
1880{
1881 return node->setBoolValue(value);
1882}
1883
1884inline bool setValue(SGPropertyNode* node, int value)
1885{
1886 return node->setIntValue(value);
1887}
1888
1889inline bool setValue(SGPropertyNode* node, long value)
1890{
1891 return node->setLongValue(value);
1892}
1893
1894inline bool setValue(SGPropertyNode* node, float value)
1895{
1896 return node->setFloatValue(value);
1897}
1898
1899inline bool setValue(SGPropertyNode* node, double value)
1900{
1901 return node->setDoubleValue(value);
1902}
1903
1904inline bool setValue(SGPropertyNode* node, const char* value)
1905{
1906 return node->setStringValue(value);
1907}
1908
1909inline bool setValue (SGPropertyNode* node, const std::string& value)
1910{
1911 return node->setStringValue(value.c_str());
1912}
1913
1914template<typename T>
1915bool SGPropertyNode::tie(const SGRawValue<T> &rawValue, bool useDefault)
1916{
1917 using namespace simgear::props;
1918 if (_type == ALIAS || _tied)
1919 return false;
1920
1921 useDefault = useDefault && hasValue();
1922 T old_val = SGRawValue<T>::DefaultValue();
1923 if (useDefault)
1924 old_val = getValue<T>(this);
1925 clearValue();
1928 else
1929 _type = EXTENDED;
1930 _tied = true;
1931 _value.val = rawValue.clone();
1932 if (useDefault) {
1933 int save_attributes = getAttributes();
1934 setAttribute( WRITE, true );
1935 setValue(old_val);
1936 setAttributes( save_attributes );
1937 }
1938 return true;
1939}
1940
1941template<>
1942bool SGPropertyNode::tie (const SGRawValue<const char *> &rawValue,
1943 bool useDefault);
1944
1945template<typename T>
1947 ::PropertyTraits<T>::Internal>::type* dummy) const
1948{
1949 using namespace simgear::props;
1950 if (_attr == (READ|WRITE) && _type == EXTENDED
1951 && _value.val->getType() == PropertyTraits<T>::type_tag) {
1952 return static_cast<SGRawValue<T>*>(_value.val)->getValue();
1953 }
1954 if (getAttribute(TRACE_READ))
1955 trace_read();
1956 if (!getAttribute(READ))
1958 switch (_type) {
1959 case EXTENDED:
1960 if (_value.val->getType() == PropertyTraits<T>::type_tag)
1961 return static_cast<SGRawValue<T>*>(_value.val)->getValue();
1962 break;
1963 case STRING:
1964 case UNSPECIFIED:
1965 return simgear::parseString<T>(make_string());
1966 break;
1967 default: // avoid compiler warning
1968 break;
1969 }
1971}
1972
1973template<typename T>
1975 ::PropertyTraits<T>::Internal>::type* dummy) const
1976{
1977 return ::getValue<T>(this);
1978}
1979
1980template<typename T, typename T_get /* = T */> // TODO use C++11 or traits
1981std::vector<T> SGPropertyNode::getChildValues(const std::string& name) const
1982{
1983 const simgear::PropertyList& props = getChildren(name);
1984 std::vector<T> values( props.size() );
1985
1986 for( size_t i = 0; i < props.size(); ++i )
1987 values[i] = props[i]->getValue<T_get>();
1988
1989 return values;
1990}
1991
1992template<typename T>
1993inline
1994std::vector<T> SGPropertyNode::getChildValues(const std::string& name) const
1995{
1996 return getChildValues<T, T>(name);
1997}
1998
1999template<typename T>
2000bool SGPropertyNode::setValue(const T& val,
2002 ::PropertyTraits<T>::Internal>::type* dummy)
2003{
2004 using namespace simgear::props;
2005 if (_attr == (READ|WRITE) && _type == EXTENDED
2006 && _value.val->getType() == PropertyTraits<T>::type_tag) {
2007 static_cast<SGRawValue<T>*>(_value.val)->setValue(val);
2008 return true;
2009 }
2010 if (getAttribute(WRITE)
2011 && ((_type == EXTENDED
2012 && _value.val->getType() == PropertyTraits<T>::type_tag)
2013 || _type == NONE || _type == UNSPECIFIED)) {
2014 if (_type == NONE || _type == UNSPECIFIED) {
2015 clearValue();
2016 _type = EXTENDED;
2017 _value.val = new SGRawValueContainer<T>(val);
2018 } else {
2019 static_cast<SGRawValue<T>*>(_value.val)->setValue(val);
2020 }
2021 if (getAttribute(TRACE_WRITE))
2022 trace_write();
2023 return true;
2024 }
2025 return false;
2026}
2027
2028template<typename T>
2029inline bool SGPropertyNode::setValue(const T& val,
2031 ::PropertyTraits<T>::Internal>::type* dummy)
2032{
2033 return ::setValue(this, val);
2034}
2035
2039inline SGPropertyNode* makeChild(SGPropertyNode* parent, const char* name,
2040 int index = 0)
2041{
2042 return parent->getChild(name, index, true);
2043}
2044
2049namespace simgear
2050{
2051template<typename StringType>
2052inline SGPropertyNode* makeNode(SGPropertyNode* parent, const StringType& name)
2053{
2054 return parent->getNode(name, true);
2055}
2056}
2057
2058// For boost::hash
2059size_t hash_value(const SGPropertyNode& node);
2060
2061// Helper comparison and hash functions for common cases
2062
2063namespace simgear
2064{
2065namespace props
2066{
2068{
2069 bool operator()(const SGPropertyNode* lhs, const SGPropertyNode* rhs) const
2070 {
2071 return SGPropertyNode::compare(*lhs, *rhs);
2072 }
2073 bool operator()(SGPropertyNode_ptr lhs, const SGPropertyNode* rhs) const
2074 {
2075 return SGPropertyNode::compare(*lhs, *rhs);
2076 }
2077 bool operator()(const SGPropertyNode* lhs, SGPropertyNode_ptr rhs) const
2078 {
2079 return SGPropertyNode::compare(*lhs, *rhs);
2080 }
2081 bool operator()(SGPropertyNode_ptr lhs, SGPropertyNode_ptr rhs) const
2082 {
2083 return SGPropertyNode::compare(*lhs, *rhs);
2084 }
2085};
2086
2087struct Hash
2088{
2089 size_t operator()(const SGPropertyNode* node) const
2090 {
2091 return hash_value(*node);
2092 }
2093 size_t operator()(SGPropertyNode_ptr node) const
2094 {
2095 return hash_value(*node);
2096 }
2097};
2098}
2099}
2100
2105template<class T>
2108{
2109public:
2110 SGPropertyChangeCallback(T* obj, void (T::*method)(SGPropertyNode*),
2111 SGPropertyNode_ptr property,bool initial=false)
2112 : _obj(obj), _callback(method), _property(property)
2113 {
2114 _property->addChangeListener(this,initial);
2115 }
2116
2118 _obj(other._obj), _callback(other._callback), _property(other._property)
2119 {
2120 _property->addChangeListener(this,false);
2121 }
2122
2124 {
2125 _property->removeChangeListener(this);
2126 }
2128 {
2129 (_obj->*_callback)(node);
2130 }
2131private:
2132 T* _obj;
2133 void (T::*_callback)(SGPropertyNode*);
2134 SGPropertyNode_ptr _property;
2135};
2136
2137#endif // __PROPS_HXX
2138
2139// end of props.hxx
Convenience class for change listener callbacks without creating a derived class implementing a "valu...
Definition props.hxx:2108
void valueChanged(SGPropertyNode *node)
Called if value of node has changed.
Definition props.hxx:2127
The property change listener interface.
Definition props.hxx:727
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:754
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:1090
bool setDoubleValue(const std::string &relative_path, double value)
Set another node's value as a double.
Definition props.hxx:1536
bool hasChild(const char *name, int index=0) const
Test whether a named child exists.
Definition props.hxx:874
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:1611
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:967
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:770
int getIndex() const
Get the node's integer index.
Definition props.hxx:833
bool setValueReadOnly(const std::string &relative_path, const T &value)
Set relative node to given value and afterwards make read only.
Definition props.hxx:1297
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:978
bool setStringValue(const std::string &value)
Set a string value for this node.
Definition props.hxx:1263
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:1915
static const int LAST_USED_ATTRIBUTE
Last used attribute Update as needed when enum Attribute is changed.
Definition props.hxx:789
simgear::PropertyList getChildren(const std::string &name) const
Get a vector of all children with the specified name.
Definition props.hxx:942
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:1064
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:1550
bool getAttribute(Attribute attr) const
Check a single mode attribute for the property node.
Definition props.hxx:1132
const SGPropertyNode * getNode(const std::string &relative_path, int index) const
Get a const pointer to another node by relative path.
Definition props.hxx:1121
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:1138
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:1384
bool untie(const std::string &relative_path)
Unbind another node from any external data source.
Definition props.hxx:1666
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:1475
bool isTied() const
Test whether this node is bound to an external data source.
Definition props.hxx:1356
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:845
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:1981
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:1152
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:1146
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:1524
bool hasChild(const std::string &name, int index=0) const
Test whether a named child exists.
Definition props.hxx:882
const SGPropertyNode * getChild(const std::string &name, int index=0) const
Get a const child node by name and index.
Definition props.hxx:930
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:1395
int nListeners() const
Get the number of listeners.
Definition props.hxx:1687
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:839
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:1434
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:1639
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:1420
bool isAlias() const
Test whether the node's leaf value is aliased to another's.
Definition props.hxx:1018
float getFloatValue(const std::string &relative_path, float defaultValue=0.0f) const
Get another node's value as a float.
Definition props.hxx:1447
bool getBoolValue(const std::string &relative_path, bool defaultValue=false) const
Get another node's value as a bool.
Definition props.hxx:1407
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:1488
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:1653
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:1597
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:856
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:1571
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:1625
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:1583
bool setIntValue(const std::string &relative_path, int value)
Set another node's value as an int.
Definition props.hxx:1500
const std::string & getNameString() const
Get the node's simple name as a string.
Definition props.hxx:822
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:817
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:1102
double getDoubleValue(const std::string &relative_path, double defaultValue=0.0) const
Get another node's value as a double.
Definition props.hxx:1461
bool alias(const std::string &path)
Alias this node's leaf value to another's by relative path.
Definition props.hxx:1005
virtual ~SGPropertyNode()
Destructor.
bool setLongValue(const std::string &relative_path, long value)
Set another node's value as a long int.
Definition props.hxx:1512
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:649
virtual bool setValue(T value)
Set the underlying value.
Definition props.hxx:673
virtual ~SGRawValueContainer()
Destructor.
Definition props.hxx:660
virtual SGRaw * clone() const
Create a copy of this raw value.
Definition props.hxx:678
virtual T getValue() const
Get the underlying value.
Definition props.hxx:665
SGRawValueContainer(const T &obj)
Explicit constructor.
Definition props.hxx:655
An indexed value bound to static functions.
Definition props.hxx:550
virtual bool setValue(T value)
Assign a new underlying value.
Definition props.hxx:561
virtual T getValue() const
Return the underlying value.
Definition props.hxx:557
A value managed through static functions.
Definition props.hxx:470
SGRawValueFunctions(getter_t getter=0, setter_t setter=0)
Explicit constructor.
Definition props.hxx:493
virtual bool setValue(T value)
Set the underlying value.
Definition props.hxx:520
virtual ~SGRawValueFunctions()
Destructor.
Definition props.hxx:499
T(* getter_t)()
The template type of a static getter function.
Definition props.hxx:476
void(* setter_t)(T)
The template type of a static setter function.
Definition props.hxx:481
virtual SGRaw * clone() const
Create a copy of this raw value, bound to the same functions.
Definition props.hxx:528
virtual T getValue() const
Get the underlying value.
Definition props.hxx:508
An indexed value managed through an object and access methods.
Definition props.hxx:616
virtual bool setValue(T value)
Assign a new underlying value.
Definition props.hxx:628
virtual T getValue() const
Return the underlying value.
Definition props.hxx:624
A value managed through an object and access methods.
Definition props.hxx:583
virtual bool setValue(T value)
Assign a new underlying value.
Definition props.hxx:594
virtual T getValue() const
Return the underlying value.
Definition props.hxx:590
A raw value bound to a pointer.
Definition props.hxx:413
virtual bool setValue(T value)
Set the underlying value.
Definition props.hxx:446
SGRawValuePointer(T *ptr)
Explicit pointer constructor.
Definition props.hxx:425
virtual SGRaw * clone() const
Create a copy of this raw value.
Definition props.hxx:453
virtual T getValue() const
Get the underlying value.
Definition props.hxx:438
virtual ~SGRawValuePointer()
Destructor.
Definition props.hxx:430
Abstract base class for a raw value.
Definition props.hxx:320
virtual simgear::props::Type getType() const
Return the type tag for this raw value type.
Definition props.hxx:379
SGRawValue()
Constructor.
Definition props.hxx:343
virtual ~SGRawValue()
Destructor.
Definition props.hxx:349
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:332
Base class for SGRawValue classes that holds no type information.
Definition props.hxx:222
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:155
Type
The possible types of an SGPropertyNode.
Definition props.hxx:160
@ ALIAS
The node "points" to another node.
Definition props.hxx:162
@ EXTENDED
The node's value is not stored in the property; the actual value and type is retrieved from an SGRawV...
Definition props.hxx:170
@ NONE
The node hasn't been assigned a value yet.
Definition props.hxx:161
Utility function for creation of a child property node using a relative path.
Definition props.hxx:77
T parseString(const std::string &str)
Parse a string as an object of a given type.
Definition props.hxx:97
SGPropertyNode * makeChild(SGPropertyNode *parent, const char *name, int index=0)
Utility function for creation of a child property node.
Definition props.hxx:2039