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

Detailed Description

This class provides a handle-based mechanism for accessing attributes safely. It manages reference counting, type safety, and automatic attribute creation when needed. It works in conjunction with the DtAttribute class to provide a clean interface for attribute manipulation.

#include <attributeHandle.h>

Inheritance diagram for makVre::DtAttributeHandle:
[legend]

Public Member Functions

 DtAttributeHandle (const DtAttributeHandle &other)
 
 DtAttributeHandle ()
 
 DtAttributeHandle (const std::string &path)
 
 DtAttributeHandle (const char *path)
 
virtual ~DtAttributeHandle ()
 
virtual void assign (const DtAttributeHandle &other, bool attrMustBeSet=false) const
 
const DtAttributeHandle & operator= (const DtAttributeHandle &other) const
 
DtAttributeHandle & operator= (const DtAttributeHandle &other)
 
bool assigned () const
 
bool assignedSame (const DtAttributeHandle &other) const
 
void unassign () const
 
bool isAlias () const
 
const std::string & aliasName () const
 
void next () const
 
DtAttribute * operator-> ()
 
const DtAttribute * operator-> () const
 
DtAttributeHandle operator[] (const std::string &name)
 
const DtAttributeHandle operator[] (const std::string &name) const
 
DtAttributeHandle operator[] (const unsigned int i)
 
const DtAttributeHandle operator[] (const unsigned int i) const
 
bool lock ()
 
bool unlock ()
 
bool isLocked () const
 
template<typename T>
bool exclusiveSet (const T &data)
 
bool recursiveLock ()
 
bool recursiveUnlock ()
 

Protected Types

using Ptr = std::shared_ptr<DtAttribute>
 

Protected Member Functions

 DtAttributeHandle (const Ptr &ptr, const std::string &aliasName="", const Ptr &aliasParent=Ptr())
 
void avoidNull () const
 

Static Protected Member Functions

static unsigned int nextKey ()
 

Protected Attributes

Ptr myAttrPtr
 
Ptr myAliasParent
 
std::string myAliasName
 
bool myLocked
 
unsigned int myKey
 

Friends

class DtAttribute
 

Member Typedef Documentation

◆ Ptr

using makVre::DtAttributeHandle::Ptr = std::shared_ptr<DtAttribute>
protected

Shared pointer type for attributes.

Constructor & Destructor Documentation

◆ DtAttributeHandle() [1/5]

makVre::DtAttributeHandle::DtAttributeHandle ( const DtAttributeHandle & other)

◆ DtAttributeHandle() [2/5]

makVre::DtAttributeHandle::DtAttributeHandle ( )

Default constructor.

Creates an unassigned handle

◆ DtAttributeHandle() [3/5]

makVre::DtAttributeHandle::DtAttributeHandle ( const std::string & path)

Constructor from attribute path.

Parameters
pathFull path, relative to root

◆ DtAttributeHandle() [4/5]

makVre::DtAttributeHandle::DtAttributeHandle ( const char * path)

Constructor from attribute path.

Parameters
pathFull path, relative to root

◆ ~DtAttributeHandle()

virtual makVre::DtAttributeHandle::~DtAttributeHandle ( )
virtual

Virtual destructor.

Calls recursiveUnlock() to release both single and recursive locks on destruction.

◆ DtAttributeHandle() [5/5]

makVre::DtAttributeHandle::DtAttributeHandle ( const Ptr & ptr,
const std::string & aliasName = "",
const Ptr & aliasParent = Ptr() )
protected

Constructor that takes a shared pointer to an attribute.

Parameters
ptrThe shared pointer to the attribute
aliasParentThe parent attribute as found in the tree if path was an alias
aliasNameThe alias name of this attribute if found by an alias path

References aliasName().

Member Function Documentation

◆ assign()

virtual void makVre::DtAttributeHandle::assign ( const DtAttributeHandle & other,
bool attrMustBeSet = false ) const
virtual

Assigns this handle to refer to the same attribute as another handle.

Parameters
otherThe handle to assign from
attrMustBeSet(Optional) If set to true, asserts if the attribute is not set, default is false

Reimplemented in makVre::DtAttributeHandleType< T >, makVre::DtAttributeHandleType< bool >, makVre::DtAttributeHandleType< BullseyeMap >, makVre::DtAttributeHandleType< DeployableObjectStateMap >, makVre::DtAttributeHandleType< double >, makVre::DtAttributeHandleType< DtDamageState >, makVre::DtAttributeHandleType< DtEntityIdentifier >, makVre::DtAttributeHandleType< DtEntityType >, makVre::DtAttributeHandleType< DtSimulationAddress >, makVre::DtAttributeHandleType< DtString >, makVre::DtAttributeHandleType< DtTaitBryan >, makVre::DtAttributeHandleType< DtU32 >, makVre::DtAttributeHandleType< DtUUID >, makVre::DtAttributeHandleType< DtVector >, makVre::DtAttributeHandleType< DtVector32 >, makVre::DtAttributeHandleType< Equipment >, makVre::DtAttributeHandleType< HumanPosture >, makVre::DtAttributeHandleType< int >, makVre::DtAttributeHandleType< LauncherState >, makVre::DtAttributeHandleType< LauncherType >, makVre::DtAttributeHandleType< makVre::BackendStatusMessage::BackendStatusData >, makVre::DtAttributeHandleType< makVre::DtEntityResolver * >, makVre::DtAttributeHandleType< makVre::DtIntersector * >, makVre::DtAttributeHandleType< makVre::DtMenuManager * >, makVre::DtAttributeHandleType< makVre::DtOwnershipTransferManager * >, makVre::DtAttributeHandleType< makVre::DtPlayerStationApp * >, makVre::DtAttributeHandleType< makVre::Equipment >, makVre::DtAttributeHandleType< makVre::HumanPosture >, makVre::DtAttributeHandleType< makVre::VrfSessionStatusMessage::VrfSessionStatusData >, makVre::DtAttributeHandleType< makVrv::DtChannel * >, makVre::DtAttributeHandleType< makVrv::DtElementID >, makVre::DtAttributeHandleType< makVrv::DtIntersector * >, makVre::DtAttributeHandleType< makVrv::DtUniqueID >, makVre::DtAttributeHandleType< ObserverAttachMode >, makVre::DtAttributeHandleType< RouteMap >, makVre::DtAttributeHandleType< SensorContactsMap >, makVre::DtAttributeHandleType< std::set< std::string > >, makVre::DtAttributeHandleType< std::string >, makVre::DtAttributeHandleType< std::vector< double > >, makVre::DtAttributeHandleType< std::vector< std::string > >, makVre::DtAttributeHandleType< TowSensorContactsMap >, makVre::DtAttributeHandleType< unsigned int >, and makVre::DtAttributeHandleType< WaypointMap >.

References DtAttributeHandle().

◆ operator=() [1/2]

const DtAttributeHandle & makVre::DtAttributeHandle::operator= ( const DtAttributeHandle & other) const

Copy assignment operator.

Assigns this handle to refer to the same attribute as another handle. If this handle currently holds a lock, it is released before reassignment.

Parameters
otherThe handle to assign from
Returns
A reference to this handle

References DtAttributeHandle().

◆ operator=() [2/2]

DtAttributeHandle & makVre::DtAttributeHandle::operator= ( const DtAttributeHandle & other)

References DtAttributeHandle().

◆ assigned()

bool makVre::DtAttributeHandle::assigned ( ) const

Checks if this handle is assigned to an attribute.

Returns
true if the handle is assigned, false otherwise

◆ assignedSame()

bool makVre::DtAttributeHandle::assignedSame ( const DtAttributeHandle & other) const

Checks if this handle is assigned to the same attribute as another handle.

Parameters
otherThe handle to compare with
Returns
true if both handles refer to the same attribute, false otherwise

References DtAttributeHandle().

◆ unassign()

void makVre::DtAttributeHandle::unassign ( ) const

Unassigns this handle from its attribute.

◆ isAlias()

bool makVre::DtAttributeHandle::isAlias ( ) const

Returns true if the handle points to an attribute found via an alias path.

Returns
true if the attribute was found via an alias path, false otherwise

◆ aliasName()

const std::string & makVre::DtAttributeHandle::aliasName ( ) const

Returns the alias name if the attribute was found via an alias path.

Referenced by DtAttributeHandle().

◆ next()

void makVre::DtAttributeHandle::next ( ) const

Treats this handle as an iterator and advances to the next sibling attribute.

◆ operator->() [1/2]

DtAttribute * makVre::DtAttributeHandle::operator-> ( )

Dereference operator for accessing the attribute.

Returns
A pointer to the attribute

References DtAttribute.

◆ operator->() [2/2]

const DtAttribute * makVre::DtAttributeHandle::operator-> ( ) const

Const dereference operator for accessing the attribute.

Returns
A const pointer to the attribute

References DtAttribute.

◆ operator[]() [1/4]

DtAttributeHandle makVre::DtAttributeHandle::operator[] ( const std::string & name)

Indexing operator for accessing child attributes by name.

Parameters
nameThe name of the child attribute
Returns
A handle to the child attribute

References DtAttributeHandle().

◆ operator[]() [2/4]

const DtAttributeHandle makVre::DtAttributeHandle::operator[] ( const std::string & name) const

Const indexing operator for accessing child attributes by name.

Parameters
nameThe name of the child attribute
Returns
A const handle to the child attribute

References DtAttributeHandle().

◆ operator[]() [3/4]

DtAttributeHandle makVre::DtAttributeHandle::operator[] ( const unsigned int i)

Indexing operator for accessing child attributes by index.

Parameters
iThe index of the child attribute
Returns
A handle to the child attribute

References DtAttributeHandle().

◆ operator[]() [4/4]

const DtAttributeHandle makVre::DtAttributeHandle::operator[] ( const unsigned int i) const

Const indexing operator for accessing child attributes by index.

Parameters
iThe index of the child attribute
Returns
A const handle to the child attribute

References DtAttributeHandle().

◆ lock()

bool makVre::DtAttributeHandle::lock ( )

Locks the attribute, making it read-only for other handles.

This handle acquires an exclusive write lock so that other handles cannot modify the attribute until unlock() is called.

Returns
true if the lock was successfully acquired

◆ unlock()

bool makVre::DtAttributeHandle::unlock ( )

Unlocks the attribute, allowing other handles to write again.

Releases the exclusive write lock previously acquired by lock().

Returns
true if the lock was successfully released

◆ isLocked()

bool makVre::DtAttributeHandle::isLocked ( ) const

Returns true if this handle currently holds the write lock.

Returns
true if this handle acquired the lock via lock()

◆ exclusiveSet()

template<typename T>
bool makVre::DtAttributeHandle::exclusiveSet ( const T & data)

Sets the attribute value, bypassing the exclusive write lock.

Temporarily releases the lock, writes the value, then re-acquires the lock. This is required because the lock blocks all writers via lockCheck(), including the lock-holding handle itself. Safe to call before the first lock() has been acquired (e.g. during initialisation); unlock() is a no-op in that case.

Note
There is a narrow TOCTOU window between unlock() and set() — a competing handle could acquire the lock in that gap. Locking attributes is not a security feature, it is intended as an error-checking mechanism to catch accidental writes to attributes that should be read-only.
Parameters
dataThe value to set
Returns
true if the value changed

◆ recursiveLock()

bool makVre::DtAttributeHandle::recursiveLock ( )

Locks this attribute and all descendants recursively.

Uses best-effort semantics: all lockable nodes are locked even if some cannot be.

Returns
true if all nodes were successfully locked

◆ recursiveUnlock()

bool makVre::DtAttributeHandle::recursiveUnlock ( )

Unlocks this attribute and all descendants locked with this handle's key.

Returns
true if all matching nodes were successfully unlocked

◆ avoidNull()

void makVre::DtAttributeHandle::avoidNull ( ) const
protected

Ensures that the handle is assigned to an attribute.

Checks if the handle is unassigned and asserts if it is

◆ nextKey()

static unsigned int makVre::DtAttributeHandle::nextKey ( )
staticprotected

Generates a new unique key for locking.

Returns
A new unique key

Friends And Related Symbol Documentation

◆ DtAttribute

friend class DtAttribute
friend

References DtAttribute.

Referenced by DtAttribute, operator->(), and operator->().

Member Data Documentation

◆ myAttrPtr

Ptr makVre::DtAttributeHandle::myAttrPtr
mutableprotected

Shared pointer to the attribute.

◆ myAliasParent

Ptr makVre::DtAttributeHandle::myAliasParent
mutableprotected

Pointer to alias parent if found by an alias path.

◆ myAliasName

std::string makVre::DtAttributeHandle::myAliasName
mutableprotected

Alias name of the attribute if found by an alias path.

◆ myLocked

bool makVre::DtAttributeHandle::myLocked
protected

Flag indicating if this handle is locked.

◆ myKey

unsigned int makVre::DtAttributeHandle::myKey
protected

Key used for locking and unlocking.


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