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 */
57 for(i=0;i<name.length();i++) {
58 if( lowercase && isupper(name[i]) )
59 name[i]=tolower(name[i]);
60 else if( isspace(name[i]) )
63 for(i=0;i<name.length();i++) {
71 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
74 FGPropertyManager::GetNode (const string &path, bool create)
76 SGPropertyNode* node=this->getNode(path.c_str(), create);
78 cout << "FGPropertyManager::GetNode() No node found for "
80 return (FGPropertyManager*)node;
83 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
86 FGPropertyManager::GetNode (const string &relpath, int index, bool create)
88 return (FGPropertyManager*)getNode(relpath.c_str(),index,create);
91 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
94 bool FGPropertyManager::HasNode (const string &path)
96 return (GetNode(path, false) != 0);
99 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
101 string FGPropertyManager::GetName( void ) {
102 return string( getName() );
105 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
107 string FGPropertyManager::GetFullyQualifiedName(void) {
108 vector<string> stack;
109 stack.push_back( getDisplayName(true) );
110 SGPropertyNode* tmpn=getParent();
113 stack.push_back( tmpn->getDisplayName(true) );
114 if( !tmpn->getParent() )
117 tmpn=tmpn->getParent();
121 for(unsigned i=stack.size()-1;i>0;i--) {
131 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
133 bool FGPropertyManager::GetBool (const string &name, bool defaultValue)
135 return getBoolValue(name.c_str(), defaultValue);
138 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
140 int FGPropertyManager::GetInt (const string &name, int defaultValue )
142 return getIntValue(name.c_str(), defaultValue);
145 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
147 int FGPropertyManager::GetLong (const string &name, long defaultValue )
149 return getLongValue(name.c_str(), defaultValue);
152 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
154 float FGPropertyManager::GetFloat (const string &name, float defaultValue )
156 return getFloatValue(name.c_str(), defaultValue);
159 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
161 double FGPropertyManager::GetDouble (const string &name, double defaultValue )
163 return getDoubleValue(name.c_str(), defaultValue);
166 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
168 string FGPropertyManager::GetString (const string &name, string defaultValue )
170 return string(getStringValue(name.c_str(), defaultValue.c_str()));
173 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
175 bool FGPropertyManager::SetBool (const string &name, bool val)
177 return setBoolValue(name.c_str(), val);
180 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
182 bool FGPropertyManager::SetInt (const string &name, int val)
184 return setIntValue(name.c_str(), val);
187 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
189 bool FGPropertyManager::SetLong (const string &name, long val)
191 return setLongValue(name.c_str(), val);
194 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
196 bool FGPropertyManager::SetFloat (const string &name, float val)
198 return setFloatValue(name.c_str(), val);
201 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
203 bool FGPropertyManager::SetDouble (const string &name, double val)
205 return setDoubleValue(name.c_str(), val);
208 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
210 bool FGPropertyManager::SetString (const string &name, const string &val)
212 return setStringValue(name.c_str(), val.c_str());
215 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
217 void FGPropertyManager::SetArchivable (const string &name, bool state )
219 SGPropertyNode * node = getNode(name.c_str());
222 "Attempt to set archive flag for non-existant property "
225 node->setAttribute(SGPropertyNode::ARCHIVE, state);
228 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
230 void FGPropertyManager::SetReadable (const string &name, bool state )
232 SGPropertyNode * node = getNode(name.c_str());
235 "Attempt to set read flag for non-existant property "
238 node->setAttribute(SGPropertyNode::READ, state);
241 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
243 void FGPropertyManager::SetWritable (const string &name, bool state )
245 SGPropertyNode * node = getNode(name.c_str());
248 "Attempt to set write flag for non-existant property "
251 node->setAttribute(SGPropertyNode::WRITE, state);
254 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
256 void FGPropertyManager::Untie (const string &name)
258 if (!untie(name.c_str()))
259 cout << "Failed to untie property " << name << endl;
262 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
264 void FGPropertyManager::Tie (const string &name, bool *pointer, bool useDefault)
266 if (!tie(name.c_str(), SGRawValuePointer<bool>(pointer),
269 "Failed to tie property " << name << " to a pointer" << endl;
272 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
274 void FGPropertyManager::Tie (const string &name, int *pointer,
277 if (!tie(name.c_str(), SGRawValuePointer<int>(pointer),
280 "Failed to tie property " << name << " to a pointer" << endl;
283 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
285 void FGPropertyManager::Tie (const string &name, long *pointer,
288 if (!tie(name.c_str(), SGRawValuePointer<long>(pointer),
291 "Failed to tie property " << name << " to a pointer" << endl;
294 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
296 void FGPropertyManager::Tie (const string &name, float *pointer,
299 if (!tie(name.c_str(), SGRawValuePointer<float>(pointer),
302 "Failed to tie property " << name << " to a pointer" << endl;
305 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
307 void FGPropertyManager::Tie (const string &name, double *pointer,
310 if (!tie(name.c_str(), SGRawValuePointer<double>(pointer),
313 "Failed to tie property " << name << " to a pointer" << endl;