JSBSim Flight Dynamics Model  1.1.11 (13 Feb 2022)
An Open Source Flight Dynamics and Control Software Library in C++
FGParameterValue.h
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2 
3  Header: FGParameterValue.h
4  Author: Bertrand Coconnier
5  Date started: December 09 2018
6 
7  --------- Copyright (C) 2018 B. Coconnier (bcoconni@users.sf.net) -----------
8 
9  This program is free software; you can redistribute it and/or modify it under
10  the terms of the GNU Lesser General Public License as published by the Free
11  Software Foundation; either version 2 of the License, or (at your option) any
12  later version.
13 
14  This program is distributed in the hope that it will be useful, but WITHOUT
15  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
17  details.
18 
19  You should have received a copy of the GNU Lesser General Public License along
20  with this program; if not, write to the Free Software Foundation, Inc., 59
21  Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 
23  Further information about the GNU Lesser General Public License can also be
24  found on the world wide web at http://www.gnu.org.
25 
26  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
27  SENTRY
28  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
29 
30 #ifndef FGPARAMETERVALUE_H
31 #define FGPARAMETERVALUE_H
32 
33 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
34  INCLUDES
35  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
36 
37 #include <stdexcept>
38 
39 #include "math/FGRealValue.h"
40 #include "math/FGPropertyValue.h"
41 #include "input_output/FGXMLElement.h"
42 
43 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
44  FORWARD DECLARATIONS
45  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
46 
47 namespace JSBSim {
48 
49 class FGPropertyManager;
50 
51 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
52  CLASS DOCUMENTATION
53  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
54 
59 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
60  DECLARATION: FGParameterValue
61  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
62 
64 {
65 public:
67  string value = el->GetDataLine();
68 
69  if (el->GetNumDataLines() != 1 || value.empty()) {
70  cerr << el->ReadFrom()
71  << "The element <" << el->GetName()
72  << "> must either contain a value number or a property name."
73  << endl;
74  throw invalid_argument("FGParameterValue: Illegal argument defining: " + el->GetName());
75  }
76 
77  Construct(value, pm);
78  }
79 
80  FGParameterValue(const std::string& value, FGPropertyManager* pm) {
81  Construct(value, pm);
82  }
83 
84  double GetValue(void) const override { return param->GetValue(); }
85  bool IsConstant(void) const override { return param->IsConstant(); }
86 
87  std::string GetName(void) const override {
88  FGPropertyValue* v = dynamic_cast<FGPropertyValue*>(param.ptr());
89  if (v)
90  return v->GetNameWithSign();
91  else
92  return to_string(param->GetValue());
93  }
94 
95  bool IsLateBound(void) const {
96  FGPropertyValue* v = dynamic_cast<FGPropertyValue*>(param.ptr());
97  return v != nullptr && v->IsLateBound();
98  }
99 private:
100  FGParameter_ptr param;
101 
102  void Construct(const std::string& value, FGPropertyManager* pm) {
103  if (is_number(value)) {
104  param = new FGRealValue(atof(value.c_str()));
105  } else {
106  // "value" must be a property if execution passes to here.
107  param = new FGPropertyValue(value, pm);
108  }
109  }
110 };
111 
112 typedef SGSharedPtr<FGParameterValue> FGParameterValue_ptr;
113 
114 } // namespace JSBSim
115 
116 #endif
JSBSim::FGRealValue
Represents a real value.
Definition: FGRealValue.h:57
JSBSim::Element::GetNumDataLines
unsigned int GetNumDataLines(void)
Returns the number of lines of data stored.
Definition: FGXMLElement.h:189
JSBSim::FGParameter
Represents various types of parameters.
Definition: FGParameter.h:58
JSBSim::FGPropertyValue
Represents a property value which can use late binding.
Definition: FGPropertyValue.h:59
JSBSim::FGParameterValue
Represents a either a real value or a property value.
Definition: FGParameterValue.h:63
JSBSim::Element::GetDataLine
std::string GetDataLine(unsigned int i=0)
Gets a line of data belonging to an element.
Definition: FGXMLElement.cpp:333
JSBSim::Element::GetName
const std::string & GetName(void) const
Retrieves the element name.
Definition: FGXMLElement.h:179
JSBSim::Element::ReadFrom
std::string ReadFrom(void) const
Return a string that contains a description of the location where the current XML element was read fr...
Definition: FGXMLElement.cpp:738
JSBSim::FGPropertyManager
Definition: FGPropertyManager.h:373
JSBSim::Element
Definition: FGXMLElement.h:143