15 #ifndef DD_ACCESS_OBSERVER_INTERFACE_H_INCLUDED
16 #define DD_ACCESS_OBSERVER_INTERFACE_H_INCLUDED
33 template <
typename MODEL_SUBJECT_T,
typename EVENT_CODE_T>
58 const std::string& additional_info) = 0;
67 template <
typename MODEL_SUBJECT_T,
typename EVENT_CODE_T>
114 for (
auto& current: _observers) {
115 if (current == observer) {
119 _observers.push_back(observer);
128 for (
auto current = _observers.begin(); current != _observers.end(); ++current) {
129 if (*current == observer) {
130 _observers.erase(current);
146 const std::string& additional_info)
149 auto observers_copy = _observers;
150 for (
auto& current: observers_copy) {
151 current->modelChanged(event_code, changed_subject, additional_info);
156 std::vector<observer_type*> _observers;
162 using dd::utility::ModelSubjectUtility;
163 using dd::utility::ModelObserverUtility;
The ModelObserver utility template.
virtual void modelChanged(event_code_type event_code, subject_type &changed_subject, const std::string &additional_info)=0
interface function to override.
virtual ~ModelObserverUtility()
protected DTOR
MODEL_SUBJECT_T subject_type
local definition of the subject code type
EVENT_CODE_T event_code_type
local definition of the event code type
Model Subject utility to define a Model Subject that notifies one or more observers.
ModelSubjectUtility()=default
CTOR.
ModelSubjectUtility & operator=(const ModelSubjectUtility &)
copy assignment operator which removes the observers in case of!
void notifyChanged(event_code_type event_code, subject_type &changed_subject, const std::string &additional_info)
helper utility function to notify the current observers
void detachObserver(observer_type *observer)
remove a observer if in list.
virtual ~ModelSubjectUtility()=default
DTOR.
ModelObserverUtility< MODEL_SUBJECT_T, EVENT_CODE_T > observer_type
local definition of the observer type to notify
MODEL_SUBJECT_T subject_type
local definition of the subject type
EVENT_CODE_T event_code_type
local definition of the event code type
ModelSubjectUtility(const ModelSubjectUtility &)
copy CTOR which removes the observers in case of!
void attachObserver(observer_type *observer)
adda a observer to notify.
definition of the ddl namespace