VR-Engage  2.3
Loading...
Searching...
No Matches
attribute.h
Go to the documentation of this file.
1/******************************************************************************
2 ** Copyright (c) 2026 MAK Technologies
3 ** All rights reserved.
4 ******************************************************************************/
5
6#pragma once
7
8//! \file attribute.h
9//! \brief Provides attribute handling system for hierarchical data storage and manipulation
10
11#include "vreUtil/export.h"
12#include "vreUtil/logger.h"
16
17#include <list>
18#include <map>
19#include <unordered_map>
20#include <chrono>
21
22#include <tbb/spin_rw_mutex.h>
23
24namespace makVre
25{
26
27//! \brief Core attribute class for shared data storage
28//!
29//! The DtAttribute class provides a flexible system for storing data to be shared
30//! between various app systems and components. It supports type-safe access and
31//! thread-safe change notifications. Attributes are organized in a heirarchical
32//! tree structure. Attribute are identified by names, which must be unique within
33//! each node.
35{
36public:
37 //! \brief Returns a reference to the root attribute
38 //!
39 //! \return A root attribute handle
41
42public:
43 //! \brief Virtual destructor
44 virtual ~DtAttribute();
45
46 //! \brief Returns the handle for this attribute
47 //!
48 //! \return A handle to this attribute
50
51 //! \brief Returns the const handle for this attribute
52 //!
53 //! \return A const handle to this attribute
55
56 //! \brief Conversion operator to DtAttributeHandle
58
59 //! \brief Conversion operator to const DtAttributeHandle
60 operator const DtAttributeHandle() const;
61
62 //! \brief Returns the name associated with this attribute
63 //!
64 //! \return The name of this attribute
65 virtual const std::string& name() const;
66
67 //! \brief Returns the full path of this attribute in the hierarchy
68 //!
69 //! \return The full path string in dot notation
70 virtual std::string path() const;
71
72 //! \brief Assigns an alias path for this attribute
73 //!
74 //! Aliases allows the same attribute to be accessed using alternate paths.
75 //!
76 //! Methods such as parent() and path() that reference the parent attribute will always
77 //! reflect the original parent.
78 //!
79 //! \param alias A handle to the attribute path that should be used as the alias path.
80 //!
81 //! The given handle must be assigned a path. The attribute at this handle must not be set,
82 //! it must not be readonly, it must have no other handles, and it cannot be Root().
83 //!
84 //! If the alias handle meets the criteria, the alias path will be created.
85 //!
86 //! \return true if the alias creation is successful, false otherwise
87 bool addAlias(DtAttributeHandle alias) const;
88
89 //! \brief Removes an alias path for this attribute
90 //!
91 //! \param alias A handle to the alias attribute path to be removed.
92 //!
93 //! The alias handle must be an alias currently assigned to this attribute.
94 //!
95 //! If the alias handle meets the criteria, the alias path will be removed.
96
97 //! \return true if the alias removal is successful, false otherwise
98 bool removeAlias(DtAttributeHandle alias) const;
99
100 //! \brief Returns the type of this attribute
101 //!
102 //! \return The type name as a string
103 //! \note Undefined attributes return DtAttributeData::UndefinedType()
104 const std::string& type() const;
105
106 //! \brief Checks if the attribute is of the specified type
107 //!
108 //! \return true if the attribute is of type T, false otherwise
109 //! \note Undefined values always return false
110 template <typename T>
111 bool isType() const;
112
113 //! \brief Checks if the attribute is of the specified type by name
114 //!
115 //! \param type The type name to check against
116 //! \return true if the attribute is of the specified type, false otherwise
117 //! \note Undefined values always return false
118 bool isType(const std::string& type) const;
119
120 //! \brief Checks if the attribute value is undefined
121 //!
122 //! \return true if the attribute has no defined value, false otherwise
123 bool isSet() const;
124
125 //! \brief Blocks execution on this thread until this attribute value is defined
126 //! \param timeout Seconds to wait; optional, default 3.0
127 //! \param silent If set true, no error is logged on timeout; optional, default false
128 //! \param assert If true, breaks with assert on failure, else just logs warning;
129 //! optional, default false
130 //! \return True if value is set before timeout, false if not
131 //!
132 //! Execution will continue once a value is set, or timeout time elapses.
133 //! If wait times out, an error will be logged. This method returns
134 //! immediately if the value of this attribute is already set.
135 //!
136 //! Do not use this unless the value will be set by another thread.
137 //!
138 //! \note To avoid stalls, consider using getOr() or a change callback
139 //! instead of await().
140 bool await(bool silent = false, bool assert = false, double timeout = 3.0) const;
141
142 //! \brief Blocks execution on this thread until the condition is satisfied
143 //! \param condition Callable to test required condition to continue
144 //! \param timeout Seconds to wait; optional, default 3.0
145 //! \param silent If set true, no error is logged on timeout; optional, default false
146 //! \param assert If true, breaks with assert on failure, else just logs warning;
147 //! optional, default false
148 //! \return True if condition is met before timeout, false if not
149 //!
150 //! Execution will continue once condition returns true, or timeout time elapses.
151 //! If wait times out, an error will be logged.
152 //!
153 //! Condition is a callable that receives this attribute as an argument, and
154 //! must return true or false.
155 //!
156 //! Do not use this unless the condition can be met by action from another thread.
157 //!
158 //! \note This is a blocking call, use with caution.
159 bool await(std::function<bool (const DtAttributeHandle)> condition,
160 bool silent = false, bool assert = false, double timeout = 3.0) const;
161
162 //! \brief Gets the value of the attribute
163 //!
164 //! \return The value of the attribute of type T
165 //! \note Throws an assertion if the attribute is of a different type
166 //! \note Undefined attributes return a zero-initialized value of type T
167 template <typename T>
168 const T get() const;
169
170 //! \brief Gets the value of the attribute or a default value if undefined
171 //!
172 //! \note Using getOr with a zero-equivalent value, i.e. getOr(0/false/"" etc)
173 //! is unnecessary and redundant, since get<T>() returns a zero-initialized
174 //! value for undefined attributes. Use /ref get<T>() directly instead of
175 //! getOr() when the default value is the zero-initialized value for the type.
176 //!
177 //! \param orValue The default value to return if the attribute is undefined
178 //! \return The attribute value or the default value
179 template <typename T>
180 T getOr(T orValue) const;
181
182 //! \brief Sets the value of the attribute
183 //!
184 //! If the new value differs from existing, change callbacks will be invoked.
185 //!
186 //! \param value The new value to set
187 //! \return true if the new value differs from existing
188 template <typename T>
189 bool set(const T& value);
190
191 // template <typename T>
192 // bool set(T&& value);//TODO
193
194 //! \brief Sets the value of the attribute only if it is currently undefined
195 //!
196 //! \param defaultValue The default value to set if the attribute is undefined
197 //! \return true if the value was set, false if the attribute already had a value
198 template <typename T>
199 bool setIfNot(const T& defaultValue);
200
201 //! \brief Establish the type of the attribute if value attribute is not yet set
202 //!
203 //! Will zero-initialize the attribute value.
204 //!
205 //! \return True if the type was set successfully, false if the attribute is already
206 //! established with a different type.
207 template <typename T>
208 bool setType();
209
210 //! \brief Reads the value of the attribute using a callback.
211 //!
212 //! Alternative to get method that allows reading from large or complex data types
213 //! without the overhead of copying the data, or when it is necessary to maintain
214 //! a read lock on the attribute value for multi-step operations,
215 //! e.g. reading a raw pointer, null-checking, then dereferencing to invoke a method.
216 //!
217 //! \tparam RET_T Return type passed back from the read callback
218 //! \param readFunc Callback that receives a const reference to the typed value
219 //! \return Returns Returns the value of type RET_T returned by the callback
220 template <typename RET_T, typename T>
221 RET_T read(std::function<RET_T(const T& value)> readFunc) const;
222
223 //! \brief Modifies the attribute value in-place using a callback.
224 //!
225 //! Calls \p modifyFunc with a direct reference to the stored value. If the callback
226 //! returns true, change callbacks are triggered without performing a before/after copy
227 //! comparison, making this faster than \ref modify() when the caller can determine
228 //! whether the value actually changed.
229 //!
230 //! \tparam T The type of the attribute value.
231 //! \param modifyFunc Callback that receives a mutable reference to the value and returns
232 //! true if the value was changed, false if it was not.
233 //!
234 //! \note This method acquires a write mutex lock on the attribute before calling
235 //! modifyFunc. Do not call other methods on this attribute from within modifyFunc. Doing
236 //! so may cause a deadlock.
237 template <typename T>
238 void modifyFast(std::function<bool(T& value)> modifyFunc);
239
240 //! \brief Modifies the attribute value in-place using a callback, with change detection.
241 //!
242 //! Calls \p modifyFunc with a direct reference to the stored value, then compares the
243 //! before and after state to determine if the value changed. Change callbacks are
244 //! triggered only if the value actually changed.
245 //!
246 //! \tparam T The type of the attribute value.
247 //! \param modifyFunc Callback that receives a mutable reference to the value.
248 //! \return true if the value changed, false otherwise.
249 //!
250 //! \note This method acquires a write mutex lock on the attribute before calling
251 //! modifyFunc. Do not call other methods on this attribute from within modifyFunc. Doing
252 //! so may cause a deadlock.
253 template <typename T>
254 bool modify(std::function<void(T& value)> modifyFunc);
255
256 //! \brief Gets the value of a child attribute
257 //!
258 //! Calls /ref get<T>() on the child attribute identified by \p attribute.
259 //! This is a convenience method directly equivalent to [attribute]->get<T>()
260 //!
261 //! \note Undefined attributes return a zero-initialize value of type T,
262 //! so getAttribute<T>() is safe to call even if the attribute doesn't exist yet.
263 //! Use hasAttribute() to check for existence if needed.
264 //!
265 //! \param attribute The name of the child attribute
266 //! \return The value of the child attribute
267 template <typename T>
268 const T getAttribute(const std::string& attribute) const;
269
270 //! \brief Gets the value of a child attribute or a default value if undefined
271 //!
272 //! Calls /ref getOr<T>() on the child attribute identified by \p attribute.
273 //! This is a convenience method directly equivalent to [attribute]->getOr<T>(orValue)
274 //!
275 //! \note Using getAttributeOr with a zero-equivalent default value, i.e.
276 //! getAttributeOr<T>(0/false/"" etc) is unnecessary and redundant, since
277 //! getAttribute<T>() returns a zero-initialized value of type T for undefined attributes.
278 //! Use /ref getAttribute<T>() directly instead of getAttributeOr() when the default value
279 //! is the zero-initialized value for the type.
280 //!
281 //! \param attribute The name of the child attribute
282 //! \param orValue The default value to return if the attribute is undefined
283 //! \return The child attribute value or the default value
284 template <typename T>
285 T getAttributeOr(const std::string& attribute, T orValue) const;
286
287 //! \brief Sets the value of a child attribute
288 //!
289 //! If the new value differs from existing, change callbacks will be invoked.
290 //!
291 //! \param attribute The name of the child attribute
292 //! \param newValue The new value to set
293 //! \return true if the value changed
294 template <typename T>
295 bool setAttribute(const std::string& attribute, const T& newValue);
296
297 //! \brief Gets string representation of the attribute value
298 //!
299 //! \return String representation of the attribute value
300 std::string getAsString() const;
301
302 //! \brief Sets the attribute value from a string representation
303 //!
304 //! If the new value differs from existing, change callbacks will be invoked.
305 //!
306 //! \param newValue String representation of the new value
307 //! \return true if the value changed
308 bool setFromString(const std::string& newValue);
309
310 //! \brief Gets the previous value of the attribute before the last change
311 //!
312 //! \return The previous value of the attribute
313 //! \note Returns a zero-initialized value of type T if the attribute is undefined or has never been changed
314 template <typename T>
315 const T previousValue() const;
316
317 //! \brief Unsets the attribute value
318 //!
319 //! Value is returned to an undefined, typeless state
320 //!
321 //! \return true if the attribute was unset, false otherwise
322 bool unset() const;
323
324 //! \brief Unsets this attribute and all child attributes, recursively
325 //!
326 //! \return true if all attributes were unset successfully
328
329 //! \brief Set whether this attribute exists w/o handles assigned
330 //!
331 //! A persistent attribute will continue to exist in the attribute tree
332 //! for the lifetime of the application. A non-persistent attribute will
333 //! be deleted as soon as no handles are assigned to it. The default
334 //! condition for attributes is persistent.
335 //!
336 //! \note When an attribute is first created, it inherits the persistence
337 //! state of its parent.
338 //!
339 //! \param persistent Set true for persistent, false for non-persistent
340 void setPersistence(bool persistent);
341
342 //! \brief Sets the persistence of this attribute and all child attributes
343 //!
344 //! \ref setPersistence
345 //!
346 //! \param persistent Set true for persistent, false for non-persistent
347 void setPersistenceRecursive(bool persistent);
348
349 //! \brief Check the persistence state of this attribute
350 //!
351 //! \ref setPersistence
352 //!
353 //! \return true if attribute is persitent, false if not
354 bool isPersistent() const;
355
356 //! \brief Checks if a child attribute exists
357 //!
358 //! \note Note that every attribute lookup creaste and attribute at that path. Unless
359 //! the persistence state has been set false, that attribute will continue to exist,
360 //! even if it has no value set. This means that any code calling almost any method,
361 //! however innocuous, will create that atttribute; including by not limited to get
362 //! methods. This will cause all subsequent hasAttribute() calls to return true.
363 //! Use hasAttribute() with caution. In most cases, the check is not necessary at all,
364 //! since get and set are always safe to call even if the attribute does not yet exist.
365 //! In other cases, consider whether checking /ref isSet() would be more appropriate.
366 //!
367 //! \return true if the child attribute exists, false otherwise
368 bool hasAttribute(const std::string& name) const;
369
370 //! \brief Checks if the given attribute is a direct or indirect child of this attribute.
371 //!
372 //! Recursively searches the subtree rooted at this attribute to determine if \p attr
373 //! is a descendant.
374 //!
375 //! \param attr The attribute handle to search for.
376 //! \return true if \p attr is a descendant of this attribute, false otherwise.
377 bool contains(const DtAttributeHandle& attr) const;
378
379 //! \brief Checks if this attribute is a direct or indirect child of the given attribute.
380 //!
381 //! Walks up the parent chain from this attribute to determine if \p attr is an ancestor.
382 //!
383 //! \param attr The attribute handle to test as a potential ancestor.
384 //! \return true if this attribute is a descendant of \p attr, false otherwise.
385 bool containedBy(const DtAttributeHandle& attr) const;
386
387 //! \brief Gets a handle to a child attribute
388 //!
389 //! \param name The name of the child attribute. Name may be
390 //! a path to child subattributes in format
391 //! "ChildName.GrandChild.GreatGrandChild"
392 //! \return A handle to the child attribute
393 DtAttributeHandle attribute(const std::string& name);
394
395 //! \brief Const version of \ref attribute(const std::string&)
396 const DtAttributeHandle attribute(const std::string& name) const;
397
398 //! \brief Gets a handle to the parent attribute
399 //!
400 //! \return A handle to the parent attribute
402
403 //! \brief Gets a const handle to the parent attribute
404 //!
405 //! \return A const handle to the parent attribute
407
408 //! \brief Gets a handle to the first child attribute
409 //!
410 //! \return A handle to the first child attribute
412
413 //! \brief Gets a const handle to the first child attribute
414 //!
415 //! \return A const handle to the first child attribute
417
418 //! \brief Calls the given function for each immediate child attribute.
419 //!
420 //! The child map is locked only per-entry so callbacks may safely access
421 //! other attributes without deadlocking.
422 //!
423 //! \param forEachFun Function to call with a handle to each child attribute.
424 void forEach(const std::function<void(DtAttributeHandle)>& forEachFun);
425
426 //! \brief Const version of \ref forEach(std::function<void(DtAttributeHandle)>)
427 void forEach(const std::function<void(const DtAttributeHandle)>& forEachFun) const;
428
429 //! \brief Checks if this attribute is the root attribute
430 //!
431 //! \return true if this is the root attribute, false otherwise
432 bool isRoot() const;
433
434 //! \brief Gets the raw data pointer
435 //!
436 //! \return The raw data pointer
437 const void* raw() const;
438
439 //! \brief Checks if the attribute is write-locked
440 //!
441 //! \return true if the attribute is readOnly, false if value change is allowed
442 bool isLocked() const;
443
444 //! \brief Create a temporary write-lock on this attribute
445 //!
446 //! Creates a write-blocking mutex lock that will block any other thread attempting to change
447 //! the value. Use sparingly when necessary to assure value does not change in critical use
448 //! section, e.g. when checking and then dereferencing a raw pointer value. Use with caution,
449 //! overuse will harm app performance.
450 //!
451 //! \note Do not attempt to set the attribute value while holding this lock!
452 //MutexLock lockMutex() const;
453
454 //! \brief Adds a change callback for this attribute
455 //!
456 //! \param callback The callback to add
458
459 //! \brief Removes a change callback from this attribute
460 //!
461 //! \param callback The callback to remove
463
465
467
468 static void callbackDispatchTick();
469
470 //! \brief Gets the number of handles currently assigned to this attribute
471 unsigned int handleCount() const;
472
473 //! \brief Recursively dumps the attribute hierarchy to a table
474 //!
475 //! \param depth The current depth in the hierarchy
476 //! \return A table representation of the attribute hierarchy
477 using DumpItem = std::pair<DtAttributeHandle, std::list<std::string>>;
478 using DumpTable = std::list<DumpItem>;
479 static void recursiveDumpToTable(const DtAttributeHandle attrToDump, DumpTable& output, int depth = 0);
480
481 static void quickDump(const DtAttributeHandle, bool includeValues = false, int depth = 0);
482
483 //! \brief Statistics structure for tracking attribute usage
484 struct Stats
485 {
486 //! \brief Constructor initializing all counters to zero
488 : myLookups(0)
489 , myCreates(0)
490 , mySets(0)
491 , myChanges(0)
492 , myGets(0)
493 , myGetsUndefined(0)
494 {
495 }
496
497 //! \brief Time when the attribute was created
498 std::chrono::time_point<std::chrono::high_resolution_clock> myCreateTime;
499
500 //! \brief Number of attribute lookups
501 std::atomic<unsigned int> myLookups;
502
503 //! \brief Number of attribute creations
504 std::atomic<unsigned int> myCreates;
505
506 //! \brief Number of attribute value sets
507 std::atomic<unsigned int> mySets;
508
509 //! \brief Number of attribute value changes
510 std::atomic<unsigned int> myChanges;
511
512 //! \brief Number of attribute value gets
513 std::atomic<unsigned int> myGets;
514
515 //! \brief Number of attribute value gets when undefined
516 std::atomic<unsigned int> myGetsUndefined;
517 };
518
519 //! \brief Gets the attribute statistics
520 //!
521 //! \return The attribute statistics
522 const Stats& stats() const { return myStats; }
523
524 //! \brief Trace level for diagnostic attribute access logging.
525 //!
526 //! When a trace is queued via \ref QueueTrace(), the attribute system will trigger
527 //! a debug break the next time the specified access type occurs on the target attribute.
528 enum Trace
529 {
530 OFF, //!< Tracing disabled.
531 SET, //!< Trace on the next value set.
532 CHANGE, //!< Trace on the next value change.
533 GET, //!< Trace on the next value get.
534 LOOKUP //!< Trace on the next attribute lookup.
535 };
536
537 //! \brief Queues a one-shot diagnostic trace for the specified attribute and access type.
538 //!
539 //! The trace fires the next time the given access type occurs on \p attribute, then the
540 //! queue is cleared. Only one trace can be queued at a time.
541 //!
542 //! \param attribute The attribute to trace.
543 //! \param trace The access type that should trigger the trace.
545
546 //! \brief Returns the currently queued trace entry.
547 //!
548 //! \return A pair containing the target attribute handle and the trace type. If no trace
549 //! is queued, the handle is unassigned and the type is \ref Trace::OFF.
550 static std::pair<DtAttributeHandle, Trace> QueuedTrace();
551
552 //! \brief Cancels any currently queued diagnostic trace.
553 static void CancelQueuedTrace();
554
555 //! \brief Perform any necessary cleanup of expired attribute entries in the attribute tree.
556 static void TidyUp();
557
558protected:
559 friend class DtAttributeHandle;
560
561 //! \brief Shared pointer type for attributes
562 using Ptr = std::shared_ptr<DtAttribute>;
563
564 //! \brief Weak pointer type for attributes
565 using Ref = std::weak_ptr<DtAttribute>;
566
567 //! \brief Map type for storing child attributes
568 using Map = std::map<std::string, std::pair<Ptr, Ref>>;
569
570 //! \brief Shared pointer type for attribute data storage
571 using DataPtr = std::shared_ptr<DtAttributeData>;
572
573 //! \brief Ordered list of raw callback pointers for a single thread
574 using CallbackList = std::list<const DtAttributeCallbackBase*>;
575
576 //! \brief Mutex type used for thread-safe attribute access
577 using Mutex = tbb::spin_rw_mutex;
578 using MutexLock = tbb::spin_rw_mutex::scoped_lock;
579
580 //! \brief Callback state scoped to a single thread.
581 //!
582 //! Tracks whether the attribute value changed since the last dispatch and
583 //! holds the list of registered callbacks for the owning thread.
585 {
586 //! \brief True if the attribute value has changed and callbacks have not yet been dispatched.
587 bool valueChanged = false;
588
589 //! \brief Callbacks registered for this thread.
591
592 //! \brief True if the attribute has expired entries in the CallbackList that should be cleaned up.
593 bool hasExpired = false;
594 };
595
596 //! \brief Map of per-thread callback state, keyed by thread ID.
597 using CallbackThreadMap = std::map<unsigned int, CallbacksForThread>;
598
599 //! \brief Factory method that creates and registers a named child attribute.
600 //!
601 //! \param name The name of the new attribute.
602 //! \param parent Shared pointer to the parent attribute.
603 //! \return Shared pointer to the newly created attribute.
604 static Ptr create(const std::string& name, const Ptr& parent);
605
606 //! \brief Default constructor
608
609 //! \brief Constructor with name and parent
610 //!
611 //! \param name The name of the attribute
612 //! \param parent The parent attribute
613 DtAttribute(const std::string& name, const Ptr& parent);
614
615 //! \brief Gets a shared pointer to this attribute
616 //!
617 //! \return A shared pointer to this attribute
618 const Ptr self() const;
619
620 //! \brief Non-const version of \ref self()
622
623 //! \brief Locks write access to attribute value
624 //!
625 //! \param key Chosen key that will be required to unlock
626 //! \return true on success, false if already locked
627 //! \note Attempts to set value while locked will fail and produce warning in log
628 bool lock(unsigned int key);
629
630 //! \brief Unlocks write access
631 //!
632 //! \param key Must be the same key used to lock
633 //! \return true on success, false if the key was incorrect or attribute not locked
634 bool unlock(unsigned int key);
635
636 //! \brief Get the first child attribute, excluding aliases
637 //!
638 //! \return Shared pointer to the first child attribute, or null if no children exist.
639 const Ptr pFirst() const;
640
641 //! \brief Non-const version of \ref pFirst()
643
644 //! \brief Gets a shared pointer to the next sibling attribute after the current child, excluding aliases
645 //!
646 //! \param current Shared pointer to the current child attribute
647 //! \return Shared pointer to the next sibling attribute, or null if no more siblings exist
648 const Ptr pNext(const Ptr& current) const;
649
650 //! \brief Non-const version of \ref pNext(const Ptr&)
651 Ptr pNext(const Ptr& current);
652
653 //! \brief Generate a handle to the child attribute, with alias support
654 //!
655 //! Checks the parent of child, returns an alias handle if the parent is not this attribute.
656 //!
657 //! \param child Shared pointer to the child attribute
658 //! \param it Iterator to the map entry corresponding to the child attribute
659 //! \return Handle to the child attribute, or an unassigned handle if not found
660 DtAttributeHandle handleFor(const Ptr& child, const Map::const_iterator& ) const;
661
662 //! \brief Get the next valid child entry
663 //!
664 //! Safety wrapper checks for expired entires.
665 //!
666 //! \param fromIt Iterator to start searching from
667 //! \return Shared pointer to the next valid child attribute, or null if no more valid children exist
668 Ptr _nextValid(Map::iterator& fromIt) const;
669
670 //! \brief Gets a handle to the next child attribute after the reference child
671 //!
672 //! \param ref Handle to a reference child to start from
673 //! \return The next child after the reference attribute, or an unassigned handle if the reference
674 //! attribute was the last child, or if the reference attribute is not a child of this attribute.
676
677 //! \brief Const version of \ref nextAfter(const DtAttributeHandle&)
679
680 //! \brief Calls the given function for each immediate child, excluding aliases.
681 //!
682 //! Lower-overhead internal forEach using shared pointers instead of handles. Skips aliases.
683 //!
684 //! \param forEachFun Function to call for each child.
685 void forEach(const std::function<void(Ptr)>& forEachFun);
686
687 //! \brief Const version of \ref forEach(std::function<void(Ptr)>)
688 void forEach(const std::function<void(const Ptr)>& forEachFun) const;
689
690 //! \brief Recursive search for child attribute at path, relative to this
691 //!
692 //! Recursive child names in path are delimited by '.', e.g. find("childName.grandChildName.greatGrandChildName")
693 //!
694 //! \param path Name or path of names of child attribute to find
695 //! \param orCreate If true, creates the attribute (and any intermediate path attributes) if not found; if false,
696 //! returns null pointer when not found
697 //! \param[out] foundAs Optional output for the alias name when the final path component resolves through
698 //! an alias; unchanged otherwise.
699 //! \param[out] foundIn Optional output for the attribute containing the final alias entry; unchanged otherwise.
700 //!
701 //! \return Shared pointer to the found or created attribute, or null if not found and orCreate is false
702 Ptr find(const std::string& path, bool orCreate = false, std::string* foundAs = nullptr, Ptr* foundIn = nullptr);
703
704 //! \brief Const overload of find().
705 //! \param path Name or path of names of child attribute to find.
706 //! \param orCreate If true, creates missing attributes along the path; if false, returns null when not found.
707 //! \param[out] foundAs Optional output for the alias name when the final path component resolves through
708 //! an alias; unchanged otherwise.
709 //! \param[out] foundIn Optional output for the attribute containing the final alias entry; unchanged otherwise.
710 //! \return Shared pointer to the found or created attribute, or null if not found and orCreate is false.
711 const Ptr find(const std::string& path, bool orCreate = false, std::string* foundAs = nullptr, Ptr* foundIn = nullptr) const;
712
713 //! \brief Creates and registers a new child attribute with the given name.
714 //!
715 //! If an attribute with the same name already exists, the existing attribute is returned.
716 //! Thread-safe.
717 //!
718 //! \param name The name of the child attribute to create.
719 //! \param[out] aliasExists Set to true if an existing entry is an alias, or false if it is not.
720 //! Unchanged when a new attribute is created; initialize to false before calling.
721 //! \return Shared pointer to the created or existing child attribute.
722 Ptr addAttribute(const std::string& name, bool& aliasExists);
723
724 //! \brief Const overload of addAttribute().
725 //! \param name The name of the child attribute to create.
726 //! \param[out] aliasExists Set to true if an existing entry is an alias, or false if it is not.
727 //! Unchanged when a new attribute is created; initialize to false before calling.
728 //! \return Shared pointer to the created or existing child attribute.
729 const Ptr addAttribute(const std::string& name, bool& aliasExists) const;
730
731 //! \brief Internal implementation of type()
732 //!
733 //! \return The type name as a string
734 //! \note Not thread safe
735 const std::string& _type() const;
736
737 //! \brief Internal implementation of isType()
738 //!
739 //! \return true if the attribute is of type T, false otherwise
740 //! \note Not thread safe
741 template <typename T>
742 bool _isType() const;
743
744 //! \brief Throws an assertion if the attribute is not of type T
745 //! \note No mutex guard
746 template <typename T>
747 void _assertType() const;
748
749 //! \brief Internal implementation of isType()
750 //!
751 //! \param type The type name to check against
752 //! \return true if the attribute is of the specified type, false otherwise
753 //! \note Not thread safe
754 bool _isType(const std::string& type) const;
755
756 //! \brief Internal implementation of isSet()
757 //!
758 //! \return true if the attribute has no defined value, false otherwise
759 //! \note Not thread safe
760 bool _isSet() const;
761
762 //! \brief Internal implementation of isLocked()
763 //!
764 //! \return true if the attribute is locked, false otherwise
765 //! \note Not thread safe
766 bool _isLocked() const;
767
768 //! \brief Creates data storage for the specified type
769 //!
770 //! \note This is used to initialize the attribute data
771 template <typename T>
772 void _createData() const;
773
774 //! \brief Validates that the attribute data is of the specified type
775 template <typename T>
777
778 //! \brief Checks and dispatches pending change callbacks for this attribute and all descendants.
779 //!
780 //! Calls invokePendingCallbacks() on this attribute, then recursively on all children. Typically
781 //! called from multi-threaded tick functions to deliver deferred callback notifications on the
782 //! correct thread.
784
785 //! \brief Checks and dispatches pending change callbacks for the calling thread.
786 //!
787 //! If this attribute's value was changed since the last dispatch for the calling thread,
788 //! invokes all registered callbacks for that thread. Normally called by
789 //! \ref invokePendingCallbacksRecursive() or \ref valueChanged().
791
792 //! \brief Invokes all registered change callbacks
793 void invokeCallbacks(const Ptr& changed, const unsigned int threadId);
794
795 //! \brief Marks the value as changed and dispatches callbacks for the current thread.
796 //!
797 //! Updates the changed flag for all registered threads and immediately invokes
798 //! callbacks for the calling thread via \ref checkPendingCallbacks().
800
801 //! \brief Gets the list of thread IDs that are known or registered to invoke callbacks
802 static std::unordered_map<unsigned int, bool> callbackThreadIds();
803
804 //! \brief Gets the thread ID on which a callback from the current thread may be invoked
805 //!
806 //! This will return the current thread ID if the current thread is registered to invoke
807 //! callbacks, else it will return the first registered callback thread, which should be
808 //! the main thread.
809 static unsigned int callbackThreadIdForThread(const unsigned int threadId);
810
811 //! \brief Record that the given thread is invoking callbacks
812 static void callbacksStartedOnThread(const unsigned int threadId);
813
814 //! \brief Record that the given thread is done invoking callbacks
815 static void callbacksFinishedOnThread(const unsigned int threadId);
816
817 //! \brief Returns whether the given thread is invoking callbacks
818 static bool callbacksRunningOnThread(const unsigned int threadId);
819
820 //! \brief Checks if the attribute is locked against the given caller key
821 //!
822 //! \param callerKey Key to test against the lock owner; a matching key bypasses the lock
823 //! \return true if locked and action should be prevented, false otherwise
824 bool _lockCheck(unsigned int callerKey = 0) const;
825
826 //! \brief Locks this attribute and all descendants recursively.
827 //!
828 //! Uses best-effort semantics: continues even if a child is already locked by a
829 //! different key, but returns false if any node could not be locked.
830 //!
831 //! \param callerKey The key to use for locking
832 //! \return true if all nodes were successfully locked, false otherwise
833 bool recursiveLock(unsigned int callerKey);
834
835 //! \brief Unlocks this attribute and all descendants whose lock key matches callerKey.
836 //!
837 //! Nodes locked by a different key are left untouched.
838 //!
839 //! \param callerKey The key used when locking
840 //! \return true if all nodes matching callerKey were successfully unlocked
841 bool recursiveUnlock(unsigned int callerKey);
842
843 //! \brief Triggers a diagnostic debug break and logs trace context for this attribute.
844 //!
845 //! Called internally when a queued trace condition is met. Outputs attribute path,
846 //! value, and stack information to the log.
847 void doTraceIf(Trace which) const;
848
849 //! \brief Increments the handle count for this attribute
851
852 //! \brief Decrements the handle count for this attribute
854
855 //! \brief Performs cleanup of expired child attribute entries in the map.
857
858 //! \brief Marks the attribute as needing tidying, adds to list to be cleaned up on the next call to TidyUp().
859 static void needsTidying(DtAttribute::Ptr dirty);
860
861protected:
862 //! \brief The name of this attribute
863 std::string myName;
864
865 //! \brief The data stored in this attribute
867
868 //! \brief Flag indicating if the type was explicitly set
869 mutable bool myExplicitType;
870
871 //! \brief Attribute data value mutex for thread safety
873
874 //! \brief Sub-attribute map mutex for thread safety
876
877 //! \brief Value change callback mutex for thread safety
879
880 //! \brief List of change callbacks
882
884
885 static std::unordered_map<unsigned int, bool> TheCallbackThreadMap;
886
887 //! \brief Statistics for this attribute
888 mutable Stats myStats;
889
890 //! \brief Weak reference to self
892
893 //! \brief Temporary shared pointer to self for initialization of mySelf
895
896 //! \brief Shared pointer to parent
898
899 //! \brief Map of child attributes
901
902 //! \brief Iterator in parent's attribute map referring to this attribute
903 Map::iterator myItr;
904
905 //! \brief Write permission key
906 unsigned int myWriteKey;
907
908 //! \brief The currently queued one-shot diagnostic trace, if any.
909 static std::pair<Ref, Trace> TheQueuedTrace;
910
911 //! \brief The most recent trace that was fired, stored for debugging purposes.
912 static std::pair<Ref, std::string> TheLastTrace;
913
914 //! \brief Mutex guard for trace queue
916
917 //! \brief Atmoic flag to avoid unnecessary mutex locks when no trace queued
918 static std::atomic<bool> TheTraceQueuedFlag;
919
920 //! \brief Count of active attribute handles to this attribute
921 std::atomic<unsigned int> myHandleCount = 0;
922
923 //! \brief Mutex protecting the static tidy list and related operations
925
926 //! \brief List of attributes that need tidying up due to expired child entries
927 static std::map<void*, Ref> TheAttributesNeedTidying;
928};
929
930//! \brief Type-specific attribute class
931//!
932//! This template class extends DtAttribute to provide type-specific
933//! access to attribute values. It ensures type safety when getting
934//! or setting values.
935template <typename T>
937{
938public:
939 //! \brief Verifies that the attribute is of the correct type
940 //!
941 //! \return true if the attribute is of type T, false otherwise
942 bool verifyType() const;
943
944 //! \brief Gets the value of the attribute
945 //!
946 //! \return The value of the attribute
947 const T get() const;
948
949 //! \brief Gets the value of the attribute or a default value if undefined
950 //!
951 //! \note Using getOr with a zero-equivalent value, i.e. getOr(0/false/"" etc)
952 //! is unnecessary and redundant, since get() returns a zero-initialized
953 //! value for undefined attributes. Use /ref get() directly instead of
954 //! getOr() when the default value is the zero-initialized value for the type.
955 //!
956 //! \param orValue The default value to return if the attribute is undefined
957 //! \return The attribute value or the default value
958 T getOr(T orValue) const;
959
960 //! \brief Sets the value of the attribute
961 //!
962 //! \param value The new value to set
963 //! \return true if the value was successfully set, false otherwise
964 bool set(const T& value);
965
966 // bool set(T&& value);//TODO
967
968 //! \brief Sets the value of the attribute only if it is currently undefined
969 //!
970 //! \param value The value to set if the attribute is undefined
971 //! \return true if the value was set, false if the attribute already had a value
972 bool setIfNot(const T& value);
973
974 //! \brief Reads the value of the attribute using a callback.
975 //!
976 //! Alternative to get method that allows reading from large or complex data types
977 //! without the overhead of copying the data, or when it is necessary to maintain
978 //! a read lock on the attribute value for multi-step operations,
979 //! e.g. reading a raw pointer, null-checking, then dereferencing to invoke a method.
980 //!
981 //! \tparam RET_T Return type passed back from the read callback
982 //! \param readFunc Callback that receives a const reference to the typed value
983 //! \return Returns Returns the value of type RET_T returned by the callback
984 template <typename RET_T>
985 RET_T read(std::function<RET_T(const T& value)> readFunc) const;
986
987 //! \brief Modifies the attribute value in-place using a callback.
988 //!
989 //! Delegates to \ref DtAttribute::modifyFast(). See that function for full semantics.
990 //!
991 //! \param modifyFunc Callback that receives a mutable reference to the typed value and
992 //! returns true if the value was changed.
993 void modifyFast(std::function<bool(T& value)> modifyFunc);
994
995 //! \brief Modifies the attribute value in-place with change detection.
996 //!
997 //! Delegates to \ref DtAttribute::modify(). See that function for full semantics.
998 //!
999 //! \param modifyFunc Callback that receives a mutable reference to the typed value.
1000 //! \return true if the value changed, false otherwise.
1001 bool modify(std::function<void(T& value)> modifyFunc);
1002
1003 //! \brief Returns the previous value of this attribute before the last change.
1004 //!
1005 //! \return Const reference to the value held before the most recent \ref set() call.
1006 const T previousValue() const;
1007};
1008
1009} // namespace makVre
1010
1011#include "attribute_data.inl"
1012#include "attribute.inl"
1013#include "attributeHandle.inl"
1014#include "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.
Abstract base class for all attribute change callbacks.
Definition attributeCallback.h:34
Mutex myCallbackMutex
Value change callback mutex for thread safety.
Definition attribute.h:878
static std::unordered_map< unsigned int, bool > TheCallbackThreadMap
Definition attribute.h:885
bool removeAlias(DtAttributeHandle alias) const
Removes an alias path for this attribute.
Ptr mySelfInit
Temporary shared pointer to self for initialization of mySelf.
Definition attribute.h:894
bool _isType(const std::string &type) const
Internal implementation of isType()
static std::atomic< bool > TheTraceQueuedFlag
Atmoic flag to avoid unnecessary mutex locks when no trace queued.
Definition attribute.h:918
void modifyFast(std::function< bool(T &value)> modifyFunc)
Modifies the attribute value in-place using a callback.
unsigned int myWriteKey
Write permission key.
Definition attribute.h:906
const void * raw() const
Gets the raw data pointer.
DtAttributeHandle nextAfter(const DtAttributeHandle &ref)
Gets a handle to the next child attribute after the reference child.
bool containedBy(const DtAttributeHandle &attr) const
Checks if this attribute is a direct or indirect child of the given attribute.
static void callbackDispatchTick()
std::string myName
The name of this attribute.
Definition attribute.h:863
bool setType()
Establish the type of the attribute if value attribute is not yet set.
void cleanTheMap()
Performs cleanup of expired child attribute entries in the map.
std::string getAsString() const
Gets string representation of the attribute value.
DtAttributeHandle parent()
Gets a handle to the parent attribute.
const Ptr addAttribute(const std::string &name, bool &aliasExists) const
Const overload of addAttribute().
DtAttribute(const std::string &name, const Ptr &parent)
Constructor with name and parent.
bool isLocked() const
Checks if the attribute is write-locked.
void decHandleCount()
Decrements the handle count for this attribute.
DtAttributeHandle attribute(const std::string &name)
Gets a handle to a child attribute.
bool unset() const
Unsets the attribute value.
bool isRoot() const
Checks if this attribute is the root attribute.
Ptr find(const std::string &path, bool orCreate=false, std::string *foundAs=nullptr, Ptr *foundIn=nullptr)
Recursive search for child attribute at path, relative to this.
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.
bool _isSet() const
Internal implementation of isSet()
bool await(bool silent=false, bool assert=false, double timeout=3.0) const
Blocks execution on this thread until this attribute value is defined.
static void unregisterCallbackThread()
DtAttributeHandle handleFor(const Ptr &child, const Map::const_iterator &) const
Generate a handle to the child attribute, with alias support.
void doTraceIf(Trace which) const
Triggers a diagnostic debug break and logs trace context for this attribute.
Trace
Trace level for diagnostic attribute access logging.
Definition attribute.h:529
@ LOOKUP
Trace on the next attribute lookup.
Definition attribute.h:534
@ CHANGE
Trace on the next value change.
Definition attribute.h:532
@ OFF
Tracing disabled.
Definition attribute.h:530
@ GET
Trace on the next value get.
Definition attribute.h:533
@ SET
Trace on the next value set.
Definition attribute.h:531
Ptr pFirst()
Non-const version of pFirst()
bool myExplicitType
Flag indicating if the type was explicitly set.
Definition attribute.h:869
static bool callbacksRunningOnThread(const unsigned int threadId)
Returns whether the given thread is invoking callbacks.
const Stats & stats() const
Gets the attribute statistics.
Definition attribute.h:522
bool setIfNot(const T &defaultValue)
Sets the value of the attribute only if it is currently undefined.
std::weak_ptr< DtAttribute > Ref
Weak pointer type for attributes.
Definition attribute.h:565
static void TidyUp()
Perform any necessary cleanup of expired attribute entries in the attribute tree.
static void recursiveDumpToTable(const DtAttributeHandle attrToDump, DumpTable &output, int depth=0)
bool isType() const
Checks if the attribute is of the specified type.
static std::unordered_map< unsigned int, bool > callbackThreadIds()
Gets the list of thread IDs that are known or registered to invoke callbacks.
const std::string & _type() const
Internal implementation of type()
const DtAttributeHandle attribute(const std::string &name) const
Const version of attribute(const std::string&)
void _createData() const
Creates data storage for the specified type.
bool contains(const DtAttributeHandle &attr) const
Checks if the given attribute is a direct or indirect child of this attribute.
bool 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.
virtual const std::string & name() const
Returns the name associated with this attribute.
const DtAttributeHandle nextAfter(const DtAttributeHandle &ref) const
Const version of nextAfter(const DtAttributeHandle&)
const Ptr pFirst() const
Get the first child attribute, excluding aliases.
DtAttribute()
Default constructor.
Ptr _nextValid(Map::iterator &fromIt) const
Get the next valid child entry.
Map::iterator myItr
Iterator in parent's attribute map referring to this attribute.
Definition attribute.h:903
static Ptr create(const std::string &name, const Ptr &parent)
Factory method that creates and registers a named child attribute.
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:477
static void QueueTrace(DtAttributeHandle attribute, Trace trace)
Queues a one-shot diagnostic trace for the specified attribute and access type.
static Mutex TheTraceMutex
Mutex guard for trace queue.
Definition attribute.h:915
static void CancelQueuedTrace()
Cancels any currently queued diagnostic trace.
Mutex myMapMutex
Sub-attribute map mutex for thread safety.
Definition attribute.h:875
const T getAttribute(const std::string &attribute) const
Gets the value of a child attribute.
void _assertType() const
Throws an assertion if the attribute is not of type T.
virtual std::string path() const
Returns the full path of this attribute in the hierarchy.
unsigned int handleCount() const
Gets the number of handles currently assigned to this attribute.
static void needsTidying(DtAttribute::Ptr dirty)
Marks the attribute as needing tidying, adds to list to be cleaned up on the next call to TidyUp().
Ref mySelf
Weak reference to self.
Definition attribute.h:891
bool setAttribute(const std::string &attribute, const T &newValue)
Sets the value of a child attribute.
static Mutex TheTidyMutex
Mutex protecting the static tidy list and related operations.
Definition attribute.h:924
bool unlock(unsigned int key)
Unlocks write access.
void addCallback(const DtAttributeCallbackBase &callback)
Create a temporary write-lock on this attribute.
void forEach(const std::function< void(Ptr)> &forEachFun)
Calls the given function for each immediate child, excluding aliases.
static void callbacksFinishedOnThread(const unsigned int threadId)
Record that the given thread is done invoking callbacks.
void invokePendingCallbacksRecursive()
Checks and dispatches pending change callbacks for this attribute and all descendants.
void forEach(const std::function< void(const DtAttributeHandle)> &forEachFun) const
Const version of forEach(std::function<void(DtAttributeHandle)>)
CallbackThreadMap myChangeCallbacks
List of change callbacks.
Definition attribute.h:881
const Ptr find(const std::string &path, bool orCreate=false, std::string *foundAs=nullptr, Ptr *foundIn=nullptr) const
Const overload of find().
bool _isLocked() const
Internal implementation of isLocked()
DataPtr myData
The data stored in this attribute.
Definition attribute.h:866
bool modify(std::function< void(T &value)> modifyFunc)
Modifies the attribute value in-place using a callback, with change detection.
tbb::spin_rw_mutex Mutex
Mutex type used for thread-safe attribute access.
Definition attribute.h:577
Ptr addAttribute(const std::string &name, bool &aliasExists)
Creates and registers a new child attribute with the given name.
bool isSet() const
Checks if the attribute value is undefined.
std::map< unsigned int, CallbacksForThread > CallbackThreadMap
Map of per-thread callback state, keyed by thread ID.
Definition attribute.h:597
void valueChanged()
Marks the value as changed and dispatches callbacks for the current thread.
static void callbacksStartedOnThread(const unsigned int threadId)
Record that the given thread is invoking callbacks.
static std::pair< Ref, std::string > TheLastTrace
The most recent trace that was fired, stored for debugging purposes.
Definition attribute.h:912
std::map< std::string, std::pair< Ptr, Ref > > Map
Map type for storing child attributes.
Definition attribute.h:568
static void quickDump(const DtAttributeHandle, bool includeValues=false, int depth=0)
const T get() const
Gets the value of the attribute.
Ptr self()
Non-const version of self()
void forEach(const std::function< void(const Ptr)> &forEachFun) const
Const version of forEach(std::function<void(Ptr)>)
tbb::spin_rw_mutex::scoped_lock MutexLock
Definition attribute.h:578
Map myAttributes
Map of child attributes.
Definition attribute.h:900
bool _isType() const
Internal implementation of isType()
std::atomic< unsigned int > myHandleCount
Count of active attribute handles to this attribute.
Definition attribute.h:921
void forEach(const std::function< void(DtAttributeHandle)> &forEachFun)
Calls the given function for each immediate child attribute.
std::shared_ptr< DtAttribute > Ptr
Shared pointer type for attributes.
Definition attribute.h:562
static std::map< void *, Ref > TheAttributesNeedTidying
List of attributes that need tidying up due to expired child entries.
Definition attribute.h:927
bool unsetRecursive()
Unsets this attribute and all child attributes, recursively.
static unsigned int callbackThreadIdForThread(const unsigned int threadId)
Gets the thread ID on which a callback from the current thread may be invoked.
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.
bool recursiveLock(unsigned int callerKey)
Locks this attribute and all descendants recursively.
Stats myStats
Statistics for this attribute.
Definition attribute.h:888
std::shared_ptr< DtAttributeData > DataPtr
Shared pointer type for attribute data storage.
Definition attribute.h:571
const DtAttributeHandle handle() const
Returns the const handle for this attribute.
void validateData(MutexLock &lock) const
Validates that the attribute data is of the specified type.
const Ptr self() const
Gets a shared pointer to this attribute.
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.
static Mutex TheCallbackThreadMapMutex
Definition attribute.h:883
void invokeCallbacks(const Ptr &changed, const unsigned int threadId)
Invokes all registered change callbacks.
static DtAttributeHandle Root()
Returns a reference to the root attribute.
const Ptr pNext(const Ptr &current) const
Gets a shared pointer to the next sibling attribute after the current child, excluding aliases.
const T previousValue() const
Gets the previous value of the attribute before the last change.
static void registerCallbackThread()
friend class DtAttributeHandle
Definition attribute.h:559
std::list< DumpItem > DumpTable
Definition attribute.h:478
DtAttributeHandle handle()
Returns the handle for this attribute.
bool isPersistent() const
Check the persistence state of this attribute.
bool lock(unsigned int key)
Locks write access to attribute value.
virtual ~DtAttribute()
Virtual destructor.
static std::pair< Ref, Trace > TheQueuedTrace
The currently queued one-shot diagnostic trace, if any.
Definition attribute.h:909
RET_T read(std::function< RET_T(const T &value)> readFunc) const
Reads the value of the attribute using a callback.
void setPersistenceRecursive(bool persistent)
Sets the persistence of this attribute and all child attributes.
Ptr myParent
Shared pointer to parent.
Definition attribute.h:897
bool set(const T &value)
Sets the value of the attribute.
void invokePendingCallbacks()
Checks and dispatches pending change callbacks for the calling thread.
std::list< const DtAttributeCallbackBase * > CallbackList
Ordered list of raw callback pointers for a single thread.
Definition attribute.h:574
bool recursiveUnlock(unsigned int callerKey)
Unlocks this attribute and all descendants whose lock key matches callerKey.
void removeCallback(const DtAttributeCallbackBase &callback)
Removes a change callback from this attribute.
const std::string & type() const
Returns the type of this attribute.
Mutex myValueMutex
Attribute data value mutex for thread safety.
Definition attribute.h:872
static std::pair< DtAttributeHandle, Trace > QueuedTrace()
Returns the currently queued trace entry.
bool addAlias(DtAttributeHandle alias) const
Assigns an alias path for this attribute.
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.
Ptr pNext(const Ptr &current)
Non-const version of pNext(const Ptr&)
void incHandleCount()
Increments the handle count for this attribute.
bool _lockCheck(unsigned int callerKey=0) const
Checks if the attribute is locked against the given caller key.
Type-specific attribute class.
Definition attribute.h:937
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)
Modifies the attribute value in-place using a callback.
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.
RET_T read(std::function< RET_T(const T &value)> readFunc) const
Reads the value of the attribute using a callback.
T getOr(T orValue) const
Gets the value of the attribute or a default value if undefined.
const T previousValue() const
Returns the previous value of this attribute before the last change.
bool modify(std::function< void(T &value)> modifyFunc)
Modifies the attribute value in-place with change detection.
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.
!
Definition glsVreMessageUtil.h:50
Callback state scoped to a single thread.
Definition attribute.h:585
bool hasExpired
True if the attribute has expired entries in the CallbackList that should be cleaned up.
Definition attribute.h:593
bool valueChanged
True if the attribute value has changed and callbacks have not yet been dispatched.
Definition attribute.h:587
CallbackList callbacks
Callbacks registered for this thread.
Definition attribute.h:590
Statistics structure for tracking attribute usage.
Definition attribute.h:485
std::atomic< unsigned int > myGets
Number of attribute value gets.
Definition attribute.h:513
std::atomic< unsigned int > myGetsUndefined
Number of attribute value gets when undefined.
Definition attribute.h:516
std::atomic< unsigned int > myCreates
Number of attribute creations.
Definition attribute.h:504
Stats()
Constructor initializing all counters to zero.
Definition attribute.h:487
std::chrono::time_point< std::chrono::high_resolution_clock > myCreateTime
Time when the attribute was created.
Definition attribute.h:498
std::atomic< unsigned int > myChanges
Number of attribute value changes.
Definition attribute.h:510
std::atomic< unsigned int > mySets
Number of attribute value sets.
Definition attribute.h:507
std::atomic< unsigned int > myLookups
Number of attribute lookups.
Definition attribute.h:501