Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,7 @@ set(CORE_SOURCE
src/backend/PatchRecord.cpp
src/backend/PatchRecordComponent.cpp
src/backend/Writable.cpp
src/backend/ScientificDefaults.cpp
src/auxiliary/OneDimensionalBlockSlicer.cpp
src/helper/list_series.cpp
src/snapshots/ContainerImpls.cpp
Expand Down
6 changes: 5 additions & 1 deletion include/openPMD/Iteration.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "openPMD/auxiliary/Variant.hpp"
#include "openPMD/backend/Attributable.hpp"
#include "openPMD/backend/Container.hpp"
#include "openPMD/backend/ScientificDefaults.hpp"

#include <cstdint>
#include <deque>
Expand Down Expand Up @@ -142,7 +143,9 @@ namespace internal
* @see
* https://github.com/openPMD/openPMD-standard/blob/latest/STANDARD.md#required-attributes-for-the-basepath
*/
class Iteration : public Attributable
class Iteration
: public Attributable
, internal::ScientificDefaults<Iteration>
{
template <typename T, typename T_key, typename T_container>
friend class Container;
Expand All @@ -153,6 +156,7 @@ class Iteration : public Attributable
friend class Writable;
friend class StatefulIterator;
friend class StatefulSnapshotsContainer;
friend class internal::ScientificDefaults<Iteration>;

public:
Iteration(Iteration const &) = default;
Expand Down
14 changes: 13 additions & 1 deletion include/openPMD/Mesh.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
#include "openPMD/UnitDimension.hpp"
#include "openPMD/backend/Attributable.hpp"
#include "openPMD/backend/BaseRecord.hpp"
#include "openPMD/backend/Container.hpp"
#include "openPMD/backend/MeshRecordComponent.hpp"
#include "openPMD/backend/ScientificDefaults.hpp"

#include <ostream>
#include <string>
Expand All @@ -37,10 +39,14 @@ namespace openPMD
* @see
* https://github.com/openPMD/openPMD-standard/blob/latest/STANDARD.md#mesh-based-records
*/
class Mesh : public BaseRecord<MeshRecordComponent>
class Mesh
: public BaseRecord<MeshRecordComponent>
, internal::ScientificDefaults<Mesh>
{
friend class Container<Mesh>;
friend class Iteration;
template <typename>
friend class internal::ScientificDefaults;

public:
Mesh(Mesh const &) = default;
Expand Down Expand Up @@ -328,8 +334,14 @@ class Mesh : public BaseRecord<MeshRecordComponent>
void
flush_impl(std::string const &, internal::FlushParams const &) override;
void read();
auto retrieveDimensionality() const -> uint64_t;
}; // Mesh

static_assert(internal::IsContainer_v<Mesh>);
static_assert(std::is_same_v<
Container<MeshRecordComponent>,
internal::AsContainer_t<Mesh>>);

template <typename T>
inline std::vector<T> Mesh::gridSpacing() const
{
Expand Down
7 changes: 6 additions & 1 deletion include/openPMD/ParticleSpecies.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,24 @@
#include "openPMD/Record.hpp"
#include "openPMD/backend/Attributable.hpp"
#include "openPMD/backend/Container.hpp"
#include "openPMD/backend/ScientificDefaults.hpp"

#include <string>

namespace openPMD
{

class ParticleSpecies : public Container<Record>
class ParticleSpecies
: public Container<Record>
, internal::ScientificDefaults<ParticleSpecies>
{
friend class Container<ParticleSpecies>;
friend class Container<Record>;
friend class Iteration;
template <typename T>
friend T &internal::makeOwning(T &self, Series);
template <typename>
friend class internal::ScientificDefaults;

public:
ParticlePatches particlePatches;
Expand Down
9 changes: 8 additions & 1 deletion include/openPMD/Record.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,22 @@
#include "openPMD/RecordComponent.hpp"
#include "openPMD/UnitDimension.hpp"
#include "openPMD/backend/BaseRecord.hpp"
#include "openPMD/backend/ScientificDefaults.hpp"

#include <string>
#include <type_traits>

namespace openPMD
{
class Record : public BaseRecord<RecordComponent>
class Record
: public BaseRecord<RecordComponent>
, internal::ScientificDefaults<Record>
{
friend class Container<Record>;
friend class Iteration;
friend class ParticleSpecies;
template <typename>
friend class internal::ScientificDefaults;

public:
Record(Record const &) = default;
Expand All @@ -57,6 +62,8 @@ class Record : public BaseRecord<RecordComponent>
[[nodiscard]] internal::HomogenizeExtents read();
}; // Record

static_assert(internal::HasScientificDefaults_v<Record>);

template <typename T>
inline T Record::timeOffset() const
{
Expand Down
7 changes: 6 additions & 1 deletion include/openPMD/RecordComponent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "openPMD/auxiliary/UniquePtr.hpp"
#include "openPMD/backend/Attributable.hpp"
#include "openPMD/backend/BaseRecordComponent.hpp"
#include "openPMD/backend/ScientificDefaults.hpp"

// comment to prevent this include from being moved by clang-format
#include "openPMD/DatatypeMacros.hpp"
Expand Down Expand Up @@ -110,7 +111,9 @@ namespace internal
template <typename>
class BaseRecord;

class RecordComponent : public BaseRecordComponent
class RecordComponent
: public BaseRecordComponent
, internal::ScientificDefaults<RecordComponent>
{
template <typename T, typename T_key, typename T_container>
friend class Container;
Expand All @@ -128,6 +131,8 @@ class RecordComponent : public BaseRecordComponent
friend class MeshRecordComponent;
template <typename T>
friend T &internal::makeOwning(T &self, Series);
template <typename>
friend class internal::ScientificDefaults;

public:
enum class Allocation
Expand Down
28 changes: 28 additions & 0 deletions include/openPMD/auxiliary/TypeTraits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,34 @@ namespace detail
// little trick to avoid trailing commas in the macro expansions below
template <typename Arg, typename... Args>
using variant_tail_t = std::variant<Args...>;

template <template <typename...> class Base, typename... Args>
auto infer_template_args(Base<Args...> &) -> Base<Args...>;

template <
template <typename...> class Base,
typename T,
typename SFINAE = void>
struct IsTemplateBaseOf
{
static constexpr bool value = false;
};

template <template <typename...> class Base, typename T>
struct IsTemplateBaseOf<
Base,
T,
std::void_t<decltype(detail::infer_template_args<Base>(
std::declval<T &>()))>>
{
static constexpr bool value = true;
using type =
decltype(detail::infer_template_args<Base>(std::declval<T &>()));
};
} // namespace detail

template <template <typename...> class Base, typename T>
constexpr bool IsTemplateBaseOf_v = detail::IsTemplateBaseOf<Base, T>::value;
template <template <typename...> class Base, typename T>
using AsTemplateBase_t = typename detail::IsTemplateBaseOf<Base, T>::type;
} // namespace openPMD::auxiliary
4 changes: 4 additions & 0 deletions include/openPMD/backend/BaseRecord.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "openPMD/auxiliary/Variant.hpp"
#include "openPMD/backend/BaseRecordComponent.hpp"
#include "openPMD/backend/Container.hpp"
#include "openPMD/backend/ScientificDefaults.hpp"

#include <array>
#include <stdexcept>
Expand Down Expand Up @@ -179,6 +180,7 @@ template <typename T_elem>
class BaseRecord
: public Container<T_elem>
, public T_elem // T_RecordComponent
, internal::ScientificDefaults<BaseRecord<T_elem>>
{
public:
using T_RecordComponent = T_elem;
Expand All @@ -197,6 +199,8 @@ class BaseRecord
friend class internal::ScalarIterator;
template <typename T>
friend T &internal::makeOwning(T &self, Series);
template <typename>
friend class internal::ScientificDefaults;

using Data_t =
internal::BaseRecordData<T_elem, typename T_RecordComponent::Data_t>;
Expand Down
9 changes: 9 additions & 0 deletions include/openPMD/backend/Container.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include "openPMD/Error.hpp"
#include "openPMD/IO/Access.hpp"
#include "openPMD/auxiliary/TypeTraits.hpp"
#include "openPMD/backend/Attributable.hpp"

#include <initializer_list>
Expand Down Expand Up @@ -343,5 +344,13 @@ namespace internal

~EraseStaleEntries();
};

template <typename T>
constexpr bool IsContainer_v = auxiliary::IsTemplateBaseOf_v<Container, T>;
template <typename T>
using AsContainer_t = auxiliary::AsTemplateBase_t<Container, T>;

static_assert(!IsContainer_v<int>);
static_assert(IsContainer_v<Container<Attributable>>);
} // namespace internal
} // namespace openPMD
7 changes: 6 additions & 1 deletion include/openPMD/backend/MeshRecordComponent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#pragma once

#include "openPMD/RecordComponent.hpp"
#include "openPMD/backend/ScientificDefaults.hpp"

#include <vector>

Expand All @@ -32,14 +33,18 @@ namespace internal
class BaseRecordData;
}

class MeshRecordComponent : public RecordComponent
class MeshRecordComponent
: public RecordComponent
, internal::ScientificDefaults<MeshRecordComponent>
{
template <typename T, typename T_key, typename T_container>
friend class Container;
template <typename>
friend class BaseRecord;
template <typename, typename>
friend class internal::BaseRecordData;
template <typename>
friend class internal::ScientificDefaults;

friend class Mesh;

Expand Down
7 changes: 6 additions & 1 deletion include/openPMD/backend/PatchRecordComponent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "openPMD/RecordComponent.hpp"
#include "openPMD/auxiliary/ShareRawInternal.hpp"
#include "openPMD/backend/BaseRecordComponent.hpp"
#include "openPMD/backend/ScientificDefaults.hpp"

#include <memory>
#include <sstream>
Expand All @@ -42,7 +43,9 @@ namespace openPMD
/**
* @todo add support for constant patch record components
*/
class PatchRecordComponent : public RecordComponent
class PatchRecordComponent
: public RecordComponent
, internal::ScientificDefaults<PatchRecordComponent>
{
template <typename T, typename T_key, typename T_container>
friend class Container;
Expand All @@ -53,6 +56,8 @@ class PatchRecordComponent : public RecordComponent
friend class ParticlePatches;
friend class PatchRecord;
friend class ParticleSpecies;
template <typename>
friend class internal::ScientificDefaults;

public:
/**
Expand Down
75 changes: 75 additions & 0 deletions include/openPMD/backend/ScientificDefaults.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#pragma once

#include "openPMD/IO/Access.hpp"
#include <type_traits>

namespace openPMD::detail
{
template <typename F, typename SFINAE = void>
struct IsCallable
{
static constexpr bool value = false;
using type = F;
};

template <typename F>
struct IsCallable<F, std::void_t<decltype(std::declval<F>()())>>
{
static constexpr bool value = true;
using type = decltype(std::declval<F>()());
};

template <typename F>
constexpr bool IsCallable_v = IsCallable<F>::value;
template <typename F>
using CallResult_t = typename IsCallable<F>::type;
} // namespace openPMD::detail

namespace openPMD::internal
{
template <typename Child> // CRT
class ScientificDefaults
{
private:
auto asChild() -> Child &;
auto asChild() const -> Child const &;

template <typename F>
using setter_t = Child &(Child::*)();

template <typename Setter = void, typename V>
void addDefaultFor_worker(char const *key, V &&value, Setter &&setter);

template <typename V>
void addDefaultFor_worker(char const *key, V &&value);

template <typename F, typename... Args>
void addDefaultFor_resolveValue(char const *key, F &&get_value, Args &&...);

// These two below overloads exist only for type inference purposes
// Apart from this, they just forward their arguments to
// addDefaultFor_resolveValue
template <typename Setter = void, typename F>
void addDefaultFor(
char const *key,
F &&get_value,
Child &(Child::*)(std::conditional_t<
std::is_void_v<Setter>,
std::remove_reference_t<detail::CallResult_t<F>>,
Setter>));

template <typename F>
void addDefaultFor(char const *key, F &&get_value);

template <typename Parent>
void addParentDefaults();

protected:
void finalize(Access);
void addDefaults();
};

template <typename Child>
constexpr bool HasScientificDefaults_v =
std::is_base_of_v<ScientificDefaults<Child>, Child>;
} // namespace openPMD::internal
4 changes: 4 additions & 0 deletions include/openPMD/backend/Writable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ namespace internal
class SharedAttributableData;
class AttributableData;
class SeriesData;
template <typename>
class ScientificDefaults;
} // namespace internal
namespace detail
{
Expand Down Expand Up @@ -106,6 +108,8 @@ class Writable final
friend void debug::printDirty(Series const &);
friend struct Parameter<Operation::CREATE_DATASET>;
friend struct Parameter<Operation::OPEN_DATASET>;
template <typename>
friend class internal::ScientificDefaults;

private:
Writable(internal::AttributableData *);
Expand Down
Loading
Loading