From f734cbdd768282cf17e41fda820b9361b0b2f3f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franz=20P=C3=B6schel?= Date: Tue, 4 Oct 2022 10:06:32 +0200 Subject: [PATCH] Inherit BaseRecord from T_RecordComponent --- include/openPMD/RecordComponent.hpp | 6 +- include/openPMD/backend/Attributable.hpp | 4 +- include/openPMD/backend/BaseRecord.hpp | 89 ++++++++++++------- .../openPMD/backend/PatchRecordComponent.hpp | 2 +- include/openPMD/backend/Writable.hpp | 2 +- 5 files changed, 62 insertions(+), 41 deletions(-) diff --git a/include/openPMD/RecordComponent.hpp b/include/openPMD/RecordComponent.hpp index e8b5b465c8..d3278dd78a 100644 --- a/include/openPMD/RecordComponent.hpp +++ b/include/openPMD/RecordComponent.hpp @@ -129,7 +129,7 @@ class RecordComponent : public BaseRecordComponent friend class Container; friend class Iteration; friend class ParticleSpecies; - template + template friend class BaseRecord; template friend class BaseRecordInterface; @@ -316,12 +316,12 @@ class RecordComponent : public BaseRecordComponent std::shared_ptr m_recordComponentData{ new internal::RecordComponentData()}; - RecordComponent(); - // clang-format off OPENPMD_protected // clang-format on + RecordComponent(); + inline internal::RecordComponentData const &get() const { return *m_recordComponentData; diff --git a/include/openPMD/backend/Attributable.hpp b/include/openPMD/backend/Attributable.hpp index 0818a715bb..1b72d206ab 100644 --- a/include/openPMD/backend/Attributable.hpp +++ b/include/openPMD/backend/Attributable.hpp @@ -123,7 +123,7 @@ namespace internal } } - template + template class BaseRecordData; } // namespace internal @@ -137,7 +137,7 @@ class Attributable // @todo remove unnecessary friend (wew that sounds bitter) using A_MAP = std::map; friend Writable *getWritable(Attributable *); - template + template friend class BaseRecord; template friend class BaseRecordInterface; diff --git a/include/openPMD/backend/BaseRecord.hpp b/include/openPMD/backend/BaseRecord.hpp index 1086962c74..4c6feb2b71 100644 --- a/include/openPMD/backend/BaseRecord.hpp +++ b/include/openPMD/backend/BaseRecord.hpp @@ -28,13 +28,17 @@ #include #include #include +#include // std::remove_reference_t +#include // std::declval namespace openPMD { namespace internal { - template - class BaseRecordData : public ContainerData + template + class BaseRecordData + : public ContainerData + , public T_RecordComponentData { public: /** @@ -65,28 +69,36 @@ namespace internal * We specify the above concept by BaseRecord instead and use the * auxiliary::OkOr class template to treat the void type specially. */ -template +template < + typename T_elem_maybe_void, + typename T_RecordComponent = RecordComponent> class BaseRecord : public Container< typename auxiliary::OkOr >::type> + , public T_RecordComponent { using T_elem = typename auxiliary::OkOr >::type; + using T_Container = Container; + using T_RecordComponentData = std::remove_reference_t< + decltype(*std::declval().m_recordComponentData)>; friend class Iteration; friend class ParticleSpecies; friend class PatchRecord; friend class Record; friend class Mesh; - std::shared_ptr > m_baseRecordData{ - new internal::BaseRecordData()}; + std::shared_ptr > + m_baseRecordData{ + new internal::BaseRecordData()}; - inline internal::BaseRecordData &get() + inline internal::BaseRecordData &get() { return *m_baseRecordData; } - inline internal::BaseRecordData const &get() const + inline internal::BaseRecordData const & + get() const { return *m_baseRecordData; } @@ -113,6 +125,8 @@ class BaseRecord mapped_type &operator[](key_type &&key) override; size_type erase(key_type const &key) override; iterator erase(iterator res) override; + bool empty() const noexcept; + //! @todo add also, as soon as added in Container: // iterator erase(const_iterator first, const_iterator last) override; @@ -143,7 +157,7 @@ class BaseRecord bool scalar() const; protected: - BaseRecord(internal::BaseRecordData *); + // BaseRecord(internal::BaseRecordData *); void readBase(); private: @@ -167,8 +181,8 @@ class BaseRecord namespace internal { - template - BaseRecordData::BaseRecordData() + template + BaseRecordData::BaseRecordData() { Attributable impl; impl.setData({this, [](auto const *) {}}); @@ -178,15 +192,15 @@ namespace internal } } // namespace internal -template -BaseRecord::BaseRecord() +template +BaseRecord::BaseRecord() { Container::setData(m_baseRecordData); } -template -inline typename BaseRecord::mapped_type & -BaseRecord::operator[](key_type const &key) +template +inline typename BaseRecord::mapped_type & +BaseRecord::operator[](key_type const &key) { auto it = this->find(key); if (it != this->end()) @@ -210,9 +224,9 @@ BaseRecord::operator[](key_type const &key) } } -template -inline typename BaseRecord::mapped_type & -BaseRecord::operator[](key_type &&key) +template +inline typename BaseRecord::mapped_type & +BaseRecord::operator[](key_type &&key) { auto it = this->find(key); if (it != this->end()) @@ -236,9 +250,9 @@ BaseRecord::operator[](key_type &&key) } } -template -inline typename BaseRecord::size_type -BaseRecord::erase(key_type const &key) +template +inline typename BaseRecord::size_type +BaseRecord::erase(key_type const &key) { bool const keyScalar = (key == RecordComponent::SCALAR); size_type res; @@ -266,9 +280,9 @@ BaseRecord::erase(key_type const &key) return res; } -template -inline typename BaseRecord::iterator -BaseRecord::erase(iterator res) +template +inline typename BaseRecord::iterator +BaseRecord::erase(iterator res) { bool const keyScalar = (res->first == RecordComponent::SCALAR); iterator ret; @@ -296,21 +310,28 @@ BaseRecord::erase(iterator res) return ret; } -template -inline std::array BaseRecord::unitDimension() const +template +bool BaseRecord::empty() const noexcept +{ + return T_Container::empty(); +} + +template +inline std::array +BaseRecord::unitDimension() const { return this->getAttribute("unitDimension") .template get >(); } -template -inline bool BaseRecord::scalar() const +template +inline bool BaseRecord::scalar() const { return get().m_containsScalar; } -template -inline void BaseRecord::readBase() +template +inline void BaseRecord::readBase() { using DT = Datatype; Parameter aRead; @@ -354,8 +375,8 @@ inline void BaseRecord::readBase() "Unexpected Attribute datatype for 'timeOffset'"); } -template -inline void BaseRecord::flush( +template +inline void BaseRecord::flush( std::string const &name, internal::FlushParams const &flushParams) { if (!this->written() && this->empty()) @@ -369,8 +390,8 @@ inline void BaseRecord::flush( // method doesn't do it } -template -inline bool BaseRecord::dirtyRecursive() const +template +inline bool BaseRecord::dirtyRecursive() const { if (this->dirty()) { diff --git a/include/openPMD/backend/PatchRecordComponent.hpp b/include/openPMD/backend/PatchRecordComponent.hpp index 8855fa34b8..7abfaf9a6e 100644 --- a/include/openPMD/backend/PatchRecordComponent.hpp +++ b/include/openPMD/backend/PatchRecordComponent.hpp @@ -63,7 +63,7 @@ class PatchRecordComponent : public BaseRecordComponent { template friend class Container; - template + template friend class BaseRecord; friend class ParticlePatches; friend class PatchRecord; diff --git a/include/openPMD/backend/Writable.hpp b/include/openPMD/backend/Writable.hpp index 81d83955f9..3abd8a33fc 100644 --- a/include/openPMD/backend/Writable.hpp +++ b/include/openPMD/backend/Writable.hpp @@ -64,7 +64,7 @@ class Writable final { friend class internal::AttributableData; friend class Attributable; - template + template friend class BaseRecord; template friend class BaseRecordInterface;