VR-Engage  2.3
Loading...
Searching...
No Matches
makVre::DtAttributeCallbackManager Class Reference

Detailed Description

DtAttributeCallbackManager simplifies callback lifetime management by owning all registered callbacks internally. Each attribute path maps to exactly one callback; registering a new callback for an attribute that already has one replaces the old entry. All connections are automatically cleaned up when the manager is destroyed.

#include <attributeCallback.h>

Public Member Functions

 DtAttributeCallbackManager ()
 
virtual ~DtAttributeCallbackManager ()
 
 DtAttributeCallbackManager (const DtAttributeCallbackManager &)=delete
 
DtAttributeCallbackManager & operator= (const DtAttributeCallbackManager &)=delete
 
template<class OBJECT_T>
void connect (DtAttributeHandle attr, OBJECT_T *object, void(OBJECT_T::*method)(const DtAttributeHandle &), bool includeChildren=false, bool invokeNowIfSet=false)
 
void connect (DtAttributeHandle attr, void(*func)(const DtAttributeHandle &), bool includeChildren=false, bool invokeNowIfSet=false)
 
template<class OBJECT_T, typename ATTRIBUTE_T>
void connect (DtAttributeHandle attr, OBJECT_T *object, void(OBJECT_T::*method)(const ATTRIBUTE_T &), bool invokeNowIfSet=false)
 
template<class OBJECT_T, typename ATTRIBUTE_T>
void connect (DtAttributeHandle attr, OBJECT_T *object, void(OBJECT_T::*method)(ATTRIBUTE_T), bool invokeNowIfSet=false)
 
template<typename ATTRIBUTE_T>
void connect (DtAttributeHandle attr, void(*func)(const ATTRIBUTE_T &), bool invokeNowIfSet=false)
 
template<typename ATTRIBUTE_T>
void connect (DtAttributeHandle attr, void(*func)(ATTRIBUTE_T), bool invokeNowIfSet=false)
 
template<typename Callable>
void connect (DtAttributeHandle attr, Callable &&callable, bool includeChildren=false, bool invokeNowIfSet=false)
 
template<typename ATTRIBUTE_T, typename Callable>
void connect (DtAttributeHandle attr, Callable &&callable, bool invokeNowIfSet=false)
 
bool isConnected (DtAttributeHandle attr) const
 
DtAttributeCallbackBase * connection (DtAttributeHandle attr)
 
void disconnect (DtAttributeHandle attr)
 
void disconnectAll ()
 

Protected Attributes

std::map< std::string, std::unique_ptr< DtAttributeCallbackBase > > myCallbackMap
 

Constructor & Destructor Documentation

◆ DtAttributeCallbackManager() [1/2]

makVre::DtAttributeCallbackManager::DtAttributeCallbackManager ( )

Default constructor.

Referenced by DtAttributeCallbackManager(), and operator=().

◆ ~DtAttributeCallbackManager()

virtual makVre::DtAttributeCallbackManager::~DtAttributeCallbackManager ( )
virtual

Virtual destructor.

Destroys all owned callbacks, which disconnects them from their attributes.

◆ DtAttributeCallbackManager() [2/2]

makVre::DtAttributeCallbackManager::DtAttributeCallbackManager ( const DtAttributeCallbackManager & )
delete

Member Function Documentation

◆ operator=()

DtAttributeCallbackManager & makVre::DtAttributeCallbackManager::operator= ( const DtAttributeCallbackManager & )
delete

◆ connect() [1/8]

template<class OBJECT_T>
void makVre::DtAttributeCallbackManager::connect ( DtAttributeHandle attr,
OBJECT_T * object,
void(OBJECT_T::* method )(const DtAttributeHandle &),
bool includeChildren = false,
bool invokeNowIfSet = false )

Connects a member function callback for untyped attribute changes.

The callback receives a DtAttributeHandle whenever the attribute at attr changes.

Template Parameters
OBJECT_TType of the object that owns the method
Parameters
attrThe attribute to observe
objectPointer to the owning object
methodMember function to invoke on change
includeChildrenIf true, also observes changes to descendants of attr (default: false)
invokeNowIfSetIf true, invokes the callback immediately when connecting if attr already has a value (default: false)

◆ connect() [2/8]

void makVre::DtAttributeCallbackManager::connect ( DtAttributeHandle attr,
void(* func )(const DtAttributeHandle &),
bool includeChildren = false,
bool invokeNowIfSet = false )

Connects a free-function callback for untyped attribute changes.

Parameters
attrThe attribute to observe
funcFree function to invoke when the attribute changes
includeChildrenIf true, also observes changes to descendants of attr (default: false)
invokeNowIfSetIf true, invokes the callback immediately when connecting if attr already has a value (default: false)

◆ connect() [3/8]

template<class OBJECT_T, typename ATTRIBUTE_T>
void makVre::DtAttributeCallbackManager::connect ( DtAttributeHandle attr,
OBJECT_T * object,
void(OBJECT_T::* method )(const ATTRIBUTE_T &),
bool invokeNowIfSet = false )

Connects a member function callback receiving the new attribute value by const reference.

Template Parameters
OBJECT_TType of the object that owns the method
ATTRIBUTE_TValue type of the attribute
Parameters
attrThe attribute to observe
objectPointer to the owning object
methodMember function invoked with the new value as const ATTRIBUTE_T&
invokeNowIfSetIf true, invokes the callback immediately when connecting if attr already has a value (default: false)

◆ connect() [4/8]

template<class OBJECT_T, typename ATTRIBUTE_T>
void makVre::DtAttributeCallbackManager::connect ( DtAttributeHandle attr,
OBJECT_T * object,
void(OBJECT_T::* method )(ATTRIBUTE_T),
bool invokeNowIfSet = false )

Connects a member function callback receiving the new attribute value by value.

Template Parameters
OBJECT_TType of the object that owns the method
ATTRIBUTE_TValue type of the attribute
Parameters
attrThe attribute to observe
objectPointer to the owning object
methodMember function invoked with the new value as ATTRIBUTE_T
invokeNowIfSetIf true, invokes the callback immediately when connecting if attr already has a value (default: false)

◆ connect() [5/8]

template<typename ATTRIBUTE_T>
void makVre::DtAttributeCallbackManager::connect ( DtAttributeHandle attr,
void(* func )(const ATTRIBUTE_T &),
bool invokeNowIfSet = false )

Connects a free-function callback receiving the new attribute value by const reference.

Template Parameters
ATTRIBUTE_TValue type of the attribute
Parameters
attrThe attribute to observe
funcFree function invoked with the new value as const ATTRIBUTE_T&
invokeNowIfSetIf true, invokes the callback immediately when connecting if attr already has a value (default: false)

◆ connect() [6/8]

template<typename ATTRIBUTE_T>
void makVre::DtAttributeCallbackManager::connect ( DtAttributeHandle attr,
void(* func )(ATTRIBUTE_T),
bool invokeNowIfSet = false )

Connects a free-function callback receiving the new attribute value by value.

Template Parameters
ATTRIBUTE_TValue type of the attribute
Parameters
attrThe attribute to observe
funcFree function invoked with the new value as ATTRIBUTE_T
invokeNowIfSetIf true, invokes the callback immediately when connecting if attr already has a value (default: false)

◆ connect() [7/8]

template<typename Callable>
void makVre::DtAttributeCallbackManager::connect ( DtAttributeHandle attr,
Callable && callable,
bool includeChildren = false,
bool invokeNowIfSet = false )

Connects a callable (lambda, functor) for untyped attribute changes.

The callback receives a DtAttributeHandle whenever the attribute at attr changes.

Template Parameters
CallableType of the callable object
Parameters
attrThe attribute to observe
callableCallable to invoke on change; must accept const DtAttributeHandle&
includeChildrenIf true, also observes changes to descendants of attr (default: false)
invokeNowIfSetIf true, invokes the callback immediately when connecting if attr already has a value (default: false)

◆ connect() [8/8]

template<typename ATTRIBUTE_T, typename Callable>
void makVre::DtAttributeCallbackManager::connect ( DtAttributeHandle attr,
Callable && callable,
bool invokeNowIfSet = false )

Connects a callable (lambda, functor) for typed attribute value changes.

The callback receives the new value of type ATTRIBUTE_T when the attribute changes. The value type must be explicitly specified, e.g. connect<int>(attr, callable).

Template Parameters
ATTRIBUTE_TValue type of the attribute
CallableType of the callable object
Parameters
attrThe attribute to observe
callableCallable to invoke with the new attribute value
invokeNowIfSetIf true, invokes the callback immediately when connecting if attr already has a value (default: false)

◆ isConnected()

bool makVre::DtAttributeCallbackManager::isConnected ( DtAttributeHandle attr) const

Checks whether a callback is currently registered for the given attribute.

Parameters
attrThe attribute to check
Returns
True if a callback is registered and connected for attr

◆ connection()

DtAttributeCallbackBase * makVre::DtAttributeCallbackManager::connection ( DtAttributeHandle attr)

Returns a non-owning pointer to the callback registered for the given attribute.

Parameters
attrThe attribute whose callback is requested
Returns
Pointer to the registered callback, or nullptr if none is registered

◆ disconnect()

void makVre::DtAttributeCallbackManager::disconnect ( DtAttributeHandle attr)

Removes and destroys the callback registered for the given attribute.

Parameters
attrThe attribute whose callback should be removed

◆ disconnectAll()

void makVre::DtAttributeCallbackManager::disconnectAll ( )

Removes and destroys all registered callbacks.

Member Data Documentation

◆ myCallbackMap

std::map<std::string, std::unique_ptr<DtAttributeCallbackBase> > makVre::DtAttributeCallbackManager::myCallbackMap
protected

Owns all registered callbacks, keyed by the full attribute path.


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