ACF $AcfVersion:0$
Public Types | Public Member Functions | List of all members
imod::TMultiModelObserverBase< ModelInterface > Class Template Reference

Basic implementation of a multiple model observer. More...

#include <TMultiModelObserverBase.h>

Inheritance diagram for imod::TMultiModelObserverBase< ModelInterface >:
imod::CMultiModelObserverBase imod::IObserver istd::IPolymorphic

Public Types

typedef CMultiModelObserverBase BaseClass
 
typedef ModelInterface ModelType
 

Public Member Functions

ModelInterface * GetObservedObject (int objectIndex) const
 Get instance of observed object.
 
ModelInterface * GetObjectPtr (int objectIndex) const
 Get instance of observed object.
 
virtual bool OnModelAttached (imod::IModel *modelPtr, istd::IChangeable::ChangeSet &changeMask) override
 Callback invoked when an observable model is about to be attached to this observer.
 
- Public Member Functions inherited from imod::CMultiModelObserverBase
 CMultiModelObserverBase ()
 
virtual ~CMultiModelObserverBase ()
 
int GetModelCount () const
 Gets the number of connected models.
 
IModelGetObservedModel (int modelIndex) const
 Get access to connected model with the index index.
 
IModelGetModelPtr (int modelIndex) const
 Get access to connected model with the index index.
 
void EnsureModelsDetached ()
 Ensure all attached models are detached.
 
void SetObservedIds (const istd::IChangeable::ChangeSet &changeMask)
 Set list of ID's beeing observed.
 
virtual bool IsModelAttached (const IModel *modelPtr) const override
 Checks if the specified model is currently attached to this observer.
 
virtual bool OnModelDetached (IModel *modelPtr) override
 Callback invoked when an observable model is about to be detached from this observer.
 
virtual void BeforeUpdate (IModel *modelPtr) override
 Callback invoked before an update of the observer's content occurs.
 
virtual void AfterUpdate (IModel *modelPtr, const istd::IChangeable::ChangeSet &changeSet) override
 Callback invoked after an update of the observer's content occurs.
 
- Public Member Functions inherited from istd::IPolymorphic
virtual ~IPolymorphic ()
 

Additional Inherited Members

- Protected Member Functions inherited from imod::CMultiModelObserverBase
virtual void OnUpdate (IModel *modelPtr, const istd::IChangeable::ChangeSet &changeSet)
 Called on update of observed model.
 

Detailed Description

template<class ModelInterface>
class imod::TMultiModelObserverBase< ModelInterface >

Basic implementation of a multiple model observer.

Definition at line 22 of file TMultiModelObserverBase.h.

Member Typedef Documentation

◆ BaseClass

template<class ModelInterface >
typedef CMultiModelObserverBase imod::TMultiModelObserverBase< ModelInterface >::BaseClass

Definition at line 25 of file TMultiModelObserverBase.h.

◆ ModelType

template<class ModelInterface >
typedef ModelInterface imod::TMultiModelObserverBase< ModelInterface >::ModelType

Definition at line 26 of file TMultiModelObserverBase.h.

Member Function Documentation

◆ GetObjectPtr()

template<class ModelInterface >
ModelInterface * imod::TMultiModelObserverBase< ModelInterface >::GetObjectPtr ( int  objectIndex) const

Get instance of observed object.

Deprecated:
use GetObservedObject instead.

Definition at line 57 of file TMultiModelObserverBase.h.

◆ GetObservedObject()

template<class ModelInterface >
ModelInterface * imod::TMultiModelObserverBase< ModelInterface >::GetObservedObject ( int  objectIndex) const

Get instance of observed object.

Parameters
objectIndexindex of object

Definition at line 47 of file TMultiModelObserverBase.h.

◆ OnModelAttached()

template<class ModelInterface >
bool imod::TMultiModelObserverBase< ModelInterface >::OnModelAttached ( imod::IModel modelPtr,
istd::IChangeable::ChangeSet changeMask 
)
overridevirtual

Callback invoked when an observable model is about to be attached to this observer.

This method is called by the model when attempting to establish an observer relationship. The implementation should:

  1. Validate that the model is of an acceptable type
  2. Set the changeMask to specify which changes to monitor
  3. Return true to accept the attachment, or false to reject it
Parameters
modelPtrPointer to the model object being attached. Never nullptr.
changeMaskOutput parameter where the observer specifies which change types it wants to be notified about. Set the appropriate change flags using changeMask.Set(changeId). An empty mask means the observer wants all changes.
Returns
true if the model is accepted and attachment succeeds, false to reject the attachment (e.g., if the model is of incompatible type).
Note
After successful attachment, the observer should initialize its state based on the current model data.
The changeMask allows filtering notifications for better performance. Only changes matching the mask will trigger AfterUpdate() calls.
virtual bool OnModelAttached(IModel* modelPtr,
{
// Type check
CMyModel* model = dynamic_cast<CMyModel*>(modelPtr);
if (!model) return false;
// Set up change filtering
changeMask.Set(CMyModel::CF_DATA_CHANGED);
changeMask.Set(CMyModel::CF_STATUS_CHANGED);
// Don't set CF_INTERNAL_CHANGED - we don't care about those
// Initialize view from current model state
UpdateViewFromModel(model);
return true;
}
Common interface for model objects, that supports Model/Observer design pattern.
Definition IModel.h:25
virtual bool OnModelAttached(imod::IModel *modelPtr, istd::IChangeable::ChangeSet &changeMask) override
Callback invoked when an observable model is about to be attached to this observer.
Set of change flags (its IDs).
Definition IChangeable.h:36
See also
OnModelDetached(), IsModelAttached(), AfterUpdate()

Reimplemented from imod::CMultiModelObserverBase.

Definition at line 69 of file TMultiModelObserverBase.h.

References NULL.


The documentation for this class was generated from the following file: