$darkmode
cloe::Signal Class Reference

#include <data_broker.hpp>

Public Types

template<typename T >
using typed_get_value_function_t = std::function< databroker::signal_type_cref_t< T >()>
 
using type_erased_get_value_function_t = std::any
 
template<typename T >
using typed_set_value_function_t = std::function< void(databroker::signal_type_cref_t< T >)>
 
using type_erased_set_value_function_t = std::any
 
template<typename T >
using typed_value_changed_event_t = databroker::Event< databroker::signal_type_cref_t< T > >
 
using type_erased_value_changed_event_t = std::any
 
template<typename T >
using typed_on_value_change_event_function_t = std::function< void(databroker::signal_type_cref_t< T >)>
 
using type_erased_on_value_change_event_function_t = std::any
 

Public Member Functions

 Signal (access_token)
 
 Signal (const Signal &)=delete
 
 Signal (Signal &&)=default
 
Signaloperator= (const Signal &)=delete
 
Signaloperator= (Signal &&)=default
 
constexpr const std::type_info * type () const
 
template<typename T >
const typed_get_value_function_t< T > * getter () const
 
template<typename T >
void set_getter (typed_get_value_function_t< T > get_value_fn)
 
template<typename T >
databroker::signal_type_cref_t< T > value () const
 
template<typename T >
const typed_set_value_function_t< T > * setter () const
 
template<typename T >
void set_setter (typed_set_value_function_t< T > set_value_fn)
 
template<typename T >
void set_value (databroker::signal_type_cref_t< T > value) const
 
template<typename T >
const typed_on_value_change_event_function_t< T > & trigger () const
 
template<typename T >
std::enable_if_t<!std::is_void_v< typename T::tag_type > > add (typename T::tag_type metadata)
 
template<typename T , typename... TArgs>
std::enable_if_t<!std::is_void_v< typename T::tag_type > > add (TArgs &&... args)
 
template<typename T >
std::enable_if_t< std::is_void_v< typename T::tag_type > > add ()
 
template<typename T >
auto metadata () -> decltype(metainformations_.get< T >())
 
const MetaInformationmetadatas () const
 
template<typename T >
void subscribe (databroker::on_value_changed_callback_t< T > callback)
 
std::size_t subscriber_count () const
 
bool has_subscriber () const
 
const std::vector< std::string > & names () const
 
const std::string & name () const
 
std::string name_or (std::string def) const
 
void add_name (std::string_view name)
 

Friends

template<typename T >
class BasicContainer
 
class DataBroker
 

Detailed Description

Signal represents the properties of a signal at runtime

Note
: Design-Goals:
: Implementation-Notes:
  • Implementation-#1: Type specific aspects are implemented in templates (Design-#1)
  • Implementation-#2: Objects are created via a factory-method (to prevent instances of incomplete initialization)
  • Implementation-#3: An access-token is used to have a public c'tor which in fact shall be inaccesible (Design-#2).

Member Typedef Documentation

◆ typed_get_value_function_t

template<typename T >
using cloe::Signal::typed_get_value_function_t = std::function<databroker::signal_type_cref_t<T>()>

Getter-function types

Note: When implementing this function with lamdas (e.g. set_getter<>() ) take care to explicitly define the return-type.

Example: []() -> const int& { return value; }

Undefined behaviour: []() { return value; } ^^^ No return type specified

◆ typed_on_value_change_event_function_t

template<typename T >
using cloe::Signal::typed_on_value_change_event_function_t = std::function<void(databroker::signal_type_cref_t<T>)>

Event trigger-function types

◆ typed_set_value_function_t

template<typename T >
using cloe::Signal::typed_set_value_function_t = std::function<void(databroker::signal_type_cref_t<T>)>

Setter-function types

◆ typed_value_changed_event_t

Constructor & Destructor Documentation

◆ Signal()

cloe::Signal::Signal ( access_token  )
inlineexplicit

Public c'tor, accessible only via private access-token

Note
: Design-#1: The class shall be constructible via external helpers

Member Function Documentation

◆ add() [1/3]

template<typename T >
std::enable_if_t< std::is_void_v<typename T::tag_type> > cloe::Signal::add ( )
inline

Tags a signal with a void tag

Template Parameters
TType of the tag

◆ add() [2/3]

template<typename T , typename... TArgs>
std::enable_if_t<!std::is_void_v<typename T::tag_type> > cloe::Signal::add ( TArgs &&...  args)
inline

Tags a signal with metadata constructed from parameters

Template Parameters
TType of the tag
TArgsType of the metadata c'tor parameters
Parameters
argsMetadata c'tor arguments
Note
This is the overload for non-void tags (T2 != void)

◆ add() [3/3]

template<typename T >
std::enable_if_t<!std::is_void_v<typename T::tag_type> > cloe::Signal::add ( typename T::tag_type  metadata)
inline

Tags a signal with metadata

Template Parameters
TType of the tag
Parameters
metadataMetadata used to tag the signal
Note
This is the overload for non-void tags (T2 != void)
Here is the call graph for this function:

◆ add_name()

void cloe::Signal::add_name ( std::string_view  name)
inline

Add a name of the signal.

Parameters
nameName of the signal
Here is the call graph for this function:

◆ getter()

template<typename T >
const typed_get_value_function_t<T>* cloe::Signal::getter ( ) const
inline

Return the getter function of the signal.

Template Parameters
TType of the signal
Returns
Getter function of the signal

Example:

Signal s = ...;
const typed_get_value_function_t<int>* f = s.getter<int>();
int v = (*f)();

◆ has_subscriber()

bool cloe::Signal::has_subscriber ( ) const
inline

Indicate whether the value_changed event has subscribers.

Returns
bool True if the value_changed event has subscribers, false otherwise
Here is the call graph for this function:

◆ metadata()

template<typename T >
auto cloe::Signal::metadata ( ) -> decltype(metainformations_.get<T>())
inline

Get a tag of the signal

Template Parameters
TType of the tag
Returns
const typename T::tag_type* pointing to the tag-value (or nullptr), if typename T::tag_type != void
bool expressing the presence of the tag, if typename T::tag_type == void
Here is the caller graph for this function:

◆ metadatas()

const MetaInformation& cloe::Signal::metadatas ( ) const
inline

Get all tags of the signal

◆ name()

const std::string& cloe::Signal::name ( ) const
inline

Return the first assigned name of the signal.

Returns
First name of the signal
Here is the caller graph for this function:

◆ name_or()

std::string cloe::Signal::name_or ( std::string  def) const
inline

Return the first assigned name of the signal.

Returns
First name of the signal

◆ names()

const std::vector<std::string>& cloe::Signal::names ( ) const
inline

Return the list of names assigned to the signal.

Returns
List of names assigned to the signal

◆ set_getter()

template<typename T >
void cloe::Signal::set_getter ( typed_get_value_function_t< T >  get_value_fn)
inline

Set the getter function of the signal.

Template Parameters
TType of the signal
Parameters
get_valueGetter function of the signal

Example:

Signal s = ...;
s.set_getter<type>([&]() -> const type & { return value; });
constexpr const std::type_info * type() const
Definition: data_broker.hpp:790
databroker::signal_type_cref_t< T > value() const
Definition: data_broker.hpp:870

Usage Note: When using lambdas, the explicit return-type definition is important!

Undefined behaviour:

Signal s = ...;
s.set_getter<type>([&]() { return value; });
^^^ No return type specified, type conversion rules apply

◆ set_setter()

template<typename T >
void cloe::Signal::set_setter ( typed_set_value_function_t< T >  set_value_fn)
inline

Set the setter function of the signal.

Template Parameters
TType of the signal
Parameters
set_valueGetter function of the signal

◆ set_value()

template<typename T >
void cloe::Signal::set_value ( databroker::signal_type_cref_t< T >  value) const
inline

Set the value of the signal.

Template Parameters
TType of the signal
Parameters
valueValue of the signal
Here is the call graph for this function:

◆ setter()

template<typename T >
const typed_set_value_function_t<T>* cloe::Signal::setter ( ) const
inline

Return the getter function of the signal.

Template Parameters
TType of the signal
Returns
const typed_set_value_function_t<T>*, Getter function of the signal

◆ subscribe()

template<typename T >
void cloe::Signal::subscribe ( databroker::on_value_changed_callback_t< T >  callback)
inline

Subscribe to value-changed events.

Template Parameters
TType of the signal
Parameters
callbackevent-function which will be called when the value changed
Here is the call graph for this function:

◆ subscriber_count()

std::size_t cloe::Signal::subscriber_count ( ) const
inline

Return the count of subscribers to the value_changed event.

Returns
size_t Count of subscribers to the value_changed event
Here is the caller graph for this function:

◆ trigger()

template<typename T >
const typed_on_value_change_event_function_t<T>& cloe::Signal::trigger ( ) const
inline

Return the trigger function for the value_changed event.

Template Parameters
TType of the signal
Returns
Trigger function for raising the value_changed event

◆ type()

constexpr const std::type_info* cloe::Signal::type ( ) const
inlineconstexpr

Return the type info for the signal.

◆ value()

template<typename T >
databroker::signal_type_cref_t<T> cloe::Signal::value ( ) const
inline

Return the current value of the signal.

Template Parameters
TType of the signal
Returns
databroker::signal_type_cref_t<T>, Current value of the signal
Note
databroker::compatible_base_t<T> == T, if the method compiles
Here is the caller graph for this function:

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