Skip to content

Commit

Permalink
Use Datatype::UNDEFINED to indicate no dataset definition in template
Browse files Browse the repository at this point in the history
  • Loading branch information
franzpoeschel committed Aug 4, 2023
1 parent d07b6b1 commit c6c8698
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 17 deletions.
2 changes: 1 addition & 1 deletion include/openPMD/Dataset.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
26 changes: 18 additions & 8 deletions src/RecordComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
19 changes: 11 additions & 8 deletions src/backend/PatchRecordComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit c6c8698

Please sign in to comment.