]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGPropertyManager.cpp
JSBSim updates. This update changes the file format, so an update of the base
[flightgear.git] / src / FDM / JSBSim / FGPropertyManager.cpp
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2  
3  Header:       FGPropertyManager.cpp
4  Author:       Tony Peden
5                Based on work originally by David Megginson
6  Date:         2/2002
7  
8  ------------- Copyright (C) 2002 -------------
9  
10  This program is free software; you can redistribute it and/or modify it under
11  the terms of the GNU General Public License as published by the Free Software
12  Foundation; either version 2 of the License, or (at your option) any later
13  version.
14  
15  This program is distributed in the hope that it will be useful, but WITHOUT
16  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17  FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
18  details.
19  
20  You should have received a copy of the GNU General Public License along with
21  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
22  Place - Suite 330, Boston, MA  02111-1307, USA.
23
24  Further information about the GNU General Public License can also be found on
25  the world wide web at http://www.gnu.org.
26
27 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
28 INCLUDES
29 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
30
31 #include <simgear/misc/props.hxx>
32 #include "FGPropertyManager.h"
33
34 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35 DEFINITIONS
36 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
37
38
39 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
40 FORWARD DECLARATIONS
41 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
42
43 using namespace std;
44
45 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
46 COMMENTS, REFERENCES, and NOTES [use "class documentation" below for API docs]
47 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
48 */
49
50 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
51
52 string FGPropertyManager::mkPropertyName(string name, bool lowercase) {
53   
54   /* do this two pass to avoid problems with characters getting skipped
55      because the index changed */
56
57   for(unsigned i=0;i<name.length();i++) {
58     if( lowercase && isupper(name[i]) )
59       name[i]=tolower(name[i]);
60     else if( isspace(name[i]) ) 
61       name[i]='-';
62   }
63   for(unsigned i=0;i<name.length();i++) {
64     if( name[i] == '/' )
65       name.erase(i,1);  
66   }
67
68   return name;
69 }
70
71 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
72
73 FGPropertyManager*  
74 FGPropertyManager::GetNode (const string &path, bool create)
75 {
76   SGPropertyNode* node=this->getNode(path.c_str(), create);
77   if(node == 0) 
78     cout << "FGPropertyManager::GetNode() No node found for " 
79          << path << endl;
80   return (FGPropertyManager*)node;
81 }
82
83 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
84
85 FGPropertyManager* 
86 FGPropertyManager::GetNode (const string &relpath, int index, bool create)
87 {
88     return (FGPropertyManager*)getNode(relpath.c_str(),index,create);
89 }    
90
91 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
92
93
94 bool FGPropertyManager::HasNode (const string &path)
95 {
96   return (GetNode(path, false) != 0);
97 }
98
99 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
100
101 string FGPropertyManager::GetName( void ) {
102   return string( getName() );
103 }  
104
105 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
106
107 bool FGPropertyManager::GetBool (const string &name, bool defaultValue)
108 {
109   return getBoolValue(name.c_str(), defaultValue);
110 }
111
112 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
113
114 int FGPropertyManager::GetInt (const string &name, int defaultValue )
115 {
116   return getIntValue(name.c_str(), defaultValue);
117 }
118
119 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
120
121 int FGPropertyManager::GetLong (const string &name, long defaultValue )
122 {
123   return getLongValue(name.c_str(), defaultValue);
124 }
125
126 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
127
128 float FGPropertyManager::GetFloat (const string &name, float defaultValue )
129 {
130   return getFloatValue(name.c_str(), defaultValue);
131 }
132
133 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
134
135 double FGPropertyManager::GetDouble (const string &name, double defaultValue )
136 {
137   return getDoubleValue(name.c_str(), defaultValue);
138 }
139
140 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
141
142 string FGPropertyManager::GetString (const string &name, string defaultValue )
143 {
144   return string(getStringValue(name.c_str(), defaultValue.c_str()));
145 }
146
147 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
148
149 bool FGPropertyManager::SetBool (const string &name, bool val)
150 {
151   return setBoolValue(name.c_str(), val);
152 }
153
154 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
155
156 bool FGPropertyManager::SetInt (const string &name, int val)
157 {
158   return setIntValue(name.c_str(), val);
159 }
160
161 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
162
163 bool FGPropertyManager::SetLong (const string &name, long val)
164 {
165   return setLongValue(name.c_str(), val);
166 }
167
168 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
169
170 bool FGPropertyManager::SetFloat (const string &name, float val)
171 {
172   return setFloatValue(name.c_str(), val);
173 }
174
175 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
176
177 bool FGPropertyManager::SetDouble (const string &name, double val)
178 {
179   return setDoubleValue(name.c_str(), val);
180 }
181
182 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
183
184 bool FGPropertyManager::SetString (const string &name, const string &val)
185 {
186   return setStringValue(name.c_str(), val.c_str());
187 }
188
189 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
190
191 void FGPropertyManager::SetArchivable (const string &name, bool state )
192 {
193   SGPropertyNode * node = getNode(name.c_str());
194   if (node == 0)
195     cout <<
196            "Attempt to set archive flag for non-existant property "
197            << name << endl;
198   else
199     node->setAttribute(SGPropertyNode::ARCHIVE, state);
200 }
201
202 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
203
204 void FGPropertyManager::SetReadable (const string &name, bool state )
205 {
206   SGPropertyNode * node = getNode(name.c_str());
207   if (node == 0)
208     cout <<
209            "Attempt to set read flag for non-existant property "
210            << name << endl;
211   else
212     node->setAttribute(SGPropertyNode::READ, state);
213 }
214
215 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
216
217 void FGPropertyManager::SetWritable (const string &name, bool state )
218 {
219   SGPropertyNode * node = getNode(name.c_str());
220   if (node == 0)
221     cout <<
222            "Attempt to set write flag for non-existant property "
223            << name << endl;
224   else
225     node->setAttribute(SGPropertyNode::WRITE, state);
226 }
227
228 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
229
230 void FGPropertyManager::Untie (const string &name)
231 {
232   if (!untie(name.c_str()))
233     cout << "Failed to untie property " << name << endl;
234 }
235
236 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
237
238 void FGPropertyManager::Tie (const string &name, bool *pointer, bool useDefault)
239 {
240   if (!tie(name.c_str(), SGRawValuePointer<bool>(pointer),
241                                  useDefault))
242     cout <<
243            "Failed to tie property " << name << " to a pointer" << endl;
244 }
245
246 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
247
248 void FGPropertyManager::Tie (const string &name, int *pointer, 
249                                           bool useDefault )
250 {
251   if (!tie(name.c_str(), SGRawValuePointer<int>(pointer),
252                                  useDefault))
253     cout <<
254            "Failed to tie property " << name << " to a pointer" << endl;
255 }
256
257 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
258
259 void FGPropertyManager::Tie (const string &name, long *pointer, 
260                                           bool useDefault )
261 {
262   if (!tie(name.c_str(), SGRawValuePointer<long>(pointer),
263                                  useDefault))
264     cout <<
265            "Failed to tie property " << name << " to a pointer" << endl;
266 }
267
268 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
269
270 void FGPropertyManager::Tie (const string &name, float *pointer, 
271                                           bool useDefault )
272 {
273   if (!tie(name.c_str(), SGRawValuePointer<float>(pointer),
274                                  useDefault))
275     cout <<
276            "Failed to tie property " << name << " to a pointer" << endl;
277 }
278
279 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
280
281 void FGPropertyManager::Tie (const string &name, double *pointer, 
282                                            bool useDefault)
283 {
284   if (!tie(name.c_str(), SGRawValuePointer<double>(pointer),
285                                  useDefault))
286     cout <<
287            "Failed to tie property " << name << " to a pointer" << endl;
288 }