]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/filtersjb/FGSwitch.h
Compiler warning fixes and small updates
[flightgear.git] / src / FDM / JSBSim / filtersjb / FGSwitch.h
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2
3  Header:       FGSwitch.h
4  Author:       Jon S. Berndt
5  Date started: 12/23/2002
6
7  ------------- Copyright (C)  -------------
8
9  This program is free software; you can redistribute it and/or modify it under
10  the terms of the GNU 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 General Public License for more
17  details.
18
19  You should have received a copy of the GNU 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 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 FGSWITCH_H
34 #define FGSWITCH_H
35
36 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
37 INCLUDES
38 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
39
40 #include "FGFCSComponent.h"
41 #include "../FGConfigFile.h"
42 #include "FGCondition.h"
43
44 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
45 DEFINITIONS
46 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
47
48 #define ID_SWITCH "$Id$"
49
50 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
51 COMMENTS, REFERENCES, and NOTES [use "class documentation" below for API docs]
52 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
53
54 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
55 CLASS DOCUMENTATION
56 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
57
58 /** Encapsulates a switch for the flight control system.
59
60 The SWITCH component models a switch - either on/off or a multi-choice rotary
61 switch. The switch can represent a physical cockpit switch, or can represent a
62 logical switch, where several conditions might need to be satisfied before a
63 particular state is reached. The VALUE of the switch - the output value - is
64 chosen depending on the state of the switch. Each switch is comprised of two or
65 more TESTs. Each TEST has a VALUE associated with it. The first TEST that
66 evaluates to TRUE will set the output value of the switch according to the VALUE
67 parameter belonging to that TEST. Each TEST contains one or more CONDITIONS, which
68 each must be logically related (if there are more than one) given the value of
69 the LOGIC parameter, and which takes the form:
70
71   property conditional property|value
72
73 e.g.
74
75   qbar GE 21.0
76
77 or,
78
79   roll_rate < pitch_rate
80
81 Within a TEST, a CONDITION_GROUP can be specified. A CONDITION_GROUP allows for
82 complex groupings of logical comparisons. Each CONDITION_GROUP contains
83 additional conditions, as well as possibly additional CONDITION_GROUPs.
84
85 <COMPONENT NAME="switch1" TYPE="SWITCH">
86   <TEST LOGIC="{AND|OR|DEFAULT}" OUTPUT="{property|value}">
87     {property} {conditional} {property|value}
88     <CONDITION_GROUP LOGIC="{AND|OR}">
89       {property} {conditional} {property|value}
90       ...
91     </CONDITION_GROUP>
92     ...
93   </TEST>
94   <TEST LOGIC="{AND|OR}" OUTPUT="{property|value}">
95     {property} {conditional} {property|value}
96     ...
97   </TEST>
98   ...
99 </COMPONENT>
100 */
101    
102 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
103 CLASS DECLARATION
104 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
105 namespace JSBSim {
106
107
108 class FGSwitch  : public FGFCSComponent
109 {
110 public:
111   FGSwitch(FGFCS* fcs, FGConfigFile* AC_cfg);
112   ~FGSwitch();
113
114   bool Run(void);
115
116 private:
117   FGFCS* fcs;
118   FGConfigFile* AC_cfg;
119
120   enum eLogic {elUndef=0, eAND, eOR, eDefault};
121   enum eComparison {ecUndef=0, eEQ, eNE, eGT, eGE, eLT, eLE};
122   map <const string, eComparison> mComparison;
123
124   struct test {
125     vector <FGCondition> conditions;
126     eLogic Logic;
127     double OutputVal;
128     FGPropertyManager *OutputProp;
129     
130     double GetValue(void) {
131       if (OutputProp == 0L) return OutputVal;
132       else                  return OutputProp->getDoubleValue();
133     }
134
135     test(void) { // constructor for the test structure
136       Logic      = elUndef;
137       OutputVal  = 0.0;
138       OutputProp = 0L;
139     }
140
141   };
142
143   vector <test> tests;
144   
145   void Debug(int from);
146 };
147 }
148 #endif