Loading...
Searching...
No Matches
observer

## Classes

class | etl::delegate_observable< TNotification, Max_Observers >
class | etl::observer_exception
class | etl::observer_list_full
class | etl::observable< TObserver, Max_Observers >
class | etl::observer< T1, T2, T3, T4, T5, T6, T7, T8 >
class | etl::observer< T1, T2, T3, T4, T5, T6, T7 >
class | etl::observer< T1, T2, T3, T4, T5, T6 >
class | etl::observer< T1, T2, T3, T4, T5 >
class | etl::observer< T1, T2, T3, T4 >
class | etl::observer< T1, T2, T3 >
class | etl::observer< T1, T2 >
class | etl::observer< T1 >
class | etl::observer< void >

## Detailed Description

A templated implementation to simplify the creation of the observer pattern and attempts to eliminate certain runtime errors by turning them into compile errors. The pattern consists of two template classes.

- Observer
  This template may take up to eight notification types. Each notification type will generate a pure virtual 'notification' function. The class that inherits from this must define all of the 'notification' function overloads otherwise the object will remain 'abstract' and will not compile. This ensures that no overload can be forgotten.

- observable
  The class derived from this will be observed by the above class. It keeps a list of registered observers and will notify all of them with the notifications.

## Class Documentation

## etl::delegate_observable

class etl::delegate_observable

template<typename TNotification, size_t Max_Observers>
class etl::delegate_observable< TNotification, Max_Observers >

An obserable type that uses delegates to notify observers.

Template Parameters

  TNotification | The notification type sent to the observers.
  Max_Observers | The maximum number of observers that can be accommodated.

### Public Types

typedef etl::delegate< void(TNotification)> | delegate_type
| The type of the observers.
typedef size_t | size_type
| The type for sizes.
typedef TNotification | notification_type
| The type of the notification.

### Public Member Functions

ETL_CONSTEXPR14 | delegate_observable ()
| Default constructor.
ETL_CONSTEXPR14 bool | add_observer (delegate_type observer)
ETL_CONSTEXPR14 bool | remove_observer (const delegate_type &observer)
ETL_CONSTEXPR14 void | clear_observers ()
| Clear all observers.
ETL_CONSTEXPR14 size_type | number_of_observers () const
| Returns the number of observers.
ETL_CONSTEXPR14 void | notify_observers (notification_type n) const

#### Member Function Documentation

## add_observer()

template<typename TNotification, size_t Max_Observers>

ETL_CONSTEXPR14 bool etl::delegate_observable< TNotification, Max_Observers >::add_observer | ( | delegate_type | observer | ) |

inline

Add an observer to the list.

Parameters

  observer | A reference to the observer.

Returns
  true if the observer was added or already exists, b>false if not.

## notify_observers()

template<typename TNotification, size_t Max_Observers>

ETL_CONSTEXPR14 void etl::delegate_observable< TNotification, Max_Observers >::notify_observers | ( | notification_type | n | ) | const

inline

Notify all of the observers, sending them the notification.

Template Parameters

  TNotification | The notification type.

Parameters

  n | The notification.

## remove_observer()

template<typename TNotification, size_t Max_Observers>

ETL_CONSTEXPR14 bool etl::delegate_observable< TNotification, Max_Observers >::remove_observer | ( | const delegate_type & | observer | ) |

inline

Remove a particular observer from the list.

Parameters

  observer | A reference to the observer.

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

## etl::observer_exception

class etl::observer_exception

The base class for observer exceptions.

### Public Member Functions

| observer_exception (string_type reason_, string_type file_name_, numeric_type line_number_)
Public Member Functions inherited from etl::exception
ETL_EXCEPTION_CONSTEXPR | exception (string_type reason_, string_type, numeric_type)
| Constructor.
ETL_EXCEPTION_CONSTEXPR string_type | what () const ETL_NOEXCEPT ETL_EXCEPTION_OVERRIDE
ETL_EXCEPTION_CONSTEXPR string_type | file_name () const
ETL_EXCEPTION_CONSTEXPR numeric_type | line_number () const

## Additional Inherited Members

Public Types inherited from etl::exception
typedef const char * | string_type
typedef int | numeric_type

## etl::observer_list_full

class etl::observer_list_full

The exception thrown when the observer list is full.

### Public Member Functions

| observer_list_full (string_type file_name_, numeric_type line_number_)
Public Member Functions inherited from etl::observer_exception
| observer_exception (string_type reason_, string_type file_name_, numeric_type line_number_)
Public Member Functions inherited from etl::exception
ETL_EXCEPTION_CONSTEXPR | exception (string_type reason_, string_type, numeric_type)
| Constructor.
ETL_EXCEPTION_CONSTEXPR string_type | what () const ETL_NOEXCEPT ETL_EXCEPTION_OVERRIDE
ETL_EXCEPTION_CONSTEXPR string_type | file_name () const
ETL_EXCEPTION_CONSTEXPR numeric_type | line_number () const

## Additional Inherited Members

Public Types inherited from etl::exception
typedef const char * | string_type
typedef int | numeric_type

## etl::observable

class etl::observable

template<typename TObserver, const size_t Max_Observers>
class etl::observable< TObserver, Max_Observers >

The object that is being observed.

Template Parameters

  TObserver | The observer type.
  Max_Observers | The maximum number of observers that can be accommodated.

### Public Types

typedef size_t | size_type
typedef etl::vector< observer_item, Max_Observers > | Observer_List

### Public Member Functions

void | add_observer (TObserver &observer)
bool | remove_observer (TObserver &observer)
void | enable_observer (TObserver &observer, bool state=true)
void | disable_observer (TObserver &observer)
| Disable an observer.
void | clear_observers ()
| Clear all observers from the list.
size_type | number_of_observers () const
| Returns the number of observers.
template<typename TNotification>
void | notify_observers (TNotification n)
void | notify_observers ()
| Notify all of the observers, sending them the notification.

#### Member Function Documentation

## add_observer()

template<typename TObserver, const size_t Max_Observers>

void etl::observable< TObserver, Max_Observers >::add_observer | ( | TObserver & | observer | ) |

inline

Add an observer to the list. If asserts or exceptions are enabled then an etl::observable_observer_list_full is emitted if the observer list is already full.

Parameters

  observer | A reference to the observer.

## enable_observer()

template<typename TObserver, const size_t Max_Observers>

void etl::observable< TObserver, Max_Observers >::enable_observer | ( | TObserver & | observer,
|  | bool | state = true )

inline

Enable an observer

Parameters

  observer | A reference to the observer.
  state | true to enable, false to disable. Default is enable.

## notify_observers()

template<typename TObserver, const size_t Max_Observers>
template<typename TNotification>

void etl::observable< TObserver, Max_Observers >::notify_observers | ( | TNotification | n | ) |

inline

Notify all of the observers, sending them the notification.

Template Parameters

  TNotification | The notification type.

Parameters

  n | The notification.

## remove_observer()

template<typename TObserver, const size_t Max_Observers>

bool etl::observable< TObserver, Max_Observers >::remove_observer | ( | TObserver & | observer | ) |

inline

Remove a particular observer from the list.

Parameters

  observer | A reference to the observer.

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

## etl::observer

class etl::observer

template<typename T1, typename T2 = void, typename T3 = void, typename T4 = void, typename T5 = void, typename T6 = void, typename T7 = void, typename T8 = void>
class etl::observer< T1, T2, T3, T4, T5, T6, T7, T8 >

The observer interface for eight notification types.

## etl::observer< T1, T2, T3, T4, T5, T6, T7 >

class etl::observer< T1, T2, T3, T4, T5, T6, T7 >

template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
class etl::observer< T1, T2, T3, T4, T5, T6, T7 >

The observer interface for seven notification types.

## Additional Inherited Members

Public Member Functions inherited from etl::observer< T1 >
virtual void | notification (T1)=0

#### Constructor & Destructor Documentation

## ~observer()

template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>

virtual etl::observer< T1, T2, T3, T4, T5, T6, T7 >::~observer | ( |  | ) |

inline virtual

Reimplemented from etl::observer< T1 >.

## etl::observer< T1, T2, T3, T4, T5, T6 >

class etl::observer< T1, T2, T3, T4, T5, T6 >

template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
class etl::observer< T1, T2, T3, T4, T5, T6 >

The observer interface for six notification types.

## Additional Inherited Members

Public Member Functions inherited from etl::observer< T1 >
virtual void | notification (T1)=0

#### Constructor & Destructor Documentation

## ~observer()

template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>

virtual etl::observer< T1, T2, T3, T4, T5, T6 >::~observer | ( |  | ) |

inline virtual

Reimplemented from etl::observer< T1 >.

## etl::observer< T1, T2, T3, T4, T5 >

class etl::observer< T1, T2, T3, T4, T5 >

template<typename T1, typename T2, typename T3, typename T4, typename T5>
class etl::observer< T1, T2, T3, T4, T5 >

The observer interface for five notification types.

## Additional Inherited Members

Public Member Functions inherited from etl::observer< T1 >
virtual void | notification (T1)=0

#### Constructor & Destructor Documentation

## ~observer()

template<typename T1, typename T2, typename T3, typename T4, typename T5>

virtual etl::observer< T1, T2, T3, T4, T5 >::~observer | ( |  | ) |

inline virtual

Reimplemented from etl::observer< T1 >.

## etl::observer< T1, T2, T3, T4 >

class etl::observer< T1, T2, T3, T4 >

template<typename T1, typename T2, typename T3, typename T4>
class etl::observer< T1, T2, T3, T4 >

The observer interface for four notification types.

## Additional Inherited Members

Public Member Functions inherited from etl::observer< T1 >
virtual void | notification (T1)=0

#### Constructor & Destructor Documentation

## ~observer()

template<typename T1, typename T2, typename T3, typename T4>

virtual etl::observer< T1, T2, T3, T4 >::~observer | ( |  | ) |

inline virtual

Reimplemented from etl::observer< T1 >.

## etl::observer< T1, T2, T3 >

class etl::observer< T1, T2, T3 >

template<typename T1, typename T2, typename T3>
class etl::observer< T1, T2, T3 >

The observer interface for three notification types.

## Additional Inherited Members

Public Member Functions inherited from etl::observer< T1 >
virtual void | notification (T1)=0

#### Constructor & Destructor Documentation

## ~observer()

template<typename T1, typename T2, typename T3>

virtual etl::observer< T1, T2, T3 >::~observer | ( |  | ) |

inline virtual

Reimplemented from etl::observer< T1 >.

## etl::observer< T1, T2 >

class etl::observer< T1, T2 >

template<typename T1, typename T2>
class etl::observer< T1, T2 >

The observer interface for two notification types.

## Additional Inherited Members

Public Member Functions inherited from etl::observer< T1 >
virtual void | notification (T1)=0

#### Constructor & Destructor Documentation

## ~observer()

template<typename T1, typename T2>

virtual etl::observer< T1, T2 >::~observer | ( |  | ) |

inline virtual

Reimplemented from etl::observer< T1 >.

## etl::observer< T1 >

class etl::observer< T1 >

template<typename T1>
class etl::observer< T1 >

The observer interface for one notification type.

### Public Member Functions

virtual void | notification (T1)=0

## etl::observer< void >

class etl::observer< void >

The observer interface for void argument notification type.

### Public Member Functions

virtual void | notification ()=0