TMultiModelObserverBase.h
Go to the documentation of this file.
1 #ifndef imod_TMultiModelObserverBase_included
2 #define imod_TMultiModelObserverBase_included
3 
4 
5 // ACF includes
7 
8 #include <imod/imod.h>
9 
10 
11 namespace imod
12 {
13 
14 
20 template<class ModelInterface>
22 {
23 public:
25  typedef ModelInterface ModelType;
26 
31  ModelInterface* GetObservedObject(int objectIndex) const;
36  ModelInterface* GetObjectPtr(int objectIndex) const;
37 
38  // reimplemented (imod::IObserver)
39  virtual bool OnModelAttached(imod::IModel* modelPtr, istd::IChangeable::ChangeSet& changeMask);
40 };
41 
42 
43 // public methods
44 
45 template<class ModelInterface>
46 ModelInterface* TMultiModelObserverBase<ModelInterface>::GetObservedObject(int objectIndex) const
47 {
48  Q_ASSERT(objectIndex >= 0);
49  Q_ASSERT(objectIndex < GetModelCount());
50 
51  return dynamic_cast<ModelInterface*>(GetObservedModel(objectIndex));
52 }
53 
54 
55 template<class ModelInterface>
56 ModelInterface* TMultiModelObserverBase<ModelInterface>::GetObjectPtr(int objectIndex) const
57 {
58  Q_ASSERT(objectIndex >= 0);
59  Q_ASSERT(objectIndex < GetModelCount());
60 
61  return dynamic_cast<ModelInterface*>(GetObservedModel(objectIndex));
62 }
63 
64 
65 // reimplemented (imod::IObserver)
66 
67 template<class ModelInterface>
69 {
70  ModelInterface* objectPtr = dynamic_cast<ModelInterface*>(modelPtr);
71  if (objectPtr == NULL){
72  return false;
73  }
74 
75  return BaseClass::OnModelAttached(modelPtr, changeMask);
76 }
77 
78 
79 } // namespace imod
80 
81 
82 #endif // !imod_TMultiModelObserverBase_included
83 
ModelInterface * GetObjectPtr(int objectIndex) const
Get instance of observed object.
Basic implementation of a multiple model observer.
Basic implementation of a multiple model observer.
ModelInterface * GetObservedObject(int objectIndex) const
Get instance of observed object.
#define NULL
Definition: istd.h:64
virtual bool OnModelAttached(imod::IModel *modelPtr, istd::IChangeable::ChangeSet &changeMask)
This call back function will be called, if an observable object is about to be attached.
Common interface for model objects, that supports Model/Observer design pattern.
Definition: IModel.h:23
Set of change flags (its IDs).
Definition: IChangeable.h:30

© 2007-2017 Witold Gantzke and Kirill Lepskiy