37#include "kamping/assertion_levels.hpp"
40#include "kamping/kabool.hpp"
42#include "kamping/span.hpp"
43#include "kassert/kassert.hpp"
74#if KASSERT_ENABLED(KAMPING_ASSERTION_LEVEL_NORMAL)
83#if KASSERT_ENABLED(KAMPING_ASSERTION_LEVEL_NORMAL)
88#if KASSERT_ENABLED(KAMPING_ASSERTION_LEVEL_NORMAL)
95template <
typename,
typename =
void>
109template <
class T,
template <
class...>
class Template>
125template <
template <
class...>
class Template,
class...
Args>
131template <
typename T,
typename =
void>
142 typename std::enable_if<!has_value_type_v<std::remove_cv_t<std::remove_reference_t<T>>>>::type> =
false;
151 std::is_same_v<typename std::remove_cv_t<std::remove_reference_t<T>>::value_type,
bool>;
162template <
typename Container>
169template <
typename Container>
189template <
template <
typename...>
typename Container>
193 template <
typename...
Ts>
198template <
template <
typename...>
typename Container>
206template <
template <
typename...>
typename Container>
237template <
typename,
typename =
void>
304template <
typename MemberType>
341 typename ValueType = default_value_type_tag>
369 std::conditional_t<is_modifiable, MemberType, MemberType const>;
389 std::is_same_v<ValueType, default_value_type_tag> || std::is_same_v<ValueType, value_type>,
390 "The requested value type of the buffer does not match the value type of the underlying container"
393 std::conditional_t<is_modifiable, value_type, value_type const>;
397 "A constant data buffer requires the that the resize policy is no_resize."
401 "A single element data buffer requires the that the resize policy is no_resize."
406 "The underlying container does not provide a resize function, which is required by the resize policy."
411 template <
bool enabled = ownership == BufferOwnership::referencing, std::enable_if_t<enabled,
bool> = true>
416 template <
bool enabled = ownership == BufferOwnership::owning, std::enable_if_t<enabled,
bool> = true>
420 template <
bool enabled = allocation == BufferAllocation::lib_allocated, std::enable_if_t<enabled,
bool> = true>
422 static_assert(
ownership == BufferOwnership::owning,
"Lib allocated buffers must be owning");
423 static_assert(
is_modifiable,
"Lib allocated buffers must be modifiable");
445 typename std::enable_if_t<_resize_policy == resize_to_fit, bool> =
true>
460 typename std::enable_if_t<_resize_policy == grow_only, bool> =
true>
463 if (this->
size() < size) {
470 typename std::enable_if_t<_resize_policy == no_resize, bool> =
true>
479 template <
typename SizeFunc>
512 return {this->
data(), this->
size()};
519 return {this->
data(), this->
size()};
524 template <
bool enabled = is_single_element, std::enable_if_t<enabled,
bool> = true>
537 "Buffers based on std::vector<bool> are not supported, use std::vector<kamping::kabool> instead."
544 template <
bool enabled = modifiability == BufferModifiability::modifiable, std::enable_if_t<enabled,
bool> = true>
550 "Buffers based on std::vector<bool> are not supported, use std::vector<kamping::kabool> instead."
559 template <
bool enabled = is_owning, std::enable_if_t<enabled,
bool> = true>
563 "Moving out of a reference should not be done because it would leave "
564 "a users container in an unspecified state."
617 std::conditional_t<is_modifiable, MemberType, MemberType const>;
629 template <
bool enabled = ownership == BufferOwnership::referencing, std::enable_if_t<enabled,
bool> = true>
634 template <
bool enabled = ownership == BufferOwnership::owning, std::enable_if_t<enabled,
bool> = true>
646 template <
bool enabled = modifiability == BufferModifiability::modifiable, std::enable_if_t<enabled,
bool> = true>
656 template <
bool enabled = is_owning, std::enable_if_t<enabled,
bool> = true>
660 "Moving out of a reference should not be done because it would leave "
661 "a users container in an unspecified state."
676template <
typename Data, ParameterType type, BufferType buffer_type_param>
715 template <
typename SizeFunc>
724template <
typename T, ParameterType type, BufferType buffer_type_param>
755 std::is_rvalue_reference_v<Data&&> ? BufferOwnership::owning : BufferOwnership::referencing;
764 std::remove_const_t<std::remove_reference_t<Data>>,
771 BufferAllocation::user_allocated,
796 typename ValueType = default_value_type_tag,
803 BufferModifiability::modifiable,
804 BufferOwnership::owning,
807 BufferAllocation::lib_allocated,
832 typename ValueType = default_value_type_tag,
833 template <
typename...>
838 !std::is_same_v<ValueType, default_value_type_tag>,
839 "Value type for new library allocated container can not be deduced."
845 BufferModifiability::modifiable,
846 BufferOwnership::owning,
849 BufferAllocation::lib_allocated,
Helper functions that make casts safer.
STL-compatible allocator for requesting memory using the builtin MPI allocator.
Definition allocator.hpp:32
Data buffer used for named parameters.
Definition data_buffer.hpp:342
DataBuffer(MemberType container)
Constructor for owning ContainerBasedBuffer.
Definition data_buffer.hpp:417
value_type const * data() const
Get const access to the underlying container.
Definition data_buffer.hpp:488
static constexpr bool is_lib_allocated
Indicates whether the buffer is allocated by KaMPIng.
Definition data_buffer.hpp:358
void resize_if_requested(SizeFunc &&compute_required_size)
Resizes the underlying container if the buffer the buffer's resize policy allows and resizing is nece...
Definition data_buffer.hpp:480
Span< value_type const > get() const
Get read-only access to the underlying storage.
Definition data_buffer.hpp:510
static constexpr TParameterType parameter_type
The type of parameter this buffer represents.
Definition data_buffer.hpp:344
value_type const get_single_element() const
Get the single element wrapped by this object.
Definition data_buffer.hpp:525
std::conditional_t< ownership==BufferOwnership::owning, MemberTypeWithConst, MemberTypeWithConst & > MemberTypeWithConstAndRef
Definition data_buffer.hpp:380
static constexpr bool is_single_element
Definition data_buffer.hpp:365
static constexpr bool is_owning
Indicates whether the buffer owns its underlying storage.
Definition data_buffer.hpp:360
Span< value_type_with_const > get()
Get access to the underlying storage.
Definition data_buffer.hpp:517
static constexpr BufferType buffer_type
The type of the buffer, i.e., in, out, or in_out.
Definition data_buffer.hpp:347
static constexpr BufferResizePolicy resize_policy
The policy specifying in which cases the buffer shall be resized.
Definition data_buffer.hpp:349
size_t size() const
The size of the underlying container.
Definition data_buffer.hpp:427
value_type_with_const * data()
Get access to the underlying container.
Definition data_buffer.hpp:499
MemberType const & underlying() const
Provides access to the underlying data.
Definition data_buffer.hpp:532
static constexpr bool is_modifiable
Indicates whether the underlying storage is modifiable.
Definition data_buffer.hpp:363
DataBuffer(MemberTypeWithConst &container)
Constructor for referencing ContainerBasedBuffer.
Definition data_buffer.hpp:412
void resize(size_t size)
Resizes the underlying container such that it holds exactly size elements of value_type.
Definition data_buffer.hpp:446
std::conditional_t< is_modifiable, MemberType, MemberType const > MemberTypeWithConst
Definition data_buffer.hpp:368
typename ValueTypeWrapper<!is_single_element, MemberType >::value_type value_type
Value type of the buffer.
Definition data_buffer.hpp:386
std::conditional_t< is_modifiable, value_type, value_type const > value_type_with_const
Definition data_buffer.hpp:392
static constexpr bool is_out_buffer
true if the buffer is an out or in/out buffer that results will be written to and false otherwise.
Definition data_buffer.hpp:354
DataBuffer()
Constructor for lib allocated ContainerBasedBuffer.
Definition data_buffer.hpp:421
MemberType & underlying()
Provides access to the underlying data.
Definition data_buffer.hpp:545
MemberTypeWithConst extract()
Extract the underlying container. This will leave the DataBuffer in an unspecified state.
Definition data_buffer.hpp:560
Empty buffer that can be used as default argument for optional buffer parameters.
Definition data_buffer.hpp:677
static constexpr BufferType buffer_type
The type of the buffer, usually ignore for this special buffer.
Definition data_buffer.hpp:683
size_t size() const
Get the number of elements in the underlying storage.
Definition data_buffer.hpp:694
static constexpr bool is_single_element
An empty buffer contains no elements.
Definition data_buffer.hpp:689
static constexpr bool is_modifiable
This pseudo buffer is not modifiable since it represents no actual buffer.
Definition data_buffer.hpp:680
Span< value_type > get() const
Returns a span containing a nullptr.
Definition data_buffer.hpp:706
static constexpr bool is_out_buffer
An empty buffer is never output.
Definition data_buffer.hpp:687
value_type const * data() const
Get a nullptr.
Definition data_buffer.hpp:700
static constexpr ParameterType parameter_type
The type of parameter this buffer represents.
Definition data_buffer.hpp:679
static constexpr bool is_lib_allocated
An empty buffer is not allocated.
Definition data_buffer.hpp:688
static constexpr bool is_owning
An empty buffer does not own anything.
Definition data_buffer.hpp:690
void resize_if_requested(SizeFunc &&compute_required_size)
Resizes the underlying container if the buffer the buffer's resize policy allows and resizing is nece...
Definition data_buffer.hpp:716
static constexpr BufferResizePolicy resize_policy
An empty buffer can not be resized.
Definition data_buffer.hpp:686
A more generic version of a DataBuffer which stores an object of type.
Definition data_buffer.hpp:596
MemberType const & underlying() const
Provides access to the underlying data.
Definition data_buffer.hpp:639
static constexpr BufferType buffer_type
The type of the buffer, i.e., in, out, or in_out.
Definition data_buffer.hpp:601
std::conditional_t< is_modifiable, MemberType, MemberType const > MemberTypeWithConst
Definition data_buffer.hpp:616
std::conditional_t< ownership==BufferOwnership::owning, MemberTypeWithConst, MemberTypeWithConst & > MemberTypeWithConstAndRef
Definition data_buffer.hpp:621
static constexpr bool is_out_buffer
true if the buffer is an out or in/out buffer that results will be written to and false otherwise.
Definition data_buffer.hpp:605
GenericDataBuffer(MemberType container)
Constructor for owning GenericDataBuffer.
Definition data_buffer.hpp:635
GenericDataBuffer(MemberTypeWithConst &container)
Constructor for referencing GenericDataBuffer.
Definition data_buffer.hpp:630
MemberTypeWithConst extract()
Extract the underlying container. This will leave the DataBuffer in an unspecified state.
Definition data_buffer.hpp:657
static constexpr TParameterType parameter_type
The type of parameter this buffer represents.
Definition data_buffer.hpp:598
static constexpr bool is_owning
Indicates whether the buffer owns its underlying storage.
Definition data_buffer.hpp:608
MemberType & underlying()
Provides access to the underlying data.
Definition data_buffer.hpp:647
static constexpr bool is_modifiable
Indicates whether the underlying storage is modifiable.
Definition data_buffer.hpp:611
Base object for parameter objects which deletes copy constructor and assignment operator and enables ...
Definition data_buffer.hpp:58
void set_extracted()
Set the extracted flag to indicate that the status stored in this buffer has been moved out.
Definition data_buffer.hpp:73
ParameterObjectBase & operator=(ParameterObjectBase const &)=delete
Copy assignment operator is deleted as buffers should only be moved.
ParameterObjectBase & operator=(ParameterObjectBase &&)=default
Move assignment operator.
ParameterObjectBase(ParameterObjectBase &&)=default
Move constructor.
void kassert_not_extracted(std::string const message) const
Throws an assertion if the extracted flag is set, i.e. the underlying status has been moved out.
Definition data_buffer.hpp:82
ParameterObjectBase(ParameterObjectBase const &)=delete
Copy constructor is deleted as buffers should only be moved.
typename T::value_type value_type
The value type of T.
Definition data_buffer.hpp:298
Wrapper to get the value type of a non-container type (aka the type itself).
Definition data_buffer.hpp:285
T value_type
The value type of T.
Definition data_buffer.hpp:287
constexpr int normal
Default assertion level. This level is used if no assertion level is specified.
Definition assertion_levels.hpp:19
constexpr BufferResizePolicy grow_only
Definition data_buffer.hpp:273
constexpr BufferResizePolicy resize_to_fit
Definition data_buffer.hpp:276
static constexpr bool is_alloc_new_using_v
Helper to decide if an allocation tag is an AllocNewUsingT.
Definition data_buffer.hpp:203
static constexpr auto alloc_container_of
Convenience wrapper for creating library allocated containers. See AllocContainerOfT for details.
Definition data_buffer.hpp:224
BufferResizePolicy
Enum to specify in which cases a buffer is resized.
Definition data_buffer.hpp:262
static constexpr bool is_alloc_new_v
Helper to decide if an allocation tag is an AllocNewT.
Definition data_buffer.hpp:174
static constexpr bool is_alloc_container_of_v
Helper to decide if an allocation tag is an AllocContainerOfT.
Definition data_buffer.hpp:228
static constexpr auto alloc_new_using
Convenience wrapper for creating library allocated containers. See AllocNewUsingT for details.
Definition data_buffer.hpp:199
constexpr BufferResizePolicy no_resize
Definition data_buffer.hpp:270
static constexpr auto alloc_new
Convenience wrapper for creating library allocated containers. See AllocNewT for details.
Definition data_buffer.hpp:170
@ no_resize
Policy indicating that the underlying buffer shall never be resized.
ParameterType
Each input parameter to one of the MPI calls wrapped by KaMPIng needs to has one of the following tag...
Definition named_parameter_types.hpp:33
Macros for generating concept-like type traits to check for member functions of objects.
#define KAMPING_MAKE_HAS_MEMBER(Member)
Macro for generating has_member_xxx and has_member_xxx_v templates. They return true if the type give...
Definition has_member.hpp:91
File containing the parameter types used by the KaMPIng library.
constexpr bool has_data_member_v
Boolean value helping to decide if data type has .data() method.
Definition data_buffer.hpp:248
constexpr BufferResizePolicy maximum_viable_resize_policy
for a given
Definition data_buffer.hpp:305
static constexpr bool is_vector_bool_v
Boolean value helping to check if a type is an instance of std::vector<bool>.
Definition data_buffer.hpp:132
static constexpr bool has_value_type_v
Boolean value helping to decide if type has a value_type member type.
Definition data_buffer.hpp:96
BufferAllocation
Enum to specify whether a buffer is allocated by the library or the user.
Definition data_buffer.hpp:255
constexpr bool is_empty_data_buffer_v
Helper to decide if a type is an instance of EmptyDataBuffer.
Definition data_buffer.hpp:721
BufferOwnership
Enum to specify whether a buffer owns its data.
Definition data_buffer.hpp:253
BufferModifiability
Enum to specify whether a buffer is modifiable.
Definition data_buffer.hpp:251
auto make_data_buffer(Data &&data)
Creates a user allocated DataBuffer containing the supplied data (a container or a single element)
Definition data_buffer.hpp:753
BufferType
Enum to specify whether a buffer is an in buffer of an out buffer. Out buffer will be used to directl...
Definition data_buffer.hpp:258
constexpr internal::ignore_t< T > ignore
Tag for parameters that can be omitted on some PEs (e.g., root PE, or non-root PEs).
Definition parameter_objects.hpp:570
Buffer allocation tag used for indicating that a buffer of type T should be allocated by KaMPIng.
Definition data_buffer.hpp:217
T value_type
The value type to use for the allocated buffer.
Definition data_buffer.hpp:219
Buffer allocation tag used for indicating that a buffer should be allocated by KaMPIng.
Definition data_buffer.hpp:163
Buffer allocation tag used for indicating that a buffer should be allocated by KaMPIng.
Definition data_buffer.hpp:190
tag type to indicate that the value_type should be inferred from the container
Definition data_buffer.hpp:291
Helper to decide if data type has .data() method.
Definition data_buffer.hpp:238
Type trait to check if a type is an instance of a templated type.
Definition data_buffer.hpp:110