| 1 | // flipflop.hxx - implementation of multiple flip flop types |
| 2 | // |
| 3 | // Written by Torsten Dreyer |
| 4 | // |
| 5 | // Copyright (C) 2010 Torsten Dreyer - Torsten (at) t3r (dot) de |
| 6 | // |
| 7 | // This program is free software; you can redistribute it and/or |
| 8 | // modify it under the terms of the GNU General Public License as |
| 9 | // published by the Free Software Foundation; either version 2 of the |
| 10 | // License, or (at your option) any later version. |
| 11 | // |
| 12 | // This program is distributed in the hope that it will be useful, but |
| 13 | // WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | // General Public License for more details. |
| 16 | // |
| 17 | // You should have received a copy of the GNU General Public License |
| 18 | // along with this program; if not, write to the Free Software |
| 19 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 20 | // |
| 21 | #ifndef __FLIPFLOPCOMPONENT_HXX |
| 22 | #define __FLIPFLOPCOMPONENT_HXX 1 |
| 23 | |
| 24 | #include "logic.hxx" |
| 25 | |
| 26 | namespace FGXMLAutopilot { |
| 27 | |
| 28 | /** |
| 29 | * @brief Interface for a flip flop implementation. Can be configured from a property node and |
| 30 | * returns a state depending on input lines. |
| 31 | */ |
| 32 | class FlipFlopImplementation : public SGReferenced { |
| 33 | protected: |
| 34 | /** |
| 35 | * @brief configure this component from a property node. Iterates through all nodes found |
| 36 | * as childs under configNode and calls configure of the derived class for each child. |
| 37 | * @param configNode the property node containing the configuration |
| 38 | */ |
| 39 | virtual bool configure( SGPropertyNode& cfg_node, |
| 40 | const std::string& cfg_name, |
| 41 | SGPropertyNode& prop_root ) |
| 42 | { return false; } |
| 43 | public: |
| 44 | virtual ~FlipFlopImplementation() {} |
| 45 | /** |
| 46 | * @brief evaluates the output state from the input lines |
| 47 | * @param dt the elapsed time in seconds from since the last call |
| 48 | * @param input a map of named input lines |
| 49 | * @param q a reference to a boolean variable to receive the output state |
| 50 | * @return true if the state has changed, false otherwise |
| 51 | */ |
| 52 | virtual bool getState( double dt, DigitalComponent::InputMap input, bool & q ) { return false; } |
| 53 | |
| 54 | /** |
| 55 | * @brief configure this component from a property node. Iterates through all nodes found |
| 56 | * as childs under configNode and calls configure of the derived class for each child. |
| 57 | * @param configNode the property node containing the configuration |
| 58 | */ |
| 59 | bool configure( SGPropertyNode& prop_root, |
| 60 | SGPropertyNode& cfg ); |
| 61 | |
| 62 | virtual bool isConfigProperty(const std::string& cfg_name) const { return false; } |
| 63 | }; |
| 64 | |
| 65 | /** |
| 66 | * @brief A simple flipflop implementation |
| 67 | */ |
| 68 | class FlipFlop : public Logic |
| 69 | { |
| 70 | public: |
| 71 | // Subsystem identification. |
| 72 | static const char* staticSubsystemClassId() { return "flipflop"; } |
| 73 | |
| 74 | protected: |
| 75 | /** |
| 76 | * @brief Over-rideable hook method to allow derived classes to refine top-level |
| 77 | * node parsing. |
| 78 | * @param aName |
| 79 | * @param aNode |
| 80 | * @return true if the node was handled, false otherwise. |
| 81 | */ |
| 82 | virtual bool configure( SGPropertyNode& cfg_node, |
| 83 | const std::string& cfg_name, |
| 84 | SGPropertyNode& prop_root ); |
| 85 | |
| 86 | /** |
| 87 | * @brief Implementation of the pure virtual function of the Component class. Gets called from |
| 88 | * the update method if it's not disabled with the firstTime parameter set to true if this |
| 89 | * is the first call after being enabled |
| 90 | * @param firstTime set to true if this is the first update call since this component has |
| 91 | been enabled. Set to false for every subsequent call. |
| 92 | * @param dt the elapsed time since the last call |
| 93 | */ |
| 94 | void update( bool firstTime, double dt ); |
| 95 | |
| 96 | private: |
| 97 | /** |
| 98 | * @brief Pointer to the actual flip flop implementation |
| 99 | */ |
| 100 | SGSharedPtr<FlipFlopImplementation> _implementation; |
| 101 | }; |
| 102 | |
| 103 | } |
| 104 | #endif // FLIPFLOPCOMPONENT_HXX |