ImageRegionObserverStorage Class Reference

#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)>

公共成员函数

template<typename T_ObserverRef >
Result < T_ObserverRef >  GetObserver (const Id &observerId) const
Result < void >  初始化 (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] observerId The identifier of the observer. This identifier must be unique.
[in] observer The 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] addObserver The add function for an observer.
返回
OK on success.

成员函数文档编制

◆  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] initializeObservers The function that adds the observers.
[in] lazyRegistration Determines 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
private

◆  _lazyRegistration

LazyInitThreaded _lazyRegistration
mutable private

the initialization state.

◆  _observers

HashMap < Id , StoredObserver > _observers
mutable private

the lazy execute-once registration function.

◆  _observableHandler

ImageRegionObservableHandlerRef _observableHandler private

the collection of managed observers.