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