divider.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_H_
21 #define INCLUDE_FKIE_MESSAGE_FILTERS_DIVIDER_H_
22 
23 
24 #include "source.h"
25 #include "sink.h"
26 #include "helpers/tuple.h"
27 
28 namespace fkie_message_filters
29 {
30 
58 template<class... Inputs>
59 class Divider : public Sink<Inputs...>
60 {
61 public:
62  using Sink<Inputs...>::NUM_INPUTS;
64  using Connections = std::array<Connection, NUM_INPUTS>;
66  template<std::size_t N> using SourceType = helpers::select_nth<N, Source<Inputs>...>;
68  template<std::size_t N>
69  SourceType<N>& source() noexcept;
71  template<std::size_t N>
72  const SourceType<N>& source() const noexcept;
77  Connections connect_to_sinks(Sink<Inputs>&... sinks) noexcept;
82  void disconnect_from_all_sinks() noexcept;
87  void disconnect() noexcept override;
88 protected:
89  void receive (const Inputs&... in) override;
90 private:
91  template<class Input>
92  class DividerSource : public Source<Input>
93  {
94  public:
95  void forward(const Input& in);
96  };
97  std::tuple<DividerSource<Inputs>...> sources_;
98  template<std::size_t N, typename ThisInput, typename... OtherInputs>
99  void forward_to_sources(const ThisInput& in, const OtherInputs&... ins);
100  template<std::size_t N>
101  void forward_to_sources();
102  template<std::size_t N, typename ThisSink, typename... OtherSinks>
103  void connect_to_sinks_impl(Connections& conn, ThisSink& sink, OtherSinks&... sinks) noexcept;
104  template<std::size_t N>
105  void connect_to_sinks_impl(Connections& conn) noexcept;
106 };
107 
108 template<class... Inputs>
109 class Divider<IO<Inputs...>> : public Divider<Inputs...> {};
110 
111 } // namespace fkie_message_filters
112 
113 #include "divider_impl.h"
114 
115 #endif /* INCLUDE_FKIE_MESSAGE_FILTERS_DIVIDER_H_ */
std::tuple_element_t< N, std::tuple< Ts... > > select_nth
Definition: tuple.h:31
Base class for data consumers.
Definition: sink.h:46
static constexpr std::size_t NUM_INPUTS
Number of input arguments.
Definition: sink.h:51
SourceType< N > & source() noexcept
Access the source for the Nth data element.
Base class for data providers.
Definition: sink.h:33
void receive(const Inputs &... in) override
Process incoming data.
Definition: divider_impl.h:77
Group multiple data types as filter input or output.
Definition: io.h:27
IO< Inputs... > Input
Grouped input types.
Definition: sink.h:56
Split an N-ary source into N unary ones.
Definition: divider.h:59
Primary namespace.
Definition: buffer.h:33
void disconnect() noexcept override
Disconnect from all connected sources and sinks.
Definition: divider_impl.h:63
helpers::select_nth< N, Source< Inputs >... > SourceType
Base class of the Nth source.
Definition: divider.h:66
std::tuple< DividerSource< Inputs >... > sources_
Definition: divider.h:97
std::array< Connection, NUM_INPUTS > Connections
Array of connection objects.
Definition: divider.h:64
void connect_to_sinks_impl(Connections &conn, ThisSink &sink, OtherSinks &... sinks) noexcept
Definition: divider_impl.h:104
Connections connect_to_sinks(Sink< Inputs > &... sinks) noexcept
Convenience function to connect all sources at once.
Definition: divider_impl.h:44
void disconnect_from_all_sinks() noexcept
Disconnect all sources from their sinks.
Definition: divider_impl.h:52


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