Debian Codegraph @

src/FDM/JSBSim/math/FGPropertyValue.cpp

raw symbols SCIP
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 ([email protected]) -------------
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 using namespace std;
37
38 namespace JSBSim {
39
40 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
41 CLASS IMPLEMENTATION
42 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
43
44 FGPropertyValue::FGPropertyValue(const std::string& propName,
45 FGPropertyManager* propertyManager)
46 : PropertyManager(propertyManager), PropertyNode(nullptr),
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
58 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
59
60 FGPropertyNode* FGPropertyValue::GetNode(void) const
61 {
62 if (!PropertyNode) {
63 FGPropertyNode* node = PropertyManager->GetNode(PropertyName);
64
65 if (!node)
66 throw BaseException("FGPropertyValue::GetValue() The property " +
67 PropertyName + " does not exist.");
68
69 PropertyNode = node;
70 }
71
72 return PropertyNode;
73 }
74
75 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
76
77 double FGPropertyValue::GetValue(void) const
78 {
79 return GetNode()->getDoubleValue()*Sign;
80 }
81
82 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
83
84 void FGPropertyValue::SetValue(double value)
85 {
86 // SetValue() ignores the Sign flag. So make sure it is never called with a
87 // negative sign.
88 assert(Sign == 1);
89 GetNode()->setDoubleValue(value);
90 }
91
92 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
93
94 std::string FGPropertyValue::GetName(void) const
95 {
96 if (PropertyNode)
97 return PropertyNode->GetName();
98 else
99 return PropertyName;
100 }
101
102 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
103
104 std::string FGPropertyValue::GetNameWithSign(void) const
105 {
106 string name;
107
108 if (Sign < 0.0) name ="-";
109
110 name += GetName();
111
112 return name;
113 }
114
115 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
116
117 std::string FGPropertyValue::GetFullyQualifiedName(void) const
118 {
119 if (PropertyNode)
120 return PropertyNode->GetFullyQualifiedName();
121 else
122 return PropertyName;
123 }
124
125 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
126
127 std::string FGPropertyValue::GetPrintableName(void) const
128 {
129 if (PropertyNode)
130 return PropertyNode->GetPrintableName();
131 else
132 return PropertyName;
133 }
134
135 }