JSBSim Flight Dynamics Model  1.1.11 (13 Feb 2022)
An Open Source Flight Dynamics and Control Software Library in C++
FGDistributor.h
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2 
3  Header: FGDistributor.h
4  Author: Jon S. Berndt
5  Date started: 09/27/2013
6 
7  ------------- Copyright (C) 2013 jon@jsbsim.org -------------
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 HISTORY
27 --------------------------------------------------------------------------------
28 
29 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
30 SENTRY
31 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
32 
33 #ifndef FGDISTRIBUTOR_H
34 #define FGDISTRIBUTOR_H
35 
36 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
37 INCLUDES
38 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
39 
40 #include "FGFCSComponent.h"
41 #include "math/FGCondition.h"
42 #include "math/FGParameterValue.h"
43 
44 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
45 FORWARD DECLARATIONS
46 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
47 
48 namespace JSBSim {
49 
50 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
51 CLASS DOCUMENTATION
52 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
53 
121 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
122 CLASS DECLARATION
123 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
124 
126 {
127 public:
132  FGDistributor(FGFCS* fcs, Element* element);
133 
135  ~FGDistributor();
136 
139  bool Run(void) override;
140 
141 private:
142 
143  enum eType {eInclusive=0, eExclusive} Type;
144 
145  class PropValPair {
146  public:
147  PropValPair(const std::string& prop, const std::string& val,
148  FGPropertyManager* propMan)
149  : Prop(new FGPropertyValue(prop, propMan)),
150  Val(new FGParameterValue(val, propMan)) {}
151 
152  void SetPropToValue() {
153  try {
154  Prop->SetValue(Val->GetValue());
155  }
156  catch(...) {
157  throw(Prop->GetName()+" in distributor component is not known");
158  }
159  }
160 
161  std::string GetPropName() { return Prop->GetName(); }
162  std::string GetValString() { return Val->GetName(); }
163  bool GetLateBoundProp() { return Prop->IsLateBound(); }
164  bool GetLateBoundValue() {return Val->IsLateBound();
165  }
166  private:
167  FGPropertyValue_ptr Prop;
168  FGParameterValue_ptr Val;
169  };
170 
171  class Case {
172  public:
173  Case() : Test(nullptr) {}
174 
175  ~Case() {
176  for (auto pair: PropValPairs) delete pair;
177  }
178 
179  void SetTest(FGCondition* test) {Test = test;}
180  FGCondition* GetTest(void) {return Test;}
181  void AddPropValPair(PropValPair* pvPair) {PropValPairs.push_back(pvPair);}
182  void SetPropValPairs() {
183  for (auto pair: PropValPairs) pair->SetPropToValue();
184  }
185  std::vector<PropValPair*>::const_iterator IterPropValPairs(void) const
186  { return PropValPairs.cbegin(); }
187  std::vector<PropValPair*>::const_iterator EndPropValPairs(void) const
188  { return PropValPairs.cend(); }
189  bool HasTest() {return Test != nullptr;}
190  bool GetTestResult() { return Test->Evaluate(); }
191 
192  private:
193  FGCondition* Test;
194  std::vector <PropValPair*> PropValPairs;
195  };
196 
197  std::vector <Case*> Cases;
198 
199  void Debug(int from) override;
200 };
201 }
202 #endif
JSBSim::FGDistributor::FGDistributor
FGDistributor(FGFCS *fcs, Element *element)
Constructor.
Definition: FGDistributor.cpp:52
JSBSim::FGDistributor::~FGDistributor
~FGDistributor()
Destructor.
Definition: FGDistributor.cpp:86
JSBSim::FGFCSComponent
Base class for JSBSim Flight Control System Components.
Definition: FGFCSComponent.h:84
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::FGFCS
Encapsulates the Flight Control System (FCS) functionality.
Definition: FGFCS.h:187
JSBSim::FGDistributor::Run
bool Run(void) override
Executes the distributor logic.
Definition: FGDistributor.cpp:94
JSBSim::FGCondition
Encapsulates a condition, which is used in parts of JSBSim including switches.
Definition: FGCondition.h:66
JSBSim::FGPropertyManager
Definition: FGPropertyManager.h:373
JSBSim::Element
Definition: FGXMLElement.h:143
JSBSim::FGDistributor
Encapsulates a distributor for the flight control system.
Definition: FGDistributor.h:125