From d5ecbd58ab29830bb8cf9ca1f9c82906d42df154 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franz=20P=C3=B6schel?= Date: Mon, 20 Mar 2023 16:46:29 +0100 Subject: [PATCH] Add m_datasetDefined Todo: Merge functionality with #1316 --- include/openPMD/RecordComponent.hpp | 3 +++ include/openPMD/backend/BaseRecordComponent.hpp | 8 ++++++++ include/openPMD/backend/PatchRecordComponent.hpp | 3 +++ src/backend/BaseRecordComponent.cpp | 11 +++++++++++ 4 files changed, 25 insertions(+) diff --git a/include/openPMD/RecordComponent.hpp b/include/openPMD/RecordComponent.hpp index ad23dcebf1..525e96ca7f 100644 --- a/include/openPMD/RecordComponent.hpp +++ b/include/openPMD/RecordComponent.hpp @@ -440,12 +440,15 @@ OPENPMD_protected inline Data_t const &get() const { + // cannot call this in the const overload + // datasetDefined(*m_recordComponentData); return dynamic_cast(*m_attri); } inline Data_t &get() { auto &res = dynamic_cast(*m_attri); + setDatasetDefined(res); return res; } diff --git a/include/openPMD/backend/BaseRecordComponent.hpp b/include/openPMD/backend/BaseRecordComponent.hpp index fb00e2f49e..1a2409cfdf 100644 --- a/include/openPMD/backend/BaseRecordComponent.hpp +++ b/include/openPMD/backend/BaseRecordComponent.hpp @@ -49,6 +49,10 @@ namespace internal * instead defined via light-weight attributes. */ bool m_isConstant = false; + /* + * ... document this ... + */ + bool m_datasetDefined = false; BaseRecordComponentData(BaseRecordComponentData const &) = delete; BaseRecordComponentData(BaseRecordComponentData &&) = delete; @@ -114,6 +118,10 @@ class BaseRecordComponent : virtual public Attributable return dynamic_cast(*m_attri); } + void setDatasetDefined(Data_t &); + + bool datasetDefined() const; + BaseRecordComponent(); }; // BaseRecordComponent diff --git a/include/openPMD/backend/PatchRecordComponent.hpp b/include/openPMD/backend/PatchRecordComponent.hpp index ba9eb0255b..3265e7422b 100644 --- a/include/openPMD/backend/PatchRecordComponent.hpp +++ b/include/openPMD/backend/PatchRecordComponent.hpp @@ -121,12 +121,15 @@ OPENPMD_protected inline Data_t const &get() const { + // cannot call this in the const overload + // setDatasetDefined(*m_recordComponentData); return dynamic_cast(*m_attri); } inline Data_t &get() { auto &res = dynamic_cast(*m_attri); + setDatasetDefined(res); return res; } }; // PatchRecordComponent diff --git a/src/backend/BaseRecordComponent.cpp b/src/backend/BaseRecordComponent.cpp index 813927f63d..c721e98b6f 100644 --- a/src/backend/BaseRecordComponent.cpp +++ b/src/backend/BaseRecordComponent.cpp @@ -91,4 +91,15 @@ BaseRecordComponent::BaseRecordComponent() std::make_shared()); } +void BaseRecordComponent::setDatasetDefined( + internal::BaseRecordComponentData &data) +{ + data.m_datasetDefined = true; +} + +bool BaseRecordComponent::datasetDefined() const +{ + auto & data = get(); + return data.m_datasetDefined; +} } // namespace openPMD