JSBSim Flight Dynamics Model  1.0 (02 March 2017)
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 Software
13  Foundation; either version 2 of the License, or (at your option) any later
14  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 with
22  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
23  Place - Suite 330, Boston, MA 02111-1307, USA.
24 
25  Further information about the GNU Lesser General Public License can also be found on
26  the world wide web at http://www.gnu.org.
27 
28 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29 INCLUDES
30 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
31 
32 #include "FGPropertyValue.h"
33 #include "input_output/FGPropertyManager.h"
34 
35 namespace JSBSim {
36 
37 IDENT(IdSrc,"$Id: FGPropertyValue.cpp,v 1.11 2014/01/13 10:46:03 ehofman Exp $");
38 IDENT(IdHdr,ID_PROPERTYVALUE);
39 
40 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
41 CLASS IMPLEMENTATION
42 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
43 
44 FGPropertyValue::FGPropertyValue(FGPropertyNode* propNode)
45  : PropertyManager(0L), PropertyNode(propNode)
46 {
47  Sign = 1;
48 }
49 
50 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
51 
52 FGPropertyValue::FGPropertyValue(std::string propName, FGPropertyManager* propertyManager)
53  : PropertyManager(propertyManager), PropertyNode(0L)
54 {
55  Sign = 1;
56  if (propName[0] == '-') {
57  propName.erase(0,1);
58  Sign = -1;
59  }
60  PropertyName = propName;
61 }
62 
63 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
64 
65 double FGPropertyValue::GetValue(void) const
66 {
67  FGPropertyNode* node = PropertyNode;
68 
69  if (!PropertyNode) {
70  // The node cannot be cached since this is a const method.
71  node = PropertyManager->GetNode(PropertyName);
72 
73  if (!node) {
74  throw(std::string("FGPropertyValue::GetValue() The property " +
75  PropertyName + " does not exist."));
76  }
77  }
78 
79  return node->getDoubleValue()*Sign;
80 }
81 
82 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
83 
84 std::string FGPropertyValue::GetName(void) const
85 {
86  if (PropertyNode) {
87  return PropertyNode->GetName();
88  } else {
89  return PropertyName;
90  }
91 }
92 
93 }