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