]> git.mxchange.org Git - simgear.git/blob - simgear/props/propertyObject.cxx
ff90ce77afdd3701630020ee39ad712a7643cf75
[simgear.git] / simgear / props / propertyObject.cxx
1 // Copyright (C) 2010  James Turner - zakalawe@mac.com
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Library General Public
5 // License as published by the Free Software Foundation; either
6 // version 2 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Library General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with this program; if not, write to the Free Software
15 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
16 //
17
18 #ifdef HAVE_CONFIG_H
19 #  include "simgear_config.h"
20 #endif
21
22 #include "propertyObject.hxx"
23
24 namespace simgear
25 {
26
27 SGPropertyNode* static_defaultRoot = NULL;
28
29 void PropertyObjectBase::setDefaultRoot(SGPropertyNode* aRoot)
30 {
31   static_defaultRoot = aRoot;
32 }
33
34 PropertyObjectBase::PropertyObjectBase(const char* aChild) :
35   _base(NULL),
36   _path(aChild),
37   _prop(NULL)
38 {
39 }
40   
41 PropertyObjectBase::PropertyObjectBase(SGPropertyNode* aNode, const char* aChild) :
42   _base(aNode),
43   _path(aChild),
44   _prop(NULL)
45 {
46
47 }
48   
49 SGPropertyNode* PropertyObjectBase::node(bool aCreate) const
50 {
51   if (_prop) {
52     return _prop;
53   }
54   
55   _prop = _base ? _base : static_defaultRoot;
56   if (_path) {
57     _prop = _prop->getNode(_path, aCreate);
58   }
59   
60   return _prop;
61 }
62
63 } // of namespace simgear
64
65 void test()
66 {
67   SGPropObjDouble foo("/bar/foo");
68
69   SGPropertyNode* zoob;
70
71   SGPropObjDouble foo2 = SGPropObjDouble::create(zoob, "foo2", 42.0);
72   
73   foo = 1123.0;
74   foo2 =  43;
75   
76   std::string s("lalala");
77   
78   foo = "lalal";
79   
80   
81   SGPropObjString sp(zoob);
82   sp = "fooo";
83   s =  sp;
84   
85
86   SGPropObjBool bp("/some nice big path");
87   bp = false;
88   
89   bp = 456;
90   int i5 = bp;
91 }