diff --git a/include/kamping/data_buffer.hpp b/include/kamping/data_buffer.hpp index 4728cd106..ca3b965a3 100644 --- a/include/kamping/data_buffer.hpp +++ b/include/kamping/data_buffer.hpp @@ -48,9 +48,8 @@ namespace kamping { namespace internal { -/// @brief Base class containing logic to eo ensure whether a buffers data has already been extracted. This only has -/// effects if an appropiate assertion level is set. -class ExtractionStatusBase { +/// @brief Base class containing logic to verify whether a buffer's data has already been extracted. This only has effects if an appropiate assertion level is set. +class Extractable { protected: /// @brief Set the extracted flag to indicate that the status stored in this buffer has been moved out. void set_extracted() { @@ -82,37 +81,37 @@ class ExtractionStatusBase { /// can not be default constructed, due to the missing implementation in the base class. Because we provide a (default) /// implementation for the move constructor (assignment) in the base class, the derived class can construct default /// implementations. -template -class ParameterObjectBase : protected ExtractionStatusBase { +template +class CopyMoveEnabler { protected: - constexpr ParameterObjectBase() = default; - ~ParameterObjectBase() = default; + constexpr CopyMoveEnabler() = default; + ~CopyMoveEnabler() = default; /// @brief Copy constructor is deleted as buffers should only be moved. - ParameterObjectBase(ParameterObjectBase const&) = delete; + CopyMoveEnabler(CopyMoveEnabler const&) = delete; /// @brief Copy assignment operator is deleted as buffers should only be moved. - ParameterObjectBase& operator=(ParameterObjectBase const&) = delete; + CopyMoveEnabler& operator=(CopyMoveEnabler const&) = delete; /// @brief Move constructor. - ParameterObjectBase(ParameterObjectBase&&) = default; + CopyMoveEnabler(CopyMoveEnabler&&) = default; /// @brief Move assignment operator. - ParameterObjectBase& operator=(ParameterObjectBase&&) = default; + CopyMoveEnabler& operator=(CopyMoveEnabler&&) = default; }; /// @brief Specialisation of ParameterObjectBase which possesses a copy constructor. template <> -class ParameterObjectBase : protected ExtractionStatusBase { +class CopyMoveEnabler { protected: - constexpr ParameterObjectBase() = default; - ~ParameterObjectBase() = default; + constexpr CopyMoveEnabler() = default; + ~CopyMoveEnabler() = default; /// @brief Copy constructor is enabled (this is okay for buffers which only reference their data) - ParameterObjectBase(ParameterObjectBase const&) = default; + CopyMoveEnabler(CopyMoveEnabler const&) = default; /// @brief Copy assignment operator is deleted as buffers should only be moved. - ParameterObjectBase& operator=(ParameterObjectBase const&) = delete; + CopyMoveEnabler& operator=(CopyMoveEnabler const&) = delete; /// @brief Move constructor. - ParameterObjectBase(ParameterObjectBase&&) = default; + CopyMoveEnabler(CopyMoveEnabler&&) = default; /// @brief Move assignment operator. - ParameterObjectBase& operator=(ParameterObjectBase&&) = default; + CopyMoveEnabler& operator=(CopyMoveEnabler&&) = default; }; /// @brief Boolean value helping to decide if type has a \c value_type member type. @@ -369,7 +368,7 @@ template < BufferResizePolicy buffer_resize_policy_param, BufferAllocation allocation = BufferAllocation::user_allocated, typename ValueType = default_value_type_tag> -class DataBuffer : private ParameterObjectBase> { +class DataBuffer : private CopyMoveEnabler>, private Extractable { public: static constexpr TParameterType parameter_type = parameter_type_param; ///< The type of parameter this buffer represents. @@ -455,7 +454,7 @@ class DataBuffer : private ParameterObjectBasekassert_not_extracted("Cannot get the size of a buffer that has already been extracted."); + kassert_not_extracted("Cannot get the size of a buffer that has already been extracted."); if constexpr (is_single_element) { return 1; } else { @@ -474,7 +473,7 @@ class DataBuffer : private ParameterObjectBase = true> void resize(size_t size) { - this->kassert_not_extracted("Cannot resize a buffer that has already been extracted."); + kassert_not_extracted("Cannot resize a buffer that has already been extracted."); underlying().resize(size); } @@ -489,7 +488,7 @@ class DataBuffer : private ParameterObjectBase = true> void resize(size_t size) { - this->kassert_not_extracted("Cannot resize a buffer that has already been extracted."); + kassert_not_extracted("Cannot resize a buffer that has already been extracted."); if (this->size() < size) { underlying().resize(size); } @@ -516,7 +515,7 @@ class DataBuffer : private ParameterObjectBasekassert_not_extracted("Cannot get a pointer to a buffer that has already been extracted."); + kassert_not_extracted("Cannot get a pointer to a buffer that has already been extracted."); if constexpr (is_single_element) { return &underlying(); } else { @@ -527,7 +526,7 @@ class DataBuffer : private ParameterObjectBasekassert_not_extracted("Cannot get a pointer to a buffer that has already been extracted."); + kassert_not_extracted("Cannot get a pointer to a buffer that has already been extracted."); if constexpr (is_single_element) { return &underlying(); } else { @@ -538,14 +537,14 @@ class DataBuffer : private ParameterObjectBase get() const { - this->kassert_not_extracted("Cannot get a buffer that has already been extracted."); + kassert_not_extracted("Cannot get a buffer that has already been extracted."); return {this->data(), this->size()}; } /// @brief Get access to the underlying storage. /// @return Span referring to the underlying storage. Span get() { - this->kassert_not_extracted("Cannot get a buffer that has already been extracted."); + kassert_not_extracted("Cannot get a buffer that has already been extracted."); return {this->data(), this->size()}; } @@ -553,14 +552,14 @@ class DataBuffer : private ParameterObjectBase = true> value_type const get_single_element() const { - this->kassert_not_extracted("Cannot get an element from a buffer that has already been extracted."); + kassert_not_extracted("Cannot get an element from a buffer that has already been extracted."); return underlying(); } /// @brief Provides access to the underlying data. /// @return A reference to the data. MemberType const& underlying() const { - this->kassert_not_extracted("Cannot get a buffer that has already been extracted."); + kassert_not_extracted("Cannot get a buffer that has already been extracted."); // this assertion is only checked if the buffer is actually accessed. static_assert( !is_vector_bool_v, @@ -573,7 +572,7 @@ class DataBuffer : private ParameterObjectBase = true> MemberType& underlying() { - this->kassert_not_extracted("Cannot get a buffer that has already been extracted."); + kassert_not_extracted("Cannot get a buffer that has already been extracted."); // this assertion is only checked if the buffer is actually accessed. static_assert( !is_vector_bool_v, @@ -593,10 +592,10 @@ class DataBuffer : private ParameterObjectBasekassert_not_extracted("Cannot extract a buffer that has already been extracted."); + kassert_not_extracted("Cannot extract a buffer that has already been extracted."); auto extracted = std::move(underlying()); // we set is_extracted here because otherwise the call to underlying() would fail - this->set_extracted(); + set_extracted(); return extracted; } @@ -623,7 +622,7 @@ template < BufferModifiability modifiability, BufferOwnership ownership, BufferType buffer_type_param> -class GenericDataBuffer : private ParameterObjectBase> { +class GenericDataBuffer : private CopyMoveEnabler>, private Extractable { public: static constexpr TParameterType parameter_type = parameter_type_param; ///< The type of parameter this buffer represents. @@ -667,7 +666,7 @@ class GenericDataBuffer : private ParameterObjectBasekassert_not_extracted("Cannot get a buffer that has already been extracted."); + kassert_not_extracted("Cannot get a buffer that has already been extracted."); return _data; } @@ -675,7 +674,7 @@ class GenericDataBuffer : private ParameterObjectBase = true> MemberType& underlying() { - this->kassert_not_extracted("Cannot get a buffer that has already been extracted."); + kassert_not_extracted("Cannot get a buffer that has already been extracted."); return _data; } @@ -690,10 +689,10 @@ class GenericDataBuffer : private ParameterObjectBasekassert_not_extracted("Cannot extract a buffer that has already been extracted."); + kassert_not_extracted("Cannot extract a buffer that has already been extracted."); auto extracted = std::move(underlying()); // we set is_extracted here because otherwise the call to underlying() would fail - this->set_extracted(); + set_extracted(); return extracted; } diff --git a/include/kamping/parameter_objects.hpp b/include/kamping/parameter_objects.hpp index d1deab348..ddd46cb50 100644 --- a/include/kamping/parameter_objects.hpp +++ b/include/kamping/parameter_objects.hpp @@ -419,7 +419,7 @@ class RankDataBuffer final : private DataBuffer< /// This is a specialization for MPI_ANY_SOURCE which only implements /// \ref rank_signed(), without allocating any additional memory. template -class RankDataBuffer : private ParameterObjectBase<> { +class RankDataBuffer : private CopyMoveEnabler<> { public: static constexpr ParameterType parameter_type = type; ///< The type of parameter this object encapsulates. static constexpr RankType rank_type = RankType::any; ///< The rank type. @@ -444,7 +444,7 @@ class RankDataBuffer : private ParameterObjectBase<> { /// This is a specialization for MPI_PROC_NULL which only implements /// \ref rank_signed(), without allocating any additional memory. template -class RankDataBuffer : private ParameterObjectBase<> { +class RankDataBuffer : private CopyMoveEnabler<> { public: static constexpr ParameterType parameter_type = type; ///< The type of parameter this object encapsulates. static constexpr RankType rank_type = RankType::null; ///< The rank type. @@ -475,7 +475,7 @@ using send_mode_list = /// @brief Parameter object for send_mode encapsulating the send mode compile-time tag. /// @tparam SendModeTag The send mode. template -struct SendModeParameter : private ParameterObjectBase<> { +struct SendModeParameter : private CopyMoveEnabler<> { static_assert(send_mode_list::contains, "Unsupported send mode."); static constexpr ParameterType parameter_type = ParameterType::send_mode; ///< The parameter type. using send_mode = SendModeTag; ///< The send mode. @@ -514,7 +514,7 @@ class TagParam {}; /// @brief Encapsulates a message tag. Specialization if an explicit tag value is provided. template <> -class TagParam : private ParameterObjectBase<> { +class TagParam : private CopyMoveEnabler<> { public: /// @param tag The tag. TagParam(int tag) : _tag_value(tag) {} @@ -538,7 +538,7 @@ class TagParam : private ParameterObjectBase<> { /// @brief Encapsulates a message tag. Specialization if the value is MPI_ANY_TAG. template <> -class TagParam : private ParameterObjectBase<> { +class TagParam : private CopyMoveEnabler<> { public: static constexpr ParameterType parameter_type = ParameterType::tag; ///< The parameter type. static constexpr TagType tag_type = TagType::any; ///< The tag type.