FlightGear next
FGDistributor.h
Go to the documentation of this file.
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
26HISTORY
27--------------------------------------------------------------------------------
28
29%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
30SENTRY
31%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
32
33#ifndef FGDISTRIBUTOR_H
34#define FGDISTRIBUTOR_H
35
36/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
37INCLUDES
38%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
39
40#include "FGFCSComponent.h"
41#include "math/FGCondition.h"
43
44/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
45FORWARD DECLARATIONS
46%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
47
48namespace JSBSim {
49
50/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
51CLASS DOCUMENTATION
52%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
53
120
121/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
122CLASS DECLARATION
123%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
124
126{
127public:
132 FGDistributor(FGFCS* fcs, Element* element);
133
136
139 bool Run(void) override;
140
141private:
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:
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
Encapsulates a condition, which is used in parts of JSBSim including switches.
Definition FGCondition.h:67
~FGDistributor()
Destructor.
bool Run(void) override
Executes the distributor logic.
FGDistributor(FGFCS *fcs, Element *element)
Constructor.
FGFCSComponent(FGFCS *fcs, Element *el)
Constructor.
Represents a either a real value or a property value.
Represents a property value which can use late binding.
SGSharedPtr< FGPropertyValue > FGPropertyValue_ptr
SGSharedPtr< FGParameterValue > FGParameterValue_ptr