|
VR-Engage
2.3
|
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>
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 |
|
protected |
Shared pointer type for attributes.
| makVre::DtAttributeHandle::DtAttributeHandle | ( | const DtAttributeHandle & | other | ) |
Copy constructor.
| other | The handle to copy |
References DtAttributeHandle().
Referenced by assign(), makVre::DtAttributeHandleType< T >::assign(), assignedSame(), DtAttributeHandle(), makVre::DtAttributeHandleType< T >::DtAttributeHandleType(), operator=(), operator=(), operator[](), operator[](), operator[](), and operator[]().
| makVre::DtAttributeHandle::DtAttributeHandle | ( | ) |
Default constructor.
Creates an unassigned handle
| makVre::DtAttributeHandle::DtAttributeHandle | ( | const std::string & | path | ) |
Constructor from attribute path.
| path | Full path, relative to root |
| makVre::DtAttributeHandle::DtAttributeHandle | ( | const char * | path | ) |
Constructor from attribute path.
| path | Full path, relative to root |
|
virtual |
Virtual destructor.
Calls recursiveUnlock() to release both single and recursive locks on destruction.
|
protected |
Constructor that takes a shared pointer to an attribute.
| ptr | The shared pointer to the attribute |
| aliasParent | The parent attribute as found in the tree if path was an alias |
| aliasName | The alias name of this attribute if found by an alias path |
References aliasName().
|
virtual |
Assigns this handle to refer to the same attribute as another handle.
| other | The 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().
| 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.
| other | The handle to assign from |
References DtAttributeHandle().
| DtAttributeHandle & makVre::DtAttributeHandle::operator= | ( | const DtAttributeHandle & | other | ) |
References DtAttributeHandle().
| bool makVre::DtAttributeHandle::assigned | ( | ) | const |
Checks if this handle is assigned to an attribute.
| bool makVre::DtAttributeHandle::assignedSame | ( | const DtAttributeHandle & | other | ) | const |
Checks if this handle is assigned to the same attribute as another handle.
| other | The handle to compare with |
References DtAttributeHandle().
| void makVre::DtAttributeHandle::unassign | ( | ) | const |
Unassigns this handle from its attribute.
| bool makVre::DtAttributeHandle::isAlias | ( | ) | const |
Returns true if the handle points to an attribute found via an alias path.
| const std::string & makVre::DtAttributeHandle::aliasName | ( | ) | const |
Returns the alias name if the attribute was found via an alias path.
Referenced by DtAttributeHandle().
| void makVre::DtAttributeHandle::next | ( | ) | const |
Treats this handle as an iterator and advances to the next sibling attribute.
| DtAttribute * makVre::DtAttributeHandle::operator-> | ( | ) |
Dereference operator for accessing the attribute.
References DtAttribute.
| const DtAttribute * makVre::DtAttributeHandle::operator-> | ( | ) | const |
Const dereference operator for accessing the attribute.
References DtAttribute.
| DtAttributeHandle makVre::DtAttributeHandle::operator[] | ( | const std::string & | name | ) |
Indexing operator for accessing child attributes by name.
| name | The name of the child attribute |
References DtAttributeHandle().
| const DtAttributeHandle makVre::DtAttributeHandle::operator[] | ( | const std::string & | name | ) | const |
Const indexing operator for accessing child attributes by name.
| name | The name of the child attribute |
References DtAttributeHandle().
| DtAttributeHandle makVre::DtAttributeHandle::operator[] | ( | const unsigned int | i | ) |
Indexing operator for accessing child attributes by index.
| i | The index of the child attribute |
References DtAttributeHandle().
| const DtAttributeHandle makVre::DtAttributeHandle::operator[] | ( | const unsigned int | i | ) | const |
Const indexing operator for accessing child attributes by index.
| i | The index of the child attribute |
References DtAttributeHandle().
| 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.
| bool makVre::DtAttributeHandle::unlock | ( | ) |
Unlocks the attribute, allowing other handles to write again.
Releases the exclusive write lock previously acquired by lock().
| bool makVre::DtAttributeHandle::isLocked | ( | ) | const |
Returns true if this handle currently holds the write lock.
| 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.
| data | The value to set |
| 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.
| bool makVre::DtAttributeHandle::recursiveUnlock | ( | ) |
Unlocks this attribute and all descendants locked with this handle's key.
|
protected |
Ensures that the handle is assigned to an attribute.
Checks if the handle is unassigned and asserts if it is
|
staticprotected |
Generates a new unique key for locking.
|
friend |
References DtAttribute.
Referenced by DtAttribute, operator->(), and operator->().
|
mutableprotected |
Shared pointer to the attribute.
|
mutableprotected |
Pointer to alias parent if found by an alias path.
|
mutableprotected |
Alias name of the attribute if found by an alias path.
|
protected |
Flag indicating if this handle is locked.
|
protected |
Key used for locking and unlocking.