FKIE Message Filters
Improved filters for processing ROS messages
Public Types | Public Member Functions | Static Public Attributes | Protected Member Functions | List of all members
fkie_message_filters::Combiner< PolicyTmpl, IOs > Class Template Reference

Combine multiple sources into a single one. More...

#include <fkie_message_filters/combiner.h>

Inheritance diagram for fkie_message_filters::Combiner< PolicyTmpl, IOs >:
Inheritance graph
[legend]
Collaboration diagram for fkie_message_filters::Combiner< PolicyTmpl, IOs >:
Collaboration graph
[legend]

Public Types

using Connections = std::array< Connection, NUM_SINKS >
 Array of connection objects.
 
using Output = IO< Outputs... >
 Grouped output types. More...
 
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 Member Functions

 Combiner (const Policy &policy=Policy()) noexcept
 Constructor. More...
 
Connection connect_to_sink (Sink< Outputs... > &dst) noexcept
 Connect this source to a sink. More...
 
Connections connect_to_sources (helpers::io_rewrap_t< IOs, Source > &... sources) noexcept
 Convenience function to connect all sinks at once. More...
 
void disconnect () noexcept override
 Disconnect from all connected sources and sinks. More...
 
void disconnect_from_all_sinks () noexcept
 Disconnect from all connected sinks. More...
 
void disconnect_from_all_sources () noexcept
 Disconnect the sinks from their sources. More...
 
const Policypolicy () const noexcept
 Access combiner policy.
 
void reset () noexcept override
 Reset filter. More...
 
void set_policy (const Policy &policy) noexcept
 Set combiner policy. More...
 
template<std::size_t N>
SinkType< N > & sink () noexcept
 Access the sink for the Nth input.
 
template<std::size_t N>
const SinkType< N > & sink () const noexcept
 Access the sink for the Nth input.
 

Static Public Attributes

static constexpr std::size_t NUM_OUTPUTS
 Number of output arguments.
 
static constexpr std::size_t NUM_SINKS = sizeof...(IOs)
 Number of sinks.
 

Protected Member Functions

void send (const Outputs &... out)
 Pass data to all connected sinks. More...
 

Detailed Description

template<template< typename... > class PolicyTmpl, class... IOs>
class fkie_message_filters::Combiner< PolicyTmpl, 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

Member Typedef Documentation

◆ Output

using fkie_message_filters::Source< Outputs >::Output = IO<Outputs...>
inherited

Grouped output types.

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

Constructor & Destructor Documentation

◆ Combiner()

template<template< typename... > class PolicyTmpl, class... IOs>
fkie_message_filters::Combiner< PolicyTmpl, IOs >::Combiner ( const Policy policy = Policy())
explicitnoexcept

Constructor.

  • policy Instance of the policy class that applies to the combiner.
Exceptions
Does not throw any exceptions.

Member Function Documentation

◆ connect_to_sink()

Connection fkie_message_filters::Source< Outputs >::connect_to_sink ( Sink< Outputs... > &  dst)
noexceptinherited

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
Returns
a connection object that can be used to monitor or sever the created connection
Exceptions
Does not throw any exceptions.

◆ connect_to_sources()

template<template< typename... > class PolicyTmpl, class... IOs>
Connections fkie_message_filters::Combiner< PolicyTmpl, IOs >::connect_to_sources ( helpers::io_rewrap_t< IOs, Source > &...  sources)
noexcept

Convenience function to connect all sinks at once.

Exceptions
Does not throw any exceptions.

◆ disconnect()

template<template< typename... > class PolicyTmpl, class... IOs>
void fkie_message_filters::Combiner< PolicyTmpl, IOs >::disconnect ( )
overridevirtualnoexcept

Disconnect from all connected sources and sinks.

Exceptions
Does not throw any exceptions.

Reimplemented from fkie_message_filters::Source< IOs... >.

◆ disconnect_from_all_sinks()

void fkie_message_filters::Source< Outputs >::disconnect_from_all_sinks ( )
noexceptinherited

Disconnect from all connected sinks.

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

Exceptions
Does not throw any exceptions.

◆ disconnect_from_all_sources()

template<template< typename... > class PolicyTmpl, class... IOs>
void fkie_message_filters::Combiner< PolicyTmpl, IOs >::disconnect_from_all_sources ( )
noexcept

Disconnect the sinks from their sources.

Exceptions
Does not throw any exceptions.

◆ reset()

template<template< typename... > class PolicyTmpl, class... IOs>
void fkie_message_filters::Combiner< PolicyTmpl, IOs >::reset ( )
overridevirtualnoexcept

Reset filter.

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

Exceptions
Does not throw any exceptions.

Reimplemented from fkie_message_filters::FilterBase.

◆ send()

void fkie_message_filters::Source< Outputs >::send ( const Outputs &...  out)
protectedinherited

Pass data to all connected sinks.

  • out data
Exceptions
Does not throw any exceptions, but will propagate uncaught exceptions from filter callbacks.

◆ set_policy()

template<template< typename... > class PolicyTmpl, class... IOs>
void fkie_message_filters::Combiner< PolicyTmpl, IOs >::set_policy ( const Policy policy)
noexcept

Set combiner policy.

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

Exceptions
Does not throw any exceptions.

The documentation for this class was generated from the following file: