Doomsday SDK  2.3
Core engine library and supporting libraries
Classes | Public Types | Public Member Functions | Friends | List of all members
de::Observers< Type > Class Template Reference

Template for observer sets. More...

#include <observers.h>

+ Inheritance diagram for de::Observers< Type >:

Classes

class  Loop
 Iteration utility for observers. More...
 

Public Types

typedef Members::const_iterator const_iterator
 
typedef PointerSetT< Type > Members
 
typedef int size_type
 

Public Member Functions

 Observers ()
 
 Observers (Observers< Type > const &other)
 
virtual ~Observers ()
 
void add (Type *observer)
 Add an observer into the set. More...
 
void addMember (ObserverBase *member)
 
void clear ()
 
bool contains (Type const *observer) const
 
bool contains (Type const &observer) const
 
bool isEmpty () const
 
Observers< Type > & operator+= (Type *observer)
 
Observers< Type > & operator+= (Type &observer)
 
Observers< Type > const & operator+= (Type const *observer) const
 
Observers< Type > const & operator+= (Type const &observer) const
 
Observers< Type > & operator-= (Type *observer)
 
Observers< Type > & operator-= (Type &observer)
 
Observers< Type > const & operator-= (Type *observer) const
 
Observers< Type > const & operator-= (Type &observer) const
 
Observers< Type > & operator= (Observers< Type > const &other)
 
void remove (Type *observer)
 
void removeMember (ObserverBase *member)
 
void setAdditionAllowedDuringIteration (bool yes)
 Allows or denies addition of audience members while the audience is being iterated. More...
 
size_type size () const
 
- Public Member Functions inherited from de::Lockable
void lock () const
 Acquire the lock. Blocks until the operation succeeds. More...
 
void unlock () const
 Release the lock. More...
 
- Public Member Functions inherited from de::IAudience
virtual ~IAudience ()
 

Friends

class Loop
 

Detailed Description

template<typename Type>
class de::Observers< Type >

Template for observer sets.

The template type should be an interface implemented by all the observers. The observer type must implement ObserverBase.

How to use the non-pimpl audience macros

These examples explain how to create an audience called "Deletion". In general, audience names should be nouns like this so they can be used in the form "audience for (something)".

In a class declaration, define the audience in the public section of the class:

DENG2_DEFINE_AUDIENCE(Deletion, ...interface-function...)

This will generate a public member variable called audienceForDeletion that can be directly manipulated by other objects.

Note that because the audience is created as a public member variable, this can easily lead to ABI backwards compatibility issues down the road if there is need to make changes to the class.

How to use the pimpl audience macros

Another set of macros is provided for declaring and defining a pimpl-friendly audience. The caveat is that you'll need to separately declare accessor methods and define the audience inside the private implementation of the class.

First, define the audience in the public section of the class:

DENG2_DEFINE_AUDIENCE2(Deletion, ...interface-function...)

This works like DENG2_DEFINE_AUDIENCE, but without a public member variable. Instead, accessor methods are declared for accessing the audience.

Then, inside the private implementation (Instance struct), define the audience:

DENG2_PIMPL_AUDIENCE(Deletion)

Finally, define the accessor methods (for instance, just before the constructor of the class):

DENG2_AUDIENCE_METHOD(ClassName, Deletion)

It is recommended to keep the DENG2_PIMPL_AUDIENCE and DENG2_AUDIENCE_METHOD macros close together in the source file for easier maintenance. The former could be at the end of the Instance struct while the latter is immediately following the struct.

Thread-safety

Observers and Observers::Loop lock the observer set separately for reading and writing as appropriate.

Definition at line 228 of file observers.h.

Member Typedef Documentation

◆ const_iterator

template<typename Type>
typedef Members::const_iterator de::Observers< Type >::const_iterator

Definition at line 232 of file observers.h.

◆ Members

template<typename Type>
typedef PointerSetT<Type> de::Observers< Type >::Members

Definition at line 231 of file observers.h.

◆ size_type

template<typename Type>
typedef int de::Observers< Type >::size_type

Definition at line 233 of file observers.h.

Constructor & Destructor Documentation

◆ Observers() [1/2]

template<typename Type>
de::Observers< Type >::Observers ( )
inline

Definition at line 306 of file observers.h.

◆ Observers() [2/2]

template<typename Type>
de::Observers< Type >::Observers ( Observers< Type > const &  other)
inline

Definition at line 308 of file observers.h.

◆ ~Observers()

template<typename Type>
virtual de::Observers< Type >::~Observers ( )
inlinevirtual

Definition at line 312 of file observers.h.

Member Function Documentation

◆ add()

template<typename Type>
void de::Observers< Type >::add ( Type *  observer)
inline

Add an observer into the set.

The set does not receive ownership of the observer instance.

Definition at line 336 of file observers.h.

◆ addMember()

template<typename Type>
void de::Observers< Type >::addMember ( ObserverBase member)
inlinevirtual

Implements de::IAudience.

Definition at line 418 of file observers.h.

◆ clear()

template<typename Type>
void de::Observers< Type >::clear ( )
inline

Definition at line 317 of file observers.h.

◆ contains() [1/2]

template<typename Type>
bool de::Observers< Type >::contains ( Type const *  observer) const
inline

Definition at line 395 of file observers.h.

◆ contains() [2/2]

template<typename Type>
bool de::Observers< Type >::contains ( Type const &  observer) const
inline

Definition at line 400 of file observers.h.

◆ isEmpty()

template<typename Type>
bool de::Observers< Type >::isEmpty ( ) const
inline

Definition at line 391 of file observers.h.

◆ operator+=() [1/4]

template<typename Type>
Observers<Type>& de::Observers< Type >::operator+= ( Type *  observer)
inline

Definition at line 341 of file observers.h.

◆ operator+=() [2/4]

template<typename Type>
Observers<Type>& de::Observers< Type >::operator+= ( Type &  observer)
inline

Definition at line 346 of file observers.h.

◆ operator+=() [3/4]

template<typename Type>
Observers<Type> const& de::Observers< Type >::operator+= ( Type const *  observer) const
inline

Definition at line 351 of file observers.h.

◆ operator+=() [4/4]

template<typename Type>
Observers<Type> const& de::Observers< Type >::operator+= ( Type const &  observer) const
inline

Definition at line 356 of file observers.h.

◆ operator-=() [1/4]

template<typename Type>
Observers<Type>& de::Observers< Type >::operator-= ( Type *  observer)
inline

Definition at line 366 of file observers.h.

◆ operator-=() [2/4]

template<typename Type>
Observers<Type>& de::Observers< Type >::operator-= ( Type &  observer)
inline

Definition at line 371 of file observers.h.

◆ operator-=() [3/4]

template<typename Type>
Observers<Type> const& de::Observers< Type >::operator-= ( Type *  observer) const
inline

Definition at line 376 of file observers.h.

◆ operator-=() [4/4]

template<typename Type>
Observers<Type> const& de::Observers< Type >::operator-= ( Type &  observer) const
inline

Definition at line 381 of file observers.h.

◆ operator=()

template<typename Type>
Observers<Type>& de::Observers< Type >::operator= ( Observers< Type > const &  other)
inline

Definition at line 323 of file observers.h.

◆ remove()

template<typename Type>
void de::Observers< Type >::remove ( Type *  observer)
inline

Definition at line 361 of file observers.h.

◆ removeMember()

template<typename Type>
void de::Observers< Type >::removeMember ( ObserverBase member)
inlinevirtual

Implements de::IAudience.

Definition at line 419 of file observers.h.

◆ setAdditionAllowedDuringIteration()

template<typename Type>
void de::Observers< Type >::setAdditionAllowedDuringIteration ( bool  yes)
inline

Allows or denies addition of audience members while the audience is being iterated.

By default, addition is not allowed. If additions are allowed, only one Loop can be iterating the audience at a time.

Parameters
yestrue to allow additions, false to deny.

Definition at line 412 of file observers.h.

◆ size()

template<typename Type>
size_type de::Observers< Type >::size ( ) const
inline

Definition at line 386 of file observers.h.

Friends And Related Function Documentation

◆ Loop

template<typename Type>
friend class Loop
friend

Definition at line 303 of file observers.h.


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