|
VR-Engage
2.2
|
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>
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 |
| const std::string & | type () const |
| template<typename T> | |
| bool | isType () const |
| bool | isType (const std::string &type) const |
| bool | isSet () 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> | |
| 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 () |
| bool | unset (const std::string &name) |
| 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 |
| DtAttributeHandle | next () |
| const DtAttributeHandle | next () const |
| DtAttributeHandle | next_looping () |
| const DtAttributeHandle | next_looping () const |
| void | forEach (std::function< void(DtAttributeHandle)> forEachFun) |
| void | forEach (std::function< void(const DtAttributeHandle)> forEachFun) const |
| bool | isRoot () const |
| const void * | raw () const |
| bool | lock (unsigned int key) |
| bool | unlock (unsigned int key) |
| bool | locked () const |
| void | addCallback (const DtAttributeCallbackBase &callback) |
| void | removeCallback (const DtAttributeCallbackBase &callback) |
| void | checkPendingCallbacksRecursive () |
| void | recursiveDumpToTable (DumpTable &output, int depth=0) const |
| const Stats & | stats () const |
Static Public Member Functions | |
| static DtAttributeHandle & | Root () |
| static void | QueueTrace (DtAttributeHandle attribute, Trace trace) |
| static std::pair< DtAttributeHandle, Trace > | QueuedTrace () |
| static void | CancelQueuedTrace () |
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 | Mutex = tbb::spin_mutex |
| using | CallbackList = std::list<const DtAttributeCallbackBase*> |
| using | CallbackThreadMap = std::map<unsigned int, CallbacksForThread> |
Protected Member Functions | |
| DtAttribute () | |
| DtAttribute (const std::string &name, Ptr parent) | |
| Ptr | self () const |
| void | forEach (std::function< void(Ptr)> forEachFun) |
| void | forEach (std::function< void(const Ptr)> forEachFun) const |
| Ptr | find (const std::string &path, bool orCreate=false) |
| const Ptr | find (const std::string &path, bool orCreate=false) const |
| Ptr | addAttribute (const std::string &name) |
| const Ptr | addAttribute (const std::string &name) const |
| template<typename T> | |
| void | createData () const |
| template<typename T> | |
| void | validateData () const |
| void | checkPendingCallbacks () |
| void | invokeCallbacks (const Ptr &changed, unsigned int threadId) |
| void | valueChanged () |
| bool | lockCheck () const |
| void | doTrace () const |
Static Protected Member Functions | |
| static Ptr | create (const std::string &name, Ptr parent) |
Protected Attributes | |
| std::string | myName |
| DataPtr | myData |
| bool | myExplicitType |
| Mutex | myMutex |
| CallbackThreadMap | myChangeCallbacks |
| Stats | myStats |
| Ref | mySelf |
| Ptr | myParent |
| Map | myAttributes |
| Map::iterator | myItr |
| unsigned int | myLock |
Static Protected Attributes | |
| static std::pair< Ref, Trace > | TheQueuedTrace |
| static std::pair< Ref, std::string > | TheLastTrace |
Friends | |
| class | DtAttributeHandle |
| using makVre::DtAttribute::DumpItem = std::pair<DtAttributeHandle, std::list<std::string>> |
Recursively dumps the attribute hierarchy to a table.
| depth | The current depth in the hierarchy |
| using makVre::DtAttribute::DumpTable = std::list<DumpItem> |
|
protected |
Shared pointer type for attributes.
|
protected |
Weak pointer type for attributes.
|
protected |
Map type for storing child attributes.
|
protected |
|
protected |
|
protected |
|
protected |
|
virtual |
Virtual destructor.
|
protected |
Default constructor.
|
protected |
|
static |
Returns a reference to the root attribute.
References DtAttributeHandle.
| DtAttributeHandle makVre::DtAttribute::handle | ( | ) |
Returns the handle for this attribute.
References DtAttributeHandle.
| const DtAttributeHandle makVre::DtAttribute::handle | ( | ) | const |
Returns the const handle for this attribute.
References DtAttributeHandle.
| makVre::DtAttribute::operator DtAttributeHandle | ( | ) |
Conversion operator to DtAttributeHandle.
References DtAttributeHandle.
| makVre::DtAttribute::operator const DtAttributeHandle | ( | ) | const |
Conversion operator to const DtAttributeHandle.
References DtAttributeHandle.
|
virtual |
Returns the name associated with this attribute.
Referenced by addAttribute(), addAttribute(), attribute(), attribute(), create(), DtAttribute(), hasAttribute(), and unset().
|
virtual |
| const std::string & makVre::DtAttribute::type | ( | ) | const |
| bool makVre::DtAttribute::isType | ( | ) | const |
Checks if the attribute is of the specified type.
| bool makVre::DtAttribute::isType | ( | const std::string & | type | ) | const |
Checks if the attribute is of the specified type by name.
| type | The type name to check against |
References type().
| bool makVre::DtAttribute::isSet | ( | ) | const |
Checks if the attribute value is undefined.
| const T & makVre::DtAttribute::get | ( | ) | const |
Gets the value of the attribute.
| T makVre::DtAttribute::getOr | ( | T | orValue | ) | const |
Gets the value of the attribute or a default value if undefined.
| orValue | The default value to return if the attribute is undefined |
| 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.
| value | The new value to set |
| bool makVre::DtAttribute::setIfNot | ( | const T & | defaultValue | ) |
Sets the value of the attribute only if it is currently undefined.
| defaultValue | The default value to set if the attribute is undefined |
| void makVre::DtAttribute::modifyFast | ( | std::function< bool(T &value)> | modifyFunc | ) |
| bool makVre::DtAttribute::modify | ( | std::function< void(T &value)> | modifyFunc | ) |
| const T & makVre::DtAttribute::getAttribute | ( | const std::string & | attribute | ) | const |
Gets the value of a child attribute.
| attribute | The name of the child attribute |
References attribute().
| T makVre::DtAttribute::getAttributeOr | ( | const std::string & | attribute, |
| T | orValue ) const |
Gets the value of a child attribute or a default value if undefined.
| attribute | The name of the child attribute |
| orValue | The default value to return if the attribute is undefined |
References attribute().
| 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.
| attribute | The name of the child attribute |
| newValue | The new value to set |
References attribute().
| std::string makVre::DtAttribute::getAsString | ( | ) | const |
Gets string representation of the attribute value.
| 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.
| newValue | String representation of the new value |
| const T & makVre::DtAttribute::previousValue | ( | ) | const |
Gets the previous value of the attribute before the last change.
| bool makVre::DtAttribute::unset | ( | ) |
Unsets the attribute value.
Value is returned to an undefined, typeless state
| bool makVre::DtAttribute::unset | ( | const std::string & | name | ) |
Unsets (clears) a child attribute value.
Value is returned to an undefined, typeless state
| name | The name of the child attribute to unset |
References name().
| bool makVre::DtAttribute::unsetRecursive | ( | ) |
Unsets this attribute and all child attributes, recursively.
| 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.
| persistent | Set true for persistent, false for non-persistent |
| void makVre::DtAttribute::setPersistenceRecursive | ( | bool | persistent | ) |
Sets the persistence of this attribute and all child attributes.
| persistent | Set true for persistent, false for non-persistent |
| bool makVre::DtAttribute::isPersistent | ( | ) | const |
Check the persistence state of this attribute.
| bool makVre::DtAttribute::hasAttribute | ( | const std::string & | name | ) | const |
Checks if a child attribute exists.
References name().
| bool makVre::DtAttribute::contains | ( | const DtAttributeHandle & | attr | ) | const |
References DtAttributeHandle.
| bool makVre::DtAttribute::containedBy | ( | const DtAttributeHandle & | attr | ) | const |
References DtAttributeHandle.
| DtAttributeHandle makVre::DtAttribute::attribute | ( | const std::string & | name | ) |
Gets a handle to a child attribute.
| name | The name of the child attribute. Name may be a path to child subattributes in format "ChildName.GrandChild.GreatGrandChild" |
References DtAttributeHandle, and name().
Referenced by getAttribute(), getAttributeOr(), QueueTrace(), and setAttribute().
| const DtAttributeHandle makVre::DtAttribute::attribute | ( | const std::string & | name | ) | const |
Const version of attribute(const std::string&)
References DtAttributeHandle, and name().
| DtAttributeHandle makVre::DtAttribute::parent | ( | ) |
Gets a handle to the parent attribute.
References DtAttributeHandle.
Referenced by create(), and DtAttribute().
| const DtAttributeHandle makVre::DtAttribute::parent | ( | ) | const |
Gets a const handle to the parent attribute.
References DtAttributeHandle.
| DtAttributeHandle makVre::DtAttribute::first | ( | ) |
Gets a handle to the first child attribute.
References DtAttributeHandle.
| const DtAttributeHandle makVre::DtAttribute::first | ( | ) | const |
Gets a const handle to the first child attribute.
References DtAttributeHandle.
| DtAttributeHandle makVre::DtAttribute::next | ( | ) |
Gets a handle to the next sibling attribute.
References DtAttributeHandle.
| const DtAttributeHandle makVre::DtAttribute::next | ( | ) | const |
Gets a const handle to the next sibling attribute.
References DtAttributeHandle.
| DtAttributeHandle makVre::DtAttribute::next_looping | ( | ) |
Gets a handle to the next sibling attribute, looping back to the first if at the end.
References DtAttributeHandle.
| const DtAttributeHandle makVre::DtAttribute::next_looping | ( | ) | const |
Gets a const handle to the next sibling attribute, looping back to the first if at the end.
References DtAttributeHandle.
| void makVre::DtAttribute::forEach | ( | std::function< void(DtAttributeHandle)> | forEachFun | ) |
References DtAttributeHandle.
| void makVre::DtAttribute::forEach | ( | std::function< void(const DtAttributeHandle)> | forEachFun | ) | const |
References DtAttributeHandle.
| bool makVre::DtAttribute::isRoot | ( | ) | const |
Checks if this attribute is the root attribute.
| const void * makVre::DtAttribute::raw | ( | ) | const |
Gets the raw data pointer.
| bool makVre::DtAttribute::lock | ( | unsigned int | key | ) |
Locks the attribute with a key.
| key | The key to use for locking |
| bool makVre::DtAttribute::unlock | ( | unsigned int | key | ) |
Unlocks the attribute with a key.
| key | The key used for locking |
| bool makVre::DtAttribute::locked | ( | ) | const |
Checks if the attribute is locked.
| void makVre::DtAttribute::addCallback | ( | const DtAttributeCallbackBase & | callback | ) |
Adds a change callback for this attribute.
| callback | The callback to add |
| void makVre::DtAttribute::removeCallback | ( | const DtAttributeCallbackBase & | callback | ) |
Removes a change callback from this attribute.
| callback | The callback to remove |
| void makVre::DtAttribute::checkPendingCallbacksRecursive | ( | ) |
| void makVre::DtAttribute::recursiveDumpToTable | ( | DumpTable & | output, |
| int | depth = 0 ) const |
|
inline |
|
static |
References attribute(), and DtAttributeHandle.
|
static |
|
static |
|
protected |
Gets a shared pointer to this attribute.
|
protected |
|
protected |
|
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")
| path | Name or path of names of child attribute to find |
| orCreate | If true, creates the attribute (and any intermediate path attributes) if not found; if false, returns null pointer when not found |
References path().
|
protected |
Const version of find(const std::string&, bool)
References path().
|
protected |
References name().
|
protected |
Creates data storage for the specified type.
|
protected |
Validates that the attribute data is of the specified type.
|
protected |
|
protected |
Invokes all registered change callbacks.
|
protected |
|
protected |
Checks if the attribute is locked.
|
protected |
|
friend |
References DtAttributeHandle.
Referenced by attribute(), attribute(), containedBy(), contains(), DtAttributeHandle, first(), first(), forEach(), forEach(), handle(), handle(), next(), next(), next_looping(), next_looping(), operator const DtAttributeHandle(), operator DtAttributeHandle(), parent(), parent(), QueueTrace(), and Root().
|
protected |
The name of this attribute.
|
mutableprotected |
The data stored in this attribute.
|
mutableprotected |
Flag indicating if the type was explicitly set.
|
protected |
List of change callbacks.
|
mutableprotected |
Statistics for this attribute.
Referenced by stats().
|
mutableprotected |
Weak reference to self.
|
protected |
Shared pointer to parent.
|
protected |
Iterator in parent's attribute map referring to this attribute.
|
protected |
Lock key.
|
staticprotected |