Template Class Combiner

Inheritance Relationships

Base Type

Class Documentation

template<template<typename...> class PolicyTmpl, class ...IOs>
class Combiner : public fkie_message_filters::Source<IOs...>

Combine multiple sources into a single one.

Sometimes, a filter pipeline will receive corresponding inputs from different sources, which must be processed together. The combiner provides a policy-driven way to aggregate data from multiple sources into a single sink. Policies can be anything from a simple FIFO to an elaborate approximate time stamp synchronization.

The output arity of the filter is the sum of all input arities. For example, given two binary input filters (M1,M2) and (M3,M4), the combiner will create a quaternary output (M1,M2,M3,M4). Furthermore, policies which examine data generally look at the first argument of each input. In this example, the timing policies would match the inputs based on M1 and M3. You can prepend a Selector filter to swap the argument order if you need a different element examined, or the Divider filter to match all arguments independently.

namespace mf = fkie_message_filters;

using InBuffer1 = mf::Buffer<M1, M2>;
using InBuffer2 = mf::Buffer<M3, M4>;
using Combiner = mf::Combiner<mf::combiner_policies::Fifo, InBuffer1::Output, InBuffer2::Output>;
using OutBuffer = mf::Buffer<M1, M2, M3, M4>;

InBuffer1 buf1;
InBuffer2 buf2;
OutBuffer out;
Combiner combiner;

combiner.connect_to_sources(buf1, buf2);
combiner.connect_to_sink(out);

See also

combiner_policies, Divider, Selector

Public Types

using Connections = std::array<Connection, NUM_SINKS>

Array of connection objects.

using Output = IO<Outputs...>

Grouped output types.

This type can be used to define sinks with matching types.

using Policy = PolicyTmpl<IOs...>

Class type of the policy that applies to the combiner.

template<std::size_t N>
using SinkType = helpers::io_rewrap_t<helpers::select_nth<N, IOs...>, Sink>

Base class for the Nth sink.

Public Functions

explicit Combiner(const Policy &policy = Policy()) noexcept

Constructor.

  • policy Instance of the policy class that applies to the combiner.

Does not throw any exceptions.

Connection connect_to_sink(Sink<Outputs...> &dst) noexcept

Connect this source to a sink.

Can be called multiple times to connect multiple sinks; in that case, the sinks receive data in the same order as they have been connected. This function does basically the same thing as Sink::connect_to_source(), only from the opposite point of view.

  • dst the sink that is to be connected

Does not throw any exceptions.

Returns:

a connection object that can be used to monitor or sever the created connection

Connections connect_to_sources(helpers::io_rewrap_t<IOs, Source>&... sources) noexcept

Convenience function to connect all sinks at once.

Does not throw any exceptions.

virtual void disconnect() noexcept override

Disconnect from all connected sources and sinks.

Does not throw any exceptions.

void disconnect_from_all_sinks() noexcept

Disconnect from all connected sinks.

Severs the connection to all sinks, turning the send() method into a no-op.

Does not throw any exceptions.

void disconnect_from_all_sources() noexcept

Disconnect the sinks from their sources.

Does not throw any exceptions.

const Policy &policy() const noexcept

Access combiner policy.

virtual void reset() noexcept override

Reset filter.

This will reset the internal state by calling the PolicyTmpl::reset() method

Does not throw any exceptions.

void set_policy(const Policy &policy) noexcept

Set combiner policy.

Any previous policy is superseded. Implies a call to reset().

Does not throw any exceptions.

template<std::size_t N>
const SinkType<N> &sink() const noexcept

Access the sink for the Nth input.

template<std::size_t N>
const Combiner<PolicyTmpl, IOs...>::template SinkType<N> &sink() const noexcept
template<std::size_t N>
SinkType<N> &sink() noexcept

Access the sink for the Nth input.

template<std::size_t N>
Combiner<PolicyTmpl, IOs...>::template SinkType<N> &sink() noexcept

Public Static Attributes

static std::size_t NUM_OUTPUTS

Number of output arguments.

static std::size_t NUM_SINKS = sizeof...(IOs)

Number of sinks.

Protected Functions

void send(helpers::argument_t<Outputs>... out)

Pass data to all connected sinks.

  • out data

Does not throw any exceptions, but will propagate uncaught exceptions from filter callbacks.