UniSet  2.24.2
TriggerOR.h
1 /*
2  * Copyright (c) 2015 Pavel Vainerman.
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as
6  * published by the Free Software Foundation, version 2.1.
7  *
8  * This program is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  * Lesser General Lesser Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  */
16 // --------------------------------------------------------------------------
20 // --------------------------------------------------------------------------
21 //---------------------------------------------------------------------------
22 #ifndef TRIGGER_OR_H_
23 #define TRIGGER_OR_H_
24 //---------------------------------------------------------------------------
25 #include <unordered_map>
26 //---------------------------------------------------------------------------
27 namespace uniset
28 {
72  template<class Caller, typename InputType = int>
73  class TriggerOR
74  {
75  public:
76 
81  typedef void(Caller::* Action)(bool newstate);
82 
83  TriggerOR(Caller* r, Action a) noexcept;
84  ~TriggerOR() noexcept;
85 
86  inline bool state() const noexcept
87  {
88  return out;
89  }
90 
91  bool getState(InputType in) const noexcept;
92  bool commit(InputType in, bool state);
93 
94  void add(InputType in, bool state);
95  void remove(InputType in);
96 
97  typedef std::unordered_map<InputType, bool> InputMap;
98 
99  inline typename InputMap::const_iterator begin() noexcept
100  {
101  return inputs.begin();
102  }
103 
104  inline typename InputMap::const_iterator end() noexcept
105  {
106  return inputs.end();
107  }
108 
109  void update();
110  void reset();
111 
112  protected:
113  void check();
114 
115  InputMap inputs; // список входов
116  bool out = { false };
117  Caller* cal;
118  Action act;
119  };
120  // -------------------------------------------------------------------------
121 #include "TriggerOR.tcc"
122  //---------------------------------------------------------------------------
123 } // end of uniset namespace
124 //---------------------------------------------------------------------------
125 #endif
Definition: TriggerOR.h:74
void(Caller::* Action)(bool newstate)
Definition: TriggerOR.h:81
Definition: CommonEventLoop.h:15