#include <imageregionobserver_helpers.h>
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 |
using AddObserverFunc = Delegate<Result<void>(const Id & observerId, const ImageRegionObserverRef& observer)> |
Gives access to adding an observer under a unique id.
[in] | observerId | The identifier of the observer. This identifier must be unique. |
[in] | observer | The observer to add. |
using InitializeObserversFunc = Delegate<Result<void>(const AddObserverFunc& addObserver)> |
Gives access to the addition of an observer collection.
[in] | addObserver | The add function for an observer. |
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.
Result<void> Initialize | ( | const InitializeObserversFunc & | initializeObservers, |
Bool | lazyRegistration | ||
) |
Initializes the observable and creates a collection of long-living observers.
[in] | initializeObservers | The function that adds the observers. |
[in] | lazyRegistration | Determines whether the added observers should be lazily registered, or immediately. |
const ImageRegionObservableHandlerRef& GetObservableHandler | ( | ) | const |
Returns the handler to the observable, giving access to the registrar of observers and notification dispatch.
Bool IsInitialized | ( | ) | const |
Returns true if the observer storage is initialized.
|
private |
|
mutableprivate |
the initialization state.
|
mutableprivate |
the lazy execute-once registration function.
|
private |
the collection of managed observers.