-
Notifications
You must be signed in to change notification settings - Fork 472
/
Copy pathprops.hxx
2141 lines (1768 loc) · 53.3 KB
/
props.hxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* \file props.hxx
* Interface definition for a property list.
* Started Fall 2000 by David Megginson, [email protected]
* This code is released into the Public Domain.
*
* See props.html for documentation [replace with URL when available].
*
*/
#ifndef __PROPS_HXX
#define __PROPS_HXX
#ifndef PROPS_STANDALONE
#define PROPS_STANDALONE 1
#endif
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <typeinfo>
#include "simgear/compiler.h"
#include "JSBSim_API.h"
#if PROPS_STANDALONE
#ifndef SG_LOG
# define SG_GENERAL 0
# define SG_ALERT 0
# define SG_WARN 1
# define SG_LOG(type, level, message) (type) ? (std::cerr <<message << endl) : (std::cout <<message << endl)
#endif
// use this local implementation only if boost has not been included
#if !defined(BOOST_UTILITY_ENABLE_IF_HPP) && !defined(BOOST_CORE_ENABLE_IF_HPP)
// taken from: boost/utility/enable_if.hpp
namespace boost {
template <bool B, class T = void>
struct enable_if_c {
typedef T type;
};
template <class T>
struct enable_if_c<false, T> {};
template <class Cond, class T = void>
struct enable_if : public enable_if_c<Cond::value, T> {};
template <bool B, class T = void>
struct disable_if_c {
typedef T type;
};
template <class T>
struct disable_if_c<true, T> {};
template <class Cond, class T = void>
struct disable_if : public disable_if_c<Cond::value, T> {};
}
#endif
#else
# include <boost/utility.hpp>
# include <boost/type_traits/is_enum.hpp>
# include <simgear/debug/logstream.hxx>
# include <simgear/math/SGMathFwd.hxx>
# include <simgear/math/sg_types.hxx>
#endif
#include <simgear/structure/SGReferenced.hxx>
#include <simgear/structure/SGSharedPtr.hxx>
// XXX This whole file should be in the simgear namespace, but I don't
// have the guts yet...
using namespace std;
namespace simgear
{
class PropertyInterpolationMgr;
template<typename T>
std::istream& readFrom(std::istream& stream, T& result)
{
stream >> result;
return stream;
}
/**
* Parse a string as an object of a given type.
* XXX no error behavior yet.
*
* @tparam T the return type
* @param str the string
* @return the object.
*/
template<typename T>
inline T parseString(const std::string& str)
{
std::istringstream stream(str);
T result;
readFrom(stream, result);
return result;
}
/**
* Property value types.
*/
#ifdef NONE
#pragma warn A sloppy coder has defined NONE as a macro!
#undef NONE
#endif
#ifdef ALIAS
#pragma warn A sloppy coder has defined ALIAS as a macro!
#undef ALIAS
#endif
#ifdef UNSPECIFIED
#pragma warn A sloppy coder has defined UNSPECIFIED as a macro!
#undef UNSPECIFIED
#endif
#ifdef BOOL
#pragma warn A sloppy coder has defined BOOL as a macro!
#undef BOOL
#endif
#ifdef INT
#pragma warn A sloppy coder has defined INT as a macro!
#undef INT
#endif
#ifdef LONG
#pragma warn A sloppy coder has defined LONG as a macro!
#undef LONG
#endif
#ifdef FLOAT
#pragma warn A sloppy coder has defined FLOAT as a macro!
#undef FLOAT
#endif
#ifdef DOUBLE
#pragma warn A sloppy coder has defined DOUBLE as a macro!
#undef DOUBLE
#endif
#ifdef STRING
#pragma warn A sloppy coder has defined STRING as a macro!
#undef STRING
#endif
namespace props
{
/**
* The possible types of an SGPropertyNode. Types that appear after
* EXTENDED are not stored in the SGPropertyNode itself.
*/
enum Type {
NONE = 0, /**< The node hasn't been assigned a value yet. */
ALIAS, /**< The node "points" to another node. */
BOOL,
INT,
LONG,
FLOAT,
DOUBLE,
STRING,
UNSPECIFIED,
EXTENDED, /**< The node's value is not stored in the property;
* the actual value and type is retrieved from an
* SGRawValue node. This type is never returned by @see
* SGPropertyNode::getType.
*/
// Extended properties
VEC3D,
VEC4D
};
template<typename T> struct PropertyTraits;
#define DEFINTERNALPROP(TYPE, PROP) \
template<> \
struct PropertyTraits<TYPE> \
{ \
static const Type type_tag = PROP; \
enum { Internal = 1 }; \
}
DEFINTERNALPROP(bool, BOOL);
DEFINTERNALPROP(int, INT);
DEFINTERNALPROP(long, LONG);
DEFINTERNALPROP(float, FLOAT);
DEFINTERNALPROP(double, DOUBLE);
DEFINTERNALPROP(const char *, STRING);
DEFINTERNALPROP(const char[], STRING);
#undef DEFINTERNALPROP
}
}
////////////////////////////////////////////////////////////////////////
// A raw value.
//
// This is the mechanism that information-providing routines can
// use to link their own values to the property manager. Any
// SGValue can be tied to a raw value and then untied again.
//
// Note: we are forced to use inlined methods here to ensure
// that the templates will be instantiated. We're probably taking
// a small performance hit for that.
////////////////////////////////////////////////////////////////////////
/**
* Base class for SGRawValue classes that holds no type
* information. This allows some generic manipulation of the
* SGRawValue object.
*/
class SGRaw
{
public:
/**
* Get the type enumeration for the raw value.
*
* @return the type.
*/
virtual simgear::props::Type getType() const = 0;
virtual ~SGRaw() {}
/**
* Create a new deep copy of this raw value.
*
* The copy will contain its own version of the underlying value
* as well, and will be the same type.
*
* @return A deep copy of the current object.
*/
virtual SGRaw* clone() const = 0;
};
class SGRawExtended : public SGRaw
{
public:
/**
* Make an SGRawValueContainer from the SGRawValue.
*
* This is a virtual function of SGRawExtended so that
* SGPropertyNode::untie doesn't need to know the type of an
* extended property.
*/
virtual SGRawExtended* makeContainer() const = 0;
/**
* Write value out to a stream
*/
virtual std::ostream& printOn(std::ostream& stream) const = 0;
/**
* Read value from a stream and store it.
*/
virtual std::istream& readFrom(std::istream& stream) = 0;
};
// Choose between different base classes based on whether the value is
// stored internal to the property node. This frees us from defining
// the virtual functions in the SGRawExtended interface where they
// don't make sense, e.g. readFrom for the const char* type.
template<typename T, int internal = simgear::props::PropertyTraits<T>::Internal>
class SGRawBase;
template<typename T>
class SGRawBase<T, 1> : public SGRaw
{
};
template<typename T>
class SGRawBase<T, 0> : public SGRawExtended
{
virtual SGRawExtended* makeContainer() const;
virtual std::ostream& printOn(std::ostream& stream) const;
virtual std::istream& readFrom(std::istream& stream);
};
/**
* Abstract base class for a raw value.
*
* The property manager is implemented in two layers. The SGPropertyNode is the
* highest and most abstract layer, representing an LValue/RValue pair: it
* records the position of the property in the property tree and contains
* facilities for navigation to other nodes. It is guaranteed to be persistent:
* the SGPropertyNode will not change during a session, even if the property is
* bound and unbound multiple times.
*
* When the property value is not managed internally in the
* SGPropertyNode, the SGPropertyNode will contain a reference to an
* SGRawValue (this class), which provides an abstract way to get,
* set, and clone the underlying value. The SGRawValue may change
* frequently during a session as a value is retyped or bound and
* unbound to various data source, but the abstract SGPropertyNode
* layer insulates the application from those changes.
*
* The SGPropertyNode class always keeps a *copy* of a raw value, not the
* original one passed to it; if you override a derived class but do not replace
* the {@link SGRaw::clone clone()} method, strange things will happen.
*
* All derived SGRawValue classes must implement getValue(), setValue(), and
* {@link SGRaw::clone clone()} for the appropriate type.
*
* @see SGPropertyNode
* @see SGRawValuePointer
* @see SGRawValueFunctions
* @see SGRawValueFunctionsIndexed
* @see SGRawValueMethods
* @see SGRawValueMethodsIndexed
* @see SGRawValueContainer
*/
template <class T>
class SGRawValue : public SGRawBase<T>
{
public:
/**
* The default underlying value for this type.
*
* Every raw value has a default; the default is false for a
* boolean, 0 for the various numeric values, and "" for a string.
* If additional types of raw values are added in the future, they
* may need different kinds of default values (such as epoch for a
* date type). The default value is used when creating new values.
*/
static T DefaultValue()
{
return T();
}
/**
* Constructor.
*
* Use the default value for this type.
*/
SGRawValue () {}
/**
* Destructor.
*/
virtual ~SGRawValue () {}
/**
* Return the underlying value.
*
* @return The actual value for the property.
* @see #setValue
*/
virtual T getValue () const = 0;
/**
* Assign a new underlying value.
*
* If the new value cannot be set (because this is a read-only
* raw value, or because the new value is not acceptable for
* some reason) this method returns false and leaves the original
* value unchanged.
*
* @param value The actual value for the property.
* @return true if the value was set successfully, false otherwise.
* @see #getValue
*/
virtual bool setValue (T value) = 0;
/**
* Return the type tag for this raw value type.
*/
virtual simgear::props::Type getType() const
{
return simgear::props::PropertyTraits<T>::type_tag;
}
};
////////////////////////////////////////////////////////////////////////
// Default values for every type.
////////////////////////////////////////////////////////////////////////
template<> inline bool SGRawValue<bool>::DefaultValue()
{
return false;
}
template<> inline const char * SGRawValue<const char *>::DefaultValue()
{
return "";
}
/**
* A raw value bound to a pointer.
*
* This is the most efficient way to tie an external value, but also
* the most dangerous, because there is no way for the supplier to
* perform bounds checking and derived calculations except by polling
* the variable to see if it has changed. There is no default
* constructor, because this class would be meaningless without a
* pointer.
*/
template <class T>
class SGRawValuePointer : public SGRawValue<T>
{
public:
/**
* Explicit pointer constructor.
*
* Create a new raw value bound to the value of the variable
* referenced by the pointer.
*
* @param ptr The pointer to the variable to which this raw value
* will be bound.
*/
SGRawValuePointer (T * ptr) : _ptr(ptr) {}
/**
* Destructor.
*/
virtual ~SGRawValuePointer () {}
/**
* Get the underlying value.
*
* This method will dereference the pointer and return the
* variable's value.
*/
virtual T getValue () const { return *_ptr; }
/**
* Set the underlying value.
*
* This method will dereference the pointer and change the
* variable's value.
*/
virtual bool setValue (T value) { *_ptr = value; return true; }
/**
* Create a copy of this raw value.
*
* The copy will use the same external pointer as the original.
*/
virtual SGRaw* clone () const {
return new SGRawValuePointer(_ptr);
}
private:
T * _ptr;
};
/**
* A value managed through static functions.
*
* A read-only value will not have a setter; a write-only value will
* not have a getter.
*/
template <class T>
class SGRawValueFunctions : public SGRawValue<T>
{
public:
/**
* The template type of a static getter function.
*/
typedef T (*getter_t)();
/**
* The template type of a static setter function.
*/
typedef void (*setter_t)(T);
/**
* Explicit constructor.
*
* Create a new raw value bound to the getter and setter supplied.
*
* @param getter A static function for getting a value, or 0
* to read-disable the value.
* @param setter A static function for setting a value, or 0
* to write-disable the value.
*/
SGRawValueFunctions (getter_t getter = 0, setter_t setter = 0)
: _getter(getter), _setter(setter) {}
/**
* Destructor.
*/
virtual ~SGRawValueFunctions () {}
/**
* Get the underlying value.
*
* This method will invoke the getter function to get a value.
* If no getter function was supplied, this method will always
* return the default value for the type.
*/
virtual T getValue () const {
if (_getter) return (*_getter)();
else return SGRawValue<T>::DefaultValue();
}
/**
* Set the underlying value.
*
* This method will invoke the setter function to change the
* underlying value. If no setter function was supplied, this
* method will return false.
*/
virtual bool setValue (T value) {
if (_setter) { (*_setter)(value); return true; }
else return false;
}
/**
* Create a copy of this raw value, bound to the same functions.
*/
virtual SGRaw* clone () const {
return new SGRawValueFunctions(_getter,_setter);
}
private:
getter_t _getter;
setter_t _setter;
};
/**
* An indexed value bound to static functions.
*
* A read-only value will not have a setter; a write-only value will
* not have a getter. An indexed value is useful for binding one
* of a list of possible values (such as multiple engines for a
* plane). The index is hard-coded at creation time.
*
* @see SGRawValue
*/
template <class T>
class SGRawValueFunctionsIndexed : public SGRawValue<T>
{
public:
typedef T (*getter_t)(int);
typedef void (*setter_t)(int,T);
SGRawValueFunctionsIndexed (int index, getter_t getter = 0, setter_t setter = 0)
: _index(index), _getter(getter), _setter(setter) {}
virtual ~SGRawValueFunctionsIndexed () {}
virtual T getValue () const {
if (_getter) return (*_getter)(_index);
else return SGRawValue<T>::DefaultValue();
}
virtual bool setValue (T value) {
if (_setter) { (*_setter)(_index, value); return true; }
else return false;
}
virtual SGRaw* clone () const {
return new SGRawValueFunctionsIndexed(_index, _getter, _setter);
}
private:
int _index;
getter_t _getter;
setter_t _setter;
};
/**
* A value managed through an object and access methods.
*
* A read-only value will not have a setter; a write-only value will
* not have a getter.
*/
template <class C, class T>
class SGRawValueMethods : public SGRawValue<T>
{
public:
typedef T (C::*getter_t)() const;
typedef void (C::*setter_t)(T);
SGRawValueMethods (C &obj, getter_t getter = 0, setter_t setter = 0)
: _obj(obj), _getter(getter), _setter(setter) {}
virtual ~SGRawValueMethods () {}
virtual T getValue () const {
if (_getter) { return (_obj.*_getter)(); }
else { return SGRawValue<T>::DefaultValue(); }
}
virtual bool setValue (T value) {
if (_setter) { (_obj.*_setter)(value); return true; }
else return false;
}
virtual SGRaw* clone () const {
return new SGRawValueMethods(_obj, _getter, _setter);
}
private:
C &_obj;
getter_t _getter;
setter_t _setter;
};
/**
* An indexed value managed through an object and access methods.
*
* A read-only value will not have a setter; a write-only value will
* not have a getter.
*/
template <class C, class T>
class SGRawValueMethodsIndexed : public SGRawValue<T>
{
public:
typedef T (C::*getter_t)(int) const;
typedef void (C::*setter_t)(int, T);
SGRawValueMethodsIndexed (C &obj, int index,
getter_t getter = 0, setter_t setter = 0)
: _obj(obj), _index(index), _getter(getter), _setter(setter) {}
virtual ~SGRawValueMethodsIndexed () {}
virtual T getValue () const {
if (_getter) { return (_obj.*_getter)(_index); }
else { return SGRawValue<T>::DefaultValue(); }
}
virtual bool setValue (T value) {
if (_setter) { (_obj.*_setter)(_index, value); return true; }
else return false;
}
virtual SGRaw* clone () const {
return new SGRawValueMethodsIndexed(_obj, _index, _getter, _setter);
}
private:
C &_obj;
int _index;
getter_t _getter;
setter_t _setter;
};
/**
* A raw value that contains its value. This provides a way for
* property nodes to contain values that shouldn't be stored in the
* property node itself.
*/
template <class T>
class SGRawValueContainer : public SGRawValue<T>
{
public:
/**
* Explicit constructor.
*/
SGRawValueContainer(const T& obj) : _obj(obj) {}
/**
* Destructor.
*/
virtual ~SGRawValueContainer() {}
/**
* Get the underlying value.
*/
virtual T getValue() const { return _obj; }
/**
* Set the underlying value.
*
* This method will dereference the pointer and change the
* variable's value.
*/
virtual bool setValue (T value) { _obj = value; return true; }
/**
* Create a copy of this raw value.
*/
virtual SGRaw* clone () const {
return new SGRawValueContainer(_obj);
}
private:
T _obj;
};
template<typename T>
SGRawExtended* SGRawBase<T, 0>::makeContainer() const
{
return new SGRawValueContainer<T>(static_cast<const SGRawValue<T>*>(this)
->getValue());
}
template<typename T>
std::ostream& SGRawBase<T, 0>::printOn(std::ostream& stream) const
{
return stream << static_cast<SGRawValue<T>*>(this)->getValue();
}
template<typename T>
std::istream& SGRawBase<T, 0>::readFrom(std::istream& stream)
{
T value;
simgear::readFrom(stream, value);
static_cast<SGRawValue<T>*>(this)->setValue(value);
return stream;
}
/**
* The smart pointer that manage reference counting
*/
class SGPropertyNode;
typedef SGSharedPtr<SGPropertyNode> SGPropertyNode_ptr;
typedef SGSharedPtr<const SGPropertyNode> SGConstPropertyNode_ptr;
namespace simgear
{
typedef std::vector<SGPropertyNode_ptr> PropertyList;
}
/**
* The property change listener interface.
*
* <p>Any class that needs to listen for property changes must implement
* this interface.</p>
*/
class SGPropertyChangeListener
{
public:
virtual ~SGPropertyChangeListener ();
/// Called if value of \a node has changed.
virtual void valueChanged(SGPropertyNode * node);
/// Called if \a child has been added to the given \a parent.
virtual void childAdded(SGPropertyNode * parent, SGPropertyNode * child);
/// Called if \a child has been removed from its \a parent.
virtual void childRemoved(SGPropertyNode * parent, SGPropertyNode * child);
protected:
friend class SGPropertyNode;
virtual void register_property (SGPropertyNode * node);
virtual void unregister_property (SGPropertyNode * node);
private:
std::vector<SGPropertyNode *> _properties;
};
/**
* A node in a property tree.
*/
class JSBSIM_API SGPropertyNode : public SGReferenced
{
public:
/**
* Public constants.
*/
enum {
MAX_STRING_LEN = 1024
};
/**
* Access mode attributes.
*
* <p>The ARCHIVE attribute is strictly advisory, and controls
* whether the property should normally be saved and restored.</p>
*/
enum Attribute {
NO_ATTR = 0,
READ = 1,
WRITE = 2,
ARCHIVE = 4,
REMOVED = 8,
TRACE_READ = 16,
TRACE_WRITE = 32,
USERARCHIVE = 64,
PRESERVE = 128
// beware: if you add another attribute here,
// also update value of "LAST_USED_ATTRIBUTE".
};
/**
* Last used attribute
* Update as needed when enum Attribute is changed
*/
static const int LAST_USED_ATTRIBUTE;
/**
* Default constructor.
*/
SGPropertyNode ();
/**
* Copy constructor.
*/
SGPropertyNode (const SGPropertyNode &node);
/**
* Destructor.
*/
virtual ~SGPropertyNode ();
//
// Basic properties.
//
/**
* Test whether this node contains a primitive leaf value.
*/
bool hasValue () const { return (_type != simgear::props::NONE); }
/**
* Get the node's simple name as a string.
*/
const std::string& getNameString () const { return _name; }
/**
* Get the node's pretty display name, with subscript when needed.
*/
std::string getDisplayName (bool simplify = false) const;
/**
* Get the node's integer index.
*/
int getIndex () const { return _index; }
/**
* Get a non-const pointer to the node's parent.
*/
SGPropertyNode * getParent () { return _parent; }
/**
* Get a const pointer to the node's parent.
*/
const SGPropertyNode * getParent () const { return _parent; }
//
// Children.
//
/**
* Get the number of child nodes.
*/
int nChildren () const { return (int)_children.size(); }
/**
* Get a child node by position (*NOT* index).
*/
SGPropertyNode * getChild (int position);
/**
* Get a const child node by position (*NOT* index).
*/
const SGPropertyNode * getChild (int position) const;
/**
* Test whether a named child exists.
*/
bool hasChild (const char * name, int index = 0) const
{
return (getChild(name, index) != 0);
}
/**
* Test whether a named child exists.
*/
bool hasChild (const std::string& name, int index = 0) const
{
return (getChild(name, index) != 0);
}
/**
* Create a new child node with the given name and an unused index
*
* @param min_index Minimal index for new node (skips lower indices)
* @param append Whether to simply use the index after the last used index
* or use a lower, unused index if it exists
*/
SGPropertyNode * addChild ( const char* name,
int min_index = 0,
bool append = true );
SGPropertyNode * addChild ( const std::string& name,
int min_index = 0,
bool append = true )
{ return addChild(name.c_str(), min_index, append); }
/**
* Create multiple child nodes with the given name an unused indices
*
* @param count The number of nodes create
* @param min_index Minimal index for new nodes (skips lower indices)
* @param append Whether to simply use the index after the last used index
* or use a lower, unused index if it exists
*/
simgear::PropertyList addChildren ( const std::string& name,
size_t count,
int min_index = 0,
bool append = true );
/**
* Get a child node by name and index.
*/
SGPropertyNode * getChild (const char* name, int index = 0,
bool create = false);
SGPropertyNode * getChild (const std::string& name, int index = 0,
bool create = false);
/**
* Get a const child node by name and index.
*/
const SGPropertyNode * getChild (const char * name, int index = 0) const;
/**
* Get a const child node by name and index.
*/
const SGPropertyNode * getChild (const std::string& name, int index = 0) const
{ return getChild(name.c_str(), index); }
/**
* Get a vector of all children with the specified name.
*/
simgear::PropertyList getChildren (const char * name) const;
/**
* Get a vector of all children with the specified name.
*/
simgear::PropertyList getChildren (const std::string& name) const
{ return getChildren(name.c_str()); }
/**
* Remove child by pointer (if it is a child of this node).
*
* @return true, if the node was deleted.
*/
bool removeChild(SGPropertyNode* node);
// TODO do we need the removeXXX methods to return the deleted nodes?
/**
* Remove child by position.
*/
SGPropertyNode_ptr removeChild(int pos);
/**
* Remove a child node
*/
SGPropertyNode_ptr removeChild(const char * name, int index = 0);
/**
* Remove a child node
*/
SGPropertyNode_ptr removeChild(const std::string& name, int index = 0)
{ return removeChild(name.c_str(), index); }
/**
* Remove all children with the specified name.
*/
simgear::PropertyList removeChildren(const char * name);
/**
* Remove all children with the specified name.
*/
simgear::PropertyList removeChildren(const std::string& name)
{ return removeChildren(name.c_str()); }
/**
* Remove all children (does not change the value of the node)
*/
void removeAllChildren();
//
// Alias support.
//
/**
* Alias this node's leaf value to another's.
*/
bool alias (SGPropertyNode * target);
/**
* Alias this node's leaf value to another's by relative path.