]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/input_output/FGPropertyManager.cpp
remove unused files
[flightgear.git] / src / FDM / JSBSim / input_output / 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 Lesser 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 Lesser General Public License for more
18  details.
19
20  You should have received a copy of the GNU Lesser 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 Lesser 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 "FGPropertyManager.h"
32
33 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
34 DEFINITIONS
35 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
36
37
38 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
39 FORWARD DECLARATIONS
40 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
41
42 using namespace std;
43
44 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
45 COMMENTS, REFERENCES, and NOTES [use "class documentation" below for API docs]
46 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
47 */
48
49 namespace JSBSim {
50
51 bool FGPropertyManager::suppress_warning = true;
52 std::vector<SGPropertyNode_ptr> FGPropertyManager::tied_properties;
53
54 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
55
56 void FGPropertyManager::Unbind(void)
57 {
58     vector<SGPropertyNode_ptr>::iterator it;
59
60     for (it = tied_properties.begin();it < tied_properties.end();it++)
61         (*it)->untie();
62
63     tied_properties.clear();
64 }
65
66 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
67
68 string FGPropertyManager::mkPropertyName(string name, bool lowercase) {
69
70   /* do this two pass to avoid problems with characters getting skipped
71      because the index changed */
72   unsigned i;
73   for(i=0;i<name.length();i++) {
74     if( lowercase && isupper(name[i]) )
75       name[i]=tolower(name[i]);
76     else if( isspace(name[i]) )
77       name[i]='-';
78   }
79   
80   return name;
81 }
82
83 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
84
85 FGPropertyManager*
86 FGPropertyManager::GetNode (const string &path, bool create)
87 {
88   SGPropertyNode* node=this->getNode(path.c_str(), create);
89   if (node == 0 && !suppress_warning) {
90     cerr << "FGPropertyManager::GetNode() No node found for " << path << endl;
91   }
92   return (FGPropertyManager*)node;
93 }
94
95 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
96
97 FGPropertyManager*
98 FGPropertyManager::GetNode (const string &relpath, int index, bool create)
99 {
100     return (FGPropertyManager*)getNode(relpath.c_str(),index,create);
101 }
102
103 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
104
105 bool FGPropertyManager::HasNode (const string &path)
106 {
107   // Checking if a node exists shouldn't write a warning if it doesn't exist
108   suppress_warning = true;
109   bool has_node = (GetNode(path, false) != 0);
110   suppress_warning = false;
111   return has_node;
112 }
113
114 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
115
116 string FGPropertyManager::GetName( void )
117 {
118   return string( getName() );
119 }
120
121 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
122
123 string FGPropertyManager::GetPrintableName( void )
124 {
125   string temp_string(getName());
126   size_t initial_location=0;
127   size_t found_location;
128
129   found_location = temp_string.rfind("/");
130   if (found_location != string::npos)
131   temp_string = temp_string.substr(found_location);
132
133   found_location = temp_string.find('_',initial_location);
134   while (found_location != string::npos) {
135     temp_string.replace(found_location,1," ");
136     initial_location = found_location+1;
137     found_location = temp_string.find('_',initial_location);
138   }
139   return temp_string;
140 }
141
142 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
143
144 string FGPropertyManager::GetFullyQualifiedName(void) {
145     vector<string> stack;
146     stack.push_back( getDisplayName(true) );
147     SGPropertyNode* tmpn=getParent();
148     bool atroot=false;
149     while( !atroot ) {
150      stack.push_back( tmpn->getDisplayName(true) );
151      if( !tmpn->getParent() )
152       atroot=true;
153      else
154       tmpn=tmpn->getParent();
155     }
156
157     string fqname="";
158     for(unsigned i=stack.size()-1;i>0;i--) {
159       fqname+= stack[i];
160       fqname+= "/";
161     }
162     fqname+= stack[0];
163     return fqname;
164
165 }
166
167 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
168
169 string FGPropertyManager::GetRelativeName( const string &path )
170 {
171   string temp_string = GetFullyQualifiedName();
172   size_t len = path.length();
173   if ( (len > 0) && (temp_string.substr(0,len) == path) ) {
174     temp_string = temp_string.erase(0,len);
175   }
176   return temp_string;
177 }
178
179
180
181 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
182
183 bool FGPropertyManager::GetBool (const string &name, bool defaultValue)
184 {
185   return getBoolValue(name.c_str(), defaultValue);
186 }
187
188 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
189
190 int FGPropertyManager::GetInt (const string &name, int defaultValue )
191 {
192   return getIntValue(name.c_str(), defaultValue);
193 }
194
195 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
196
197 int FGPropertyManager::GetLong (const string &name, long defaultValue )
198 {
199   return getLongValue(name.c_str(), defaultValue);
200 }
201
202 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
203
204 float FGPropertyManager::GetFloat (const string &name, float defaultValue )
205 {
206   return getFloatValue(name.c_str(), defaultValue);
207 }
208
209 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
210
211 double FGPropertyManager::GetDouble (const string &name, double defaultValue )
212 {
213   return getDoubleValue(name.c_str(), defaultValue);
214 }
215
216 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
217
218 string FGPropertyManager::GetString (const string &name, string defaultValue )
219 {
220   return string(getStringValue(name.c_str(), defaultValue.c_str()));
221 }
222
223 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
224
225 bool FGPropertyManager::SetBool (const string &name, bool val)
226 {
227   return setBoolValue(name.c_str(), val);
228 }
229
230 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
231
232 bool FGPropertyManager::SetInt (const string &name, int val)
233 {
234   return setIntValue(name.c_str(), val);
235 }
236
237 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
238
239 bool FGPropertyManager::SetLong (const string &name, long val)
240 {
241   return setLongValue(name.c_str(), val);
242 }
243
244 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
245
246 bool FGPropertyManager::SetFloat (const string &name, float val)
247 {
248   return setFloatValue(name.c_str(), val);
249 }
250
251 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
252
253 bool FGPropertyManager::SetDouble (const string &name, double val)
254 {
255   return setDoubleValue(name.c_str(), val);
256 }
257
258 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
259
260 bool FGPropertyManager::SetString (const string &name, const string &val)
261 {
262   return setStringValue(name.c_str(), val.c_str());
263 }
264
265 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
266
267 void FGPropertyManager::SetArchivable (const string &name, bool state )
268 {
269   SGPropertyNode * node = getNode(name.c_str());
270   if (node == 0)
271     cerr <<
272            "Attempt to set archive flag for non-existent property "
273            << name << endl;
274   else
275     node->setAttribute(SGPropertyNode::ARCHIVE, state);
276 }
277
278 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
279
280 void FGPropertyManager::SetReadable (const string &name, bool state )
281 {
282   SGPropertyNode * node = getNode(name.c_str());
283   if (node == 0)
284     cerr <<
285            "Attempt to set read flag for non-existant property "
286            << name << endl;
287   else
288     node->setAttribute(SGPropertyNode::READ, state);
289 }
290
291 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
292
293 void FGPropertyManager::SetWritable (const string &name, bool state )
294 {
295   SGPropertyNode * node = getNode(name.c_str());
296   if (node == 0)
297     cerr <<
298            "Attempt to set write flag for non-existant property "
299            << name << endl;
300   else
301     node->setAttribute(SGPropertyNode::WRITE, state);
302 }
303
304 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
305
306 void FGPropertyManager::Untie (const string &name)
307 {
308   if (!untie(name.c_str()))
309     cerr << "Failed to untie property " << name << endl;
310 }
311
312 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
313
314 void FGPropertyManager::Tie (const string &name, bool *pointer, bool useDefault)
315 {
316   SGPropertyNode* property = getNode(name.c_str(), true);
317   if (!property) {
318     cerr << "Could not get or create property " << name << endl;
319     return;
320   }
321
322   if (!property->tie(SGRawValuePointer<bool>(pointer), useDefault))
323     cerr << "Failed to tie property " << name << " to a pointer" << endl;
324   else {
325     tied_properties.push_back(property);
326     if (debug_lvl & 0x20) cout << name << endl;
327   }
328 }
329
330 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
331
332 void FGPropertyManager::Tie (const string &name, int *pointer,
333                                           bool useDefault )
334 {
335   SGPropertyNode* property = getNode(name.c_str(), true);
336   if (!property) {
337     cerr << "Could not get or create property " << name << endl;
338     return;
339   }
340
341   if (!property->tie(SGRawValuePointer<int>(pointer), useDefault))
342     cerr << "Failed to tie property " << name << " to a pointer" << endl;
343   else {
344     tied_properties.push_back(property);
345     if (debug_lvl & 0x20) cout << name << endl;
346   }
347 }
348
349 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
350
351 void FGPropertyManager::Tie (const string &name, long *pointer,
352                                           bool useDefault )
353 {
354   SGPropertyNode* property = getNode(name.c_str(), true);
355   if (!property) {
356     cerr << "Could not get or create property " << name << endl;
357     return;
358   }
359
360   if (!property->tie(SGRawValuePointer<long>(pointer), useDefault))
361     cerr << "Failed to tie property " << name << " to a pointer" << endl;
362   else {
363     tied_properties.push_back(property);
364     if (debug_lvl & 0x20) cout << name << endl;
365   }
366 }
367
368 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
369
370 void FGPropertyManager::Tie (const string &name, float *pointer,
371                                           bool useDefault )
372 {
373   SGPropertyNode* property = getNode(name.c_str(), true);
374   if (!property) {
375     cerr << "Could not get or create property " << name << endl;
376     return;
377   }
378
379   if (!property->tie(SGRawValuePointer<float>(pointer), useDefault))
380     cerr << "Failed to tie property " << name << " to a pointer" << endl;
381   else {
382     tied_properties.push_back(property);
383     if (debug_lvl & 0x20) cout << name << endl;
384   }
385 }
386
387 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
388
389 void FGPropertyManager::Tie (const string &name, double *pointer, bool useDefault)
390 {
391   SGPropertyNode* property = getNode(name.c_str(), true);
392   if (!property) {
393     cerr << "Could not get or create property " << name << endl;
394     return;
395   }
396
397   if (!property->tie(SGRawValuePointer<double>(pointer), useDefault))
398     cerr << "Failed to tie property " << name << " to a pointer" << endl;
399   else {
400     tied_properties.push_back(property);
401     if (debug_lvl & 0x20) cout << name << endl;
402   }
403 }
404
405 } // namespace JSBSim