Debian Codegraph @

src/Autopilot/component.hxx

raw symbols SCIP
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 #pragma once
24
25 #include <simgear/structure/subsystem_mgr.hxx>
26 #include <simgear/props/propsfwd.hxx>
27
28 namespace FGXMLAutopilot {
29
30 /**
31 * @brief Base class for other autopilot components
32 */
33 class Component : public SGSubsystem
34 {
35 private:
36 SGSharedPtr<const SGCondition> _condition;
37 SGPropertyNode_ptr _enable_prop;
38 std::string * _enable_value;
39 bool _enabled;
40
41 protected:
42 virtual bool configure( SGPropertyNode& cfg_node,
43 const std::string& cfg_name,
44 SGPropertyNode& prop_root );
45
46 /**
47 * @brief pure virtual function to be implemented by the derived classes. Gets called from
48 * the update method if it's not disabled with the firstTime parameter set to true if this
49 * is the first call after being enabled
50 * @param firstTime set to true if this is the first update call since this component has
51 been enabled. Set to false for every subsequent call.
52 * @param dt the elapsed time since the last call
53 */
54 virtual void update( bool firstTime, double dt ) = 0;
55
56 /**
57 * @brief overideable method being called from the update() method if this component
58 * is disabled. It's a noop by default.
59 */
60 virtual void disabled( double dt ) {}
61
62 /**
63 * @brief debug flag, true if this component should generate some useful output
64 * on every iteration
65 */
66 bool _debug;
67
68
69 /**
70 * @brief a (historic) flag signalling the derived class that it should compute it's internal
71 * state but shall not set the output properties if /autopilot/locks/passive-mode is true.
72 */
73 bool _honor_passive;
74
75 public:
76 /**
77 * @brief A constructor for an empty Component.
78 */
79 Component();
80
81 /**
82 * virtual destructor to clean up resources
83 */
84 virtual ~Component();
85
86 // Subsystem API.
87 void update(double dt) override;
88
89 /**
90 * @brief configure this component from a property node. Iterates through
91 * all nodes found as children under configNode and calls configure
92 * of the derived class for each child.
93 *
94 * @param prop_root Property root for all relative paths
95 * @param cfg Property node containing the configuration
96 */
97 virtual bool configure( SGPropertyNode& prop_root,
98 SGPropertyNode& cfg );
99
100 /**
101 * @brief check if this component is enabled as configured in the
102 * &lt;enable&gt; section
103 * @return true if the enable-condition is true.
104 *
105 * If a &lt;condition&gt; is defined, this condition is evaluated,
106 * &lt;prop&gt; and &lt;value&gt; tags are ignored.
107 *
108 * If a &lt;prop&gt; is defined and no &lt;value&gt; is defined, the property
109 * named in the &lt;prop&gt;&lt;prop&gt; tags is evaluated as boolean.
110 *
111 * If a &lt;prop&gt; is defined and a &lt;value&gt; is defined, the property named
112 * in &lt;prop&gt;&lt;/prop&gt; is compared (as a string) to the value defined in
113 * &lt;value&gt;&lt;/value&gt;
114 *
115 * Returns true, if neither &lt;condition&gt; nor &lt;prop&gt; exists
116 */
117 bool isPropertyEnabled();
118 };
119
120 } // of namespace FGXMLAutopilot
121