Debian Codegraph @

src/Autopilot/logic.cxx

raw symbols SCIP
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 // for some obscure reason, MSVC needs this to compile
23 #ifdef _MSC_VER
24 #ifndef HAVE_CONFIG_H
25 # include <config.h>
26 #endif
27 #endif
28
29 #include "logic.hxx"
30
31 using namespace FGXMLAutopilot;
32
33 bool Logic::get_input() const
34 {
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();
39 }
40
41 void Logic::set_output( bool value )
42 {
43 // respect global inverted flag
44 if( _inverted ) value = !value;
45
46 // set all outputs to the given value
47 for( OutputMap::iterator it = _output.begin(); it != _output.end(); ++it )
48 (*it).second->setValue( value );
49 }
50
51 bool Logic::get_output() const
52 {
53 OutputMap::const_iterator it = _output.begin();
54 bool q = it != _output.end() ? (*it).second->getValue() : false;
55 return _inverted ? !q : q;
56 }
57
58 void Logic::update( bool firstTime, double dt )
59 {
60 if(_debug) {
61 bool q = get_output();
62 bool a = get_input();
63 if( a != q ) {
64 using std::endl;
65 using std::cout;
66 cout << "updating logic \"" << subsystemId() << "\"" << endl;
67 cout << "prev. Output:" << q << endl;
68 cout << "new Output:" << a << endl;
69 }
70 }
71 set_output( get_input() );
72 }
73
74
75 // Register the subsystem.
76 SGSubsystemMgr::Registrant<Logic> registrantLogic;