Template Class KPSubject

Class Documentation

template<typename T>
class KPSubject

This class is represents the “subject” of the observer pattern.

Template Parameters
  • T: Observer Type

Public Functions

int addObserver(ObserverType *o)

Add the observer to the internal data structure

Return
int Randomly generated token (use to remove the observer later)
Parameters
  • o: Pointer to the observer instance

auto addObserver(ObserverType &o)

Convient method for adding reference to the observer instance

Return
see addObserver(ObserverType * o)
Parameters

void removeObserver(int token)

Remove observer given a token

Parameters
  • token: Token generated when calling addObserver methods

template<typename F, typename ...Types>
void updateObservers(F method, Types&&... args)

Pass variable number of arguments to observers’ class member function

Template Parameters
  • F: Auto deduced type of observer’s member function
  • Types: Auto deduced types of arguments
Parameters
  • method: Pointer to member function of the observer
  • args: Arguments to pass through

Protected Types

template<>
using ObserverType = T

Protected Attributes

std::unordered_map<int, ObserverType *> observers