A C++ template library for embedded applications
MIT licensed
Designed and
maintained by
John Wellbelove

delegate_observable


 

etl::delegate_observable is a variation on the observer pattern idea, but using delegates as the callback mechanism.

 

template <typename TNotification, size_t Max_Observers>

class delegate_observable

 

TNotification is the notification type.

Max_Observers is the maximum number of observers that can be handled.

____________________________________________________________________________________________________

Template deduction guide

 

template <typename TNotification, typename... TDelegates>

delegate_observable(TNotification, TDelegates...)

  -> delegate_observable<TNotification, sizeof...(TDelegates)>;

 

Example


etl::delegate<void(int)> delegate1;

etl::delegate<void(int)> delegate2;

 

etl::delegate_observable observable(int{}, delegate1, delegate2);

____________________________________________________________________________________________________

Public types

 

delegate_type     The type of delegate used in this observer.

size_type         The type used internally for sizes.

notification_type The type of the notification.

____________________________________________________________________________________________________

Construction

 

ETL_CONSTEXPR14 delegate_observable()

Default constructor.

____________________________________________________________________________________________________

template <typename... TDelegate>

ETL_CONSTEXPR14 delegate_observable(TDelegate&&... delegates)

Construct from a collection of observers.

____________________________________________________________________________________________________

template <typename... TDelegate>

ETL_CONSTEXPR14 delegate_observable(notification_type, TDelegate&&... delegates)

Construct from notification type and a list of observers.

Variant for template deduction guide.

The notification value is ignored. It is here to allow deduction of the notification type for the template deduction guide.

____________________________________________________________________________________________________

Modifiers

 

ETL_CONSTEXPR14 bool add_observer(delegate_type observer)

Add an observer to the list.

Returns true if the observer was removed, false if not.

____________________________________________________________________________________________________

ETL_CONSTEXPR14 bool remove_observer(const delegate_type& observer)

Remove a particular observer from the list.

Returns true if the observer was removed, false if not.

____________________________________________________________________________________________________

ETL_CONSTEXPR14 void clear_observers()

Clear all observers.

____________________________________________________________________________________________________

Status

 

ETL_CONSTEXPR14 size_type number_of_observers() const

Returns the number of observers.

____________________________________________________________________________________________________

Notofication

 

ETL_CONSTEXPR14 void notify_observers(notification_type n) const

Notify all of the observers, sending them the notification.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

delegate_observable.h