32 #include "FGPropertyManager.h"
54 void FGPropertyManager::Unbind(
void)
56 for(
auto& property: tied_properties)
59 tied_properties.clear();
64 void FGPropertyManager::Unbind(
const void* instance)
66 auto it = tied_properties.begin();
68 while(it != tied_properties.end()) {
70 if (property->BindingInstance == instance) {
72 tied_properties.erase(property);
79 string FGPropertyManager::mkPropertyName(
string name,
bool lowercase) {
84 for(i=0;i<name.length();i++) {
85 if( lowercase && isupper(name[i]) )
86 name[i]=tolower(name[i]);
87 else if( isspace(name[i]) )
97 FGPropertyNode::GetNode (
const string &path,
bool create)
99 SGPropertyNode* node = getNode(path.c_str(), create);
101 cerr <<
"FGPropertyManager::GetNode() No node found for " << path << endl;
109 FGPropertyNode::GetNode (
const string &relpath,
int index,
bool create)
111 SGPropertyNode* node = getNode(relpath.c_str(), index, create);
113 cerr <<
"FGPropertyManager::GetNode() No node found for " << relpath
114 <<
"[" << index <<
"]" << endl;
116 return (FGPropertyNode*)node;
121 bool FGPropertyNode::HasNode (
const string &path)
123 const SGPropertyNode* node = getNode(path.c_str(),
false);
129 string FGPropertyNode::GetPrintableName(
void )
const
131 string temp_string(getNameString());
132 size_t initial_location=0;
133 size_t found_location;
135 found_location = temp_string.rfind(
"/");
136 if (found_location != string::npos)
137 temp_string = temp_string.substr(found_location);
139 found_location = temp_string.find(
'_',initial_location);
140 while (found_location != string::npos) {
141 temp_string.replace(found_location,1,
" ");
142 initial_location = found_location+1;
143 found_location = temp_string.find(
'_',initial_location);
150 string FGPropertyNode::GetFullyQualifiedName(
void)
const
153 const SGPropertyNode* node =
this;
155 fqname = node->getDisplayName(
true) +
"/" + fqname;
156 node = node->getParent();
160 size_t len = std::max<size_t>(1, fqname.size()-1);
161 return fqname.substr(0, len);
166 string FGPropertyNode::GetRelativeName(
const string &path )
const
168 string temp_string = GetFullyQualifiedName();
169 size_t len = path.length();
170 if ( (len > 0) && (temp_string.substr(0,len) == path) ) {
171 temp_string = temp_string.erase(0,len);
180 bool FGPropertyNode::GetBool (
const string &name,
bool defaultValue)
const
182 return getBoolValue(name.c_str(), defaultValue);
187 int FGPropertyNode::GetInt (
const string &name,
int defaultValue )
const
189 return getIntValue(name.c_str(), defaultValue);
194 int FGPropertyNode::GetLong (
const string &name,
long defaultValue )
const
196 return getLongValue(name.c_str(), defaultValue);
201 float FGPropertyNode::GetFloat (
const string &name,
float defaultValue )
const
203 return getFloatValue(name.c_str(), defaultValue);
208 double FGPropertyNode::GetDouble (
const string &name,
double defaultValue )
const
210 return getDoubleValue(name.c_str(), defaultValue);
215 string FGPropertyNode::GetString (
const string &name,
string defaultValue )
const
217 return string(getStringValue(name.c_str(), defaultValue.c_str()));
222 bool FGPropertyNode::SetBool (
const string &name,
bool val)
224 return setBoolValue(name.c_str(), val);
229 bool FGPropertyNode::SetInt (
const string &name,
int val)
231 return setIntValue(name.c_str(), val);
236 bool FGPropertyNode::SetLong (
const string &name,
long val)
238 return setLongValue(name.c_str(), val);
243 bool FGPropertyNode::SetFloat (
const string &name,
float val)
245 return setFloatValue(name.c_str(), val);
250 bool FGPropertyNode::SetDouble (
const string &name,
double val)
252 return setDoubleValue(name.c_str(), val);
257 bool FGPropertyNode::SetString (
const string &name,
const string &val)
259 return setStringValue(name.c_str(), val.c_str());
264 void FGPropertyNode::SetArchivable (
const string &name,
bool state )
266 SGPropertyNode * node = getNode(name.c_str());
269 "Attempt to set archive flag for non-existent property "
272 node->setAttribute(SGPropertyNode::ARCHIVE, state);
277 void FGPropertyNode::SetReadable (
const string &name,
bool state )
279 SGPropertyNode * node = getNode(name.c_str());
282 "Attempt to set read flag for non-existant property "
285 node->setAttribute(SGPropertyNode::READ, state);
290 void FGPropertyNode::SetWritable (
const string &name,
bool state )
292 SGPropertyNode * node = getNode(name.c_str());
295 "Attempt to set write flag for non-existant property "
298 node->setAttribute(SGPropertyNode::WRITE, state);
303 void FGPropertyManager::Untie(
const string &name)
305 SGPropertyNode*
property = root->getNode(name.c_str());
307 cerr <<
"Attempt to untie a non-existant property." << name << endl;
316 void FGPropertyManager::Untie(SGPropertyNode *property)
318 const string& name =
property->getNameString();
320 assert(property->isTied());
322 for (
auto it = tied_properties.begin(); it != tied_properties.end(); ++it) {
323 if (it->node.ptr() == property) {
325 tied_properties.erase(it);
326 if (FGJSBBase::debug_lvl & 0x20) cout <<
"Untied " << name << endl;
331 cerr <<
"Failed to untie property " << name << endl
332 <<
"JSBSim is not the owner of this property." << endl;
Class wrapper for property handling.