UniSet 2.44.3
TriggerOUT.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 TriggerOUT_H_
23#define TriggerOUT_H_
24//---------------------------------------------------------------------------
25#include <unordered_map>
26//---------------------------------------------------------------------------
27namespace uniset
28{
41 или иного выхода.
42
43 \warning Нет блокирования совместного доступа(не рассчитан на работу в многопоточной среде).
44
45 \par Пример использования
46 \code
47 #include "TriggerOUT.h"
48
49 class MyClass
50 {
51 public:
52 MyClass(){};
53 ~MyClass(){};
54
55 void out(int out_id, int val){ cout << "TriggerOUT out="<< out_id << " val=" << val <<endl;}
56 ...
57 };
58
59 ...
60 MyClass rec;
61 // Создание:
62 TriggerOUT<MyClass,int,int> tr_out(&rec, &MyClass::out);
63
64 // формируем OUT триггер с двумя 'выходами'
65 tr_out.add(1,0);
66 tr_out.add(2,0);
67
68 ...
69 // Использование:
70 // подаём сперва на первый 'выход' значение, второй должен стать в "0",
71 // потом на другой...
72
73 tr_out.set(1,4);
74
75 cout << ( tr_out.getState(2) !=0 ? "FAIL" : "OK" ) << endl;
76
77 tr_out.set(2,3);
79 cout << ( tr_out.getState(1) !=0 ? "FAIL" : "OK" ) << endl;
80
81 \endcode
82 */
83 template<class Caller, typename OutIdType = int, typename ValueType = bool>
84 class TriggerOUT
85 {
86 public:
87
92 typedef void(Caller::* Action)(OutIdType out, ValueType val);
93
94 TriggerOUT(Caller* r, Action a) noexcept;
95 ~TriggerOUT() noexcept;
96
97
99 bool getState(OutIdType out) const noexcept;
100
105 void set(OutIdType out, ValueType val);
106
111 void add(OutIdType out, ValueType val);
112
114 void remove(OutIdType out) noexcept;
115
116 void update();
117 void reset();
118
119 protected:
120 void resetOuts( OutIdType outIgnore );
121
122 typedef std::unordered_map<OutIdType, ValueType> OutList;
123 OutList outs; // список выходов
124
125 Caller* cal;
126 Action act;
127
128 };
129 // -------------------------------------------------------------------------
130#include "TriggerOUT.tcc"
131 //---------------------------------------------------------------------------
132} // end of uniset namespace
133//---------------------------------------------------------------------------
134#endif
void add(OutIdType out, ValueType val)
Определения TriggerOUT.h:41
void set(OutIdType out, ValueType val)
Определения TriggerOUT.h:78
void(Caller::* Action)(OutIdType out, ValueType val)
Определения TriggerOUT.h:92
void remove(OutIdType out) noexcept
Определения TriggerOUT.h:52
bool getState(OutIdType out) const noexcept
Определения TriggerOUT.h:65
STL namespace.
Определения Calibration.h:27