17#include <tbb/spin_mutex.h>
64 virtual const std::string&
name()
const;
69 virtual std::string
path()
const;
74 const std::string&
type()
const;
104 template <
typename T>
113 template <
typename T>
123 template <
typename T>
126 template <
typename T>
129 template <
typename T>
130 bool modify(std::function<
void(T& value)> modifyFunc);
136 template <
typename T>
144 template <
typename T>
154 template <
typename T>
173 template <
typename T>
327 using DumpItem = std::pair<DtAttributeHandle, std::list<std::string>>;
346 std::chrono::time_point<std::chrono::high_resolution_clock>
myCreateTime;
388 using Ptr = std::shared_ptr<DtAttribute>;
391 using Ref = std::weak_ptr<DtAttribute>;
394 using Map = std::map<std::string, std::pair<Ptr, Ref>>;
395 using DataPtr = std::shared_ptr<DtAttributeData>;
430 void forEach(std::function<
void(
const Ptr)> forEachFun)
const;
442 const Ptr find(
const std::string&
path,
bool orCreate =
false)
const;
450 template <
typename T>
454 template <
typename T>
550 bool modify(std::function<
void(T& value)> modifyFunc);
557#include "vreUtil/attribute_data.inl"
558#include "vreUtil/attribute.inl"
559#include "vreUtil/attributeHandle.inl"
560#include "vreUtil/attributeCallback.inl"
Defines data types for the attribute system in VREngage.
Provides a callback mechanism for attribute changes in the VREngage system.
Provides handle classes for safe access to attributes.
Definition attributeCallback.h:28
const T & get() const
Gets the value of the attribute.
void modifyFast(std::function< bool(T &value)> modifyFunc)
void invokeCallbacks(const Ptr &changed, unsigned int threadId)
Invokes all registered change callbacks.
const void * raw() const
Gets the raw data pointer.
bool containedBy(const DtAttributeHandle &attr) const
bool locked() const
Checks if the attribute is locked.
std::string myName
The name of this attribute.
Definition attribute.h:473
void forEach(std::function< void(const DtAttributeHandle)> forEachFun) const
std::string getAsString() const
Gets string representation of the attribute value.
DtAttributeHandle parent()
Gets a handle to the parent attribute.
DtAttributeHandle attribute(const std::string &name)
Gets a handle to a child attribute.
bool isRoot() const
Checks if this attribute is the root attribute.
const DtAttributeHandle first() const
Gets a const handle to the first child attribute.
bool setFromString(const std::string &newValue)
Sets the attribute value from a string representation.
static Ptr create(const std::string &name, Ptr parent)
Trace
Definition attribute.h:373
@ LOOKUP
Definition attribute.h:378
@ CHANGE
Definition attribute.h:376
@ OFF
Definition attribute.h:374
@ GET
Definition attribute.h:377
@ SET
Definition attribute.h:375
bool myExplicitType
Flag indicating if the type was explicitly set.
Definition attribute.h:479
const Stats & stats() const
Gets the attribute statistics.
Definition attribute.h:370
bool setIfNot(const T &defaultValue)
Sets the value of the attribute only if it is currently undefined.
DtAttributeHandle next()
Gets a handle to the next sibling attribute.
std::weak_ptr< DtAttribute > Ref
Weak pointer type for attributes.
Definition attribute.h:391
bool isType() const
Checks if the attribute is of the specified type.
const DtAttributeHandle attribute(const std::string &name) const
Const version of attribute(const std::string&)
bool contains(const DtAttributeHandle &attr) const
const DtAttributeHandle next_looping() const
Gets a const handle to the next sibling attribute, looping back to the first if at the end.
virtual const std::string & name() const
Returns the name associated with this attribute.
Ptr find(const std::string &path, bool orCreate=false)
Recursive search for child attribute at path, relative to this.
bool unset(const std::string &name)
Unsets (clears) a child attribute value.
DtAttribute()
Default constructor.
Ptr addAttribute(const std::string &name)
Map::iterator myItr
Iterator in parent's attribute map referring to this attribute.
Definition attribute.h:500
T getAttributeOr(const std::string &attribute, T orValue) const
Gets the value of a child attribute or a default value if undefined.
std::pair< DtAttributeHandle, std::list< std::string > > DumpItem
Recursively dumps the attribute hierarchy to a table.
Definition attribute.h:327
Ptr self() const
Gets a shared pointer to this attribute.
static void QueueTrace(DtAttributeHandle attribute, Trace trace)
static void CancelQueuedTrace()
void forEach(std::function< void(Ptr)> forEachFun)
virtual std::string path() const
Returns the full path of this attribute in the hierarchy.
Ref mySelf
Weak reference to self.
Definition attribute.h:491
bool setAttribute(const std::string &attribute, const T &newValue)
Sets the value of a child attribute.
const T & previousValue() const
Gets the previous value of the attribute before the last change.
bool unlock(unsigned int key)
Unlocks the attribute with a key.
void addCallback(const DtAttributeCallbackBase &callback)
Adds a change callback for this attribute.
Mutex myMutex
Mutex for thread synchronization.
Definition attribute.h:482
DtAttribute(const std::string &name, Ptr parent)
Constructor with name and parent.
tbb::spin_mutex Mutex
Definition attribute.h:396
CallbackThreadMap myChangeCallbacks
List of change callbacks.
Definition attribute.h:485
bool unset()
Unsets the attribute value.
DataPtr myData
The data stored in this attribute.
Definition attribute.h:476
bool modify(std::function< void(T &value)> modifyFunc)
bool lockCheck() const
Checks if the attribute is locked.
bool isSet() const
Checks if the attribute value is undefined.
std::map< unsigned int, CallbacksForThread > CallbackThreadMap
Definition attribute.h:409
static std::pair< Ref, std::string > TheLastTrace
Definition attribute.h:506
void checkPendingCallbacksRecursive()
std::map< std::string, std::pair< Ptr, Ref > > Map
Map type for storing child attributes.
Definition attribute.h:394
const Ptr find(const std::string &path, bool orCreate=false) const
Const version of find(const std::string&, bool)
Map myAttributes
Map of child attributes.
Definition attribute.h:497
std::shared_ptr< DtAttribute > Ptr
Shared pointer type for attributes.
Definition attribute.h:388
void createData() const
Creates data storage for the specified type.
bool unsetRecursive()
Unsets this attribute and all child attributes, recursively.
void validateData() const
Validates that the attribute data is of the specified type.
bool isType(const std::string &type) const
Checks if the attribute is of the specified type by name.
DtAttributeHandle first()
Gets a handle to the first child attribute.
Stats myStats
Statistics for this attribute.
Definition attribute.h:488
std::shared_ptr< DtAttributeData > DataPtr
Definition attribute.h:395
const DtAttributeHandle handle() const
Returns the const handle for this attribute.
void recursiveDumpToTable(DumpTable &output, int depth=0) const
bool hasAttribute(const std::string &name) const
Checks if a child attribute exists.
void setPersistence(bool persistent)
Set whether this attribute exists w/o handles assigned.
void forEach(std::function< void(const Ptr)> forEachFun) const
const T & getAttribute(const std::string &attribute) const
Gets the value of a child attribute.
friend class DtAttributeHandle
Definition attribute.h:385
const DtAttributeHandle next() const
Gets a const handle to the next sibling attribute.
std::list< DumpItem > DumpTable
Definition attribute.h:328
static DtAttributeHandle & Root()
Returns a reference to the root attribute.
DtAttributeHandle handle()
Returns the handle for this attribute.
bool isPersistent() const
Check the persistence state of this attribute.
bool lock(unsigned int key)
Locks the attribute with a key.
DtAttributeHandle next_looping()
Gets a handle to the next sibling attribute, looping back to the first if at the end.
virtual ~DtAttribute()
Virtual destructor.
static std::pair< Ref, Trace > TheQueuedTrace
Definition attribute.h:505
void setPersistenceRecursive(bool persistent)
Sets the persistence of this attribute and all child attributes.
void forEach(std::function< void(DtAttributeHandle)> forEachFun)
Ptr myParent
Shared pointer to parent.
Definition attribute.h:494
bool set(const T &value)
Sets the value of the attribute.
std::list< const DtAttributeCallbackBase * > CallbackList
Definition attribute.h:398
void removeCallback(const DtAttributeCallbackBase &callback)
Removes a change callback from this attribute.
unsigned int myLock
Lock key.
Definition attribute.h:503
const std::string & type() const
Returns the type of this attribute.
static std::pair< DtAttributeHandle, Trace > QueuedTrace()
T getOr(T orValue) const
Gets the value of the attribute or a default value if undefined.
const DtAttributeHandle parent() const
Gets a const handle to the parent attribute.
const Ptr addAttribute(const std::string &name) const
void checkPendingCallbacks()
Type-specific attribute class.
Definition attribute.h:516
bool verifyType() const
Verifies that the attribute is of the correct type.
bool set(const T &value)
Sets the value of the attribute.
void modifyFast(std::function< bool(T &value)> modifyFunc)
bool setIfNot(const T &value)
Sets the value of the attribute only if it is currently undefined.
const T & get() const
Gets the value of the attribute.
T getOr(T orValue) const
Gets the value of the attribute or a default value if undefined.
const T & previousValue() const
bool modify(std::function< void(T &value)> modifyFunc)
Defines export macros for the VREngage Utility library.
#define UTIL_DLL
Export/import macro for non-Windows platforms.
Definition export.h:39
Provides logging functionality with various severity levels and channels.
Include export definitions for this library.
Definition glsVreMessageUtil.h:49
CallbacksForThread()
Definition attribute.h:401
bool valueChanged
Definition attribute.h:406
CallbackList callbacks
Definition attribute.h:407
Statistics structure for tracking attribute usage.
Definition attribute.h:333
unsigned int myCreates
Number of attribute creations.
Definition attribute.h:352
unsigned int myGetsUndefined
Number of attribute value gets when undefined.
Definition attribute.h:364
unsigned int myGets
Number of attribute value gets.
Definition attribute.h:361
unsigned int mySets
Number of attribute value sets.
Definition attribute.h:355
Stats()
Constructor initializing all counters to zero.
Definition attribute.h:335
std::chrono::time_point< std::chrono::high_resolution_clock > myCreateTime
Time when the attribute was created.
Definition attribute.h:346
unsigned int myLookups
Number of attribute lookups.
Definition attribute.h:349
unsigned int myChanges
Number of attribute value changes.
Definition attribute.h:358