UniSet 2.32.1
TriggerAND.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// --------------------------------------------------------------------------
21// --------------------------------------------------------------------------
22//---------------------------------------------------------------------------
23#ifndef TRIGGER_AND_H_
24#define TRIGGER_AND_H_
25//---------------------------------------------------------------------------
26#include <unordered_map>
27//---------------------------------------------------------------------------
28namespace uniset
29{
73 template<class Caller, typename InputType = int>
75 {
76 public:
77
82 typedef void(Caller::* Action)(bool newstate);
83
84 TriggerAND(Caller* r, Action a) noexcept;
85 ~TriggerAND() noexcept;
86
87 inline bool state() const noexcept
88 {
89 return out;
90 }
91
92
93 bool getState(InputType in) const noexcept;
94 bool commit(InputType in, bool state);
95
96 void add(InputType in, bool state);
97 void remove(InputType in);
98
99 typedef std::unordered_map<InputType, bool> InputMap;
100
101 inline typename InputMap::const_iterator begin() noexcept
102 {
103 return inputs.begin();
104 }
105
106 inline typename InputMap::const_iterator end() noexcept
107 {
108 return inputs.end();
109 }
110
111 void update();
112 void reset();
113
114 protected:
115 void check();
116 InputMap inputs; // список входов
117 bool out = { false };
118 Caller* cal;
119 Action act;
120 };
121 // -------------------------------------------------------------------------
122#include "TriggerAND.tcc"
123 //---------------------------------------------------------------------------
124} // end of uniset namespace
125//---------------------------------------------------------------------------
126#endif
Definition TriggerAND.h:75
void(Caller::* Action)(bool newstate)
Definition TriggerAND.h:82
Definition Calibration.h:27