Skip to content

Commit 3f4db01

Browse files
committed
Postfix traversal, document visitHierarchy
1 parent 9b6818a commit 3f4db01

5 files changed

Lines changed: 30 additions & 10 deletions

File tree

include/openPMD/Iteration.hpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -298,12 +298,7 @@ class Iteration
298298
[[deprecated("This attribute is no longer set by the openPMD-api.")]] bool
299299
closedByWriter() const;
300300

301-
void visitHierarchy(HierarchyVisitor &v) override
302-
{
303-
v(*this);
304-
meshes.visitHierarchy(v);
305-
particles.visitHierarchy(v);
306-
}
301+
void visitHierarchy(HierarchyVisitor &v) override;
307302

308303
Meshes meshes{};
309304
Particles particles{};

include/openPMD/backend/Attributable.hpp

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,9 +402,27 @@ class Attributable
402402
*/
403403
void touch();
404404

405-
virtual void visitHierarchy(HierarchyVisitor &);
405+
/**
406+
* Visitor pattern for the openPMD object hierarchy in postfix traversal.
407+
*
408+
* @note As the HierarchyVisitor interface can be tedious to implement,
409+
* consider using visitHierarchyFromLambda for a more convenient
410+
* interface.
411+
*
412+
* @param visitor Operations to run for each object.
413+
*/
414+
virtual void visitHierarchy(HierarchyVisitor &visitor);
406415

407-
// definition inside include/openPMD/backend/HierarchyVisitorImpl.hpp
416+
/**
417+
* Visitor pattern for the openPMD object hierarchy in postfix traversal,
418+
* lambda version.
419+
*
420+
* The lambda parameter will be called with a reference to each object in
421+
* the current object's enclosed hierarchy.
422+
*
423+
* @note Definition inside include/openPMD/backend/HierarchyVisitorImpl.hpp.
424+
* @param lambda Operations to run for each object.
425+
*/
408426
template <typename Lambda>
409427
void visitHierarchyFromLambda(Lambda &&lambda);
410428

include/openPMD/backend/Container.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,11 +266,11 @@ class Container : virtual public Attributable
266266
template <typename ChildClass>
267267
void visitHierarchyImpl(HierarchyVisitor &v)
268268
{
269-
v(*static_cast<ChildClass *>(this));
270269
for (auto &p : *this)
271270
{
272271
p.second.visitHierarchy(v);
273272
}
273+
v(*static_cast<ChildClass *>(this));
274274
}
275275

276276
// clang-format off

src/Iteration.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,13 @@ bool Iteration::closedByWriter() const
254254
}
255255
}
256256

257+
void Iteration::visitHierarchy(HierarchyVisitor &v)
258+
{
259+
meshes.visitHierarchy(v);
260+
particles.visitHierarchy(v);
261+
v(*this);
262+
}
263+
257264
void Iteration::flushFileBased(
258265
std::string const &filename,
259266
IterationIndex_t i,

src/Series.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3571,8 +3571,8 @@ void Series::close()
35713571

35723572
void Series::visitHierarchy(HierarchyVisitor &v)
35733573
{
3574-
v(*this);
35753574
get().iterations.visitHierarchy(v);
3575+
v(*this);
35763576
}
35773577

35783578
auto Series::currentSnapshot() -> std::optional<std::vector<IterationIndex_t>>

0 commit comments

Comments
 (0)