-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathSource.hpp
73 lines (60 loc) · 2.3 KB
/
Source.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
* This file is part of the Arduino_ThreadsafeIO library.
* Copyright (c) 2021 Arduino SA.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef ARDUINO_THREADS_SOURCE_HPP_
#define ARDUINO_THREADS_SOURCE_HPP_
/**************************************************************************************
* INCLUDE
**************************************************************************************/
#include <list>
#include <algorithm>
/**************************************************************************************
* FORWARD DECLARATION
**************************************************************************************/
template<class T>
class SinkBase;
/**************************************************************************************
* CLASS DECLARATION
**************************************************************************************/
template<typename T>
class Source
{
public:
void connectTo(SinkBase<T> & sink);
void write(T const & value);
private:
std::list<SinkBase<T> *> _sink_list;
};
/**************************************************************************************
* PUBLIC MEMBER FUNCTIONS
**************************************************************************************/
template<typename T>
void Source<T>::connectTo(SinkBase<T> & sink)
{
_sink_list.push_back(&sink);
}
template<typename T>
void Source<T>::write(T const & value)
{
std::for_each(std::begin(_sink_list),
std::end (_sink_list),
[value](SinkBase<T> * sink)
{
sink->inject(value);
});
}
#endif /* ARDUINO_THREADS_SOURCE_HPP_ */