]> git.mxchange.org Git - flightgear.git/blob - src/Autopilot/component.hxx
Some code documentation added to the A/P flip flop implementation
[flightgear.git] / src / Autopilot / component.hxx
1 // component.hxx - Base class for 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 __COMPONENT_HXX
24 #define __COMPONENT_HXX 1
25
26 #ifdef HAVE_CONFIG_H
27 #  include <config.h>
28 #endif
29
30 #include <simgear/props/props.hxx>
31 #include <simgear/structure/subsystem_mgr.hxx>
32 #include <simgear/props/condition.hxx>
33
34 namespace FGXMLAutopilot {
35
36 /**
37  * @brief Base class for other autopilot components
38  */
39 class Component : public SGSubsystem {
40
41 private:
42
43     SGSharedPtr<const SGCondition> _condition;
44     SGPropertyNode_ptr _enable_prop;
45     std::string * _enable_value;
46     std::string _name;
47     bool _enabled;
48
49 protected:
50
51     virtual bool configure( const std::string & nodeName, SGPropertyNode_ptr configNode );
52
53     
54    /**
55     * @brief the implementation of the update() method of the SGSubsystem
56     */
57     virtual void update( double dt );
58
59    /** 
60     * @brief pure virtual function to be implemented by the derived classes. Gets called from
61     * the update method if it's not disabled with the firstTime parameter set to true if this
62     * is the first call after being enabled 
63     * @param firstTime set to true if this is the first update call since this component has
64              been enabled. Set to false for every subsequent call.
65     * @param dt  the elapsed time since the last call
66     */
67     virtual void update( bool firstTime, double dt ) = 0;
68
69    /**
70     * @brief overideable method being called from the update() method if this component
71     *        is disabled. It's a noop by default.
72     */
73     virtual void disabled( double dt ) {}
74
75     /** 
76      * @brief debug flag, true if this component should generate some useful output
77      * on every iteration
78      */
79     bool _debug;
80
81
82     /** 
83      * @brief a (historic) flag signalling the derived class that it should compute it's internal
84      *        state but shall not set the output properties if /autopilot/locks/passive-mode is true.
85      */
86     bool _honor_passive;
87     
88 public:
89     
90     /**
91      * @brief A constructor for an empty Component.
92      */
93     Component();
94
95     /**
96      * virtual destructor to clean up resources
97      */
98     virtual ~Component();
99
100     /**
101      * @brief configure this component from a property node. Iterates through all nodes found
102      *        as childs under configNode and calls configure of the derived class for each child.
103      * @param configNode the property node containing the configuration 
104      */
105     bool configure( SGPropertyNode_ptr configNode );
106
107     /**
108      * @brief getter for the name property
109      * @return the name of the component
110      */
111     inline const std::string& get_name() const { return _name; }
112
113     /**
114      * @brief setter for the name property
115      * @param name the name of the component
116      */
117     inline void set_name( const std::string & name ) { _name = name; }
118
119     /**
120      * @brief check if this component is enabled as configured in the
121      * &lt;enable&gt; section
122      * @return true if the enable-condition is true.
123      *
124      * If a &lt;condition&gt; is defined, this condition is evaluated, 
125      * &lt;prop&gt; and &lt;value&gt; tags are ignored.
126      *
127      * If a &lt;prop&gt; is defined and no &lt;value&gt; is defined, the property
128      * named in the &lt;prop&gt;&lt;prop&gt; tags is evaluated as boolean.
129      *
130      * If a &lt;prop&gt; is defined and a &lt;value&gt; is defined, the property named
131      * in &lt;prop&gt;&lt;/prop&gt; is compared (as a string) to the value defined in
132      * &lt;value&gt;&lt;/value&gt;
133      *
134      * Returns true, if neither &lt;condition&gt; nor &lt;prop&gt; exists
135      */
136     bool isPropertyEnabled();
137 };
138
139
140 }
141 #endif // COMPONENT_HXX