Skip to content

Commit 82dafb3

Browse files
committed
somewhat compiles
1 parent 12c5ee5 commit 82dafb3

6 files changed

Lines changed: 69 additions & 43 deletions

File tree

include/openPMD/backend/Attributable.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include <map>
3333
#include <memory>
3434
#include <optional>
35+
#include <stdexcept>
3536
#include <string>
3637
#include <type_traits>
3738
#include <vector>
@@ -402,7 +403,10 @@ class Attributable
402403
*/
403404
void touch();
404405

405-
virtual void visitHierarchy(HierarchyVisitor &);
406+
virtual void visitHierarchy(HierarchyVisitor &)
407+
{
408+
throw std::runtime_error("Cannot call this on base class");
409+
}
406410

407411
[[nodiscard]] OpenpmdStandard openPMDStandard() const;
408412

include/openPMD/backend/Container.hpp

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -263,15 +263,7 @@ class Container : virtual public Attributable
263263
return container().emplace(std::forward<Args>(args)...);
264264
}
265265

266-
void visitHierarchy(HierarchyVisitor &v) override
267-
{
268-
v(*this);
269-
for (auto &p : *this)
270-
{
271-
p.second.visitHierarchy(v);
272-
}
273-
}
274-
266+
void visitHierarchy(HierarchyVisitor &v) override;
275267
// clang-format off
276268
OPENPMD_protected
277269
// clang-format on

include/openPMD/backend/HierarchyVisitor.hpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#pragma once
22

3+
#include <cstdint>
34
#include <map>
45
#include <string>
56

@@ -9,28 +10,38 @@ class Series;
910
class Iteration;
1011
class Mesh;
1112
class ParticleSpecies;
13+
class ParticlePatches;
1214
class PatchRecord;
1315
class PatchRecordComponent;
1416
class RecordComponent;
1517
class MeshRecordComponent;
1618
template <typename, typename, typename>
1719
class Container;
18-
template <typename Val>
19-
using Cont = Container<Val, std::string, std::map<std::string, Val>>;
20+
template <typename Val, typename Key = std::string>
21+
using Cont = Container<Val, Key, std::map<Key, Val>>;
2022
template <typename>
2123
class BaseRecord;
24+
class Record;
2225

2326
class HierarchyVisitor
2427
{
2528
public:
2629
virtual void operator()(Series &) = 0;
2730
virtual void operator()(Iteration &) = 0;
28-
virtual void operator()(Cont<Iteration> &) = 0;
31+
virtual void operator()(Cont<Iteration, std::uint64_t> &) = 0;
2932
virtual void operator()(Cont<Mesh> &) = 0;
3033
virtual void operator()(Cont<ParticleSpecies> &) = 0;
34+
virtual void operator()(Cont<ParticlePatches> &) = 0;
3135
virtual void operator()(Cont<PatchRecord> &) = 0;
36+
virtual void operator()(Cont<Record> &) = 0;
37+
virtual void operator()(Record &) = 0;
38+
// TODO there are too many duplications here, remove most of them
39+
virtual void operator()(Cont<MeshRecordComponent> &) = 0;
40+
virtual void operator()(BaseRecord<MeshRecordComponent> &) = 0;
3241
virtual void operator()(Cont<PatchRecordComponent> &) = 0;
33-
virtual void operator()(Mesh &) = 0;
42+
virtual void operator()(BaseRecord<PatchRecordComponent> &) = 0;
43+
virtual void operator()(Cont<RecordComponent> &) = 0;
44+
virtual void operator()(BaseRecord<RecordComponent> &) = 0;
3445
virtual void operator()(ParticleSpecies &) = 0;
3546
virtual void operator()(RecordComponent &) = 0;
3647
virtual void operator()(MeshRecordComponent &) = 0;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#pragma once
2+
3+
#include "openPMD/backend/HierarchyVisitor.hpp"
4+
5+
#include "openPMD/Iteration.hpp"
6+
#include "openPMD/ParticleSpecies.hpp"
7+
#include "openPMD/Series.hpp"

src/Iteration.cpp

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -247,35 +247,37 @@ bool Iteration::closedByWriter() const
247247
void Iteration::populateDefaultMetadata()
248248
{
249249
auto standard = IOHandler()->m_standard;
250-
visitHierarchy([standard](auto &component) {
251-
using ComponentType = std::remove_reference_t<decltype(component)>;
252-
if constexpr (auxiliary::IsTemplateBaseOf_v<BaseRecord, ComponentType>)
253-
{
254-
if (component.empty() && !component.datasetDefined())
255-
{
256-
std::cerr
257-
<< "Cannot flush Record without any contained components: '"
258-
<< component.myPath().openPMDPath() << "'. Will ignore.";
259-
if (component.written())
260-
{
261-
std::cerr
262-
<< "\n(Note: The Record seems to have been written "
263-
"previously?)";
264-
}
265-
std::cerr << std::endl;
266-
return;
267-
}
268-
}
269-
270-
if constexpr (
271-
!std::is_same_v<ComponentType, Container<Mesh>> &&
272-
!std::is_same_v<ComponentType, Container<Record>> &&
273-
!std::is_same_v<ComponentType, Container<PatchRecord>> &&
274-
!std::is_same_v<ComponentType, Container<ParticleSpecies>>)
275-
{
276-
component.writeDefaults(standard);
277-
}
278-
});
250+
// visitHierarchy([standard](auto &component) {
251+
// using ComponentType = std::remove_reference_t<decltype(component)>;
252+
// if constexpr (auxiliary::IsTemplateBaseOf_v<BaseRecord,
253+
// ComponentType>)
254+
// {
255+
// if (component.empty() && !component.datasetDefined())
256+
// {
257+
// std::cerr
258+
// << "Cannot flush Record without any contained components:
259+
// '"
260+
// << component.myPath().openPMDPath() << "'. Will ignore.";
261+
// if (component.written())
262+
// {
263+
// std::cerr
264+
// << "\n(Note: The Record seems to have been written "
265+
// "previously?)";
266+
// }
267+
// std::cerr << std::endl;
268+
// return;
269+
// }
270+
// }
271+
272+
// if constexpr (
273+
// !std::is_same_v<ComponentType, Container<Mesh>> &&
274+
// !std::is_same_v<ComponentType, Container<Record>> &&
275+
// !std::is_same_v<ComponentType, Container<PatchRecord>> &&
276+
// !std::is_same_v<ComponentType, Container<ParticleSpecies>>)
277+
// {
278+
// component.writeDefaults(standard);
279+
// }
280+
// });
279281
}
280282

281283
void Iteration::flushFileBased(

src/backend/Container.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,20 @@
2626
#include "openPMD/ParticlePatches.hpp"
2727
#include "openPMD/ParticleSpecies.hpp"
2828
#include "openPMD/backend/Container.hpp"
29+
#include "openPMD/backend/HierarchyVisitorImpl.hpp"
2930
#include "openPMD/backend/PatchRecordComponent.hpp"
3031

3132
namespace openPMD
3233
{
34+
template <typename Val, typename Key, typename Map>
35+
void Container<Val, Key, Map>::visitHierarchy(HierarchyVisitor &v)
36+
{
37+
v(*this);
38+
for (auto &p : *this)
39+
{
40+
p.second.visitHierarchy(v);
41+
}
42+
}
3343
#define OPENPMD_COMMA ,
3444
#define OPENPMD_INSTANTIATE(type) template class Container<type>;
3545

0 commit comments

Comments
 (0)