]> git.mxchange.org Git - flightgear.git/blob - src/Autopilot/digitalcomponent.cxx
Trivial cleanup commit, to test continuous integration server.
[flightgear.git] / src / Autopilot / digitalcomponent.cxx
1 // digitalcomponent.cxx - Base class for digital autopilot components
2 //
3 // Written by Torsten Dreyer
4 // Based heavily on work created by Curtis Olson, started January 2004.
5 //
6 // Copyright (C) 2004  Curtis L. Olson  - http://www.flightgear.org/~curt
7 // Copyright (C) 2010  Torsten Dreyer - Torsten (at) t3r (dot) de
8 //
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.
13 //
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.
18 //
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.
22 //
23
24 #include "digitalcomponent.hxx"
25 #include <Main/fg_props.hxx>
26
27 using namespace FGXMLAutopilot;
28
29 DigitalComponent::DigitalComponent() :
30   _inverted(false)
31 {
32 }
33
34 bool DigitalComponent::InputMap::get_value( const std::string & name ) const
35 {
36   // can't use map::operator[] here since it's not const
37   const_iterator __i = lower_bound( name );
38   if (__i == end() || key_comp()(name, (*__i).first))
39     return false; // does not exist, return false
40
41   return (*__i).second->test();
42 }
43
44 /*
45   <input>
46     <name>Foo</name>
47     <condition>
48      <and>...</and>
49     </condition>
50   </input>
51   <output>
52     <name>Bar</name>
53     <property>/foo/bar</property>
54     <inverted>true</inverted>
55   </output>
56   <output>/some/property</output>
57 */
58 bool DigitalComponent::configure( const std::string & nodeName, SGPropertyNode_ptr configNode )
59 {
60   if( Component::configure( nodeName, configNode ) )
61     return true;
62
63   if (nodeName == "input") {
64     SGPropertyNode_ptr nameNode = configNode->getNode("name");
65     string name;
66     if( nameNode != NULL ) {
67       name = nameNode->getStringValue();
68     } else {
69       std::ostringstream buf;
70       buf << "Input" << _input.size();
71       name = buf.str();
72     }
73     _input[name] = sgReadCondition( fgGetNode("/"), configNode );
74     return true;
75   } 
76
77   if (nodeName == "output") {
78     SGPropertyNode_ptr n = configNode->getNode("name");
79     string name;
80     if( n != NULL ) {
81       name = n->getStringValue();
82     } else {
83       std::ostringstream buf;
84       buf << "Output" << _output.size();
85       name = buf.str();
86     }
87
88     DigitalOutput_ptr o = new DigitalOutput();
89     _output[name] = o;
90
91     if( (n = configNode->getNode("inverted")) != NULL )
92       o->setInverted( n->getBoolValue() );
93
94     if( (n = configNode->getNode("property")) != NULL )
95       o->setProperty( fgGetNode( n->getStringValue(), true ) );
96
97     if( configNode->nChildren() == 0 )
98       o->setProperty( fgGetNode( configNode->getStringValue(), true ) );
99
100     return true;
101   } 
102
103   if (nodeName == "inverted") {
104     _inverted = configNode->getBoolValue();
105     return true;
106   }
107   
108   return false;
109 }