v2.0.0
Loading...
Searching...
No Matches
observerpattern.h
Go to the documentation of this file.
1//=============================================================================================================
29
30#ifndef OBSERVERPATTERN_H
31#define OBSERVERPATTERN_H
32
33//=============================================================================================================
34// INCLUDES
35//=============================================================================================================
36
37#include "../utils_global.h"
38#include <set>
39
40//=============================================================================================================
41// QT INCLUDES
42//=============================================================================================================
43
44#include <QSet>
45#include <QSharedPointer>
46
47//=============================================================================================================
48// DEFINE NAMESPACE UTILSLIB
49//=============================================================================================================
50
51namespace UTILSLIB
52{
53
54//=============================================================================================================
55// FORWARD DECLARATIONS
56//=============================================================================================================
57
58class Subject;
59
60//=============================================================================================================
67{
68public:
69 typedef QSharedPointer<IObserver> SPtr;
70 typedef QSharedPointer<const IObserver> ConstSPtr;
71
72 //=========================================================================================================
76 virtual ~IObserver() {};
77
78 //=========================================================================================================
84 virtual void update(Subject* pSubject) = 0;
85};
86
87//=========================================================================================================
94{
95public:
96 typedef QSharedPointer<Subject> SPtr;
97 typedef QSharedPointer<const Subject> ConstSPtr;
98
99 typedef QSet<IObserver*> t_Observers;
100
101 //=========================================================================================================
105 virtual ~Subject();
106
107 //=========================================================================================================
113 void attach(IObserver* pObserver);
114
115 //=========================================================================================================
121 void detach(IObserver* pObserver);
122
123 //=========================================================================================================
128 void notify();
129
130 //=========================================================================================================
135 static bool notifyEnabled;
136
137 //=========================================================================================================
143 inline t_Observers& observers();
144
145// //=========================================================================================================
146// /**
147// * Returns attached observers.
148
149// * @return attached observers.
150// */
151// inline std::set<IObserver*>& observers();
152
153 //=========================================================================================================
159 int observerNumDebug(){return m_Observers.size();};
160
161protected:
162 //=========================================================================================================
167
168private:
169 t_Observers m_Observers;
170// std::set<IObserver*> m_Observers; /**< Holds the attached observers.*/
171};
172
173//=============================================================================================================
174// INLINE DEFINITIONS
175//=============================================================================================================
176
178{
179 return m_Observers;
180}
181
182//inline std::set<IObserver*>& Subject::observers()
183//{
184// return m_Observers;
185//}
186
187} // Namespace
188
189#endif // OBSERVERPATTERN_H
Public umbrella header for UTILSLIB exposing the UTILSSHARED_EXPORT macro and build-info accessors.
#define UTILSSHARED_EXPORT
Shared utilities (I/O helpers, spectral analysis, layout management, warp algorithms).
The IObserver interface provides the base class of every observer of the observer design pattern.
QSharedPointer< IObserver > SPtr
virtual void update(Subject *pSubject)=0
QSharedPointer< const IObserver > ConstSPtr
The Subject class provides the base class of every subject of the observer design pattern.
QSet< IObserver * > t_Observers
t_Observers & observers()
QSharedPointer< const Subject > ConstSPtr
void attach(IObserver *pObserver)
void detach(IObserver *pObserver)
QSharedPointer< Subject > SPtr
static bool notifyEnabled