]> git.mxchange.org Git - flightgear.git/blob - src/Autopilot/logic.cxx
Fix build on Windows
[flightgear.git] / src / Autopilot / logic.cxx
1 // logic.cxx - Base class for logic components
2 //
3 // Written by Torsten Dreyer
4 //
5 // Copyright (C) 2004  Curtis L. Olson  - http://www.flightgear.org/~curt
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 // General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20 //
21
22 #include "logic.hxx"
23
24 using namespace FGXMLAutopilot;
25
26 bool Logic::get_input() const
27 {
28   // return state of first configured condition
29   InputMap::const_iterator it = _input.begin();
30   if( it == _input.end() ) return false; // no inputs?
31   return (*it).second->test();
32 }
33
34 void Logic::set_output( bool value )
35 {
36   // respect global inverted flag
37   if( _inverted ) value = !value;
38
39   // set all outputs to the given value
40   for( OutputMap::iterator it = _output.begin(); it != _output.end(); it++ )
41     (*it).second->setValue( value );
42 }
43
44 bool Logic::get_output() const
45 {
46   OutputMap::const_iterator it = _output.begin();
47   return it != _output.end() ? (*it).second->getValue() : false;
48 }
49
50 void Logic::update( bool firstTime, double dt )
51 {
52   set_output( get_input() );
53 }
54