Skip to content

Commit df31bc2

Browse files
committed
--add diagnostic record, w/weak ref to target attributes.
1 parent 3f40726 commit df31bc2

File tree

2 files changed

+73
-7
lines changed

2 files changed

+73
-7
lines changed

src/esp/metadata/managers/AbstractAttributesManager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ class AbstractAttributesManager : public ManagedFileBasedContainer<T, Access> {
191191
void setValsFromJSONDoc(AttribsPtr attribs,
192192
const io::JsonGenericValue& jsonConfig) {
193193
// Clear diagnostic flags from previous run
194-
this->_DSDiagnostics->clearDiagnostics();
194+
this->_DSDiagnostics->clearSaveRequired();
195195
this->setValsFromJSONDocInternal(attribs, jsonConfig);
196196
if (this->_DSDiagnostics->saveRequired()) {
197197
ESP_WARNING(Mn::Debug::Flag::NoSpace)

src/esp/metadata/managers/DatasetDiagnosticsTool.h

Lines changed: 72 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include "esp/core/Esp.h"
1010
#include "esp/io/Json.h"
11+
#include "esp/metadata/attributes/AbstractAttributes.h"
1112

1213
namespace esp {
1314
namespace metadata {
@@ -55,6 +56,69 @@ enum class DSDiagnosticType : uint32_t {
5556
AllDiagnosticsSaveCorrected = ~0U
5657
};
5758

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+
58122
/**
59123
* @brief Constant map to provide mappings from string tags to @ref
60124
* DSDiagnosticType values. This will be used to match values set
@@ -85,7 +149,8 @@ class DatasetDiagnosticsTool {
85149

86150
/**
87151
* @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.
89154
*/
90155
void mergeDiagnosticsTool(const DatasetDiagnosticsTool& tool) {
91156
_diagnosticsFlags |= tool._diagnosticsFlags;
@@ -147,18 +212,19 @@ class DatasetDiagnosticsTool {
147212
void setSaveRequired(bool saveRequired) {
148213
_requiresCorrectedSave = saveRequired;
149214
}
215+
216+
/**
217+
* @brief Clear any flags set due to specific diagnostics
218+
*/
219+
void clearSaveRequired() { _requiresCorrectedSave = false; }
220+
150221
/**
151222
* @brief Get whether a save is required. This is to bridge from reading the
152223
* json file into the attributes and registering the attributes to the
153224
* post-registration code.
154225
*/
155226
bool saveRequired() const { return _requiresCorrectedSave; }
156227

157-
/**
158-
* @brief Clear any flags set due to specific diagnostics
159-
*/
160-
void clearDiagnostics() { _requiresCorrectedSave = false; }
161-
162228
/**
163229
* @brief Specify whether or not to test for duplicate scene object instances
164230
* in loaded @ref SceneInstanceAttributes and not process the duplicates if found.

0 commit comments

Comments
 (0)