1 // digitalcomponent.cxx - Base class for digital autopilot components
3 // Written by Torsten Dreyer
4 // Based heavily on work created by Curtis Olson, started January 2004.
6 // Copyright (C) 2004 Curtis L. Olson - http://www.flightgear.org/~curt
7 // Copyright (C) 2010 Torsten Dreyer - Torsten (at) t3r (dot) de
9 // This program is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU General Public License as
11 // published by the Free Software Foundation; either version 2 of the
12 // License, or (at your option) any later version.
14 // This program is distributed in the hope that it will be useful, but
15 // WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 // General Public License for more details.
19 // You should have received a copy of the GNU General Public License
20 // along with this program; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 #include "digitalcomponent.hxx"
25 #include <Main/fg_props.hxx>
28 using namespace FGXMLAutopilot;
30 DigitalComponent::DigitalComponent() :
35 bool DigitalComponent::InputMap::get_value( const std::string & name ) const
37 // can't use map::operator[] here since it's not const
38 const_iterator __i = lower_bound( name );
39 if (__i == end() || key_comp()(name, (*__i).first))
40 return false; // does not exist, return false
42 return (*__i).second->test();
54 <property>/foo/bar</property>
55 <inverted>true</inverted>
57 <output>/some/property</output>
59 bool DigitalComponent::configure( const std::string & nodeName, SGPropertyNode_ptr configNode )
61 if( Component::configure( nodeName, configNode ) )
64 if (nodeName == "input") {
65 SGPropertyNode_ptr nameNode = configNode->getNode("name");
67 if( nameNode != NULL ) {
68 name = nameNode->getStringValue();
70 std::ostringstream buf;
71 buf << "Input" << _input.size();
74 _input[name] = sgReadCondition( fgGetNode("/"), configNode );
78 if (nodeName == "output") {
79 SGPropertyNode_ptr n = configNode->getNode("name");
82 name = n->getStringValue();
84 std::ostringstream buf;
85 buf << "Output" << _output.size();
89 DigitalOutput_ptr o = new DigitalOutput();
92 if( (n = configNode->getNode("inverted")) != NULL )
93 o->setInverted( n->getBoolValue() );
95 if( (n = configNode->getNode("property")) != NULL )
96 o->setProperty( fgGetNode( n->getStringValue(), true ) );
98 if( configNode->nChildren() == 0 )
99 o->setProperty( fgGetNode( configNode->getStringValue(), true ) );
104 if (nodeName == "inverted") {
105 _inverted = configNode->getBoolValue();