JSBSim Flight Dynamics Model 1.3.0 (09 Apr 2026)
An Open Source Flight Dynamics and Control Software Library in C++
Loading...
Searching...
No Matches
FGPropertyValue.cpp
1/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2
3Module: FGPropertyValue.cpp
4Author: Jon Berndt
5Date started: 12/10/2004
6Purpose: Stores property values
7
8 ------------- Copyright (C) 2001 Jon S. Berndt (jon@jsbsim.org) -------------
9 ------ Copyright (C) 2010 - 2011 Anders Gidenstam (anders(at)gidenstam.org) -
10
11 This program is free software; you can redistribute it and/or modify it under
12 the terms of the GNU Lesser General Public License as published by the Free
13 Software Foundation; either version 2 of the License, or (at your option) any
14 later version.
15
16 This program is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
19 details.
20
21 You should have received a copy of the GNU Lesser General Public License along
22 with this program; if not, write to the Free Software Foundation, Inc., 59
23 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24
25 Further information about the GNU Lesser General Public License can also be
26 found on the world wide web at http://www.gnu.org.
27
28%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29INCLUDES
30%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
31
32#include <assert.h>
33
34#include "FGPropertyValue.h"
35
36using namespace std;
37
38namespace JSBSim {
39
40/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
41CLASS IMPLEMENTATION
42%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
43
44FGPropertyValue::FGPropertyValue(const std::string& propName,
45 std::shared_ptr<FGPropertyManager> propertyManager, Element* el)
46 : PropertyManager(propertyManager), PropertyNode(nullptr), XML_def(el),
47 PropertyName(propName), Sign(1.0)
48{
49 if (PropertyName[0] == '-') {
50 PropertyName.erase(0,1);
51 Sign = -1.0;
52 }
53
54 if (PropertyManager->HasNode(PropertyName)) {
55 PropertyNode = PropertyManager->GetNode(PropertyName);
56
57 assert(PropertyNode);
58 XML_def = nullptr; // Now that the property is bound, we no longer need that.
59 }
60}
61
62//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
63
64SGPropertyNode* FGPropertyValue::GetNode(void) const
65{
66 if (PropertyNode) return PropertyNode;
67
68 // Manage late binding.
69 PropertyNode = PropertyManager->GetNode(PropertyName);
70 if (!PropertyNode) {
71 unique_ptr<LogException> err;
72 if (XML_def)
73 err.reset(new XMLLogException(XML_def));
74 else
75 err.reset(new LogException);
76
77 *err << "FGPropertyValue::GetValue() The property " << PropertyName
78 << " does not exist\n";
79 throw *err;
80 }
81
82 XML_def = nullptr; // Now that the property is bound, we no longer need that.
83
84 return PropertyNode;
85}
86
87//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
88
89double FGPropertyValue::GetValue(void) const
90{
91 return GetNode()->getDoubleValue()*Sign;
92}
93
94//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
95
96void FGPropertyValue::SetValue(double value)
97{
98 // SetValue() ignores the Sign flag. So make sure it is never called with a
99 // negative sign.
100 assert(Sign == 1);
101 GetNode()->setDoubleValue(value);
102}
103
104//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
105
106std::string FGPropertyValue::GetName(void) const
107{
108 if (PropertyNode)
109 return PropertyNode->getNameString();
110 else
111 return PropertyName;
112}
113
114//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
115
116std::string FGPropertyValue::GetNameWithSign(void) const
117{
118 string name;
119
120 if (Sign < 0.0) name ="-";
121
122 name += GetName();
123
124 return name;
125}
126
127//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
128
129std::string FGPropertyValue::GetFullyQualifiedName(void) const
130{
131 if (PropertyNode)
132 return JSBSim::GetFullyQualifiedName(PropertyNode);
133 else
134 return PropertyName;
135}
136
137//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
138
139std::string FGPropertyValue::GetPrintableName(void) const
140{
141 if (PropertyNode)
142 return JSBSim::GetPrintableName(PropertyNode);
143 else
144 return PropertyName;
145}
146
147}
A node in a property tree.
Definition props.hxx:747
double getDoubleValue() const
Get a double value for this node.
Main namespace for the JSBSim Flight Dynamics Model.
Definition FGFDMExec.cpp:71