OSSIA
Open Scenario System for Interactive Application
Loading...
Searching...
No Matches
ossia::callback_container< T > Class Template Reference

The callback_container class. More...

Detailed Description

template<typename T>
class ossia::callback_container< T >

The callback_container class.

Contains callbacks. Classes that have network callbacks may want to derive from this and implement on_first_callback_added, on_removing_last_callback.

This allows to cleanly stop listening when there are no callbacks.

Public Types

using impl = std::list<T>
 impl How the callbackas are stored. A list is used since iterators to other callbacks must not be invalidated upon removal.
using iterator = typename impl::iterator

Public Member Functions

 callback_container (const callback_container &other)
 callback_container (callback_container &&other) noexcept
callback_container & operator= (const callback_container &other)
callback_container & operator= (callback_container &&other) noexcept
iterator add_callback (T &&callback)
 add_callback Add a new callback.
void remove_callback (iterator it)
 remove_callback Removes a callback identified by an iterator.
void replace_callback (iterator it, T &&cb)
 Replaces an existing callback with another function.
void replace_callbacks (impl &&cbs)
disabled_callback disable_callback (iterator it)
std::size_t callback_count () const
 callback_count
bool callbacks_empty () const
 callbacks_empty
template<typename... Args>
void send (Args &&... args)
 send Trigger all callbacks
void callbacks_clear ()
 clear Clears callbacks.
impl m_callbacks TS_GUARDED_BY (m_mutx)

Public Attributes

mutex m_mutx

Protected Member Functions

virtual void on_first_callback_added ()
 on_first_callback_added
virtual void on_removing_last_callback ()
 on_removing_last_callback

Member Function Documentation

◆ add_callback()

template<typename T>
iterator ossia::callback_container< T >::add_callback ( T && callback)
inline

add_callback Add a new callback.

Parameters
callbackmust be a std::function or similar.
Returns
iterator to save in order to be able to remove the callback.

◆ remove_callback()

template<typename T>
void ossia::callback_container< T >::remove_callback ( iterator it)
inline

remove_callback Removes a callback identified by an iterator.

Parameters
itIterator to remove.

◆ callback_count()

template<typename T>
std::size_t ossia::callback_container< T >::callback_count ( ) const
inline

callback_count

Returns
Number of active callbacks.

◆ callbacks_empty()

template<typename T>
bool ossia::callback_container< T >::callbacks_empty ( ) const
inline

callbacks_empty

Returns
True if there are no callbacks

◆ send()

template<typename T>
template<typename... Args>
void ossia::callback_container< T >::send ( Args &&... args)
inline

send Trigger all callbacks

Parameters
argsArguments to send to the callbacks.

◆ on_first_callback_added()

template<typename T>
virtual void ossia::callback_container< T >::on_first_callback_added ( )
inlineprotectedvirtual

on_first_callback_added

These functions can be reimplemented by subclasses wishing to perform special actions. For instance, when the last callback is removed, stop listening somewhere...

See also
on_removing_last_callback

Reimplemented in ossia::net::generic_parameter.

◆ on_removing_last_callback()

template<typename T>
virtual void ossia::callback_container< T >::on_removing_last_callback ( )
inlineprotectedvirtual

on_removing_last_callback

See also
on_first_callback_added

Reimplemented in ossia::net::generic_parameter.