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 Lesser 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 Lesser General Public License for more
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.
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.
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 bool FGPropertyManager::suppress_warning = true;
53 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
55 string FGPropertyManager::mkPropertyName(string name, bool lowercase) {
57 /* do this two pass to avoid problems with characters getting skipped
58 because the index changed */
60 for(i=0;i<name.length();i++) {
61 if( lowercase && isupper(name[i]) )
62 name[i]=tolower(name[i]);
63 else if( isspace(name[i]) )
67 for(i=0;i<name.length();i++) {
75 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
78 FGPropertyManager::GetNode (const string &path, bool create)
80 SGPropertyNode* node=this->getNode(path.c_str(), create);
81 if (node == 0 && !suppress_warning)
82 cout << "FGPropertyManager::GetNode() No node found for "
84 return (FGPropertyManager*)node;
87 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
90 FGPropertyManager::GetNode (const string &relpath, int index, bool create)
92 return (FGPropertyManager*)getNode(relpath.c_str(),index,create);
95 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
98 bool FGPropertyManager::HasNode (const string &path)
100 // Checking if a node exists shouldn't write a warning if it doesn't exist
101 suppress_warning = true;
102 bool has_node = (GetNode(path, false) != 0);
103 suppress_warning = false;
107 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
109 string FGPropertyManager::GetName( void ) {
110 return string( getName() );
113 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
115 string FGPropertyManager::GetFullyQualifiedName(void) {
116 vector<string> stack;
117 stack.push_back( getDisplayName(true) );
118 SGPropertyNode* tmpn=getParent();
121 stack.push_back( tmpn->getDisplayName(true) );
122 if( !tmpn->getParent() )
125 tmpn=tmpn->getParent();
129 for(unsigned i=stack.size()-1;i>0;i--) {
139 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
141 bool FGPropertyManager::GetBool (const string &name, bool defaultValue)
143 return getBoolValue(name.c_str(), defaultValue);
146 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
148 int FGPropertyManager::GetInt (const string &name, int defaultValue )
150 return getIntValue(name.c_str(), defaultValue);
153 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
155 int FGPropertyManager::GetLong (const string &name, long defaultValue )
157 return getLongValue(name.c_str(), defaultValue);
160 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
162 float FGPropertyManager::GetFloat (const string &name, float defaultValue )
164 return getFloatValue(name.c_str(), defaultValue);
167 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
169 double FGPropertyManager::GetDouble (const string &name, double defaultValue )
171 return getDoubleValue(name.c_str(), defaultValue);
174 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
176 string FGPropertyManager::GetString (const string &name, string defaultValue )
178 return string(getStringValue(name.c_str(), defaultValue.c_str()));
181 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
183 bool FGPropertyManager::SetBool (const string &name, bool val)
185 return setBoolValue(name.c_str(), val);
188 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
190 bool FGPropertyManager::SetInt (const string &name, int val)
192 return setIntValue(name.c_str(), val);
195 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
197 bool FGPropertyManager::SetLong (const string &name, long val)
199 return setLongValue(name.c_str(), val);
202 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
204 bool FGPropertyManager::SetFloat (const string &name, float val)
206 return setFloatValue(name.c_str(), val);
209 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
211 bool FGPropertyManager::SetDouble (const string &name, double val)
213 return setDoubleValue(name.c_str(), val);
216 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
218 bool FGPropertyManager::SetString (const string &name, const string &val)
220 return setStringValue(name.c_str(), val.c_str());
223 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
225 void FGPropertyManager::SetArchivable (const string &name, bool state )
227 SGPropertyNode * node = getNode(name.c_str());
230 "Attempt to set archive flag for non-existant property "
233 node->setAttribute(SGPropertyNode::ARCHIVE, state);
236 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
238 void FGPropertyManager::SetReadable (const string &name, bool state )
240 SGPropertyNode * node = getNode(name.c_str());
243 "Attempt to set read flag for non-existant property "
246 node->setAttribute(SGPropertyNode::READ, state);
249 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
251 void FGPropertyManager::SetWritable (const string &name, bool state )
253 SGPropertyNode * node = getNode(name.c_str());
256 "Attempt to set write flag for non-existant property "
259 node->setAttribute(SGPropertyNode::WRITE, state);
262 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
264 void FGPropertyManager::Untie (const string &name)
266 if (!untie(name.c_str()))
267 cout << "Failed to untie property " << name << endl;
270 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
272 void FGPropertyManager::Tie (const string &name, bool *pointer, bool useDefault)
274 if (!tie(name.c_str(), SGRawValuePointer<bool>(pointer), useDefault))
275 cout << "Failed to tie property " << name << " to a pointer" << endl;
276 else if (debug_lvl & 0x20)
277 cout << name << endl;
280 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
282 void FGPropertyManager::Tie (const string &name, int *pointer,
285 if (!tie(name.c_str(), SGRawValuePointer<int>(pointer), useDefault))
286 cout << "Failed to tie property " << name << " to a pointer" << endl;
287 else if (debug_lvl & 0x20)
288 cout << name << endl;
291 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
293 void FGPropertyManager::Tie (const string &name, long *pointer,
296 if (!tie(name.c_str(), SGRawValuePointer<long>(pointer), useDefault))
297 cout << "Failed to tie property " << name << " to a pointer" << endl;
298 else if (debug_lvl & 0x20)
299 cout << name << endl;
302 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
304 void FGPropertyManager::Tie (const string &name, float *pointer,
307 if (!tie(name.c_str(), SGRawValuePointer<float>(pointer), useDefault))
308 cout << "Failed to tie property " << name << " to a pointer" << endl;
309 else if (debug_lvl & 0x20)
310 cout << name << endl;
313 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
315 void FGPropertyManager::Tie (const string &name, double *pointer, bool useDefault)
317 if (!tie(name.c_str(), SGRawValuePointer<double>(pointer), useDefault))
318 cout << "Failed to tie property " << name << " to a pointer" << endl;
319 else if (debug_lvl & 0x20)
320 cout << name << endl;
323 } // namespace JSBSim