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 <simgear/misc/props.hxx>
32 #include "FGPropertyManager.h"
34 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
36 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
39 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
41 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
45 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
46 COMMENTS, REFERENCES, and NOTES [use "class documentation" below for API docs]
47 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
50 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
52 string FGPropertyManager::mkPropertyName(string name, bool lowercase) {
54 /* do this two pass to avoid problems with characters getting skipped
55 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]) )
64 for(i=0;i<name.length();i++) {
72 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
75 FGPropertyManager::GetNode (const string &path, bool create)
77 SGPropertyNode* node=this->getNode(path.c_str(), create);
79 cout << "FGPropertyManager::GetNode() No node found for "
81 return (FGPropertyManager*)node;
84 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
87 FGPropertyManager::GetNode (const string &relpath, int index, bool create)
89 return (FGPropertyManager*)getNode(relpath.c_str(),index,create);
92 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
95 bool FGPropertyManager::HasNode (const string &path)
97 return (GetNode(path, false) != 0);
100 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
102 string FGPropertyManager::GetName( void ) {
103 return string( getName() );
106 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
108 string FGPropertyManager::GetFullyQualifiedName(void) {
109 vector<string> stack;
110 stack.push_back( getDisplayName(true) );
111 SGPropertyNode* tmpn=getParent();
114 stack.push_back( tmpn->getDisplayName(true) );
115 if( !tmpn->getParent() )
118 tmpn=tmpn->getParent();
122 for(unsigned i=stack.size()-1;i>0;i--) {
132 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
134 bool FGPropertyManager::GetBool (const string &name, bool defaultValue)
136 return getBoolValue(name.c_str(), defaultValue);
139 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
141 int FGPropertyManager::GetInt (const string &name, int defaultValue )
143 return getIntValue(name.c_str(), defaultValue);
146 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
148 int FGPropertyManager::GetLong (const string &name, long defaultValue )
150 return getLongValue(name.c_str(), defaultValue);
153 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
155 float FGPropertyManager::GetFloat (const string &name, float defaultValue )
157 return getFloatValue(name.c_str(), defaultValue);
160 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
162 double FGPropertyManager::GetDouble (const string &name, double defaultValue )
164 return getDoubleValue(name.c_str(), defaultValue);
167 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
169 string FGPropertyManager::GetString (const string &name, string defaultValue )
171 return string(getStringValue(name.c_str(), defaultValue.c_str()));
174 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
176 bool FGPropertyManager::SetBool (const string &name, bool val)
178 return setBoolValue(name.c_str(), val);
181 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
183 bool FGPropertyManager::SetInt (const string &name, int val)
185 return setIntValue(name.c_str(), val);
188 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
190 bool FGPropertyManager::SetLong (const string &name, long val)
192 return setLongValue(name.c_str(), val);
195 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
197 bool FGPropertyManager::SetFloat (const string &name, float val)
199 return setFloatValue(name.c_str(), val);
202 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
204 bool FGPropertyManager::SetDouble (const string &name, double val)
206 return setDoubleValue(name.c_str(), val);
209 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
211 bool FGPropertyManager::SetString (const string &name, const string &val)
213 return setStringValue(name.c_str(), val.c_str());
216 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
218 void FGPropertyManager::SetArchivable (const string &name, bool state )
220 SGPropertyNode * node = getNode(name.c_str());
223 "Attempt to set archive flag for non-existant property "
226 node->setAttribute(SGPropertyNode::ARCHIVE, state);
229 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
231 void FGPropertyManager::SetReadable (const string &name, bool state )
233 SGPropertyNode * node = getNode(name.c_str());
236 "Attempt to set read flag for non-existant property "
239 node->setAttribute(SGPropertyNode::READ, state);
242 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
244 void FGPropertyManager::SetWritable (const string &name, bool state )
246 SGPropertyNode * node = getNode(name.c_str());
249 "Attempt to set write flag for non-existant property "
252 node->setAttribute(SGPropertyNode::WRITE, state);
255 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
257 void FGPropertyManager::Untie (const string &name)
259 if (!untie(name.c_str()))
260 cout << "Failed to untie property " << name << endl;
263 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
265 void FGPropertyManager::Tie (const string &name, bool *pointer, bool useDefault)
267 if (!tie(name.c_str(), SGRawValuePointer<bool>(pointer),
270 "Failed to tie property " << name << " to a pointer" << endl;
273 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
275 void FGPropertyManager::Tie (const string &name, int *pointer,
278 if (!tie(name.c_str(), SGRawValuePointer<int>(pointer),
281 "Failed to tie property " << name << " to a pointer" << endl;
284 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
286 void FGPropertyManager::Tie (const string &name, long *pointer,
289 if (!tie(name.c_str(), SGRawValuePointer<long>(pointer),
292 "Failed to tie property " << name << " to a pointer" << endl;
295 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
297 void FGPropertyManager::Tie (const string &name, float *pointer,
300 if (!tie(name.c_str(), SGRawValuePointer<float>(pointer),
303 "Failed to tie property " << name << " to a pointer" << endl;
306 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
308 void FGPropertyManager::Tie (const string &name, double *pointer,
311 if (!tie(name.c_str(), SGRawValuePointer<double>(pointer),
314 "Failed to tie property " << name << " to a pointer" << endl;