Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

ogdf::Observable< TObserver, TObserved > Class Template Reference

Base class for an observable object that can be tracked by multiple Observer objects. More...

#include <ogdf/basic/Observer.h>

Public Member Functions

 Observable ()=default
 
 Observable (const Observable &copy)=delete
 If you want to copy a subclass of Observable, call the default Observable() constructor. More...
 
 Observable (Observable &&move)=delete
 If you want to move a subclass of Observable, call the default Observable() constructor. More...
 
virtual ~Observable ()
 
Observableoperator= (const Observable &copy)=delete
 
Observableoperator= (Observable &&move)=delete
 

Protected Member Functions

void clearObservers ()
 
const ListPure< TObserver * > & getObservers () const
 

Private Member Functions

ListPure< TObserver * >::iterator registerObserver (TObserver *obs) const
 Registers an observer. More...
 
void unregisterObserver (typename ListPure< TObserver * >::iterator it) const
 Unregisters an observer. More...
 

Private Attributes

std::mutex m_mutexRegArrays
 The critical section for protecting shared access to register/unregister methods. More...
 
ListPure< TObserver * > m_regObservers
 The registered observers. More...
 
friend Observer< TObserved, TObserver >
 

Detailed Description

template<typename TObserver, typename TObserved>
class ogdf::Observable< TObserver, TObserved >

Base class for an observable object that can be tracked by multiple Observer objects.

Will notify its observers when it is destructed and can be subclassed to provide further callbacks. For compatibility with MSVC, the Observer subclass has to be defined before the Observable subclass.

Template Parameters
TObservedThe subclass of Observable that will be observed.
TObserverThe subclass of Observer that defines all virtual callback methods.

Definition at line 104 of file Observer.h.

Constructor & Destructor Documentation

◆ Observable() [1/3]

template<typename TObserver , typename TObserved >
ogdf::Observable< TObserver, TObserved >::Observable ( )
default

◆ ~Observable()

template<typename TObserver , typename TObserved >
virtual ogdf::Observable< TObserver, TObserved >::~Observable ( )
inlinevirtual

Definition at line 115 of file Observer.h.

◆ Observable() [2/3]

template<typename TObserver , typename TObserved >
ogdf::Observable< TObserver, TObserved >::Observable ( const Observable< TObserver, TObserved > &  copy)
delete

If you want to copy a subclass of Observable, call the default Observable() constructor.

Note that Observers can only observe one Observable and in this case will stay with the old one.

◆ Observable() [3/3]

template<typename TObserver , typename TObserved >
ogdf::Observable< TObserver, TObserved >::Observable ( Observable< TObserver, TObserved > &&  move)
delete

If you want to move a subclass of Observable, call the default Observable() constructor.

If you want to also point all Observers to the new location of their Observable, call register for each of them.

Member Function Documentation

◆ clearObservers()

template<typename TObserver , typename TObserved >
void ogdf::Observable< TObserver, TObserved >::clearObservers ( )
inlineprotected

Definition at line 163 of file Observer.h.

◆ getObservers()

template<typename TObserver , typename TObserved >
const ListPure<TObserver*>& ogdf::Observable< TObserver, TObserved >::getObservers ( ) const
inlineprotected

Definition at line 161 of file Observer.h.

◆ operator=() [1/2]

template<typename TObserver , typename TObserved >
Observable& ogdf::Observable< TObserver, TObserved >::operator= ( const Observable< TObserver, TObserved > &  copy)
delete

◆ operator=() [2/2]

template<typename TObserver , typename TObserved >
Observable& ogdf::Observable< TObserver, TObserved >::operator= ( Observable< TObserver, TObserved > &&  move)
delete

◆ registerObserver()

template<typename TObserver , typename TObserved >
ListPure<TObserver*>::iterator ogdf::Observable< TObserver, TObserved >::registerObserver ( TObserver *  obs) const
inlineprivate

Registers an observer.

Parameters
obsis a pointer to the observer that shall be registered
Returns
an iterator pointing to the entry for the registered observer in the list of registered observers. This iterator is required for unregistering the observer again.

Definition at line 140 of file Observer.h.

◆ unregisterObserver()

template<typename TObserver , typename TObserved >
void ogdf::Observable< TObserver, TObserved >::unregisterObserver ( typename ListPure< TObserver * >::iterator  it) const
inlineprivate

Unregisters an observer.

Parameters
itis an iterator pointing to the entry in the list of registered observers for the observer to be unregistered.

Definition at line 153 of file Observer.h.

Member Data Documentation

◆ m_mutexRegArrays

template<typename TObserver , typename TObserved >
std::mutex ogdf::Observable< TObserver, TObserved >::m_mutexRegArrays
mutableprivate

The critical section for protecting shared access to register/unregister methods.

Definition at line 108 of file Observer.h.

◆ m_regObservers

template<typename TObserver , typename TObserved >
ListPure<TObserver*> ogdf::Observable< TObserver, TObserved >::m_regObservers
mutableprivate

The registered observers.

Definition at line 110 of file Observer.h.

◆ Observer< TObserved, TObserver >

template<typename TObserver , typename TObserved >
friend ogdf::Observable< TObserver, TObserved >::Observer< TObserved, TObserver >
private

Definition at line 105 of file Observer.h.


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