JSBSim Flight Dynamics Model  1.0 (02 March 2017)
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 Software
11  Foundation; either version 2 of the License, or (at your option) any later
12  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 with
20  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21  Place - Suite 330, Boston, MA 02111-1307, USA.
22 
23  Further information about the GNU Lesser General Public License can also be found on
24  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 <iostream>
41 #include <cstdlib>
42 
43 #include "FGFCSComponent.h"
44 #include "math/FGCondition.h"
45 #include "math/FGPropertyValue.h"
46 #include "math/FGRealValue.h"
47 
48 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
49 DEFINITIONS
50 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
51 
52 #define ID_DISTRIBUTOR "$Id: FGDistributor.h,v 1.7 2015/03/28 14:49:02 bcoconni Exp $"
53 
54 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
55 FORWARD DECLARATIONS
56 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
57 
58 namespace JSBSim {
59 
60 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
61 CLASS DOCUMENTATION
62 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
63 
105 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
106 CLASS DECLARATION
107 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
108 
110 {
111 public:
116  FGDistributor(FGFCS* fcs, Element* element);
117 
119  ~FGDistributor();
120 
123  bool Run(void);
124 
125 private:
126 
127  enum eType {eInclusive=0, eExclusive} Type;
128 
129  class PropValPair {
130  public:
131  PropValPair(std::string prop, std::string val, FGPropertyManager* propMan) {
132  // Process property to be set
133  PropMan = propMan;
134  sign = 1;
135  FGPropertyNode *node = propMan->GetNode(prop, false);
136  if (node) PropNode = node;
137  else PropNode = 0;
138  PropName = prop;
139 
140  // Process set value
141  LateBoundValue = false;
142  Val = 0;
143  ValString = val;
144  if (is_number(ValString)) {
145  Val = new FGRealValue(atof(ValString.c_str()));
146  } else {
147  // "value" must be a property if execution passes to here.
148  if (ValString[0] == '-') {
149  sign = -1;
150  ValString.erase(0,1);
151  }
152  node = propMan->GetNode(ValString, false); // Reuse the node variable
153  if (node) Val = new FGPropertyValue(node);
154  else {
155  Val = new FGPropertyValue(ValString, propMan);
156  LateBoundValue = true;
157  }
158  }
159  }
160 
161  ~PropValPair() {
162  delete PropNode;
163  delete PropMan;
164  }
165 
166  void SetPropToValue() {
167  if (PropNode == 0) {
168  if (PropMan->HasNode(PropName)) {
169  PropNode = PropMan->GetNode(PropName);
170  } else {
171  throw(PropName+" in distributor component is not known");
172  }
173  }
174  PropNode->setDoubleValue(Val->GetValue()*sign);
175  }
176 
177  std::string GetPropName() {return PropName;}
178  std::string GetValString() {return ValString;}
179  FGPropertyNode* GetPropNode() {return PropNode;}
180  bool GetLateBoundValue() {return LateBoundValue;}
181  private:
182  std::string PropName;
183  FGPropertyNode* PropNode;
184  FGPropertyManager* PropMan;
185  FGParameter* Val;
186  std::string ValString;
187  bool LateBoundValue;
188  int sign;
189  };
190 
191  class Case {
192  public:
193  Case() {
194  Test = 0;
195  }
196 
197  ~Case() {
198  for (unsigned int i=0; i<PropValPairs.size(); i++) delete PropValPairs[i];
199  PropValPairs.clear();
200  }
201 
202  void SetTest(FGCondition* test) {Test = test;}
203  FGCondition* GetTest(void) {return Test;}
204  void AddPropValPair(PropValPair* pvPair) {PropValPairs.push_back(pvPair);}
205  void SetPropValPairs() {
206  for (unsigned int i=0; i<PropValPairs.size(); i++) PropValPairs[i]->SetPropToValue();
207  }
208  PropValPair* GetPropValPair(unsigned int idx) { return PropValPairs[idx]; }
209  size_t GetNumPropValPairs(void) {return PropValPairs.size();}
210  bool HasTest() {return (Test != 0);}
211  bool GetTestResult() { return Test->Evaluate(); }
212 
213  private:
214  FGCondition* Test;
215  std::vector <PropValPair*> PropValPairs;
216  };
217 
218  std::vector <Case*> Cases;
219 
220  void Debug(int from);
221 };
222 }
223 #endif
~FGDistributor()
Destructor.
Represents a property value which can use late binding.
Class wrapper for property handling.
Represents a real value.
Definition: FGRealValue.h:63
Represents various types of parameters.
Definition: FGParameter.h:63
Encapsulates the Flight Control System (FCS) functionality.
Definition: FGFCS.h:193
bool Run(void)
Executes the distributor logic.
Encapsulates a distributor for the flight control system.
Base class for JSBSim Flight Control System Components.
Encapsulates a condition, which is used in parts of JSBSim including switches.
Definition: FGCondition.h:70
FGDistributor(FGFCS *fcs, Element *element)
Constructor.