|
8 | 8 |
|
9 | 9 | #include "esp/core/Esp.h" |
10 | 10 | #include "esp/io/Json.h" |
| 11 | +#include "esp/metadata/attributes/AbstractAttributes.h" |
11 | 12 |
|
12 | 13 | namespace esp { |
13 | 14 | namespace metadata { |
@@ -55,6 +56,69 @@ enum class DSDiagnosticType : uint32_t { |
55 | 56 | AllDiagnosticsSaveCorrected = ~0U |
56 | 57 | }; |
57 | 58 |
|
| 59 | +/** |
| 60 | + * @brief Construct to record the results of a series of diagnostics against a |
| 61 | + * single attributes. |
| 62 | + */ |
| 63 | +template <class T> |
| 64 | +class DSDiagnosticRecord { |
| 65 | + public: |
| 66 | + static_assert( |
| 67 | + std::is_base_of<esp::metadata::attributes::AbstractAttributes, T>::value, |
| 68 | + "AbstractManagedPhysicsObject :: Managed physics object type must be " |
| 69 | + "derived from esp::physics::PhysicsObjectBase"); |
| 70 | + |
| 71 | + typedef std::weak_ptr<T> WeakObjRef; |
| 72 | + |
| 73 | + DSDiagnosticRecord(uint32_t diagnosticsFlags) |
| 74 | + : _diagnosticsFlags(diagnosticsFlags) {} |
| 75 | + |
| 76 | + /** |
| 77 | + * @brief set the reference to this diagnostic record's subject |
| 78 | + */ |
| 79 | + void setObjectRef(const std::shared_ptr<T>& objRef) { weakObjRef_ = objRef; } |
| 80 | + |
| 81 | + inline void setFlags(DSDiagnosticType _flag, bool _val) { |
| 82 | + if (_val) { |
| 83 | + _diagnosticsFlags |= static_cast<uint32_t>(_flag); |
| 84 | + } else { |
| 85 | + _diagnosticsFlags &= ~static_cast<uint32_t>(_flag); |
| 86 | + } |
| 87 | + } |
| 88 | + |
| 89 | + inline bool getFlags(DSDiagnosticType _flag) const { |
| 90 | + return (_diagnosticsFlags & static_cast<uint32_t>(_flag)) == |
| 91 | + static_cast<uint32_t>(_flag); |
| 92 | + } |
| 93 | + |
| 94 | + protected: |
| 95 | + /** |
| 96 | + * @brief This function accesses the underlying shared pointer of this |
| 97 | + * object's @p weakObjRef_ if it exists; if not, it provides a message. |
| 98 | + * @return Either a shared pointer of this record's object, or nullptr if |
| 99 | + * dne. |
| 100 | + */ |
| 101 | + std::shared_ptr<T> inline getObjectReference() const { |
| 102 | + std::shared_ptr<T> sp = weakObjRef_.lock(); |
| 103 | + if (!sp) { |
| 104 | + ESP_ERROR() |
| 105 | + << "This attributes no longer exists. Please delete any variable " |
| 106 | + "references."; |
| 107 | + } |
| 108 | + return sp; |
| 109 | + } // getObjectReference |
| 110 | + |
| 111 | + // Non-owning reference to attributes this record pertains to. |
| 112 | + WeakObjRef weakObjRef_; |
| 113 | + |
| 114 | + private: |
| 115 | + uint32_t _diagnosticsFlags = 0u; |
| 116 | + |
| 117 | + public: |
| 118 | + ESP_SMART_POINTERS(DSDiagnosticRecord) |
| 119 | + |
| 120 | +}; // struct DSDiagnosticRecord |
| 121 | + |
58 | 122 | /** |
59 | 123 | * @brief Constant map to provide mappings from string tags to @ref |
60 | 124 | * DSDiagnosticType values. This will be used to match values set |
@@ -85,7 +149,8 @@ class DatasetDiagnosticsTool { |
85 | 149 |
|
86 | 150 | /** |
87 | 151 | * @brief Merge the passed @ref DatasetDiagnosticsTool's @p _diagnosticsFlag |
88 | | - * settings into this one's, preserving this one's state. |
| 152 | + * settings into this one's, preserving this one's diagnostic requests as |
| 153 | + * well. |
89 | 154 | */ |
90 | 155 | void mergeDiagnosticsTool(const DatasetDiagnosticsTool& tool) { |
91 | 156 | _diagnosticsFlags |= tool._diagnosticsFlags; |
@@ -147,18 +212,19 @@ class DatasetDiagnosticsTool { |
147 | 212 | void setSaveRequired(bool saveRequired) { |
148 | 213 | _requiresCorrectedSave = saveRequired; |
149 | 214 | } |
| 215 | + |
| 216 | + /** |
| 217 | + * @brief Clear any flags set due to specific diagnostics |
| 218 | + */ |
| 219 | + void clearSaveRequired() { _requiresCorrectedSave = false; } |
| 220 | + |
150 | 221 | /** |
151 | 222 | * @brief Get whether a save is required. This is to bridge from reading the |
152 | 223 | * json file into the attributes and registering the attributes to the |
153 | 224 | * post-registration code. |
154 | 225 | */ |
155 | 226 | bool saveRequired() const { return _requiresCorrectedSave; } |
156 | 227 |
|
157 | | - /** |
158 | | - * @brief Clear any flags set due to specific diagnostics |
159 | | - */ |
160 | | - void clearDiagnostics() { _requiresCorrectedSave = false; } |
161 | | - |
162 | 228 | /** |
163 | 229 | * @brief Specify whether or not to test for duplicate scene object instances |
164 | 230 | * in loaded @ref SceneInstanceAttributes and not process the duplicates if found. |
|
0 commit comments