Skip to content

Commit

Permalink
Inherit BaseRecord from T_RecordComponent
Browse files Browse the repository at this point in the history
  • Loading branch information
franzpoeschel committed Oct 12, 2022
1 parent d4803ca commit f734cbd
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 41 deletions.
6 changes: 3 additions & 3 deletions include/openPMD/RecordComponent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class RecordComponent : public BaseRecordComponent
friend class Container;
friend class Iteration;
friend class ParticleSpecies;
template <typename T_elem>
template <typename T_elem, typename T_RecordComponent>
friend class BaseRecord;
template <typename T_elem>
friend class BaseRecordInterface;
Expand Down Expand Up @@ -316,12 +316,12 @@ class RecordComponent : public BaseRecordComponent
std::shared_ptr<internal::RecordComponentData> m_recordComponentData{
new internal::RecordComponentData()};

RecordComponent();

// clang-format off
OPENPMD_protected
// clang-format on

RecordComponent();

inline internal::RecordComponentData const &get() const
{
return *m_recordComponentData;
Expand Down
4 changes: 2 additions & 2 deletions include/openPMD/backend/Attributable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ namespace internal
}
}

template <typename>
template <typename, typename>
class BaseRecordData;
} // namespace internal

Expand All @@ -137,7 +137,7 @@ class Attributable
// @todo remove unnecessary friend (wew that sounds bitter)
using A_MAP = std::map<std::string, Attribute>;
friend Writable *getWritable(Attributable *);
template <typename T_elem>
template <typename T_elem, typename T_RecordComponent>
friend class BaseRecord;
template <typename T_elem>
friend class BaseRecordInterface;
Expand Down
89 changes: 55 additions & 34 deletions include/openPMD/backend/BaseRecord.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,17 @@
#include <array>
#include <stdexcept>
#include <string>
#include <type_traits> // std::remove_reference_t
#include <utility> // std::declval

namespace openPMD
{
namespace internal
{
template <typename T_elem>
class BaseRecordData : public ContainerData<T_elem>
template <typename T_elem, typename T_RecordComponentData>
class BaseRecordData
: public ContainerData<T_elem>
, public T_RecordComponentData
{
public:
/**
Expand Down Expand Up @@ -65,28 +69,36 @@ namespace internal
* We specify the above concept by BaseRecord<void> instead and use the
* auxiliary::OkOr class template to treat the void type specially.
*/
template <typename T_elem_maybe_void>
template <
typename T_elem_maybe_void,
typename T_RecordComponent = RecordComponent>
class BaseRecord
: public Container<
typename auxiliary::OkOr<T_elem_maybe_void, BaseRecord<void> >::type>
, public T_RecordComponent
{
using T_elem =
typename auxiliary::OkOr<T_elem_maybe_void, BaseRecord<void> >::type;
using T_Container = Container<T_elem>;
using T_RecordComponentData = std::remove_reference_t<
decltype(*std::declval<T_RecordComponent>().m_recordComponentData)>;
friend class Iteration;
friend class ParticleSpecies;
friend class PatchRecord;
friend class Record;
friend class Mesh;

std::shared_ptr<internal::BaseRecordData<T_elem> > m_baseRecordData{
new internal::BaseRecordData<T_elem>()};
std::shared_ptr<internal::BaseRecordData<T_elem, T_RecordComponentData> >
m_baseRecordData{
new internal::BaseRecordData<T_elem, T_RecordComponentData>()};

inline internal::BaseRecordData<T_elem> &get()
inline internal::BaseRecordData<T_elem, T_RecordComponentData> &get()
{
return *m_baseRecordData;
}

inline internal::BaseRecordData<T_elem> const &get() const
inline internal::BaseRecordData<T_elem, T_RecordComponentData> const &
get() const
{
return *m_baseRecordData;
}
Expand All @@ -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;

Expand Down Expand Up @@ -143,7 +157,7 @@ class BaseRecord
bool scalar() const;

protected:
BaseRecord(internal::BaseRecordData<T_elem> *);
// BaseRecord(internal::BaseRecordData<T_elem> *);
void readBase();

private:
Expand All @@ -167,8 +181,8 @@ class BaseRecord

namespace internal
{
template <typename T_elem>
BaseRecordData<T_elem>::BaseRecordData()
template <typename T_elem, typename T_RecordComponentData>
BaseRecordData<T_elem, T_RecordComponentData>::BaseRecordData()
{
Attributable impl;
impl.setData({this, [](auto const *) {}});
Expand All @@ -178,15 +192,15 @@ namespace internal
}
} // namespace internal

template <typename T_elem>
BaseRecord<T_elem>::BaseRecord()
template <typename T_elem, typename T_RecordComponent>
BaseRecord<T_elem, T_RecordComponent>::BaseRecord()
{
Container<T_elem>::setData(m_baseRecordData);
}

template <typename T_elem>
inline typename BaseRecord<T_elem>::mapped_type &
BaseRecord<T_elem>::operator[](key_type const &key)
template <typename T_elem, typename T_RecordComponent>
inline typename BaseRecord<T_elem, T_RecordComponent>::mapped_type &
BaseRecord<T_elem, T_RecordComponent>::operator[](key_type const &key)
{
auto it = this->find(key);
if (it != this->end())
Expand All @@ -210,9 +224,9 @@ BaseRecord<T_elem>::operator[](key_type const &key)
}
}

template <typename T_elem>
inline typename BaseRecord<T_elem>::mapped_type &
BaseRecord<T_elem>::operator[](key_type &&key)
template <typename T_elem, typename T_RecordComponent>
inline typename BaseRecord<T_elem, T_RecordComponent>::mapped_type &
BaseRecord<T_elem, T_RecordComponent>::operator[](key_type &&key)
{
auto it = this->find(key);
if (it != this->end())
Expand All @@ -236,9 +250,9 @@ BaseRecord<T_elem>::operator[](key_type &&key)
}
}

template <typename T_elem>
inline typename BaseRecord<T_elem>::size_type
BaseRecord<T_elem>::erase(key_type const &key)
template <typename T_elem, typename T_RecordComponent>
inline typename BaseRecord<T_elem, T_RecordComponent>::size_type
BaseRecord<T_elem, T_RecordComponent>::erase(key_type const &key)
{
bool const keyScalar = (key == RecordComponent::SCALAR);
size_type res;
Expand Down Expand Up @@ -266,9 +280,9 @@ BaseRecord<T_elem>::erase(key_type const &key)
return res;
}

template <typename T_elem>
inline typename BaseRecord<T_elem>::iterator
BaseRecord<T_elem>::erase(iterator res)
template <typename T_elem, typename T_RecordComponent>
inline typename BaseRecord<T_elem, T_RecordComponent>::iterator
BaseRecord<T_elem, T_RecordComponent>::erase(iterator res)
{
bool const keyScalar = (res->first == RecordComponent::SCALAR);
iterator ret;
Expand Down Expand Up @@ -296,21 +310,28 @@ BaseRecord<T_elem>::erase(iterator res)
return ret;
}

template <typename T_elem>
inline std::array<double, 7> BaseRecord<T_elem>::unitDimension() const
template <typename T_elem, typename T_RecordComponent>
bool BaseRecord<T_elem, T_RecordComponent>::empty() const noexcept
{
return T_Container::empty();
}

template <typename T_elem, typename T_RecordComponent>
inline std::array<double, 7>
BaseRecord<T_elem, T_RecordComponent>::unitDimension() const
{
return this->getAttribute("unitDimension")
.template get<std::array<double, 7> >();
}

template <typename T_elem>
inline bool BaseRecord<T_elem>::scalar() const
template <typename T_elem, typename T_RecordComponent>
inline bool BaseRecord<T_elem, T_RecordComponent>::scalar() const
{
return get().m_containsScalar;
}

template <typename T_elem>
inline void BaseRecord<T_elem>::readBase()
template <typename T_elem, typename T_RecordComponent>
inline void BaseRecord<T_elem, T_RecordComponent>::readBase()
{
using DT = Datatype;
Parameter<Operation::READ_ATT> aRead;
Expand Down Expand Up @@ -354,8 +375,8 @@ inline void BaseRecord<T_elem>::readBase()
"Unexpected Attribute datatype for 'timeOffset'");
}

template <typename T_elem>
inline void BaseRecord<T_elem>::flush(
template <typename T_elem, typename T_RecordComponent>
inline void BaseRecord<T_elem, T_RecordComponent>::flush(
std::string const &name, internal::FlushParams const &flushParams)
{
if (!this->written() && this->empty())
Expand All @@ -369,8 +390,8 @@ inline void BaseRecord<T_elem>::flush(
// method doesn't do it
}

template <typename T_elem>
inline bool BaseRecord<T_elem>::dirtyRecursive() const
template <typename T_elem, typename T_RecordComponent>
inline bool BaseRecord<T_elem, T_RecordComponent>::dirtyRecursive() const
{
if (this->dirty())
{
Expand Down
2 changes: 1 addition & 1 deletion include/openPMD/backend/PatchRecordComponent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class PatchRecordComponent : public BaseRecordComponent
{
template <typename T, typename T_key, typename T_container>
friend class Container;
template <typename>
template <typename, typename>
friend class BaseRecord;
friend class ParticlePatches;
friend class PatchRecord;
Expand Down
2 changes: 1 addition & 1 deletion include/openPMD/backend/Writable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class Writable final
{
friend class internal::AttributableData;
friend class Attributable;
template <typename T_elem>
template <typename T_elem, typename T_RecordComponent>
friend class BaseRecord;
template <typename T_elem>
friend class BaseRecordInterface;
Expand Down

0 comments on commit f734cbd

Please sign in to comment.