From c6c8698b17f12de87d4beb5615a3b557684d36d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franz=20P=C3=B6schel?= Date: Fri, 10 Mar 2023 15:42:59 +0100 Subject: [PATCH] Use Datatype::UNDEFINED to indicate no dataset definition in template --- include/openPMD/Dataset.hpp | 2 +- src/RecordComponent.cpp | 26 ++++++++++++++++++-------- src/backend/PatchRecordComponent.cpp | 19 +++++++++++-------- 3 files changed, 30 insertions(+), 17 deletions(-) diff --git a/include/openPMD/Dataset.hpp b/include/openPMD/Dataset.hpp index 8757a3cf0a..78ac6f0995 100644 --- a/include/openPMD/Dataset.hpp +++ b/include/openPMD/Dataset.hpp @@ -37,7 +37,7 @@ class Dataset friend class RecordComponent; public: - Dataset(Datatype, Extent, std::string options = "{}"); + Dataset(Datatype, Extent = {1}, std::string options = "{}"); /** * @brief Constructor that sets the datatype to undefined. diff --git a/src/RecordComponent.cpp b/src/RecordComponent.cpp index a54373be59..9bb10705b1 100644 --- a/src/RecordComponent.cpp +++ b/src/RecordComponent.cpp @@ -88,18 +88,28 @@ RecordComponent &RecordComponent::resetDataset(Dataset d) rc.m_hasBeenExtended = true; } - if (d.dtype == Datatype::UNDEFINED) - { - throw error::WrongAPIUsage( - "[RecordComponent] Must set specific datatype."); - } - // if( d.extent.empty() ) - // throw std::runtime_error("Dataset extent must be at least 1D."); + // if (d.dtype == Datatype::UNDEFINED) + // { + // throw error::WrongAPIUsage( + // "[RecordComponent] Must set specific datatype."); + // } + if (d.extent.empty()) + throw std::runtime_error("Dataset extent must be at least 1D."); if (std::any_of( d.extent.begin(), d.extent.end(), [](Extent::value_type const &i) { return i == 0u; })) - return makeEmpty(std::move(d)); + { + if (d.dtype != Datatype::UNDEFINED) + { + return makeEmpty(std::move(d)); + } + else + { + rc.m_dataset = std::move(d); + return *this; + } + } rc.m_isEmpty = false; if (written()) diff --git a/src/backend/PatchRecordComponent.cpp b/src/backend/PatchRecordComponent.cpp index e9aeff78ac..0e82a103f0 100644 --- a/src/backend/PatchRecordComponent.cpp +++ b/src/backend/PatchRecordComponent.cpp @@ -46,14 +46,17 @@ PatchRecordComponent &PatchRecordComponent::resetDataset(Dataset d) throw std::runtime_error( "A Records Dataset can not (yet) be changed after it has been " "written."); - if (d.extent.empty()) - throw std::runtime_error("Dataset extent must be at least 1D."); - if (std::any_of( - d.extent.begin(), d.extent.end(), [](Extent::value_type const &i) { - return i == 0u; - })) - throw std::runtime_error( - "Dataset extent must not be zero in any dimension."); + if (d.dtype != Datatype::UNDEFINED) + { + if (d.extent.empty()) + throw std::runtime_error("Dataset extent must be at least 1D."); + if (std::any_of( + d.extent.begin(), + d.extent.end(), + [](Extent::value_type const &i) { return i == 0u; })) + throw std::runtime_error( + "Dataset extent must not be zero in any dimension."); + } get().m_dataset = d; dirty() = true;