32 #include "FGPropertyManager.h"
54 void FGPropertyManager::Unbind(
void)
56 for(
auto& prop: tied_properties)
59 tied_properties.clear();
64 string FGPropertyManager::mkPropertyName(
string name,
bool lowercase) {
69 for(i=0;i<name.length();i++) {
70 if( lowercase && isupper(name[i]) )
71 name[i]=tolower(name[i]);
72 else if( isspace(name[i]) )
82 FGPropertyNode::GetNode (
const string &path,
bool create)
84 SGPropertyNode* node = getNode(path.c_str(), create);
86 cerr <<
"FGPropertyManager::GetNode() No node found for " << path << endl;
94 FGPropertyNode::GetNode (
const string &relpath,
int index,
bool create)
96 SGPropertyNode* node = getNode(relpath.c_str(), index, create);
98 cerr <<
"FGPropertyManager::GetNode() No node found for " << relpath
99 <<
"[" << index <<
"]" << endl;
101 return (FGPropertyNode*)node;
106 bool FGPropertyNode::HasNode (
const string &path)
108 const SGPropertyNode* node = getNode(path.c_str(),
false);
114 string FGPropertyNode::GetPrintableName(
void )
const
116 string temp_string(getNameString());
117 size_t initial_location=0;
118 size_t found_location;
120 found_location = temp_string.rfind(
"/");
121 if (found_location != string::npos)
122 temp_string = temp_string.substr(found_location);
124 found_location = temp_string.find(
'_',initial_location);
125 while (found_location != string::npos) {
126 temp_string.replace(found_location,1,
" ");
127 initial_location = found_location+1;
128 found_location = temp_string.find(
'_',initial_location);
135 string FGPropertyNode::GetFullyQualifiedName(
void)
const
137 vector<string> stack;
138 stack.push_back( getDisplayName(
true) );
139 const SGPropertyNode* tmpn=getParent();
142 stack.push_back( tmpn->getDisplayName(
true) );
143 if( !tmpn->getParent() )
146 tmpn=tmpn->getParent();
150 for(
size_t i=stack.size()-1;i>0;i--) {
161 string FGPropertyNode::GetRelativeName(
const string &path )
const
163 string temp_string = GetFullyQualifiedName();
164 size_t len = path.length();
165 if ( (len > 0) && (temp_string.substr(0,len) == path) ) {
166 temp_string = temp_string.erase(0,len);
175 bool FGPropertyNode::GetBool (
const string &name,
bool defaultValue)
const
177 return getBoolValue(name.c_str(), defaultValue);
182 int FGPropertyNode::GetInt (
const string &name,
int defaultValue )
const
184 return getIntValue(name.c_str(), defaultValue);
189 int FGPropertyNode::GetLong (
const string &name,
long defaultValue )
const
191 return getLongValue(name.c_str(), defaultValue);
196 float FGPropertyNode::GetFloat (
const string &name,
float defaultValue )
const
198 return getFloatValue(name.c_str(), defaultValue);
203 double FGPropertyNode::GetDouble (
const string &name,
double defaultValue )
const
205 return getDoubleValue(name.c_str(), defaultValue);
210 string FGPropertyNode::GetString (
const string &name,
string defaultValue )
const
212 return string(getStringValue(name.c_str(), defaultValue.c_str()));
217 bool FGPropertyNode::SetBool (
const string &name,
bool val)
219 return setBoolValue(name.c_str(), val);
224 bool FGPropertyNode::SetInt (
const string &name,
int val)
226 return setIntValue(name.c_str(), val);
231 bool FGPropertyNode::SetLong (
const string &name,
long val)
233 return setLongValue(name.c_str(), val);
238 bool FGPropertyNode::SetFloat (
const string &name,
float val)
240 return setFloatValue(name.c_str(), val);
245 bool FGPropertyNode::SetDouble (
const string &name,
double val)
247 return setDoubleValue(name.c_str(), val);
252 bool FGPropertyNode::SetString (
const string &name,
const string &val)
254 return setStringValue(name.c_str(), val.c_str());
259 void FGPropertyNode::SetArchivable (
const string &name,
bool state )
261 SGPropertyNode * node = getNode(name.c_str());
264 "Attempt to set archive flag for non-existent property "
267 node->setAttribute(SGPropertyNode::ARCHIVE, state);
272 void FGPropertyNode::SetReadable (
const string &name,
bool state )
274 SGPropertyNode * node = getNode(name.c_str());
277 "Attempt to set read flag for non-existant property "
280 node->setAttribute(SGPropertyNode::READ, state);
285 void FGPropertyNode::SetWritable (
const string &name,
bool state )
287 SGPropertyNode * node = getNode(name.c_str());
290 "Attempt to set write flag for non-existant property "
293 node->setAttribute(SGPropertyNode::WRITE, state);
298 void FGPropertyManager::Untie(
const string &name)
300 SGPropertyNode*
property = root->getNode(name.c_str());
302 cerr <<
"Attempt to untie a non-existant property." << name << endl;
311 void FGPropertyManager::Untie(SGPropertyNode *property)
313 const string& name =
property->getNameString();
315 assert(property->isTied());
317 for (
auto it = tied_properties.begin(); it != tied_properties.end(); ++it) {
318 if (*it == property) {
320 tied_properties.erase(it);
321 if (FGJSBBase::debug_lvl & 0x20) cout <<
"Untied " << name << endl;
326 cerr <<
"Failed to untie property " << name << endl
327 <<
"JSBSim is not the owner of this property." << endl;