ICF 3.1.1.10
Technical documentation of ICF Libraries
CModelProxy.h
Go to the documentation of this file.
1/********************************************************************************
2** This file is part of the ICF Framework. Copyright (C) Witold Gantzke & Kirill Lepskiy
3** ICF Framework may be used under the terms of the LGPL License v. 2.1 by the Free Software Foundation.
4********************************************************************************/
5
6#ifndef imod_CModelProxy_included
7#define imod_CModelProxy_included
8
9
10// Qt includes
11#include <QtCore/QVector>
12
13// ICF includes
14#include <imod/IModel.h>
16
17
18namespace imod
19{
20
21
28class CModelProxy: virtual public imod::IModel
29{
30public:
32
33 void SetModelPtr(imod::IModel* modelPtr);
34 void ResetModel();
35
36 // reimplemented (imod::IModel)
37 virtual bool AttachObserver(IObserver* observerPtr);
38 virtual void DetachObserver(IObserver* observerPtr);
39 virtual void DetachAllObservers();
40 virtual bool IsAttached(const IObserver* observerPtr) const;
41
42private:
43 void AttachProxyObservers();
44 void DetachProxyObservers();
45
46private:
47 class ModelObserver: public imod::TSingleModelObserverBase<imod::IModel>
48 {
49 public:
51
52 explicit ModelObserver(CModelProxy& parent);
53
54 // reimplemented (imod::IObserver)
55 virtual bool OnModelDetached(imod::IModel* modelPtr);
56
57 private:
58 CModelProxy& m_parent;
59 };
60
64 struct PendingObserver
65 {
66 PendingObserver(imod::IObserver* observerPtr = nullptr, bool isPending = false)
67 :m_observerPtr(observerPtr),
68 m_isPending(isPending)
69 {
70 }
71
72 bool operator == (const imod::IObserver* observerPtr) const
73 {
74 return (observerPtr == m_observerPtr);
75 }
76
77 imod::IObserver* m_observerPtr;
78 bool m_isPending;
79 };
80
81 typedef PendingObserver Observer;
82 typedef QVector<Observer> Observers;
83
84 Observers m_proxyObservers;
85 ModelObserver m_modelObserver;
86 imod::IModel* m_modelPtr;
87};
88
89
90} // namespace imod
91
92
93#endif // !imod_CModelProxy_included
94
95
Implementation of the model proxy.
Definition CModelProxy.h:29
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 DetachObserver(IObserver *observerPtr)
Detaches model object from observer observerPtr.
virtual void DetachAllObservers()
Detaches all attached observers.
virtual bool AttachObserver(IObserver *observerPtr)
Attaches model object to observer observerPtr.
Common interface for model objects, that supports Model/Observer design pattern.
Definition IModel.h:29
Common interface for all classes implementing the Observer functionality in the Model/Observer design...
Definition IObserver.h:30
Basic implementation for a single model observer with binding to concrete data object interface.
This namespace containes basic implementation of Model/Observer design pattern This package is system...
Definition CModelBase.h:20

© Witold Gantzke and Kirill Lepskiy