Skip to content

Commit af9f635

Browse files
committed
Use Datatype::UNDEFINED to indicate no dataset definition in template
1 parent bb2a2ef commit af9f635

File tree

3 files changed

+30
-17
lines changed

3 files changed

+30
-17
lines changed

include/openPMD/Dataset.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class Dataset
3737
friend class RecordComponent;
3838

3939
public:
40-
Dataset(Datatype, Extent, std::string options = "{}");
40+
Dataset(Datatype, Extent = {1}, std::string options = "{}");
4141

4242
/**
4343
* @brief Constructor that sets the datatype to undefined.

src/RecordComponent.cpp

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,18 +88,28 @@ RecordComponent &RecordComponent::resetDataset(Dataset d)
8888
rc.m_hasBeenExtended = true;
8989
}
9090

91-
if (d.dtype == Datatype::UNDEFINED)
92-
{
93-
throw error::WrongAPIUsage(
94-
"[RecordComponent] Must set specific datatype.");
95-
}
96-
// if( d.extent.empty() )
97-
// throw std::runtime_error("Dataset extent must be at least 1D.");
91+
// if (d.dtype == Datatype::UNDEFINED)
92+
// {
93+
// throw error::WrongAPIUsage(
94+
// "[RecordComponent] Must set specific datatype.");
95+
// }
96+
if (d.extent.empty())
97+
throw std::runtime_error("Dataset extent must be at least 1D.");
9898
if (std::any_of(
9999
d.extent.begin(), d.extent.end(), [](Extent::value_type const &i) {
100100
return i == 0u;
101101
}))
102-
return makeEmpty(std::move(d));
102+
{
103+
if (d.dtype != Datatype::UNDEFINED)
104+
{
105+
return makeEmpty(std::move(d));
106+
}
107+
else
108+
{
109+
rc.m_dataset = std::move(d);
110+
return *this;
111+
}
112+
}
103113

104114
rc.m_isEmpty = false;
105115
if (written())

src/backend/PatchRecordComponent.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,17 @@ PatchRecordComponent &PatchRecordComponent::resetDataset(Dataset d)
4646
throw std::runtime_error(
4747
"A Records Dataset can not (yet) be changed after it has been "
4848
"written.");
49-
if (d.extent.empty())
50-
throw std::runtime_error("Dataset extent must be at least 1D.");
51-
if (std::any_of(
52-
d.extent.begin(), d.extent.end(), [](Extent::value_type const &i) {
53-
return i == 0u;
54-
}))
55-
throw std::runtime_error(
56-
"Dataset extent must not be zero in any dimension.");
49+
if (d.dtype != Datatype::UNDEFINED)
50+
{
51+
if (d.extent.empty())
52+
throw std::runtime_error("Dataset extent must be at least 1D.");
53+
if (std::any_of(
54+
d.extent.begin(),
55+
d.extent.end(),
56+
[](Extent::value_type const &i) { return i == 0u; }))
57+
throw std::runtime_error(
58+
"Dataset extent must not be zero in any dimension.");
59+
}
5760

5861
get().m_dataset = d;
5962
dirty() = true;

0 commit comments

Comments
 (0)