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(unsigned 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(unsigned 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 bool FGPropertyManager::GetBool (const string &name, bool defaultValue)
109 return getBoolValue(name.c_str(), defaultValue);
112 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
114 int FGPropertyManager::GetInt (const string &name, int defaultValue )
116 return getIntValue(name.c_str(), defaultValue);
119 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
121 int FGPropertyManager::GetLong (const string &name, long defaultValue )
123 return getLongValue(name.c_str(), defaultValue);
126 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
128 float FGPropertyManager::GetFloat (const string &name, float defaultValue )
130 return getFloatValue(name.c_str(), defaultValue);
133 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
135 double FGPropertyManager::GetDouble (const string &name, double defaultValue )
137 return getDoubleValue(name.c_str(), defaultValue);
140 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
142 string FGPropertyManager::GetString (const string &name, string defaultValue )
144 return string(getStringValue(name.c_str(), defaultValue.c_str()));
147 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
149 bool FGPropertyManager::SetBool (const string &name, bool val)
151 return setBoolValue(name.c_str(), val);
154 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
156 bool FGPropertyManager::SetInt (const string &name, int val)
158 return setIntValue(name.c_str(), val);
161 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
163 bool FGPropertyManager::SetLong (const string &name, long val)
165 return setLongValue(name.c_str(), val);
168 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
170 bool FGPropertyManager::SetFloat (const string &name, float val)
172 return setFloatValue(name.c_str(), val);
175 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
177 bool FGPropertyManager::SetDouble (const string &name, double val)
179 return setDoubleValue(name.c_str(), val);
182 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
184 bool FGPropertyManager::SetString (const string &name, const string &val)
186 return setStringValue(name.c_str(), val.c_str());
189 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
191 void FGPropertyManager::SetArchivable (const string &name, bool state )
193 SGPropertyNode * node = getNode(name.c_str());
196 "Attempt to set archive flag for non-existant property "
199 node->setAttribute(SGPropertyNode::ARCHIVE, state);
202 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
204 void FGPropertyManager::SetReadable (const string &name, bool state )
206 SGPropertyNode * node = getNode(name.c_str());
209 "Attempt to set read flag for non-existant property "
212 node->setAttribute(SGPropertyNode::READ, state);
215 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
217 void FGPropertyManager::SetWritable (const string &name, bool state )
219 SGPropertyNode * node = getNode(name.c_str());
222 "Attempt to set write flag for non-existant property "
225 node->setAttribute(SGPropertyNode::WRITE, state);
228 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
230 void FGPropertyManager::Untie (const string &name)
232 if (!untie(name.c_str()))
233 cout << "Failed to untie property " << name << endl;
236 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
238 void FGPropertyManager::Tie (const string &name, bool *pointer, bool useDefault)
240 if (!tie(name.c_str(), SGRawValuePointer<bool>(pointer),
243 "Failed to tie property " << name << " to a pointer" << endl;
246 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
248 void FGPropertyManager::Tie (const string &name, int *pointer,
251 if (!tie(name.c_str(), SGRawValuePointer<int>(pointer),
254 "Failed to tie property " << name << " to a pointer" << endl;
257 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
259 void FGPropertyManager::Tie (const string &name, long *pointer,
262 if (!tie(name.c_str(), SGRawValuePointer<long>(pointer),
265 "Failed to tie property " << name << " to a pointer" << endl;
268 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
270 void FGPropertyManager::Tie (const string &name, float *pointer,
273 if (!tie(name.c_str(), SGRawValuePointer<float>(pointer),
276 "Failed to tie property " << name << " to a pointer" << endl;
279 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
281 void FGPropertyManager::Tie (const string &name, double *pointer,
284 if (!tie(name.c_str(), SGRawValuePointer<double>(pointer),
287 "Failed to tie property " << name << " to a pointer" << endl;