FlightGear next
digitalcomponent.hxx
Go to the documentation of this file.
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
31namespace FGXMLAutopilot {
32
36class DigitalOutput : public SGReferenced {
37
38private:
39 bool _inverted;
40 SGPropertyNode_ptr _node;
41
42protected:
43
44public:
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
59inline DigitalOutput::DigitalOutput() : _inverted(false)
60{
61}
62
63inline void DigitalOutput::setProperty( SGPropertyNode_ptr node )
64{
65 _node = node;
66 _node->setBoolValue( node->getBoolValue() );
67}
68
69inline bool DigitalOutput::getValue() const
70{
71 if( _node == NULL ) return false;
72 bool nodeState = _node->getBoolValue();
73 return _inverted ? !nodeState : nodeState;
74}
75
76inline void DigitalOutput::setValue( bool value )
77{
78 if( _node == NULL ) return;
79 _node->setBoolValue( _inverted ? !value : value );
80}
81
82typedef SGSharedPtr<DigitalOutput> DigitalOutput_ptr;
83
94{
95public:
97
98 class InputMap : public std::map<const std::string,SGSharedPtr<const SGCondition> >
99 {
100 public:
101 bool get_value( const std::string & name ) const;
102 };
103
104
105// typedef std::map<const std::string,SGSharedPtr<const SGCondition> > InputMap;
106 typedef std::map<const std::string,DigitalOutput_ptr> OutputMap;
107protected:
108
113
118
123
132 virtual bool configure( SGPropertyNode& cfg_node,
133 const std::string& cfg_name,
134 SGPropertyNode& prop_root );
135};
136
137}
138#endif // DIGITALCOMPONENT_HXX
139
Component()
A constructor for an empty Component.
Definition component.cxx:30
bool get_value(const std::string &name) const
std::map< const std::string, DigitalOutput_ptr > OutputMap
OutputMap _output
Named output "pins".
bool _inverted
Global "inverted" flag for the outputs.
InputMap _input
Named input "pins".
virtual bool configure(SGPropertyNode &cfg_node, const std::string &cfg_name, SGPropertyNode &prop_root)
Over-rideable hook method to allow derived classes to refine top-level node parsing.
void setProperty(SGPropertyNode_ptr node)
DigitalOutput()
Constructs an empty, noninverting output.
const char * name
SGSharedPtr< DigitalOutput > DigitalOutput_ptr