Skip to content

Commit fd14bd8

Browse files
committed
Insert CustomHierarchy class to Iteration
1 parent 980c298 commit fd14bd8

File tree

8 files changed

+130
-16
lines changed

8 files changed

+130
-16
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,7 @@ endif()
436436
set(CORE_SOURCE
437437
src/config.cpp
438438
src/ChunkInfo.cpp
439+
src/CustomHierarchy.cpp
439440
src/Dataset.cpp
440441
src/Datatype.cpp
441442
src/Error.cpp

include/openPMD/CustomHierarchy.hpp

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/* Copyright 2023 Franz Poeschel
2+
*
3+
* This file is part of openPMD-api.
4+
*
5+
* openPMD-api is free software: you can redistribute it and/or modify
6+
* it under the terms of of either the GNU General Public License or
7+
* the GNU Lesser General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* openPMD-api is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License and the GNU Lesser General Public License
15+
* for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* and the GNU Lesser General Public License along with openPMD-api.
19+
* If not, see <http://www.gnu.org/licenses/>.
20+
*/
21+
#pragma once
22+
23+
#include "openPMD/backend/Container.hpp"
24+
25+
#include <iostream>
26+
#include <type_traits>
27+
28+
namespace openPMD
29+
{
30+
class CustomHierarchy;
31+
namespace internal
32+
{
33+
using CustomHierarchyData = ContainerData<CustomHierarchy>;
34+
}
35+
36+
class CustomHierarchy : public Container<CustomHierarchy>
37+
{
38+
friend class Iteration;
39+
40+
private:
41+
using Container_t = Container<CustomHierarchy>;
42+
using Data_t = typename Container_t::ContainerData;
43+
static_assert(std::is_same_v<Data_t, internal::CustomHierarchyData>);
44+
45+
protected:
46+
CustomHierarchy();
47+
CustomHierarchy(NoInit);
48+
49+
inline void setData(std::shared_ptr<Data_t> data)
50+
{
51+
Container_t::setData(std::move(data));
52+
}
53+
54+
public:
55+
CustomHierarchy(CustomHierarchy const &other) = default;
56+
CustomHierarchy(CustomHierarchy &&other) = default;
57+
58+
CustomHierarchy &operator=(CustomHierarchy const &) = default;
59+
CustomHierarchy &operator=(CustomHierarchy &&) = default;
60+
};
61+
} // namespace openPMD

include/openPMD/Iteration.hpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
*/
2121
#pragma once
2222

23+
#include "openPMD/CustomHierarchy.hpp"
2324
#include "openPMD/IterationEncoding.hpp"
2425
#include "openPMD/Mesh.hpp"
2526
#include "openPMD/ParticleSpecies.hpp"
@@ -79,7 +80,7 @@ namespace internal
7980
bool beginStep = false;
8081
};
8182

82-
class IterationData : public AttributableData
83+
class IterationData : public CustomHierarchyData
8384
{
8485
public:
8586
/*
@@ -123,7 +124,7 @@ namespace internal
123124
* @see
124125
* https://github.com/openPMD/openPMD-standard/blob/latest/STANDARD.md#required-attributes-for-the-basepath
125126
*/
126-
class Iteration : public Attributable
127+
class Iteration : public CustomHierarchy
127128
{
128129
template <typename T, typename T_key, typename T_container>
129130
friend class Container;
@@ -260,14 +261,19 @@ class Iteration : public Attributable
260261
inline void setData(std::shared_ptr<Data_t> data)
261262
{
262263
m_iterationData = std::move(data);
263-
Attributable::setData(m_iterationData);
264+
CustomHierarchy::setData(m_iterationData);
264265
}
265266

266267
void flushFileBased(
267268
std::string const &, IterationIndex_t, internal::FlushParams const &);
268269
void flushGroupBased(IterationIndex_t, internal::FlushParams const &);
269270
void flushVariableBased(IterationIndex_t, internal::FlushParams const &);
270-
void flush(internal::FlushParams const &);
271+
/*
272+
* Named flushIteration instead of flush to avoid naming
273+
* conflicts with overridden virtual flush from CustomHierarchy
274+
* class.
275+
*/
276+
void flushIteration(internal::FlushParams const &);
271277
void deferParseAccess(internal::DeferredParseAccess);
272278
/*
273279
* Control flow for runDeferredParseAccess(), readFileBased(),

include/openPMD/backend/Container.hpp

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,6 @@ template <
101101
typename T_container = std::map<T_key, T> >
102102
class Container : virtual public Attributable
103103
{
104-
static_assert(
105-
std::is_base_of<Attributable, T>::value,
106-
"Type of container element must be derived from Writable");
107-
108104
friend class Iteration;
109105
friend class ParticleSpecies;
110106
friend class ParticlePatches;
@@ -463,11 +459,32 @@ OPENPMD_protected
463459

464460
Container() : Attributable(NoInit())
465461
{
462+
/*
463+
* This check cannot happen at the class scope, because T
464+
* might still be an incomplete type, e.g. in
465+
* class CustomHierarchy : public Container<CustomHierarchy>
466+
* The next-best thing is doing the check in
467+
* the constructor.
468+
*/
469+
static_assert(
470+
std::is_base_of<Attributable, T>::value,
471+
"Type of container element must be derived from Writable");
466472
setData(std::make_shared<ContainerData>());
467473
}
468474

469475
Container(NoInit) : Attributable(NoInit())
470-
{}
476+
{
477+
/*
478+
* This check cannot happen at the class scope, because T
479+
* might still be an incomplete type, e.g. in
480+
* class CustomHierarchy : public Container<CustomHierarchy>
481+
* The next-best thing is doing the check in
482+
* the constructor.
483+
*/
484+
static_assert(
485+
std::is_base_of<Attributable, T>::value,
486+
"Type of container element must be derived from Writable");
487+
}
471488

472489
public:
473490
/*

include/openPMD/binding/python/Container.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
#pragma once
2828

29+
#include "openPMD/CustomHierarchy.hpp"
2930
#include "openPMD/backend/Attributable.hpp"
3031

3132
#include <pybind11/pybind11.h>

src/CustomHierarchy.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/* Copyright 2023 Franz Poeschel
2+
*
3+
* This file is part of openPMD-api.
4+
*
5+
* openPMD-api is free software: you can redistribute it and/or modify
6+
* it under the terms of of either the GNU General Public License or
7+
* the GNU Lesser General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* openPMD-api is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License and the GNU Lesser General Public License
15+
* for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* and the GNU Lesser General Public License along with openPMD-api.
19+
* If not, see <http://www.gnu.org/licenses/>.
20+
*/
21+
22+
#include "openPMD/CustomHierarchy.hpp"
23+
24+
namespace openPMD
25+
{
26+
CustomHierarchy::CustomHierarchy() = default;
27+
CustomHierarchy::CustomHierarchy(NoInit): Container_t(NoInit()) {}
28+
}

src/Iteration.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ namespace openPMD
3636
using internal::CloseStatus;
3737
using internal::DeferredParseAccess;
3838

39-
Iteration::Iteration() : Attributable(NoInit())
39+
Iteration::Iteration() : CustomHierarchy(NoInit())
4040
{
4141
setData(std::make_shared<Data_t>());
4242
setTime(static_cast<double>(0));
@@ -231,7 +231,7 @@ void Iteration::flushFileBased(
231231
case FlushLevel::SkeletonOnly:
232232
case FlushLevel::InternalFlush:
233233
case FlushLevel::UserFlush:
234-
flush(flushParams);
234+
flushIteration(flushParams);
235235
break;
236236
}
237237
}
@@ -254,7 +254,7 @@ void Iteration::flushGroupBased(
254254
case FlushLevel::SkeletonOnly:
255255
case FlushLevel::InternalFlush:
256256
case FlushLevel::UserFlush:
257-
flush(flushParams);
257+
flushIteration(flushParams);
258258
break;
259259
}
260260
}
@@ -285,12 +285,12 @@ void Iteration::flushVariableBased(
285285
case FlushLevel::SkeletonOnly:
286286
case FlushLevel::InternalFlush:
287287
case FlushLevel::UserFlush:
288-
flush(flushParams);
288+
flushIteration(flushParams);
289289
break;
290290
}
291291
}
292292

293-
void Iteration::flush(internal::FlushParams const &flushParams)
293+
void Iteration::flushIteration(internal::FlushParams const &flushParams)
294294
{
295295
if (access::readOnly(IOHandler()->m_frontendAccess))
296296
{

src/Series.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,7 @@ void Series::flushFileBased(
764764
break;
765765
case IO::HasBeenOpened:
766766
// continue below
767-
it->second.flush(flushParams);
767+
it->second.flushIteration(flushParams);
768768
break;
769769
}
770770

@@ -874,7 +874,7 @@ void Series::flushGorVBased(
874874
break;
875875
case IO::HasBeenOpened:
876876
// continue below
877-
it->second.flush(flushParams);
877+
it->second.flushIteration(flushParams);
878878
break;
879879
}
880880

0 commit comments

Comments
 (0)