1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 Header: FGPropertyManager.cpp
5 Based on work originally by David Megginson
8 ------------- Copyright (C) 2002 -------------
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
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
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.
24 Further information about the GNU General Public License can also be found on
25 the world wide web at http://www.gnu.org.
27 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
31 #include "FGPropertyManager.h"
33 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
38 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
40 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
44 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
45 COMMENTS, REFERENCES, and NOTES [use "class documentation" below for API docs]
46 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
51 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
53 string FGPropertyManager::mkPropertyName(string name, bool lowercase) {
55 /* do this two pass to avoid problems with characters getting skipped
56 because the index changed */
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]) )
65 for(i=0;i<name.length();i++) {
73 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
76 FGPropertyManager::GetNode (const string &path, bool create)
78 SGPropertyNode* node=this->getNode(path.c_str(), create);
79 if (node == 0 && !suppress_warning)
80 cout << "FGPropertyManager::GetNode() No node found for "
82 return (FGPropertyManager*)node;
85 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
88 FGPropertyManager::GetNode (const string &relpath, int index, bool create)
90 return (FGPropertyManager*)getNode(relpath.c_str(),index,create);
93 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
96 bool FGPropertyManager::HasNode (const string &path)
98 // Checking if a node exists shouldn't write a warning if it doesn't exist
99 suppress_warning = true;
100 bool has_node = (GetNode(path, false) != 0);
101 suppress_warning = false;
105 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
107 string FGPropertyManager::GetName( void ) {
108 return string( getName() );
111 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
113 string FGPropertyManager::GetFullyQualifiedName(void) {
114 vector<string> stack;
115 stack.push_back( getDisplayName(true) );
116 SGPropertyNode* tmpn=getParent();
119 stack.push_back( tmpn->getDisplayName(true) );
120 if( !tmpn->getParent() )
123 tmpn=tmpn->getParent();
127 for(unsigned i=stack.size()-1;i>0;i--) {
137 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
139 bool FGPropertyManager::GetBool (const string &name, bool defaultValue)
141 return getBoolValue(name.c_str(), defaultValue);
144 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
146 int FGPropertyManager::GetInt (const string &name, int defaultValue )
148 return getIntValue(name.c_str(), defaultValue);
151 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
153 int FGPropertyManager::GetLong (const string &name, long defaultValue )
155 return getLongValue(name.c_str(), defaultValue);
158 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
160 float FGPropertyManager::GetFloat (const string &name, float defaultValue )
162 return getFloatValue(name.c_str(), defaultValue);
165 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
167 double FGPropertyManager::GetDouble (const string &name, double defaultValue )
169 return getDoubleValue(name.c_str(), defaultValue);
172 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
174 string FGPropertyManager::GetString (const string &name, string defaultValue )
176 return string(getStringValue(name.c_str(), defaultValue.c_str()));
179 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
181 bool FGPropertyManager::SetBool (const string &name, bool val)
183 return setBoolValue(name.c_str(), val);
186 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
188 bool FGPropertyManager::SetInt (const string &name, int val)
190 return setIntValue(name.c_str(), val);
193 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
195 bool FGPropertyManager::SetLong (const string &name, long val)
197 return setLongValue(name.c_str(), val);
200 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
202 bool FGPropertyManager::SetFloat (const string &name, float val)
204 return setFloatValue(name.c_str(), val);
207 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
209 bool FGPropertyManager::SetDouble (const string &name, double val)
211 return setDoubleValue(name.c_str(), val);
214 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
216 bool FGPropertyManager::SetString (const string &name, const string &val)
218 return setStringValue(name.c_str(), val.c_str());
221 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
223 void FGPropertyManager::SetArchivable (const string &name, bool state )
225 SGPropertyNode * node = getNode(name.c_str());
228 "Attempt to set archive flag for non-existant property "
231 node->setAttribute(SGPropertyNode::ARCHIVE, state);
234 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
236 void FGPropertyManager::SetReadable (const string &name, bool state )
238 SGPropertyNode * node = getNode(name.c_str());
241 "Attempt to set read flag for non-existant property "
244 node->setAttribute(SGPropertyNode::READ, state);
247 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
249 void FGPropertyManager::SetWritable (const string &name, bool state )
251 SGPropertyNode * node = getNode(name.c_str());
254 "Attempt to set write flag for non-existant property "
257 node->setAttribute(SGPropertyNode::WRITE, state);
260 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
262 void FGPropertyManager::Untie (const string &name)
264 if (!untie(name.c_str()))
265 cout << "Failed to untie property " << name << endl;
268 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
270 void FGPropertyManager::Tie (const string &name, bool *pointer, bool useDefault)
272 if (!tie(name.c_str(), SGRawValuePointer<bool>(pointer), useDefault))
273 cout << "Failed to tie property " << name << " to a pointer" << endl;
274 else if (debug_lvl & 0x20)
275 cout << name << endl;
278 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
280 void FGPropertyManager::Tie (const string &name, int *pointer,
283 if (!tie(name.c_str(), SGRawValuePointer<int>(pointer), useDefault))
284 cout << "Failed to tie property " << name << " to a pointer" << endl;
285 else if (debug_lvl & 0x20)
286 cout << name << endl;
289 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
291 void FGPropertyManager::Tie (const string &name, long *pointer,
294 if (!tie(name.c_str(), SGRawValuePointer<long>(pointer), useDefault))
295 cout << "Failed to tie property " << name << " to a pointer" << endl;
296 else if (debug_lvl & 0x20)
297 cout << name << endl;
300 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
302 void FGPropertyManager::Tie (const string &name, float *pointer,
305 if (!tie(name.c_str(), SGRawValuePointer<float>(pointer), useDefault))
306 cout << "Failed to tie property " << name << " to a pointer" << endl;
307 else if (debug_lvl & 0x20)
308 cout << name << endl;
311 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
313 void FGPropertyManager::Tie (const string &name, double *pointer, bool useDefault)
315 if (!tie(name.c_str(), SGRawValuePointer<double>(pointer), useDefault))
316 cout << "Failed to tie property " << name << " to a pointer" << endl;
317 else if (debug_lvl & 0x20)
318 cout << name << endl;
321 } // namespace JSBSim