UniSet  2.6.0
TriggerOR.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 // --------------------------------------------------------------------------
00020 // --------------------------------------------------------------------------
00021 //---------------------------------------------------------------------------
00022 #ifndef TRIGGER_OR_H_
00023 #define TRIGGER_OR_H_
00024 //---------------------------------------------------------------------------
00025 #include <unordered_map>
00026 //---------------------------------------------------------------------------
00027 namespace uniset
00028 {
00072 template<class Caller, typename InputType = int>
00073 class TriggerOR
00074 {
00075     public:
00076 
00081         typedef void(Caller::* Action)(bool newstate);
00082 
00083         TriggerOR(Caller* r, Action a) noexcept;
00084         ~TriggerOR() noexcept;
00085 
00086         inline bool state() const noexcept
00087         {
00088             return out;
00089         }
00090 
00091         bool getState(InputType in) const noexcept;
00092         bool commit(InputType in, bool state);
00093 
00094         void add(InputType in, bool state);
00095         void remove(InputType in);
00096 
00097         typedef std::unordered_map<InputType, bool> InputMap;
00098 
00099         inline typename InputMap::const_iterator begin() noexcept
00100         {
00101             return inputs.begin();
00102         }
00103 
00104         inline typename InputMap::const_iterator end() noexcept
00105         {
00106             return inputs.end();
00107         }
00108 
00109         void update();
00110         void reset();
00111 
00112     protected:
00113         void check();
00114 
00115         InputMap inputs; // список входов
00116         bool out;
00117         Caller* cal;
00118         Action act;
00119 };
00120 // -------------------------------------------------------------------------
00121 #include "TriggerOR.tcc"
00122 //---------------------------------------------------------------------------
00123 } // end of uniset namespace
00124 //---------------------------------------------------------------------------
00125 #endif