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
31 using namespace FGXMLAutopilot;
33 bool Logic::get_input() const
35 // return state of first configured condition
36 InputMap::const_iterator it = _input.begin();
37 if( it == _input.end() ) return false; // no inputs?
38 return (*it).second->test();
41 void Logic::set_output( bool value )
43 // respect global inverted flag
44 if( _inverted ) value = !value;
46 // set all outputs to the given value
47 for( OutputMap::iterator it = _output.begin(); it != _output.end(); ++it )
48 (*it).second->setValue( value );
51 bool Logic::get_output() const
53 OutputMap::const_iterator it = _output.begin();
54 bool q = it != _output.end() ? (*it).second->getValue() : false;
55 return _inverted ? !q : q;
58 void Logic::update( bool firstTime, double dt )
60 set_output( get_input() );