Skip to content

Commit d6f8057

Browse files
committed
Add m_datasetDefined
See in-code documentation.
1 parent dbd07b7 commit d6f8057

File tree

4 files changed

+29
-0
lines changed

4 files changed

+29
-0
lines changed

include/openPMD/RecordComponent.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,11 +440,14 @@ OPENPMD_protected
440440

441441
inline Data_t const &get() const
442442
{
443+
// cannot call this in the const overload
444+
// datasetDefined(*m_recordComponentData);
443445
return *m_recordComponentData;
444446
}
445447

446448
inline Data_t &get()
447449
{
450+
setDatasetDefined(*m_recordComponentData);
448451
return *m_recordComponentData;
449452
}
450453

include/openPMD/backend/BaseRecordComponent.hpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ namespace internal
4949
* instead defined via light-weight attributes.
5050
*/
5151
bool m_isConstant = false;
52+
/**
53+
* Tracks if there was any write access to the record component.
54+
* Necessary in BaseRecord<T> to track if the scalar component has been
55+
* used and is used by BaseRecord<T> to determine the return value of
56+
* the BaseRecord<T>::scalar() method.
57+
*/
58+
bool m_datasetDefined = false;
5259

5360
BaseRecordComponentData(BaseRecordComponentData const &) = delete;
5461
BaseRecordComponentData(BaseRecordComponentData &&) = delete;
@@ -166,6 +173,10 @@ class BaseRecordComponent : virtual public Attributable
166173
Attributable::setData(m_baseRecordComponentData);
167174
}
168175

176+
void setDatasetDefined(Data_t &);
177+
178+
bool datasetDefined() const;
179+
169180
BaseRecordComponent();
170181
BaseRecordComponent(NoInit);
171182
}; // BaseRecordComponent

include/openPMD/backend/PatchRecordComponent.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,14 @@ OPENPMD_protected
124124

125125
inline Data_t const &get() const
126126
{
127+
// cannot call this in the const overload
128+
// setDatasetDefined(*m_recordComponentData);
127129
return *m_patchRecordComponentData;
128130
}
129131

130132
inline Data_t &get()
131133
{
134+
setDatasetDefined(*m_patchRecordComponentData);
132135
return *m_patchRecordComponentData;
133136
}
134137

src/backend/BaseRecordComponent.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,16 @@ BaseRecordComponent::BaseRecordComponent() : Attributable(NoInit())
9292

9393
BaseRecordComponent::BaseRecordComponent(NoInit) : Attributable(NoInit())
9494
{}
95+
96+
void BaseRecordComponent::setDatasetDefined(
97+
internal::BaseRecordComponentData &data)
98+
{
99+
data.m_datasetDefined = true;
100+
}
101+
102+
bool BaseRecordComponent::datasetDefined() const
103+
{
104+
auto & data = get();
105+
return data.m_datasetDefined;
106+
}
95107
} // namespace openPMD

0 commit comments

Comments
 (0)