ImageRegionObserverStorage Class Reference

#include <imageregionobserver_helpers.h>

Detailed Description

This class is a convenience wrapper to manage the lifetime of and access to long-living observers. It is only recommended to be used if smarter observer lifetime management is not feasible. It can be easily placed into or along-side image data owning classes. Observers are lazily registered on first fetch to avoid overhead if they are not used for a particular instance.


struct  StoredObserver

Public Types

using AddObserverFunc = Delegate< Result< void >(const Id &observerId, const ImageRegionObserverRef &observer)>
using InitializeObserversFunc = Delegate< Result< void >(const AddObserverFunc &addObserver)>

Public Member Functions

template<typename T_ObserverRef >
Result< T_ObserverRef > GetObserver (const Id &observerId) const
Result< void > Initialize (const InitializeObserversFunc &initializeObservers, Bool lazyRegistration)
const ImageRegionObservableHandlerRef & GetObservableHandler () const
Bool IsInitialized () const

Private Attributes

Bool _isInitialized
LazyInitThreaded _lazyRegistration
HashMap< Id, StoredObserver_observers
ImageRegionObservableHandlerRef _observableHandler

Member Typedef Documentation

◆ AddObserverFunc

using AddObserverFunc = Delegate<Result<void>(const Id & observerId, const ImageRegionObserverRef& observer)>

Gives access to adding an observer under a unique id.

[in]observerIdThe identifier of the observer. This identifier must be unique.
[in]observerThe observer to add.
OK on success.

◆ InitializeObserversFunc

using InitializeObserversFunc = Delegate<Result<void>(const AddObserverFunc& addObserver)>

Gives access to the addition of an observer collection.

[in]addObserverThe add function for an observer.
OK on success.

Member Function Documentation

◆ GetObserver()

Result<T_ObserverRef> GetObserver ( const Id observerId) const

Returns an observer that has added under a particular id. The first call to the method will trigger the lazy registration of all added observers.

A valid observer reference, or error.

◆ Initialize()

Result<void> Initialize ( const InitializeObserversFunc initializeObservers,
Bool  lazyRegistration 

Initializes the observable and creates a collection of long-living observers.

[in]initializeObserversThe function that adds the observers.
[in]lazyRegistrationDetermines whether the added observers should be lazily registered, or immediately.
OK on success.

◆ GetObservableHandler()

const ImageRegionObservableHandlerRef& GetObservableHandler ( ) const

Returns the handler to the observable, giving access to the registrar of observers and notification dispatch.

The observable.

◆ IsInitialized()

Bool IsInitialized ( ) const

Returns true if the observer storage is initialized.

True if initialized, false otherwise.

Member Data Documentation

◆ _isInitialized

Bool _isInitialized

◆ _lazyRegistration

LazyInitThreaded _lazyRegistration

the initialization state.

◆ _observers

HashMap<Id, StoredObserver> _observers

the lazy execute-once registration function.

◆ _observableHandler

ImageRegionObservableHandlerRef _observableHandler

the collection of managed observers.