UniSet  2.6.0
TriggerAND.h
00001 /*
00002  * Copyright (c) 2015 Pavel Vainerman.
00003  *
00004  * This program is free software: you can redistribute it and/or modify
00005  * it under the terms of the GNU Lesser General Public License as
00006  * published by the Free Software Foundation, version 2.1.
00007  *
00008  * This program is distributed in the hope that it will be useful, but
00009  * WITHOUT ANY WARRANTY; without even the implied warranty of
00010  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00011  * Lesser General Lesser Public License for more details.
00012  *
00013  * You should have received a copy of the GNU Lesser General Public License
00014  * along with this program. If not, see <http://www.gnu.org/licenses/>.
00015  */
00016 // --------------------------------------------------------------------------
00021 // --------------------------------------------------------------------------
00022 //---------------------------------------------------------------------------
00023 #ifndef TRIGGER_AND_H_
00024 #define TRIGGER_AND_H_
00025 //---------------------------------------------------------------------------
00026 #include <unordered_map>
00027 //---------------------------------------------------------------------------
00028 namespace uniset
00029 {
00073 template<class Caller, typename InputType = int>
00074 class TriggerAND
00075 {
00076     public:
00077 
00082         typedef void(Caller::* Action)(bool newstate);
00083 
00084         TriggerAND(Caller* r, Action a) noexcept;
00085         ~TriggerAND() noexcept;
00086 
00087         inline bool state() const noexcept
00088         {
00089             return out;
00090         }
00091 
00092 
00093         bool getState(InputType in) const noexcept;
00094         bool commit(InputType in, bool state);
00095 
00096         void add(InputType in, bool state);
00097         void remove(InputType in);
00098 
00099         typedef std::unordered_map<InputType, bool> InputMap;
00100 
00101         inline typename InputMap::const_iterator begin() noexcept
00102         {
00103             return inputs.begin();
00104         }
00105 
00106         inline typename InputMap::const_iterator end() noexcept
00107         {
00108             return inputs.end();
00109         }
00110 
00111         void update();
00112         void reset();
00113 
00114     protected:
00115         void check();
00116         InputMap inputs; // список входов
00117         bool out;
00118         Caller* cal;
00119         Action act;
00120 };
00121 // -------------------------------------------------------------------------
00122 #include "TriggerAND.tcc"
00123 //---------------------------------------------------------------------------
00124 } // end of uniset namespace
00125 //---------------------------------------------------------------------------
00126 #endif