Open Search
    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.

    Classes

    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.

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

    ◆ InitializeObserversFunc

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

    Gives access to the addition of an observer collection.

    Parameters
    [in]addObserverThe add function for an observer.
    Returns
    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.

    Returns
    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.

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

    ◆ GetObservableHandler()

    const ImageRegionObservableHandlerRef& GetObservableHandler ( ) const

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

    Returns
    The observable.

    ◆ IsInitialized()

    Bool IsInitialized ( ) const

    Returns true if the observer storage is initialized.

    Returns
    True if initialized, false otherwise.

    Member Data Documentation

    ◆ _isInitialized

    Bool _isInitialized
    private

    ◆ _lazyRegistration

    LazyInitThreaded _lazyRegistration
    mutableprivate

    the initialization state.

    ◆ _observers

    HashMap<Id, StoredObserver> _observers
    mutableprivate

    the lazy execute-once registration function.

    ◆ _observableHandler

    ImageRegionObservableHandlerRef _observableHandler
    private

    the collection of managed observers.