Public Types | Public Member Functions | Protected Member Functions | Private Attributes | List of all members
fkie_message_filters::UserFilter< IO< Inputs... >, IO< Outputs... > > Class Template Reference

Generic filter with user-defined callback function. More...

#include <user_filter.h>

Inheritance diagram for fkie_message_filters::UserFilter< IO< Inputs... >, IO< Outputs... > >:
Inheritance graph
[legend]

Public Types

using CallbackFunction = FilterCB< Outputs... >
 Callback function type. More...
 
using ProcessingFunction = std::function< void(const Inputs &..., const CallbackFunction &)>
 Processing function type. More...
 
- Public Types inherited from fkie_message_filters::Sink< Inputs... >
using Input = IO< Inputs... >
 Grouped input types. More...
 
- Public Types inherited from fkie_message_filters::Source< Outputs... >
using Output = IO< Outputs... >
 Grouped output types. More...
 

Public Member Functions

void set_processing_function (const ProcessingFunction &f) noexcept
 Set the user-defined processing function. More...
 
- Public Member Functions inherited from fkie_message_filters::Sink< Inputs... >
Connection connect_to_source (Source< Inputs... > &src) noexcept
 Connect this sink to a source. More...
 
void disconnect_from_all_sources () noexcept
 Disconnect from all connected sources. More...
 
virtual ~Sink ()
 
- Public Member Functions inherited from fkie_message_filters::FilterBase
virtual void reset () noexcept
 Reset filter state. More...
 
virtual ~FilterBase ()
 
- Public Member Functions inherited from fkie_message_filters::Source< Outputs... >
Connection connect_to_sink (Sink< Outputs... > &dst) noexcept
 Connect this source to a sink. More...
 
void disconnect_from_all_sinks () noexcept
 Disconnect from all connected sinks. More...
 
virtual ~Source ()
 

Protected Member Functions

void receive (const Inputs &... in) override
 Process incoming data. More...
 
- Protected Member Functions inherited from fkie_message_filters::Source< Outputs... >
void send (const Outputs &... out)
 Pass data to all connected sinks. More...
 

Private Attributes

ProcessingFunction f_
 

Additional Inherited Members

- Static Public Attributes inherited from fkie_message_filters::Sink< Inputs... >
static constexpr std::size_t NUM_INPUTS
 Number of input arguments. More...
 
- Static Public Attributes inherited from fkie_message_filters::Source< Outputs... >
static constexpr std::size_t NUM_OUTPUTS
 Number of output arguments. More...
 

Detailed Description

template<class... Inputs, class... Outputs>
class fkie_message_filters::UserFilter< IO< Inputs... >, IO< Outputs... > >

Generic filter with user-defined callback function.

You can implement your own filter logic and integrate it with the filter pipeline. For this, you need to define your own function that takes the Inputs and a CallbackFunction as arguments. The function will be called by the generic filter, and expects you to feed back the processed data using the callback function. Typically, your code will look similar to this:

using InBuffer = mf::Buffer<T1, T2>;
using OutBuffer = mf::Buffer<T3, T4>;
void my_processing_func(const T1& t1, const T2& t2, const MyFilter::CallbackFunction& cb)
{
// Process the inputs t1 and t2 and prepare the outputs t3 and t4
T3 t3;
T4 t4;
// ...
// Feed the outputs back into the filter pipeline
cb(t3, t4);
}

Set up your filter pipeline like this:

InBuffer in;
MyFilter flt;
OutBuffer out;
flt.set_processing_function(my_processing_func);
mf::chain(in, flt, out);

In your processing function, you can call the callback function as often as you want, or even not at all. There is no requirement that each input produces exactly one output. When you have no output at all, or the output is the same as the input, you should consider the SimpleUserFilter instead, which is easier to set up.

The filter will throw a std::bad_function_call exception if it is invoked without a user-defined processing function.

Definition at line 96 of file user_filter.h.

Member Typedef Documentation

◆ CallbackFunction

template<class... Inputs, class... Outputs>
using fkie_message_filters::UserFilter< IO< Inputs... >, IO< Outputs... > >::CallbackFunction = FilterCB<Outputs...>

Callback function type.

This is the signature of the callback function pointer your processing function will receive.

Definition at line 107 of file user_filter.h.

◆ ProcessingFunction

template<class... Inputs, class... Outputs>
using fkie_message_filters::UserFilter< IO< Inputs... >, IO< Outputs... > >::ProcessingFunction = std::function<void(const Inputs&..., const CallbackFunction&)>

Processing function type.

This can be any user-defined function and will be called to process incoming data. The results are expected be returned via the callback function.

Definition at line 113 of file user_filter.h.

Member Function Documentation

◆ receive()

template<class... Inputs, class... Outputs>
void fkie_message_filters::UserFilter< IO< Inputs... >, IO< Outputs... > >::receive ( const Inputs &...  in)
overrideprotectedvirtual

Process incoming data.

Derived classes need to override this method to handle all data that is to be consumed by the sink.

\abstractthrow

Implements fkie_message_filters::Sink< Inputs... >.

Definition at line 53 of file user_filter_impl.h.

◆ set_processing_function()

template<class... Inputs, class... Outputs>
void fkie_message_filters::UserFilter< IO< Inputs... >, IO< Outputs... > >::set_processing_function ( const ProcessingFunction f)
noexcept

Set the user-defined processing function.

You must call this method before the filter gets invoked with incoming data.

\nothrow

Definition at line 47 of file user_filter_impl.h.

Member Data Documentation

◆ f_

template<class... Inputs, class... Outputs>
ProcessingFunction fkie_message_filters::UserFilter< IO< Inputs... >, IO< Outputs... > >::f_
private

Definition at line 124 of file user_filter.h.


The documentation for this class was generated from the following files:
fkie_message_filters
Definition: buffer.h:33
fkie_message_filters::chain
void chain(Filter1 &flt1, Filter2 &flt2, MoreFilters &... filters) noexcept
Convenience function to chain multiple filters.
Definition: filter_impl.h:71
fkie_message_filters::Buffer
Store and forward data.
Definition: buffer.h:121
fkie_message_filters::UserFilter
Definition: user_filter.h:49


fkie_message_filters
Author(s): Timo Röhling
autogenerated on Wed Mar 2 2022 00:18:57