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/props/props.hxx>
32 #include "FGPropertyManager.h"
34 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
36 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
39 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
41 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
45 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
46 COMMENTS, REFERENCES, and NOTES [use "class documentation" below for API docs]
47 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
52 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
54 string FGPropertyManager::mkPropertyName(string name, bool lowercase) {
56 /* do this two pass to avoid problems with characters getting skipped
57 because the index changed */
59 for(i=0;i<name.length();i++) {
60 if( lowercase && isupper(name[i]) )
61 name[i]=tolower(name[i]);
62 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);
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 return (GetNode(path, false) != 0);
101 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
103 string FGPropertyManager::GetName( void ) {
104 return string( getName() );
107 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
109 string FGPropertyManager::GetFullyQualifiedName(void) {
110 vector<string> stack;
111 stack.push_back( getDisplayName(true) );
112 SGPropertyNode* tmpn=getParent();
115 stack.push_back( tmpn->getDisplayName(true) );
116 if( !tmpn->getParent() )
119 tmpn=tmpn->getParent();
123 for(unsigned i=stack.size()-1;i>0;i--) {
133 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
135 bool FGPropertyManager::GetBool (const string &name, bool defaultValue)
137 return getBoolValue(name.c_str(), defaultValue);
140 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
142 int FGPropertyManager::GetInt (const string &name, int defaultValue )
144 return getIntValue(name.c_str(), defaultValue);
147 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
149 int FGPropertyManager::GetLong (const string &name, long defaultValue )
151 return getLongValue(name.c_str(), defaultValue);
154 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
156 float FGPropertyManager::GetFloat (const string &name, float defaultValue )
158 return getFloatValue(name.c_str(), defaultValue);
161 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
163 double FGPropertyManager::GetDouble (const string &name, double defaultValue )
165 return getDoubleValue(name.c_str(), defaultValue);
168 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
170 string FGPropertyManager::GetString (const string &name, string defaultValue )
172 return string(getStringValue(name.c_str(), defaultValue.c_str()));
175 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
177 bool FGPropertyManager::SetBool (const string &name, bool val)
179 return setBoolValue(name.c_str(), val);
182 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
184 bool FGPropertyManager::SetInt (const string &name, int val)
186 return setIntValue(name.c_str(), val);
189 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
191 bool FGPropertyManager::SetLong (const string &name, long val)
193 return setLongValue(name.c_str(), val);
196 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
198 bool FGPropertyManager::SetFloat (const string &name, float val)
200 return setFloatValue(name.c_str(), val);
203 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
205 bool FGPropertyManager::SetDouble (const string &name, double val)
207 return setDoubleValue(name.c_str(), val);
210 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
212 bool FGPropertyManager::SetString (const string &name, const string &val)
214 return setStringValue(name.c_str(), val.c_str());
217 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
219 void FGPropertyManager::SetArchivable (const string &name, bool state )
221 SGPropertyNode * node = getNode(name.c_str());
224 "Attempt to set archive flag for non-existant property "
227 node->setAttribute(SGPropertyNode::ARCHIVE, state);
230 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
232 void FGPropertyManager::SetReadable (const string &name, bool state )
234 SGPropertyNode * node = getNode(name.c_str());
237 "Attempt to set read flag for non-existant property "
240 node->setAttribute(SGPropertyNode::READ, state);
243 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
245 void FGPropertyManager::SetWritable (const string &name, bool state )
247 SGPropertyNode * node = getNode(name.c_str());
250 "Attempt to set write flag for non-existant property "
253 node->setAttribute(SGPropertyNode::WRITE, state);
256 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
258 void FGPropertyManager::Untie (const string &name)
260 if (!untie(name.c_str()))
261 cout << "Failed to untie property " << name << endl;
264 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
266 void FGPropertyManager::Tie (const string &name, bool *pointer, bool useDefault)
268 if (!tie(name.c_str(), SGRawValuePointer<bool>(pointer),
271 "Failed to tie property " << name << " to a pointer" << endl;
274 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
276 void FGPropertyManager::Tie (const string &name, int *pointer,
279 if (!tie(name.c_str(), SGRawValuePointer<int>(pointer),
282 "Failed to tie property " << name << " to a pointer" << endl;
285 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
287 void FGPropertyManager::Tie (const string &name, long *pointer,
290 if (!tie(name.c_str(), SGRawValuePointer<long>(pointer),
293 "Failed to tie property " << name << " to a pointer" << endl;
296 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
298 void FGPropertyManager::Tie (const string &name, float *pointer,
301 if (!tie(name.c_str(), SGRawValuePointer<float>(pointer),
304 "Failed to tie property " << name << " to a pointer" << endl;
307 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
309 void FGPropertyManager::Tie (const string &name, double *pointer,
312 if (!tie(name.c_str(), SGRawValuePointer<double>(pointer),
315 "Failed to tie property " << name << " to a pointer" << endl;
318 } // namespace JSBSim