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