divider_impl.h
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * fkie_message_filters
4  * Copyright © 2018-2020 Fraunhofer FKIE
5  * Author: Timo Röhling
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  ****************************************************************************/
20 #ifndef INCLUDE_FKIE_MESSAGE_FILTERS_DIVIDER_IMPL_H_
21 #define INCLUDE_FKIE_MESSAGE_FILTERS_DIVIDER_IMPL_H_
22 
23 #include "divider.h"
24 #include "helpers/tuple.h"
25 
26 namespace fkie_message_filters
27 {
28 
29 template<class... Inputs>
30 template<std::size_t N>
31 typename Divider<Inputs...>::template SourceType<N>& Divider<Inputs...>::source() noexcept
32 {
33  return std::get<N>(sources_);
34 }
35 
36 template<class... Inputs>
37 template<std::size_t N>
38 const typename Divider<Inputs...>::template SourceType<N>& Divider<Inputs...>::source() const noexcept
39 {
40  return std::get<N>(sources_);
41 }
42 
43 template<class... Inputs>
45 {
46  Connections conn;
47  connect_to_sinks_impl<0>(conn, sinks...);
48  return conn;
49 }
50 
51 template<class... Inputs>
53 {
54  helpers::for_each_apply<sizeof...(Inputs)>(
55  [this](auto I)
56  {
57  std::get<I>(this->sources_).disconnect_from_all_sinks();
58  }
59  );
60 }
61 
62 template<class... Inputs>
64 {
65  this->disconnect_from_all_sources();
66  disconnect_from_all_sinks();
67 }
68 
69 template<class... Inputs>
70 template<class Input>
72 {
73  this->send(in);
74 }
75 
76 template<class... Inputs>
77 void Divider<Inputs...>::receive(const Inputs&... ins)
78 {
79  forward_to_sources<0>(ins...);
80 }
81 
82 template<class... Inputs>
83 template<std::size_t N>
85 {
86 }
87 
88 template<class... Inputs>
89 template<std::size_t N, typename ThisInput, typename... OtherInputs>
90 void Divider<Inputs...>::forward_to_sources(const ThisInput& in, const OtherInputs&... ins)
91 {
92  std::get<N>(sources_).forward(in);
93  forward_to_sources<N + 1>(ins...);
94 }
95 
96 template<class... Inputs>
97 template<std::size_t N>
99 {
100 }
101 
102 template<class... Inputs>
103 template<std::size_t N, typename ThisSink, typename... OtherSinks>
104 void Divider<Inputs...>::connect_to_sinks_impl(Connections& conn, ThisSink& sink, OtherSinks&... sinks) noexcept
105 {
106  conn[N] = std::get<N>(sources_).connect_to_sink(sink);
107  connect_to_sinks_impl<N + 1>(conn, sinks...);
108 }
109 
110 } // namespace fkie_message_filters
111 
112 #endif /* INCLUDE_FKIE_MESSAGE_FILTERS_DIVIDER_IMPL_H_ */
Base class for data consumers.
Definition: sink.h:46
SourceType< N > & source() noexcept
Access the source for the Nth data element.
void for_each_apply(Function f)
Definition: tuple.h:52
Split an N-ary source into N unary ones.
Definition: divider.h:59
Primary namespace.
Definition: buffer.h:33
helpers::select_nth< N, Source< Inputs >... > SourceType
Base class of the Nth source.
Definition: divider.h:66
std::array< Connection, NUM_INPUTS > Connections
Array of connection objects.
Definition: divider.h:64


fkie_message_filters
Author(s): Timo Röhling
autogenerated on Mon Feb 28 2022 22:21:43