]> git.mxchange.org Git - flightgear.git/blob - src/Autopilot/digitalcomponent.hxx
Fixes for include-file flattening - condition.hxx no longer pulls in props or props_io
[flightgear.git] / src / Autopilot / digitalcomponent.hxx
1 // digitalcomponent.hxx - 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 #ifndef __DIGITALCOMPONENT_HXX
24 #define __DIGITALCOMPONENT_HXX 1
25
26 #include "component.hxx"
27
28 #include <simgear/props/props.hxx>
29 #include <simgear/props/condition.hxx>
30
31 namespace FGXMLAutopilot {
32
33 /**
34  * @brief Models a digital output bound to a property. May be an inverted output.
35  */
36 class DigitalOutput : public SGReferenced {
37
38 private:
39   bool _inverted;
40   SGPropertyNode_ptr _node;
41
42 protected:
43
44 public:
45   /**
46    * @brief Constructs an empty, noninverting output
47    */
48   DigitalOutput();
49
50   inline void setProperty( SGPropertyNode_ptr node );
51
52   inline void setInverted( bool value ) { _inverted = value; }
53   inline bool isInverted() const { return _inverted; }
54
55   bool getValue() const;
56   void setValue( bool value );
57 };
58
59 inline DigitalOutput::DigitalOutput() : _inverted(false) 
60 {
61 }
62
63 inline void DigitalOutput::setProperty( SGPropertyNode_ptr node ) 
64
65   _node->setBoolValue( (_node = node)->getBoolValue() );
66 }
67
68 inline bool DigitalOutput::getValue() const 
69 {
70   if( _node == NULL ) return false;
71   bool nodeState = _node->getBoolValue();
72   return _inverted ? !nodeState : nodeState;
73 }
74
75 inline void DigitalOutput::setValue( bool value ) 
76 {
77   if( _node == NULL ) return;
78   _node->setBoolValue( _inverted ? !value : value );
79 }
80
81 typedef SGSharedPtr<DigitalOutput> DigitalOutput_ptr;
82
83 /**
84  * @brief Base class for digital autopilot components
85  *
86  * Each digital component has (at least)
87  * <ul>
88  *   <li>one value input</li>
89  *   <li>any number of output properties</li>
90  * </ul>
91  */
92 class DigitalComponent : public Component {
93 public:
94     DigitalComponent();
95
96     class InputMap : public std::map<const std::string,SGSharedPtr<const SGCondition> > {
97       public:
98         bool get_value( const std::string & name ) const;
99     };
100
101
102 //    typedef std::map<const std::string,SGSharedPtr<const SGCondition> > InputMap;
103     typedef std::map<const std::string,DigitalOutput_ptr> OutputMap;
104 protected:
105
106     /**
107      * @brief Named input "pins"
108      */
109     InputMap _input;
110
111     /**
112      * @brief Named output "pins"
113      */
114     OutputMap _output;
115
116     /**
117      * @brief Global "inverted" flag for the outputs
118      */
119     bool _inverted;
120
121     /**
122      * @brief Over-rideable hook method to allow derived classes to refine top-level
123      * node parsing. 
124      * @param aName
125      * @param aNode
126      * @return true if the node was handled, false otherwise.
127      */
128     virtual bool configure( const std::string & nodeName, SGPropertyNode_ptr configNode );
129 };
130
131 }
132 #endif // DIGITALCOMPONENT_HXX
133