]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGPropertyManager.cpp
Changed much inline code to non-inline. The inline code that remains in the header...
[flightgear.git] / src / FDM / JSBSim / FGPropertyManager.cpp
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2  
3  Header:       FGPropertyManager.cpp
4  Author:       Tony Peden
5                Based on work originally by David Megginson
6  Date:         2/2002
7  
8  ------------- Copyright (C) 2002 -------------
9  
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
13  version.
14  
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
18  details.
19  
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.
23
24  Further information about the GNU General Public License can also be found on
25  the world wide web at http://www.gnu.org.
26
27 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
28 INCLUDES
29 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
30
31 #include <simgear/misc/props.hxx>
32 #include "FGPropertyManager.h"
33
34
35 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
36 FORWARD DECLARATIONS
37 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
38
39 using namespace std;
40
41 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
42 COMMENTS, REFERENCES, and NOTES [use "class documentation" below for API docs]
43 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
44 */
45
46 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
47
48 string FGPropertyManager::mkPropertyName(string name, bool lowercase) {
49   
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]) ) 
54       name[i]='-';
55   }
56   return name;
57 }
58   
59 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
60
61 FGPropertyManager*  
62 FGPropertyManager::GetNode (const string &path, bool create)
63 {
64   SGPropertyNode* node=this->getNode(path.c_str(), create);
65   if(node == 0) 
66     cout << "FGPropertyManager::GetNode() No node found for " 
67          << path << endl;
68   return (FGPropertyManager*)node;
69 }
70
71 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
72
73 FGPropertyManager* 
74 FGPropertyManager::GetNode (const string &relpath, int index, bool create)
75 {
76     return (FGPropertyManager*)getNode(relpath.c_str(),index,create);
77 }    
78
79 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
80
81
82 bool FGPropertyManager::HasNode (const string &path)
83 {
84   return (GetNode(path, false) != 0);
85 }
86
87 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
88
89 string FGPropertyManager::GetName( void ) {
90   return string( getName() );
91 }  
92
93 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
94
95 bool FGPropertyManager::GetBool (const string &name, bool defaultValue)
96 {
97   return getBoolValue(name.c_str(), defaultValue);
98 }
99
100 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
101
102 int FGPropertyManager::GetInt (const string &name, int defaultValue )
103 {
104   return getIntValue(name.c_str(), defaultValue);
105 }
106
107 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
108
109 int FGPropertyManager::GetLong (const string &name, long defaultValue )
110 {
111   return getLongValue(name.c_str(), defaultValue);
112 }
113
114 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
115
116 float FGPropertyManager::GetFloat (const string &name, float defaultValue )
117 {
118   return getFloatValue(name.c_str(), defaultValue);
119 }
120
121 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
122
123 double FGPropertyManager::GetDouble (const string &name, double defaultValue )
124 {
125   return getDoubleValue(name.c_str(), defaultValue);
126 }
127
128 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
129
130 string FGPropertyManager::GetString (const string &name, string defaultValue )
131 {
132   return string(getStringValue(name.c_str(), defaultValue.c_str()));
133 }
134
135 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
136
137 bool FGPropertyManager::SetBool (const string &name, bool val)
138 {
139   return setBoolValue(name.c_str(), val);
140 }
141
142 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
143
144 bool FGPropertyManager::SetInt (const string &name, int val)
145 {
146   return setIntValue(name.c_str(), val);
147 }
148
149 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
150
151 bool FGPropertyManager::SetLong (const string &name, long val)
152 {
153   return setLongValue(name.c_str(), val);
154 }
155
156 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
157
158 bool FGPropertyManager::SetFloat (const string &name, float val)
159 {
160   return setFloatValue(name.c_str(), val);
161 }
162
163 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
164
165 bool FGPropertyManager::SetDouble (const string &name, double val)
166 {
167   return setDoubleValue(name.c_str(), val);
168 }
169
170 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
171
172 bool FGPropertyManager::SetString (const string &name, const string &val)
173 {
174   return setStringValue(name.c_str(), val.c_str());
175 }
176
177 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
178
179 void FGPropertyManager::SetArchivable (const string &name, bool state )
180 {
181   SGPropertyNode * node = getNode(name.c_str());
182   if (node == 0)
183     cout <<
184            "Attempt to set archive flag for non-existant property "
185            << name << endl;
186   else
187     node->setAttribute(SGPropertyNode::ARCHIVE, state);
188 }
189
190 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
191
192 void FGPropertyManager::SetReadable (const string &name, bool state )
193 {
194   SGPropertyNode * node = getNode(name.c_str());
195   if (node == 0)
196     cout <<
197            "Attempt to set read flag for non-existant property "
198            << name << endl;
199   else
200     node->setAttribute(SGPropertyNode::READ, state);
201 }
202
203 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
204
205 void FGPropertyManager::SetWritable (const string &name, bool state )
206 {
207   SGPropertyNode * node = getNode(name.c_str());
208   if (node == 0)
209     cout <<
210            "Attempt to set write flag for non-existant property "
211            << name << endl;
212   else
213     node->setAttribute(SGPropertyNode::WRITE, state);
214 }
215
216 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
217
218 void FGPropertyManager::Untie (const string &name)
219 {
220   if (!untie(name.c_str()))
221     cout << "Failed to untie property " << name << endl;
222 }
223
224 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
225
226 void FGPropertyManager::Tie (const string &name, bool *pointer, bool useDefault)
227 {
228   if (!tie(name.c_str(), SGRawValuePointer<bool>(pointer),
229                                  useDefault))
230     cout <<
231            "Failed to tie property " << name << " to a pointer" << endl;
232 }
233
234 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
235
236 void FGPropertyManager::Tie (const string &name, int *pointer, 
237                                           bool useDefault )
238 {
239   if (!tie(name.c_str(), SGRawValuePointer<int>(pointer),
240                                  useDefault))
241     cout <<
242            "Failed to tie property " << name << " to a pointer" << endl;
243 }
244
245 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
246
247 void FGPropertyManager::Tie (const string &name, long *pointer, 
248                                           bool useDefault )
249 {
250   if (!tie(name.c_str(), SGRawValuePointer<long>(pointer),
251                                  useDefault))
252     cout <<
253            "Failed to tie property " << name << " to a pointer" << endl;
254 }
255
256 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
257
258 void FGPropertyManager::Tie (const string &name, float *pointer, 
259                                           bool useDefault )
260 {
261   if (!tie(name.c_str(), SGRawValuePointer<float>(pointer),
262                                  useDefault))
263     cout <<
264            "Failed to tie property " << name << " to a pointer" << endl;
265 }
266
267 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
268
269 void FGPropertyManager::Tie (const string &name, double *pointer, 
270                                            bool useDefault)
271 {
272   if (!tie(name.c_str(), SGRawValuePointer<double>(pointer),
273                                  useDefault))
274     cout <<
275            "Failed to tie property " << name << " to a pointer" << endl;
276 }