Template Class KPSubject¶
- Defined in File KPSubject.hpp
Class Documentation¶
-
template<typename
T>
classKPSubject¶ 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>
voidupdateObservers(F method, Types&&... args)¶ Pass variable number of arguments to observers’ class member function
- Template Parameters
F: Auto deduced type of observer’s member functionTypes: Auto deduced types of arguments
- Parameters
method: Pointer to member function of the observerargs: Arguments to pass through
Protected Types
-
template<>
usingObserverType= T¶
Protected Attributes
-
std::unordered_map<int, ObserverType *>
observers¶