CModelProxy.h
Go to the documentation of this file.
1 #ifndef imod_CModelProxy_included
2 #define imod_CModelProxy_included
3 
4 
5 // Qt includes
6 #include <QtCore/QVector>
7 
8 // ACF includes
9 #include <imod/IModel.h>
11 
12 
13 namespace imod
14 {
15 
16 
23 class CModelProxy: virtual public imod::IModel
24 {
25 public:
26  CModelProxy();
27 
28  void SetModelPtr(imod::IModel* modelPtr);
29  void ResetModel();
30 
31  // reimplemented (imod::IModel)
32  virtual bool AttachObserver(IObserver* observerPtr);
33  virtual void DetachObserver(IObserver* observerPtr);
34  virtual void DetachAllObservers();
35  virtual bool IsAttached(const IObserver* observerPtr) const;
36 
37 private:
38  void AttachProxyObservers();
39  void DetachProxyObservers();
40 
41 private:
42  class ModelObserver: public imod::TSingleModelObserverBase<imod::IModel>
43  {
44  public:
46 
47  explicit ModelObserver(CModelProxy& parent);
48 
49  // reimplemented (imod::IObserver)
50  virtual bool OnModelDetached(imod::IModel* modelPtr);
51 
52  private:
53  CModelProxy& m_parent;
54  };
55 
59  struct PendingObserver
60  {
61  PendingObserver(imod::IObserver* observerPtr = NULL, bool isPending = false)
62  :m_observerPtr(observerPtr),
63  m_isPending(isPending)
64  {
65  }
66 
67  bool operator == (const imod::IObserver* observerPtr) const
68  {
69  return (observerPtr == m_observerPtr);
70  }
71 
72  imod::IObserver* m_observerPtr;
73  bool m_isPending;
74  };
75 
76  typedef PendingObserver Observer;
77  typedef QVector<Observer> Observers;
78 
79  Observers m_proxyObservers;
80  ModelObserver m_modelObserver;
81  imod::IModel* m_modelPtr;
82 };
83 
84 
85 } // namespace imod
86 
87 
88 #endif // !imod_CModelProxy_included
89 
90 
virtual bool AttachObserver(IObserver *observerPtr)
Attaches model object to observer observerPtr.
Basic implementation for a single model observer with binding to concrete data object interface...
Implementation of the model proxy.
Definition: CModelProxy.h:23
void SetModelPtr(imod::IModel *modelPtr)
virtual bool IsAttached(const IObserver *observerPtr) const
Returns true if observer observer is attached to this model object.
virtual void DetachAllObservers()
Detaches all attached observers.
#define NULL
Definition: istd.h:64
Common interface for all classes implementing the Observer functionality in the Model/Observer design...
Definition: IObserver.h:24
Common interface for model objects, that supports Model/Observer design pattern.
Definition: IModel.h:23
virtual void DetachObserver(IObserver *observerPtr)
Detaches model object from observer observerPtr.

© 2007-2017 Witold Gantzke and Kirill Lepskiy