JSBSim Flight Dynamics Model  1.1.11 (13 Feb 2022)
An Open Source Flight Dynamics and Control Software Library in C++
FGPropertyValue.cpp
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2 
3 Module: FGPropertyValue.cpp
4 Author: Jon Berndt
5 Date started: 12/10/2004
6 Purpose: 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 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29 INCLUDES
30 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
31 
32 #include <assert.h>
33 
34 #include "FGPropertyValue.h"
35 
36 namespace JSBSim {
37 
38 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
39 CLASS IMPLEMENTATION
40 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
41 
42 FGPropertyValue::FGPropertyValue(const std::string& propName,
43  FGPropertyManager* propertyManager)
44  : PropertyManager(propertyManager), PropertyNode(nullptr),
45  PropertyName(propName), Sign(1.0)
46 {
47  if (PropertyName[0] == '-') {
48  PropertyName.erase(0,1);
49  Sign = -1.0;
50  }
51 
52  if (PropertyManager->HasNode(PropertyName))
53  PropertyNode = PropertyManager->GetNode(PropertyName);
54 }
55 
56 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
57 
58 FGPropertyNode* FGPropertyValue::GetNode(void) const
59 {
60  if (!PropertyNode) {
61  FGPropertyNode* node = PropertyManager->GetNode(PropertyName);
62 
63  if (!node)
64  throw(std::string("FGPropertyValue::GetValue() The property " +
65  PropertyName + " does not exist."));
66 
67  PropertyNode = node;
68  }
69 
70  return PropertyNode;
71 }
72 
73 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
74 
75 double FGPropertyValue::GetValue(void) const
76 {
77  return GetNode()->getDoubleValue()*Sign;
78 }
79 
80 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
81 
82 void FGPropertyValue::SetValue(double value)
83 {
84  // SetValue() ignores the Sign flag. So make sure it is never called with a
85  // negative sign.
86  assert(Sign == 1);
87  GetNode()->setDoubleValue(value);
88 }
89 
90 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
91 
92 std::string FGPropertyValue::GetName(void) const
93 {
94  if (PropertyNode)
95  return PropertyNode->GetName();
96  else
97  return PropertyName;
98 }
99 
100 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
101 
102 std::string FGPropertyValue::GetNameWithSign(void) const
103 {
104  string name;
105 
106  if (Sign < 0.0) name ="-";
107 
108  name += GetName();
109 
110  return name;
111 }
112 
113 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
114 
115 std::string FGPropertyValue::GetFullyQualifiedName(void) const
116 {
117  if (PropertyNode)
118  return PropertyNode->GetFullyQualifiedName();
119  else
120  return PropertyName;
121 }
122 
123 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
124 
125 std::string FGPropertyValue::GetPrintableName(void) const
126 {
127  if (PropertyNode)
128  return PropertyNode->GetPrintableName();
129  else
130  return PropertyName;
131 }
132 
133 }