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"
35 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
37 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
41 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
42 COMMENTS, REFERENCES, and NOTES [use "class documentation" below for API docs]
43 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
46 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
48 string FGPropertyManager::mkPropertyName(string name, bool lowercase) {
50 for(unsigned i=0;i<name.length();i++) {
51 if( lowercase && isupper(name[i]) )
52 name[i]=tolower(name[i]);
53 else if( isspace(name[i]) )
59 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
62 FGPropertyManager::GetNode (const string &path, bool create)
64 SGPropertyNode* node=this->getNode(path.c_str(), create);
66 cout << "FGPropertyManager::GetNode() No node found for "
68 return (FGPropertyManager*)node;
71 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
74 FGPropertyManager::GetNode (const string &relpath, int index, bool create)
76 return (FGPropertyManager*)getNode(relpath.c_str(),index,create);
79 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
82 bool FGPropertyManager::HasNode (const string &path)
84 return (GetNode(path, false) != 0);
87 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
89 string FGPropertyManager::GetName( void ) {
90 return string( getName() );
93 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
95 bool FGPropertyManager::GetBool (const string &name, bool defaultValue)
97 return getBoolValue(name.c_str(), defaultValue);
100 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
102 int FGPropertyManager::GetInt (const string &name, int defaultValue )
104 return getIntValue(name.c_str(), defaultValue);
107 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
109 int FGPropertyManager::GetLong (const string &name, long defaultValue )
111 return getLongValue(name.c_str(), defaultValue);
114 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
116 float FGPropertyManager::GetFloat (const string &name, float defaultValue )
118 return getFloatValue(name.c_str(), defaultValue);
121 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
123 double FGPropertyManager::GetDouble (const string &name, double defaultValue )
125 return getDoubleValue(name.c_str(), defaultValue);
128 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
130 string FGPropertyManager::GetString (const string &name, string defaultValue )
132 return string(getStringValue(name.c_str(), defaultValue.c_str()));
135 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
137 bool FGPropertyManager::SetBool (const string &name, bool val)
139 return setBoolValue(name.c_str(), val);
142 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
144 bool FGPropertyManager::SetInt (const string &name, int val)
146 return setIntValue(name.c_str(), val);
149 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
151 bool FGPropertyManager::SetLong (const string &name, long val)
153 return setLongValue(name.c_str(), val);
156 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
158 bool FGPropertyManager::SetFloat (const string &name, float val)
160 return setFloatValue(name.c_str(), val);
163 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
165 bool FGPropertyManager::SetDouble (const string &name, double val)
167 return setDoubleValue(name.c_str(), val);
170 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
172 bool FGPropertyManager::SetString (const string &name, const string &val)
174 return setStringValue(name.c_str(), val.c_str());
177 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
179 void FGPropertyManager::SetArchivable (const string &name, bool state )
181 SGPropertyNode * node = getNode(name.c_str());
184 "Attempt to set archive flag for non-existant property "
187 node->setAttribute(SGPropertyNode::ARCHIVE, state);
190 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
192 void FGPropertyManager::SetReadable (const string &name, bool state )
194 SGPropertyNode * node = getNode(name.c_str());
197 "Attempt to set read flag for non-existant property "
200 node->setAttribute(SGPropertyNode::READ, state);
203 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
205 void FGPropertyManager::SetWritable (const string &name, bool state )
207 SGPropertyNode * node = getNode(name.c_str());
210 "Attempt to set write flag for non-existant property "
213 node->setAttribute(SGPropertyNode::WRITE, state);
216 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
218 void FGPropertyManager::Untie (const string &name)
220 if (!untie(name.c_str()))
221 cout << "Failed to untie property " << name << endl;
224 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
226 void FGPropertyManager::Tie (const string &name, bool *pointer, bool useDefault)
228 if (!tie(name.c_str(), SGRawValuePointer<bool>(pointer),
231 "Failed to tie property " << name << " to a pointer" << endl;
234 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
236 void FGPropertyManager::Tie (const string &name, int *pointer,
239 if (!tie(name.c_str(), SGRawValuePointer<int>(pointer),
242 "Failed to tie property " << name << " to a pointer" << endl;
245 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
247 void FGPropertyManager::Tie (const string &name, long *pointer,
250 if (!tie(name.c_str(), SGRawValuePointer<long>(pointer),
253 "Failed to tie property " << name << " to a pointer" << endl;
256 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
258 void FGPropertyManager::Tie (const string &name, float *pointer,
261 if (!tie(name.c_str(), SGRawValuePointer<float>(pointer),
264 "Failed to tie property " << name << " to a pointer" << endl;
267 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
269 void FGPropertyManager::Tie (const string &name, double *pointer,
272 if (!tie(name.c_str(), SGRawValuePointer<double>(pointer),
275 "Failed to tie property " << name << " to a pointer" << endl;