Loading [MathJax]/extensions/tex2jax.js
JSBSim Flight Dynamics Model 1.2.2 (22 Mar 2025)
An Open Source Flight Dynamics and Control Software Library in C++
All Classes Functions Variables Enumerations Enumerator Friends Pages
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
64FGPropertyNode* FGPropertyValue::GetNode(void) const
65{
66 if (PropertyNode) return PropertyNode;
67
68 // Manage late binding.
69 PropertyNode = PropertyManager->GetNode(PropertyName);
70 if (!PropertyNode) {
71 if (XML_def)
72 cerr << XML_def->ReadFrom()
73 << "Property " << PropertyName << " does not exist" << endl;
74 throw BaseException("FGPropertyValue::GetValue() The property " +
75 PropertyName + " does not exist.");
76 }
77
78 XML_def = nullptr; // Now that the property is bound, we no longer need that.
79
80 return PropertyNode;
81}
82
83//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
84
85double FGPropertyValue::GetValue(void) const
86{
87 return GetNode()->getDoubleValue()*Sign;
88}
89
90//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
91
92void FGPropertyValue::SetValue(double value)
93{
94 // SetValue() ignores the Sign flag. So make sure it is never called with a
95 // negative sign.
96 assert(Sign == 1);
97 GetNode()->setDoubleValue(value);
98}
99
100//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
101
102std::string FGPropertyValue::GetName(void) const
103{
104 if (PropertyNode)
105 return PropertyNode->GetName();
106 else
107 return PropertyName;
108}
109
110//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
111
112std::string FGPropertyValue::GetNameWithSign(void) const
113{
114 string name;
115
116 if (Sign < 0.0) name ="-";
117
118 name += GetName();
119
120 return name;
121}
122
123//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
124
125std::string FGPropertyValue::GetFullyQualifiedName(void) const
126{
127 if (PropertyNode)
128 return PropertyNode->GetFullyQualifiedName();
129 else
130 return PropertyName;
131}
132
133//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
134
135std::string FGPropertyValue::GetPrintableName(void) const
136{
137 if (PropertyNode)
138 return PropertyNode->GetPrintableName();
139 else
140 return PropertyName;
141}
142
143}