JSBSim Flight Dynamics Model 1.2.3 (07 Jun 2025)
An Open Source Flight Dynamics and Control Software Library in C++
Loading...
Searching...
No Matches
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 Lesser 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 Lesser General Public License for more
18 details.
19
20 You should have received a copy of the GNU Lesser 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 Lesser General Public License can also be found on
25 the world wide web at http://www.gnu.org.
26
27%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
28INCLUDES
29%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
30
31#include <assert.h>
32#include "FGPropertyManager.h"
33
34/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35DEFINITIONS
36%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
37
38
39/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
40FORWARD DECLARATIONS
41%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
42
43using namespace std;
44
45/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
46COMMENTS, REFERENCES, and NOTES [use "class documentation" below for API docs]
47%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
48*/
49
50namespace JSBSim {
51
52//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
53
55{
56 for(auto& property: tied_properties)
57 property.untie();
58
59 tied_properties.clear();
60}
61
62//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
63
64void FGPropertyManager::Unbind(const void* instance)
65{
66 auto it = tied_properties.begin();
67
68 while(it != tied_properties.end()) {
69 auto property = it++;
70 if (property->BindingInstance == instance) {
71 property->untie();
72 tied_properties.erase(property);
73 }
74 }
75}
76
77//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
78
79string FGPropertyManager::mkPropertyName(string name, bool lowercase) {
80
81 /* do this two pass to avoid problems with characters getting skipped
82 because the index changed */
83 unsigned i;
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]) )
88 name[i]='-';
89 }
90
91 return name;
92}
93
94//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
95
96string GetPrintableName(const SGPropertyNode* node)
97{
98 string temp_string(node->getNameString());
99 size_t initial_location=0;
100 size_t found_location;
101
102 found_location = temp_string.rfind("/");
103 if (found_location != string::npos)
104 temp_string = temp_string.substr(found_location);
105
106 found_location = temp_string.find('_',initial_location);
107 while (found_location != string::npos) {
108 temp_string.replace(found_location,1," ");
109 initial_location = found_location+1;
110 found_location = temp_string.find('_',initial_location);
111 }
112 return temp_string;
113}
114
115//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
116
117string GetFullyQualifiedName(const SGPropertyNode* node)
118{
119 string fqname = node->getDisplayName(true);
120 const SGPropertyNode* parent = node->getParent();
121 if (!parent) return "/"; // node is the root.
122
123 while(parent) {
124 fqname = parent->getDisplayName(true) + "/" + fqname;
125 parent = parent->getParent();
126 }
127
128 return fqname;
129}
130
131//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
132
133string GetRelativeName(const SGPropertyNode* node, const string &path)
134{
135 string temp_string = GetFullyQualifiedName(node);
136 size_t len = path.length();
137 if ( (len > 0) && (temp_string.substr(0,len) == path) ) {
138 temp_string = temp_string.erase(0,len);
139 }
140 return temp_string;
141}
142
143//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
144
145void FGPropertyManager::Untie(const string &name)
146{
147 SGPropertyNode* property = root->getNode(name.c_str());
148 if (!property) {
149 cerr << "Attempt to untie a non-existant property." << name << endl;
150 return;
151 }
152
153 Untie(property);
154}
155
156//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
157
159{
160 const string& name = property->getNameString();
161
162 assert(property->isTied());
163
164 for (auto it = tied_properties.begin(); it != tied_properties.end(); ++it) {
165 if (it->node.ptr() == property) {
166 it->untie();
167 tied_properties.erase(it);
168 if (FGJSBBase::debug_lvl & 0x20) cout << "Untied " << name << endl;
169 return;
170 }
171 }
172
173 cerr << "Failed to untie property " << name << endl
174 << "JSBSim is not the owner of this property." << endl;
175}
176} // namespace JSBSim
void Untie(const std::string &name)
Untie a property from an external data source.
std::string mkPropertyName(std::string name, bool lowercase)
Property-ify a name replaces spaces with '-' and, optionally, makes name all lower case.
void Unbind(void)
Unbind all properties bound by this manager to an external data source.
A node in a property tree.
Definition props.hxx:754
bool isTied() const
Test whether this node is bound to an external data source.
Definition props.hxx:1356
SGPropertyNode * getParent()
Get a non-const pointer to the node's parent.
Definition props.hxx:839
std::string getDisplayName(bool simplify=false) const
Get the node's pretty display name, with subscript when needed.
const std::string & getNameString() const
Get the node's simple name as a string.
Definition props.hxx:822