]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGPropertyManager.cpp
putting back the pilot-g used by accel.xml gadget
[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/props/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 namespace JSBSim {
51
52 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
53
54 string FGPropertyManager::mkPropertyName(string name, bool lowercase) {
55   
56   /* do this two pass to avoid problems with characters getting skipped
57      because the index changed */
58   unsigned i;
59   for(i=0;i<name.length();i++) {
60     if( lowercase && isupper(name[i]) )
61       name[i]=tolower(name[i]);
62     else if( isspace(name[i]) ) 
63       name[i]='-';
64   }
65   for(i=0;i<name.length();i++) {
66     if( name[i] == '/' )
67       name.erase(i,1);  
68   }
69
70   return name;
71 }
72
73 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
74
75 FGPropertyManager*  
76 FGPropertyManager::GetNode (const string &path, bool create)
77 {
78   SGPropertyNode* node=this->getNode(path.c_str(), create);
79   if(node == 0) 
80     cout << "FGPropertyManager::GetNode() No node found for " 
81          << path << endl;
82   return (FGPropertyManager*)node;
83 }
84
85 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
86
87 FGPropertyManager* 
88 FGPropertyManager::GetNode (const string &relpath, int index, bool create)
89 {
90     return (FGPropertyManager*)getNode(relpath.c_str(),index,create);
91 }    
92
93 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
94
95
96 bool FGPropertyManager::HasNode (const string &path)
97 {
98   return (GetNode(path, false) != 0);
99 }
100
101 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
102
103 string FGPropertyManager::GetName( void ) {
104   return string( getName() );
105 }  
106
107 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
108
109 string FGPropertyManager::GetFullyQualifiedName(void) {
110     vector<string> stack;
111     stack.push_back( getDisplayName(true) );
112     SGPropertyNode* tmpn=getParent();
113     bool atroot=false;
114     while( !atroot ) {
115      stack.push_back( tmpn->getDisplayName(true) );
116      if( !tmpn->getParent() ) 
117       atroot=true;
118      else 
119       tmpn=tmpn->getParent();
120     }
121     
122     string fqname="";
123     for(unsigned i=stack.size()-1;i>0;i--) {
124       fqname+= stack[i];
125       fqname+= "/";
126     }
127     fqname+= stack[0];
128     return fqname;  
129        
130 }    
131     
132     
133 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
134
135 bool FGPropertyManager::GetBool (const string &name, bool defaultValue)
136 {
137   return getBoolValue(name.c_str(), defaultValue);
138 }
139
140 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
141
142 int FGPropertyManager::GetInt (const string &name, int defaultValue )
143 {
144   return getIntValue(name.c_str(), defaultValue);
145 }
146
147 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
148
149 int FGPropertyManager::GetLong (const string &name, long defaultValue )
150 {
151   return getLongValue(name.c_str(), defaultValue);
152 }
153
154 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
155
156 float FGPropertyManager::GetFloat (const string &name, float defaultValue )
157 {
158   return getFloatValue(name.c_str(), defaultValue);
159 }
160
161 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
162
163 double FGPropertyManager::GetDouble (const string &name, double defaultValue )
164 {
165   return getDoubleValue(name.c_str(), defaultValue);
166 }
167
168 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
169
170 string FGPropertyManager::GetString (const string &name, string defaultValue )
171 {
172   return string(getStringValue(name.c_str(), defaultValue.c_str()));
173 }
174
175 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
176
177 bool FGPropertyManager::SetBool (const string &name, bool val)
178 {
179   return setBoolValue(name.c_str(), val);
180 }
181
182 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
183
184 bool FGPropertyManager::SetInt (const string &name, int val)
185 {
186   return setIntValue(name.c_str(), val);
187 }
188
189 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
190
191 bool FGPropertyManager::SetLong (const string &name, long val)
192 {
193   return setLongValue(name.c_str(), val);
194 }
195
196 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
197
198 bool FGPropertyManager::SetFloat (const string &name, float val)
199 {
200   return setFloatValue(name.c_str(), val);
201 }
202
203 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
204
205 bool FGPropertyManager::SetDouble (const string &name, double val)
206 {
207   return setDoubleValue(name.c_str(), val);
208 }
209
210 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
211
212 bool FGPropertyManager::SetString (const string &name, const string &val)
213 {
214   return setStringValue(name.c_str(), val.c_str());
215 }
216
217 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
218
219 void FGPropertyManager::SetArchivable (const string &name, bool state )
220 {
221   SGPropertyNode * node = getNode(name.c_str());
222   if (node == 0)
223     cout <<
224            "Attempt to set archive flag for non-existant property "
225            << name << endl;
226   else
227     node->setAttribute(SGPropertyNode::ARCHIVE, state);
228 }
229
230 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
231
232 void FGPropertyManager::SetReadable (const string &name, bool state )
233 {
234   SGPropertyNode * node = getNode(name.c_str());
235   if (node == 0)
236     cout <<
237            "Attempt to set read flag for non-existant property "
238            << name << endl;
239   else
240     node->setAttribute(SGPropertyNode::READ, state);
241 }
242
243 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
244
245 void FGPropertyManager::SetWritable (const string &name, bool state )
246 {
247   SGPropertyNode * node = getNode(name.c_str());
248   if (node == 0)
249     cout <<
250            "Attempt to set write flag for non-existant property "
251            << name << endl;
252   else
253     node->setAttribute(SGPropertyNode::WRITE, state);
254 }
255
256 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
257
258 void FGPropertyManager::Untie (const string &name)
259 {
260   if (!untie(name.c_str()))
261     cout << "Failed to untie property " << name << endl;
262 }
263
264 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
265
266 void FGPropertyManager::Tie (const string &name, bool *pointer, bool useDefault)
267 {
268   if (!tie(name.c_str(), SGRawValuePointer<bool>(pointer),
269                                  useDefault))
270     cout <<
271            "Failed to tie property " << name << " to a pointer" << endl;
272 }
273
274 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
275
276 void FGPropertyManager::Tie (const string &name, int *pointer, 
277                                           bool useDefault )
278 {
279   if (!tie(name.c_str(), SGRawValuePointer<int>(pointer),
280                                  useDefault))
281     cout <<
282            "Failed to tie property " << name << " to a pointer" << endl;
283 }
284
285 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
286
287 void FGPropertyManager::Tie (const string &name, long *pointer, 
288                                           bool useDefault )
289 {
290   if (!tie(name.c_str(), SGRawValuePointer<long>(pointer),
291                                  useDefault))
292     cout <<
293            "Failed to tie property " << name << " to a pointer" << endl;
294 }
295
296 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
297
298 void FGPropertyManager::Tie (const string &name, float *pointer, 
299                                           bool useDefault )
300 {
301   if (!tie(name.c_str(), SGRawValuePointer<float>(pointer),
302                                  useDefault))
303     cout <<
304            "Failed to tie property " << name << " to a pointer" << endl;
305 }
306
307 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
308
309 void FGPropertyManager::Tie (const string &name, double *pointer, 
310                                            bool useDefault)
311 {
312   if (!tie(name.c_str(), SGRawValuePointer<double>(pointer),
313                                  useDefault))
314     cout <<
315            "Failed to tie property " << name << " to a pointer" << endl;
316 }
317
318 } // namespace JSBSim