1 // logic.cxx - Base class for logic components
3 // Written by Torsten Dreyer
5 // Copyright (C) 2004 Curtis L. Olson - http://www.flightgear.org/~curt
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.
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.
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.
22 // for some obscure reason, MSVC needs this to compile
27 #include <simgear/math/SGMath.hxx>
32 using namespace FGXMLAutopilot;
34 bool Logic::get_input() const
36 // return state of first configured condition
37 InputMap::const_iterator it = _input.begin();
38 if( it == _input.end() ) return false; // no inputs?
39 return (*it).second->test();
42 void Logic::set_output( bool value )
44 // respect global inverted flag
45 if( _inverted ) value = !value;
47 // set all outputs to the given value
48 for( OutputMap::iterator it = _output.begin(); it != _output.end(); it++ )
49 (*it).second->setValue( value );
52 bool Logic::get_output() const
54 OutputMap::const_iterator it = _output.begin();
55 bool q = it != _output.end() ? (*it).second->getValue() : false;
56 return _inverted ? !q : q;
59 void Logic::update( bool firstTime, double dt )
61 set_output( get_input() );