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

Detailed Description

The DtAttribute class provides a flexible system for storing data to be shared between various app systems and components. It supports type-safe access and thread-safe change notifications. Attributes are organized in a heirarchical tree structure. Attribute are identified by names, which must be unique within each node.

#include <attribute.h>

Inheritance diagram for makVre::DtAttribute:
[legend]

Classes

struct  CallbacksForThread
 
struct  Stats
 

Public Types

enum  Trace {
  OFF , SET , CHANGE , GET ,
  LOOKUP
}
 
using DumpItem = std::pair<DtAttributeHandle, std::list<std::string>>
 
using DumpTable = std::list<DumpItem>
 

Public Member Functions

virtual ~DtAttribute ()
 
DtAttributeHandle handle ()
 
const DtAttributeHandle handle () const
 
 operator DtAttributeHandle ()
 
 operator const DtAttributeHandle () const
 
virtual const std::string & name () const
 
virtual std::string path () const
 
bool addAlias (DtAttributeHandle alias) const
 
bool removeAlias (DtAttributeHandle alias) const
 
const std::string & type () const
 
template<typename T>
bool isType () const
 
bool isType (const std::string &type) const
 
bool isSet () const
 
bool await (bool silent=false, bool assert=false, double timeout=3.0) const
 
bool await (std::function< bool(const DtAttributeHandle)> condition, bool silent=false, bool assert=false, double timeout=3.0) const
 
template<typename T>
const T get () const
 
template<typename T>
T getOr (T orValue) const
 
template<typename T>
bool set (const T &value)
 
template<typename T>
bool setIfNot (const T &defaultValue)
 
template<typename T>
bool setType ()
 
template<typename RET_T, typename T>
RET_T read (std::function< RET_T(const T &value)> readFunc) const
 
template<typename T>
void modifyFast (std::function< bool(T &value)> modifyFunc)
 
template<typename T>
bool modify (std::function< void(T &value)> modifyFunc)
 
template<typename T>
const T getAttribute (const std::string &attribute) const
 
template<typename T>
T getAttributeOr (const std::string &attribute, T orValue) const
 
template<typename T>
bool setAttribute (const std::string &attribute, const T &newValue)
 
std::string getAsString () const
 
bool setFromString (const std::string &newValue)
 
template<typename T>
const T previousValue () const
 
bool unset () const
 
bool unsetRecursive ()
 
void setPersistence (bool persistent)
 
void setPersistenceRecursive (bool persistent)
 
bool isPersistent () const
 
bool hasAttribute (const std::string &name) const
 
bool contains (const DtAttributeHandle &attr) const
 
bool containedBy (const DtAttributeHandle &attr) const
 
DtAttributeHandle attribute (const std::string &name)
 
const DtAttributeHandle attribute (const std::string &name) const
 
DtAttributeHandle parent ()
 
const DtAttributeHandle parent () const
 
DtAttributeHandle first ()
 
const DtAttributeHandle first () const
 
void forEach (const std::function< void(DtAttributeHandle)> &forEachFun)
 
void forEach (const std::function< void(const DtAttributeHandle)> &forEachFun) const
 
bool isRoot () const
 
const void * raw () const
 
bool isLocked () const
 
void addCallback (const DtAttributeCallbackBase &callback)
 
void removeCallback (const DtAttributeCallbackBase &callback)
 
unsigned int handleCount () const
 
const Stats & stats () const
 

Static Public Member Functions

static DtAttributeHandle Root ()
 
static void registerCallbackThread ()
 
static void unregisterCallbackThread ()
 
static void callbackDispatchTick ()
 
static void recursiveDumpToTable (const DtAttributeHandle attrToDump, DumpTable &output, int depth=0)
 
static void quickDump (const DtAttributeHandle, bool includeValues=false, int depth=0)
 
static void QueueTrace (DtAttributeHandle attribute, Trace trace)
 
static std::pair< DtAttributeHandle, Trace > QueuedTrace ()
 
static void CancelQueuedTrace ()
 
static void TidyUp ()
 

Protected Types

using Ptr = std::shared_ptr<DtAttribute>
 
using Ref = std::weak_ptr<DtAttribute>
 
using Map = std::map<std::string, std::pair<Ptr, Ref>>
 
using DataPtr = std::shared_ptr<DtAttributeData>
 
using CallbackList = std::list<const DtAttributeCallbackBase*>
 
using Mutex = tbb::spin_rw_mutex
 
using MutexLock = tbb::spin_rw_mutex::scoped_lock
 
using CallbackThreadMap = std::map<unsigned int, CallbacksForThread>
 

Protected Member Functions

 DtAttribute ()
 
 DtAttribute (const std::string &name, const Ptr &parent)
 
const Ptr self () const
 
Ptr self ()
 
bool lock (unsigned int key)
 
bool unlock (unsigned int key)
 
const Ptr pFirst () const
 
Ptr pFirst ()
 
const Ptr pNext (const Ptr &current) const
 
Ptr pNext (const Ptr &current)
 
DtAttributeHandle handleFor (const Ptr &child, const Map::const_iterator &) const
 
Ptr _nextValid (Map::iterator &fromIt) const
 
DtAttributeHandle nextAfter (const DtAttributeHandle &ref)
 
const DtAttributeHandle nextAfter (const DtAttributeHandle &ref) const
 
void forEach (const std::function< void(Ptr)> &forEachFun)
 
void forEach (const std::function< void(const Ptr)> &forEachFun) const
 
Ptr find (const std::string &path, bool orCreate=false, std::string *foundAs=nullptr, Ptr *foundIn=nullptr)
 
const Ptr find (const std::string &path, bool orCreate=false, std::string *foundAs=nullptr, Ptr *foundIn=nullptr) const
 
Ptr addAttribute (const std::string &name, bool &aliasExists)
 
const Ptr addAttribute (const std::string &name, bool &aliasExists) const
 
const std::string & _type () const
 
template<typename T>
bool _isType () const
 
template<typename T>
void _assertType () const
 
bool _isType (const std::string &type) const
 
bool _isSet () const
 
bool _isLocked () const
 
template<typename T>
void _createData () const
 
template<typename T>
void validateData (MutexLock &lock) const
 
void invokePendingCallbacksRecursive ()
 
void invokePendingCallbacks ()
 
void invokeCallbacks (const Ptr &changed, const unsigned int threadId)
 
void valueChanged ()
 
bool _lockCheck (unsigned int callerKey=0) const
 
bool recursiveLock (unsigned int callerKey)
 
bool recursiveUnlock (unsigned int callerKey)
 
void doTraceIf (Trace which) const
 
void incHandleCount ()
 
void decHandleCount ()
 
void cleanTheMap ()
 

Static Protected Member Functions

static Ptr create (const std::string &name, const Ptr &parent)
 
static std::unordered_map< unsigned int, bool > callbackThreadIds ()
 
static unsigned int callbackThreadIdForThread (const unsigned int threadId)
 
static void callbacksStartedOnThread (const unsigned int threadId)
 
static void callbacksFinishedOnThread (const unsigned int threadId)
 
static bool callbacksRunningOnThread (const unsigned int threadId)
 
static void needsTidying (DtAttribute::Ptr dirty)
 

Protected Attributes

std::string myName
 
DataPtr myData
 
bool myExplicitType
 
Mutex myValueMutex
 
Mutex myMapMutex
 
Mutex myCallbackMutex
 
CallbackThreadMap myChangeCallbacks
 
Stats myStats
 
Ref mySelf
 
Ptr mySelfInit
 
Ptr myParent
 
Map myAttributes
 
Map::iterator myItr
 
unsigned int myWriteKey
 
std::atomic< unsigned int > myHandleCount = 0
 

Static Protected Attributes

static Mutex TheCallbackThreadMapMutex
 
static std::unordered_map< unsigned int, bool > TheCallbackThreadMap
 
static std::pair< Ref, Trace > TheQueuedTrace
 
static std::pair< Ref, std::string > TheLastTrace
 
static Mutex TheTraceMutex
 
static std::atomic< bool > TheTraceQueuedFlag
 
static Mutex TheTidyMutex
 
static std::map< void *, Ref > TheAttributesNeedTidying
 

Friends

class DtAttributeHandle
 

Member Typedef Documentation

◆ DumpItem

using makVre::DtAttribute::DumpItem = std::pair<DtAttributeHandle, std::list<std::string>>

Recursively dumps the attribute hierarchy to a table.

Parameters
depthThe current depth in the hierarchy
Returns
A table representation of the attribute hierarchy

◆ DumpTable

◆ Ptr

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

Shared pointer type for attributes.

◆ Ref

using makVre::DtAttribute::Ref = std::weak_ptr<DtAttribute>
protected

Weak pointer type for attributes.

◆ Map

using makVre::DtAttribute::Map = std::map<std::string, std::pair<Ptr, Ref>>
protected

Map type for storing child attributes.

◆ DataPtr

using makVre::DtAttribute::DataPtr = std::shared_ptr<DtAttributeData>
protected

Shared pointer type for attribute data storage.

◆ CallbackList

using makVre::DtAttribute::CallbackList = std::list<const DtAttributeCallbackBase*>
protected

Ordered list of raw callback pointers for a single thread.

◆ Mutex

using makVre::DtAttribute::Mutex = tbb::spin_rw_mutex
protected

Mutex type used for thread-safe attribute access.

◆ MutexLock

using makVre::DtAttribute::MutexLock = tbb::spin_rw_mutex::scoped_lock
protected

◆ CallbackThreadMap

using makVre::DtAttribute::CallbackThreadMap = std::map<unsigned int, CallbacksForThread>
protected

Map of per-thread callback state, keyed by thread ID.

Member Enumeration Documentation

◆ Trace

Trace level for diagnostic attribute access logging.

When a trace is queued via QueueTrace(), the attribute system will trigger a debug break the next time the specified access type occurs on the target attribute.

Enumerator
OFF 

Tracing disabled.

SET 

Trace on the next value set.

CHANGE 

Trace on the next value change.

GET 

Trace on the next value get.

LOOKUP 

Trace on the next attribute lookup.

Constructor & Destructor Documentation

◆ ~DtAttribute()

virtual makVre::DtAttribute::~DtAttribute ( )
virtual

Virtual destructor.

◆ DtAttribute() [1/2]

makVre::DtAttribute::DtAttribute ( )
protected

Default constructor.

◆ DtAttribute() [2/2]

makVre::DtAttribute::DtAttribute ( const std::string & name,
const Ptr & parent )
protected

Constructor with name and parent.

Parameters
nameThe name of the attribute
parentThe parent attribute

References name(), and parent().

Member Function Documentation

◆ Root()

static DtAttributeHandle makVre::DtAttribute::Root ( )
static

Returns a reference to the root attribute.

Returns
A root attribute handle

References DtAttributeHandle.

◆ handle() [1/2]

DtAttributeHandle makVre::DtAttribute::handle ( )

Returns the handle for this attribute.

Returns
A handle to this attribute

References DtAttributeHandle.

◆ handle() [2/2]

const DtAttributeHandle makVre::DtAttribute::handle ( ) const

Returns the const handle for this attribute.

Returns
A const handle to this attribute

References DtAttributeHandle.

◆ operator DtAttributeHandle()

makVre::DtAttribute::operator DtAttributeHandle ( )

Conversion operator to DtAttributeHandle.

References DtAttributeHandle.

◆ operator const DtAttributeHandle()

makVre::DtAttribute::operator const DtAttributeHandle ( ) const

Conversion operator to const DtAttributeHandle.

References DtAttributeHandle.

◆ name()

virtual const std::string & makVre::DtAttribute::name ( ) const
virtual

Returns the name associated with this attribute.

Returns
The name of this attribute

Referenced by addAttribute(), addAttribute(), attribute(), attribute(), create(), DtAttribute(), and hasAttribute().

◆ path()

virtual std::string makVre::DtAttribute::path ( ) const
virtual

Returns the full path of this attribute in the hierarchy.

Returns
The full path string in dot notation

Referenced by find(), and find().

◆ addAlias()

bool makVre::DtAttribute::addAlias ( DtAttributeHandle alias) const

Assigns an alias path for this attribute.

Aliases allows the same attribute to be accessed using alternate paths.

Methods such as parent() and path() that reference the parent attribute will always reflect the original parent.

Parameters
aliasA handle to the attribute path that should be used as the alias path.

The given handle must be assigned a path. The attribute at this handle must not be set, it must not be readonly, it must have no other handles, and it cannot be Root().

If the alias handle meets the criteria, the alias path will be created.

Returns
true if the alias creation is successful, false otherwise

References DtAttributeHandle.

◆ removeAlias()

bool makVre::DtAttribute::removeAlias ( DtAttributeHandle alias) const

Removes an alias path for this attribute.

Parameters
aliasA handle to the alias attribute path to be removed.

The alias handle must be an alias currently assigned to this attribute.

If the alias handle meets the criteria, the alias path will be removed.

Returns
true if the alias removal is successful, false otherwise

References DtAttributeHandle.

◆ type()

const std::string & makVre::DtAttribute::type ( ) const

Returns the type of this attribute.

Returns
The type name as a string
Note
Undefined attributes return DtAttributeData::UndefinedType()

Referenced by _isType(), and isType().

◆ isType() [1/2]

template<typename T>
bool makVre::DtAttribute::isType ( ) const

Checks if the attribute is of the specified type.

Returns
true if the attribute is of type T, false otherwise
Note
Undefined values always return false

◆ isType() [2/2]

bool makVre::DtAttribute::isType ( const std::string & type) const

Checks if the attribute is of the specified type by name.

Parameters
typeThe type name to check against
Returns
true if the attribute is of the specified type, false otherwise
Note
Undefined values always return false

References type().

◆ isSet()

bool makVre::DtAttribute::isSet ( ) const

Checks if the attribute value is undefined.

Returns
true if the attribute has no defined value, false otherwise

◆ await() [1/2]

bool makVre::DtAttribute::await ( bool silent = false,
bool assert = false,
double timeout = 3.0 ) const

Blocks execution on this thread until this attribute value is defined.

Parameters
timeoutSeconds to wait; optional, default 3.0
silentIf set true, no error is logged on timeout; optional, default false
assertIf true, breaks with assert on failure, else just logs warning; optional, default false
Returns
True if value is set before timeout, false if not

Execution will continue once a value is set, or timeout time elapses. If wait times out, an error will be logged. This method returns immediately if the value of this attribute is already set.

Do not use this unless the value will be set by another thread.

Note
To avoid stalls, consider using getOr() or a change callback instead of await().

◆ await() [2/2]

bool makVre::DtAttribute::await ( std::function< bool(const DtAttributeHandle)> condition,
bool silent = false,
bool assert = false,
double timeout = 3.0 ) const

Blocks execution on this thread until the condition is satisfied.

Parameters
conditionCallable to test required condition to continue
timeoutSeconds to wait; optional, default 3.0
silentIf set true, no error is logged on timeout; optional, default false
assertIf true, breaks with assert on failure, else just logs warning; optional, default false
Returns
True if condition is met before timeout, false if not

Execution will continue once condition returns true, or timeout time elapses. If wait times out, an error will be logged.

Condition is a callable that receives this attribute as an argument, and must return true or false.

Do not use this unless the condition can be met by action from another thread.

Note
This is a blocking call, use with caution.

References DtAttributeHandle.

◆ get()

template<typename T>
const T makVre::DtAttribute::get ( ) const

Gets the value of the attribute.

Returns
The value of the attribute of type T
Note
Throws an assertion if the attribute is of a different type
Undefined attributes return a zero-initialized value of type T

◆ getOr()

template<typename T>
T makVre::DtAttribute::getOr ( T orValue) const

Gets the value of the attribute or a default value if undefined.

Note
Using getOr with a zero-equivalent value, i.e. getOr(0/false/"" etc) is unnecessary and redundant, since get<T>() returns a zero-initialized value for undefined attributes. Use /ref get<T>() directly instead of getOr() when the default value is the zero-initialized value for the type.
Parameters
orValueThe default value to return if the attribute is undefined
Returns
The attribute value or the default value

◆ set()

template<typename T>
bool makVre::DtAttribute::set ( const T & value)

Sets the value of the attribute.

If the new value differs from existing, change callbacks will be invoked.

Parameters
valueThe new value to set
Returns
true if the new value differs from existing

◆ setIfNot()

template<typename T>
bool makVre::DtAttribute::setIfNot ( const T & defaultValue)

Sets the value of the attribute only if it is currently undefined.

Parameters
defaultValueThe default value to set if the attribute is undefined
Returns
true if the value was set, false if the attribute already had a value

◆ setType()

template<typename T>
bool makVre::DtAttribute::setType ( )

Establish the type of the attribute if value attribute is not yet set.

Will zero-initialize the attribute value.

Returns
True if the type was set successfully, false if the attribute is already established with a different type.

◆ read()

template<typename RET_T, typename T>
RET_T makVre::DtAttribute::read ( std::function< RET_T(const T &value)> readFunc) const

Reads the value of the attribute using a callback.

Alternative to get method that allows reading from large or complex data types without the overhead of copying the data, or when it is necessary to maintain a read lock on the attribute value for multi-step operations, e.g. reading a raw pointer, null-checking, then dereferencing to invoke a method.

Template Parameters
RET_TReturn type passed back from the read callback
Parameters
readFuncCallback that receives a const reference to the typed value
Returns
Returns Returns the value of type RET_T returned by the callback

◆ modifyFast()

template<typename T>
void makVre::DtAttribute::modifyFast ( std::function< bool(T &value)> modifyFunc)

Modifies the attribute value in-place using a callback.

Calls modifyFunc with a direct reference to the stored value. If the callback returns true, change callbacks are triggered without performing a before/after copy comparison, making this faster than modify() when the caller can determine whether the value actually changed.

Template Parameters
TThe type of the attribute value.
Parameters
modifyFuncCallback that receives a mutable reference to the value and returns true if the value was changed, false if it was not.
Note
This method acquires a write mutex lock on the attribute before calling modifyFunc. Do not call other methods on this attribute from within modifyFunc. Doing so may cause a deadlock.

◆ modify()

template<typename T>
bool makVre::DtAttribute::modify ( std::function< void(T &value)> modifyFunc)

Modifies the attribute value in-place using a callback, with change detection.

Calls modifyFunc with a direct reference to the stored value, then compares the before and after state to determine if the value changed. Change callbacks are triggered only if the value actually changed.

Template Parameters
TThe type of the attribute value.
Parameters
modifyFuncCallback that receives a mutable reference to the value.
Returns
true if the value changed, false otherwise.
Note
This method acquires a write mutex lock on the attribute before calling modifyFunc. Do not call other methods on this attribute from within modifyFunc. Doing so may cause a deadlock.

◆ getAttribute()

template<typename T>
const T makVre::DtAttribute::getAttribute ( const std::string & attribute) const

Gets the value of a child attribute.

Calls /ref get<T>() on the child attribute identified by attribute. This is a convenience method directly equivalent to [attribute]->get<T>()

Note
Undefined attributes return a zero-initialize value of type T, so getAttribute<T>() is safe to call even if the attribute doesn't exist yet. Use hasAttribute() to check for existence if needed.
Parameters
attributeThe name of the child attribute
Returns
The value of the child attribute

References attribute().

◆ getAttributeOr()

template<typename T>
T makVre::DtAttribute::getAttributeOr ( const std::string & attribute,
T orValue ) const

Gets the value of a child attribute or a default value if undefined.

Calls /ref getOr<T>() on the child attribute identified by attribute. This is a convenience method directly equivalent to [attribute]->getOr<T>(orValue)

Note
Using getAttributeOr with a zero-equivalent default value, i.e. getAttributeOr<T>(0/false/"" etc) is unnecessary and redundant, since getAttribute<T>() returns a zero-initialized value of type T for undefined attributes. Use /ref getAttribute<T>() directly instead of getAttributeOr() when the default value is the zero-initialized value for the type.
Parameters
attributeThe name of the child attribute
orValueThe default value to return if the attribute is undefined
Returns
The child attribute value or the default value

References attribute().

◆ setAttribute()

template<typename T>
bool makVre::DtAttribute::setAttribute ( const std::string & attribute,
const T & newValue )

Sets the value of a child attribute.

If the new value differs from existing, change callbacks will be invoked.

Parameters
attributeThe name of the child attribute
newValueThe new value to set
Returns
true if the value changed

References attribute().

◆ getAsString()

std::string makVre::DtAttribute::getAsString ( ) const

Gets string representation of the attribute value.

Returns
String representation of the attribute value

◆ setFromString()

bool makVre::DtAttribute::setFromString ( const std::string & newValue)

Sets the attribute value from a string representation.

If the new value differs from existing, change callbacks will be invoked.

Parameters
newValueString representation of the new value
Returns
true if the value changed

◆ previousValue()

template<typename T>
const T makVre::DtAttribute::previousValue ( ) const

Gets the previous value of the attribute before the last change.

Returns
The previous value of the attribute
Note
Returns a zero-initialized value of type T if the attribute is undefined or has never been changed

◆ unset()

bool makVre::DtAttribute::unset ( ) const

Unsets the attribute value.

Value is returned to an undefined, typeless state

Returns
true if the attribute was unset, false otherwise

◆ unsetRecursive()

bool makVre::DtAttribute::unsetRecursive ( )

Unsets this attribute and all child attributes, recursively.

Returns
true if all attributes were unset successfully

◆ setPersistence()

void makVre::DtAttribute::setPersistence ( bool persistent)

Set whether this attribute exists w/o handles assigned.

A persistent attribute will continue to exist in the attribute tree for the lifetime of the application. A non-persistent attribute will be deleted as soon as no handles are assigned to it. The default condition for attributes is persistent.

Note
When an attribute is first created, it inherits the persistence state of its parent.
Parameters
persistentSet true for persistent, false for non-persistent

◆ setPersistenceRecursive()

void makVre::DtAttribute::setPersistenceRecursive ( bool persistent)

Sets the persistence of this attribute and all child attributes.

setPersistence

Parameters
persistentSet true for persistent, false for non-persistent

◆ isPersistent()

bool makVre::DtAttribute::isPersistent ( ) const

Check the persistence state of this attribute.

setPersistence

Returns
true if attribute is persitent, false if not

◆ hasAttribute()

bool makVre::DtAttribute::hasAttribute ( const std::string & name) const

Checks if a child attribute exists.

Note
Note that every attribute lookup creaste and attribute at that path. Unless the persistence state has been set false, that attribute will continue to exist, even if it has no value set. This means that any code calling almost any method, however innocuous, will create that atttribute; including by not limited to get methods. This will cause all subsequent hasAttribute() calls to return true. Use hasAttribute() with caution. In most cases, the check is not necessary at all, since get and set are always safe to call even if the attribute does not yet exist. In other cases, consider whether checking /ref isSet() would be more appropriate.
Returns
true if the child attribute exists, false otherwise

References name().

◆ contains()

bool makVre::DtAttribute::contains ( const DtAttributeHandle & attr) const

Checks if the given attribute is a direct or indirect child of this attribute.

Recursively searches the subtree rooted at this attribute to determine if attr is a descendant.

Parameters
attrThe attribute handle to search for.
Returns
true if attr is a descendant of this attribute, false otherwise.

References DtAttributeHandle.

◆ containedBy()

bool makVre::DtAttribute::containedBy ( const DtAttributeHandle & attr) const

Checks if this attribute is a direct or indirect child of the given attribute.

Walks up the parent chain from this attribute to determine if attr is an ancestor.

Parameters
attrThe attribute handle to test as a potential ancestor.
Returns
true if this attribute is a descendant of attr, false otherwise.

References DtAttributeHandle.

◆ attribute() [1/2]

DtAttributeHandle makVre::DtAttribute::attribute ( const std::string & name)

Gets a handle to a child attribute.

Parameters
nameThe name of the child attribute. Name may be a path to child subattributes in format "ChildName.GrandChild.GreatGrandChild"
Returns
A handle to the child attribute

References DtAttributeHandle, and name().

Referenced by getAttribute(), getAttributeOr(), QueueTrace(), and setAttribute().

◆ attribute() [2/2]

const DtAttributeHandle makVre::DtAttribute::attribute ( const std::string & name) const

Const version of attribute(const std::string&)

References DtAttributeHandle, and name().

◆ parent() [1/2]

DtAttributeHandle makVre::DtAttribute::parent ( )

Gets a handle to the parent attribute.

Returns
A handle to the parent attribute

References DtAttributeHandle.

Referenced by create(), and DtAttribute().

◆ parent() [2/2]

const DtAttributeHandle makVre::DtAttribute::parent ( ) const

Gets a const handle to the parent attribute.

Returns
A const handle to the parent attribute

References DtAttributeHandle.

◆ first() [1/2]

DtAttributeHandle makVre::DtAttribute::first ( )

Gets a handle to the first child attribute.

Returns
A handle to the first child attribute

References DtAttributeHandle.

◆ first() [2/2]

const DtAttributeHandle makVre::DtAttribute::first ( ) const

Gets a const handle to the first child attribute.

Returns
A const handle to the first child attribute

References DtAttributeHandle.

◆ forEach() [1/4]

void makVre::DtAttribute::forEach ( const std::function< void(DtAttributeHandle)> & forEachFun)

Calls the given function for each immediate child attribute.

The child map is locked only per-entry so callbacks may safely access other attributes without deadlocking.

Parameters
forEachFunFunction to call with a handle to each child attribute.

References DtAttributeHandle.

◆ forEach() [2/4]

void makVre::DtAttribute::forEach ( const std::function< void(const DtAttributeHandle)> & forEachFun) const

Const version of forEach(std::function<void(DtAttributeHandle)>)

References DtAttributeHandle.

◆ isRoot()

bool makVre::DtAttribute::isRoot ( ) const

Checks if this attribute is the root attribute.

Returns
true if this is the root attribute, false otherwise

◆ raw()

const void * makVre::DtAttribute::raw ( ) const

Gets the raw data pointer.

Returns
The raw data pointer

◆ isLocked()

bool makVre::DtAttribute::isLocked ( ) const

Checks if the attribute is write-locked.

Returns
true if the attribute is readOnly, false if value change is allowed

◆ addCallback()

void makVre::DtAttribute::addCallback ( const DtAttributeCallbackBase & callback)

Create a temporary write-lock on this attribute.

Creates a write-blocking mutex lock that will block any other thread attempting to change the value. Use sparingly when necessary to assure value does not change in critical use section, e.g. when checking and then dereferencing a raw pointer value. Use with caution, overuse will harm app performance.

Note
Do not attempt to set the attribute value while holding this lock!

Adds a change callback for this attribute

Parameters
callbackThe callback to add

◆ removeCallback()

void makVre::DtAttribute::removeCallback ( const DtAttributeCallbackBase & callback)

Removes a change callback from this attribute.

Parameters
callbackThe callback to remove

◆ registerCallbackThread()

static void makVre::DtAttribute::registerCallbackThread ( )
static

◆ unregisterCallbackThread()

static void makVre::DtAttribute::unregisterCallbackThread ( )
static

◆ callbackDispatchTick()

static void makVre::DtAttribute::callbackDispatchTick ( )
static

◆ handleCount()

unsigned int makVre::DtAttribute::handleCount ( ) const

Gets the number of handles currently assigned to this attribute.

◆ recursiveDumpToTable()

static void makVre::DtAttribute::recursiveDumpToTable ( const DtAttributeHandle attrToDump,
DumpTable & output,
int depth = 0 )
static

References DtAttributeHandle.

◆ quickDump()

static void makVre::DtAttribute::quickDump ( const DtAttributeHandle ,
bool includeValues = false,
int depth = 0 )
static

References DtAttributeHandle.

◆ stats()

const Stats & makVre::DtAttribute::stats ( ) const
inline

Gets the attribute statistics.

Returns
The attribute statistics

References myStats.

◆ QueueTrace()

static void makVre::DtAttribute::QueueTrace ( DtAttributeHandle attribute,
Trace trace )
static

Queues a one-shot diagnostic trace for the specified attribute and access type.

The trace fires the next time the given access type occurs on attribute, then the queue is cleared. Only one trace can be queued at a time.

Parameters
attributeThe attribute to trace.
traceThe access type that should trigger the trace.

References attribute(), and DtAttributeHandle.

◆ QueuedTrace()

static std::pair< DtAttributeHandle, Trace > makVre::DtAttribute::QueuedTrace ( )
static

Returns the currently queued trace entry.

Returns
A pair containing the target attribute handle and the trace type. If no trace is queued, the handle is unassigned and the type is Trace::OFF.

◆ CancelQueuedTrace()

static void makVre::DtAttribute::CancelQueuedTrace ( )
static

Cancels any currently queued diagnostic trace.

◆ TidyUp()

static void makVre::DtAttribute::TidyUp ( )
static

Perform any necessary cleanup of expired attribute entries in the attribute tree.

◆ create()

static Ptr makVre::DtAttribute::create ( const std::string & name,
const Ptr & parent )
staticprotected

Factory method that creates and registers a named child attribute.

Parameters
nameThe name of the new attribute.
parentShared pointer to the parent attribute.
Returns
Shared pointer to the newly created attribute.

References name(), and parent().

◆ self() [1/2]

const Ptr makVre::DtAttribute::self ( ) const
protected

Gets a shared pointer to this attribute.

Returns
A shared pointer to this attribute

◆ self() [2/2]

Ptr makVre::DtAttribute::self ( )
protected

Non-const version of self()

◆ lock()

bool makVre::DtAttribute::lock ( unsigned int key)
protected

Locks write access to attribute value.

Parameters
keyChosen key that will be required to unlock
Returns
true on success, false if already locked
Note
Attempts to set value while locked will fail and produce warning in log

Referenced by validateData().

◆ unlock()

bool makVre::DtAttribute::unlock ( unsigned int key)
protected

Unlocks write access.

Parameters
keyMust be the same key used to lock
Returns
true on success, false if the key was incorrect or attribute not locked

◆ pFirst() [1/2]

const Ptr makVre::DtAttribute::pFirst ( ) const
protected

Get the first child attribute, excluding aliases.

Returns
Shared pointer to the first child attribute, or null if no children exist.

◆ pFirst() [2/2]

Ptr makVre::DtAttribute::pFirst ( )
protected

Non-const version of pFirst()

◆ pNext() [1/2]

const Ptr makVre::DtAttribute::pNext ( const Ptr & current) const
protected

Gets a shared pointer to the next sibling attribute after the current child, excluding aliases.

Parameters
currentShared pointer to the current child attribute
Returns
Shared pointer to the next sibling attribute, or null if no more siblings exist

◆ pNext() [2/2]

Ptr makVre::DtAttribute::pNext ( const Ptr & current)
protected

Non-const version of pNext(const Ptr&)

◆ handleFor()

DtAttributeHandle makVre::DtAttribute::handleFor ( const Ptr & child,
const Map::const_iterator &  ) const
protected

Generate a handle to the child attribute, with alias support.

Checks the parent of child, returns an alias handle if the parent is not this attribute.

Parameters
childShared pointer to the child attribute
itIterator to the map entry corresponding to the child attribute
Returns
Handle to the child attribute, or an unassigned handle if not found

References DtAttributeHandle.

◆ _nextValid()

Ptr makVre::DtAttribute::_nextValid ( Map::iterator & fromIt) const
protected

Get the next valid child entry.

Safety wrapper checks for expired entires.

Parameters
fromItIterator to start searching from
Returns
Shared pointer to the next valid child attribute, or null if no more valid children exist

◆ nextAfter() [1/2]

DtAttributeHandle makVre::DtAttribute::nextAfter ( const DtAttributeHandle & ref)
protected

Gets a handle to the next child attribute after the reference child.

Parameters
refHandle to a reference child to start from
Returns
The next child after the reference attribute, or an unassigned handle if the reference attribute was the last child, or if the reference attribute is not a child of this attribute.

References DtAttributeHandle.

◆ nextAfter() [2/2]

const DtAttributeHandle makVre::DtAttribute::nextAfter ( const DtAttributeHandle & ref) const
protected

◆ forEach() [3/4]

void makVre::DtAttribute::forEach ( const std::function< void(Ptr)> & forEachFun)
protected

Calls the given function for each immediate child, excluding aliases.

Lower-overhead internal forEach using shared pointers instead of handles. Skips aliases.

Parameters
forEachFunFunction to call for each child.

◆ forEach() [4/4]

void makVre::DtAttribute::forEach ( const std::function< void(const Ptr)> & forEachFun) const
protected

Const version of forEach(std::function<void(Ptr)>)

◆ find() [1/2]

Ptr makVre::DtAttribute::find ( const std::string & path,
bool orCreate = false,
std::string * foundAs = nullptr,
Ptr * foundIn = nullptr )
protected

Recursive search for child attribute at path, relative to this.

Recursive child names in path are delimited by '.', e.g. find("childName.grandChildName.greatGrandChildName")

Parameters
pathName or path of names of child attribute to find
orCreateIf true, creates the attribute (and any intermediate path attributes) if not found; if false, returns null pointer when not found
[out]foundAsOptional output for the alias name when the final path component resolves through an alias; unchanged otherwise.
[out]foundInOptional output for the attribute containing the final alias entry; unchanged otherwise.
Returns
Shared pointer to the found or created attribute, or null if not found and orCreate is false

References path().

◆ find() [2/2]

const Ptr makVre::DtAttribute::find ( const std::string & path,
bool orCreate = false,
std::string * foundAs = nullptr,
Ptr * foundIn = nullptr ) const
protected

Const overload of find().

Parameters
pathName or path of names of child attribute to find.
orCreateIf true, creates missing attributes along the path; if false, returns null when not found.
[out]foundAsOptional output for the alias name when the final path component resolves through an alias; unchanged otherwise.
[out]foundInOptional output for the attribute containing the final alias entry; unchanged otherwise.
Returns
Shared pointer to the found or created attribute, or null if not found and orCreate is false.

References path().

◆ addAttribute() [1/2]

Ptr makVre::DtAttribute::addAttribute ( const std::string & name,
bool & aliasExists )
protected

Creates and registers a new child attribute with the given name.

If an attribute with the same name already exists, the existing attribute is returned. Thread-safe.

Parameters
nameThe name of the child attribute to create.
[out]aliasExistsSet to true if an existing entry is an alias, or false if it is not. Unchanged when a new attribute is created; initialize to false before calling.
Returns
Shared pointer to the created or existing child attribute.

References name().

◆ addAttribute() [2/2]

const Ptr makVre::DtAttribute::addAttribute ( const std::string & name,
bool & aliasExists ) const
protected

Const overload of addAttribute().

Parameters
nameThe name of the child attribute to create.
[out]aliasExistsSet to true if an existing entry is an alias, or false if it is not. Unchanged when a new attribute is created; initialize to false before calling.
Returns
Shared pointer to the created or existing child attribute.

References name().

◆ _type()

const std::string & makVre::DtAttribute::_type ( ) const
protected

Internal implementation of type()

Returns
The type name as a string
Note
Not thread safe

◆ _isType() [1/2]

template<typename T>
bool makVre::DtAttribute::_isType ( ) const
protected

Internal implementation of isType()

Returns
true if the attribute is of type T, false otherwise
Note
Not thread safe

◆ _assertType()

template<typename T>
void makVre::DtAttribute::_assertType ( ) const
protected

Throws an assertion if the attribute is not of type T.

Note
No mutex guard

◆ _isType() [2/2]

bool makVre::DtAttribute::_isType ( const std::string & type) const
protected

Internal implementation of isType()

Parameters
typeThe type name to check against
Returns
true if the attribute is of the specified type, false otherwise
Note
Not thread safe

References type().

◆ _isSet()

bool makVre::DtAttribute::_isSet ( ) const
protected

Internal implementation of isSet()

Returns
true if the attribute has no defined value, false otherwise
Note
Not thread safe

◆ _isLocked()

bool makVre::DtAttribute::_isLocked ( ) const
protected

Internal implementation of isLocked()

Returns
true if the attribute is locked, false otherwise
Note
Not thread safe

◆ _createData()

template<typename T>
void makVre::DtAttribute::_createData ( ) const
protected

Creates data storage for the specified type.

Note
This is used to initialize the attribute data

◆ validateData()

template<typename T>
void makVre::DtAttribute::validateData ( MutexLock & lock) const
protected

Validates that the attribute data is of the specified type.

References lock().

◆ invokePendingCallbacksRecursive()

void makVre::DtAttribute::invokePendingCallbacksRecursive ( )
protected

Checks and dispatches pending change callbacks for this attribute and all descendants.

Calls invokePendingCallbacks() on this attribute, then recursively on all children. Typically called from multi-threaded tick functions to deliver deferred callback notifications on the correct thread.

◆ invokePendingCallbacks()

void makVre::DtAttribute::invokePendingCallbacks ( )
protected

Checks and dispatches pending change callbacks for the calling thread.

If this attribute's value was changed since the last dispatch for the calling thread, invokes all registered callbacks for that thread. Normally called by invokePendingCallbacksRecursive() or valueChanged().

◆ invokeCallbacks()

void makVre::DtAttribute::invokeCallbacks ( const Ptr & changed,
const unsigned int threadId )
protected

Invokes all registered change callbacks.

◆ valueChanged()

void makVre::DtAttribute::valueChanged ( )
protected

Marks the value as changed and dispatches callbacks for the current thread.

Updates the changed flag for all registered threads and immediately invokes callbacks for the calling thread via checkPendingCallbacks().

◆ callbackThreadIds()

static std::unordered_map< unsigned int, bool > makVre::DtAttribute::callbackThreadIds ( )
staticprotected

Gets the list of thread IDs that are known or registered to invoke callbacks.

◆ callbackThreadIdForThread()

static unsigned int makVre::DtAttribute::callbackThreadIdForThread ( const unsigned int threadId)
staticprotected

Gets the thread ID on which a callback from the current thread may be invoked.

This will return the current thread ID if the current thread is registered to invoke callbacks, else it will return the first registered callback thread, which should be the main thread.

◆ callbacksStartedOnThread()

static void makVre::DtAttribute::callbacksStartedOnThread ( const unsigned int threadId)
staticprotected

Record that the given thread is invoking callbacks.

◆ callbacksFinishedOnThread()

static void makVre::DtAttribute::callbacksFinishedOnThread ( const unsigned int threadId)
staticprotected

Record that the given thread is done invoking callbacks.

◆ callbacksRunningOnThread()

static bool makVre::DtAttribute::callbacksRunningOnThread ( const unsigned int threadId)
staticprotected

Returns whether the given thread is invoking callbacks.

◆ _lockCheck()

bool makVre::DtAttribute::_lockCheck ( unsigned int callerKey = 0) const
protected

Checks if the attribute is locked against the given caller key.

Parameters
callerKeyKey to test against the lock owner; a matching key bypasses the lock
Returns
true if locked and action should be prevented, false otherwise

◆ recursiveLock()

bool makVre::DtAttribute::recursiveLock ( unsigned int callerKey)
protected

Locks this attribute and all descendants recursively.

Uses best-effort semantics: continues even if a child is already locked by a different key, but returns false if any node could not be locked.

Parameters
callerKeyThe key to use for locking
Returns
true if all nodes were successfully locked, false otherwise

◆ recursiveUnlock()

bool makVre::DtAttribute::recursiveUnlock ( unsigned int callerKey)
protected

Unlocks this attribute and all descendants whose lock key matches callerKey.

Nodes locked by a different key are left untouched.

Parameters
callerKeyThe key used when locking
Returns
true if all nodes matching callerKey were successfully unlocked

◆ doTraceIf()

void makVre::DtAttribute::doTraceIf ( Trace which) const
protected

Triggers a diagnostic debug break and logs trace context for this attribute.

Called internally when a queued trace condition is met. Outputs attribute path, value, and stack information to the log.

◆ incHandleCount()

void makVre::DtAttribute::incHandleCount ( )
protected

Increments the handle count for this attribute.

◆ decHandleCount()

void makVre::DtAttribute::decHandleCount ( )
protected

Decrements the handle count for this attribute.

◆ cleanTheMap()

void makVre::DtAttribute::cleanTheMap ( )
protected

Performs cleanup of expired child attribute entries in the map.

◆ needsTidying()

static void makVre::DtAttribute::needsTidying ( DtAttribute::Ptr dirty)
staticprotected

Marks the attribute as needing tidying, adds to list to be cleaned up on the next call to TidyUp().

Friends And Related Symbol Documentation

◆ DtAttributeHandle

Member Data Documentation

◆ myName

std::string makVre::DtAttribute::myName
protected

The name of this attribute.

◆ myData

DataPtr makVre::DtAttribute::myData
mutableprotected

The data stored in this attribute.

◆ myExplicitType

bool makVre::DtAttribute::myExplicitType
mutableprotected

Flag indicating if the type was explicitly set.

◆ myValueMutex

Mutex makVre::DtAttribute::myValueMutex
mutableprotected

Attribute data value mutex for thread safety.

◆ myMapMutex

Mutex makVre::DtAttribute::myMapMutex
mutableprotected

Sub-attribute map mutex for thread safety.

◆ myCallbackMutex

Mutex makVre::DtAttribute::myCallbackMutex
mutableprotected

Value change callback mutex for thread safety.

◆ myChangeCallbacks

CallbackThreadMap makVre::DtAttribute::myChangeCallbacks
protected

List of change callbacks.

◆ TheCallbackThreadMapMutex

Mutex makVre::DtAttribute::TheCallbackThreadMapMutex
staticprotected

◆ TheCallbackThreadMap

std::unordered_map<unsigned int, bool> makVre::DtAttribute::TheCallbackThreadMap
staticprotected

◆ myStats

Stats makVre::DtAttribute::myStats
mutableprotected

Statistics for this attribute.

Referenced by stats().

◆ mySelf

Ref makVre::DtAttribute::mySelf
protected

Weak reference to self.

◆ mySelfInit

Ptr makVre::DtAttribute::mySelfInit
protected

Temporary shared pointer to self for initialization of mySelf.

◆ myParent

Ptr makVre::DtAttribute::myParent
protected

Shared pointer to parent.

◆ myAttributes

Map makVre::DtAttribute::myAttributes
mutableprotected

Map of child attributes.

◆ myItr

Map::iterator makVre::DtAttribute::myItr
protected

Iterator in parent's attribute map referring to this attribute.

◆ myWriteKey

unsigned int makVre::DtAttribute::myWriteKey
protected

Write permission key.

◆ TheQueuedTrace

std::pair<Ref, Trace> makVre::DtAttribute::TheQueuedTrace
staticprotected

The currently queued one-shot diagnostic trace, if any.

◆ TheLastTrace

std::pair<Ref, std::string> makVre::DtAttribute::TheLastTrace
staticprotected

The most recent trace that was fired, stored for debugging purposes.

◆ TheTraceMutex

Mutex makVre::DtAttribute::TheTraceMutex
staticprotected

Mutex guard for trace queue.

◆ TheTraceQueuedFlag

std::atomic<bool> makVre::DtAttribute::TheTraceQueuedFlag
staticprotected

Atmoic flag to avoid unnecessary mutex locks when no trace queued.

◆ myHandleCount

std::atomic<unsigned int> makVre::DtAttribute::myHandleCount = 0
protected

Count of active attribute handles to this attribute.

◆ TheTidyMutex

Mutex makVre::DtAttribute::TheTidyMutex
staticprotected

Mutex protecting the static tidy list and related operations.

◆ TheAttributesNeedTidying

std::map<void*, Ref> makVre::DtAttribute::TheAttributesNeedTidying
staticprotected

List of attributes that need tidying up due to expired child entries.


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