Supported data types#
Overview#
MPL enables processes to send and to receive messages containing data of different data types. The following elementary data types are supported by MPL in all messaging operations:
all standard integer types, signed as well as unsigned, such as
int
,unsigned int
etc.,the character types
char
,signed char
,unsigned char
as well as the wide character typeswchar_t
,char8_t
(if compiler supports C++-20 features),char16_t
andchar32_t
,the floating point types
float
,double
andlong double
,the complex types
std::complex<float>
,std::complex<double>
andstd::complex<long double>
,the Boolean type
bool
,the type
std::byte
andenumeration types.
MPL would not be very limited if it would only support these elementary data types. Therefore, MPL comes also with some support for user-defined data types. To be able to exchange data of custom types via a message passing library the library must have some knowledge about the internal representation of user-defined data types. Because C++ has very limited type introspection capabilities, this knowledge cannot be obtained automatically by the message passing library. Instead, information about the internal structure of user-defined types (structures and classes) has to be exposed explicitly to the message passing library. Therefore, MPL supports message exchange of data when information about the internal representation can be obtained automatically and introduces a mechanism to expose the internal representation of custom types to MPL if this is not possible.
The data types, where MPL can infer their internal representation are
C arrays of constant size (one-dimensional and multidimensional arras up to 4 dimensions) and
the template classes
std::array
,std::pair
andstd::tuple
of the C++ Standard Template Library.
The only limitation is, that the C arrays as well as the mentioned STL template classes must hold data elements of types that can be sent or received by MPL, e.g., the elementary types mentioned above. This rule can be applied recursively, which allows one to build quite complex data structures. This means, for example, one can send and receive data of type std::pair<int, double>
, because int
and double
can be sent or received. But also std::array<std::pair<int, double>, 8>
, which represents 8 pairs of int
and double
, can be used in a message.
User-defined data structures usually come as structures or classes. Provided that these classes hold only non-static non-const data members of types, which MPL is able to send or receive, it is possible to expose these data members to MPL via template specialization of the class struct_builder
such that messages containing objects of these classes can be exchanged. Template specialization of the class struct_builder
is illustrated in the example program in section Using structs. The specialized template has to derived from base_struct_builder
and the internal data representation of the user-defined class is exposed to MPL in the constructor.
Class documentation#
Every new template specialization of the class struct_builder
must derive from base_struct_builder
. The template specialization of struct_builder
defines a default constructor that collects the required type information by utilizing the struct_layout
class as demonstrated in the example program in section Using structs.
Template class base_struct_builder#
-
template<typename T>
class base_struct_builder# Base class used to manage information about structures/classes and their public members.
See also
class
struct_builder
- Template Parameters:
T – the structure or class type
Public Functions
-
base_struct_builder(const base_struct_builder&) = delete#
-
void operator=(const base_struct_builder&) = delete#
Friends
- friend class detail::datatype_traits_impl< T, void >
Template class struct_builder#
-
template<typename T>
class struct_builder# Template class used to manage information about structures/classes and their public members.
See also
class
base_struct_builder
Note
This template class needs to be specialized for each structure/class type that shall be used in message passing operations. Specializations must derive from class
base_struct_builder
. MPL provides some specializations for common types.- Template Parameters:
T – the structure or class type
Public Types
-
using data_type_category = detail::unsupported_type#
-
template<typename T, std::size_t N>
class struct_builder<std::array<T, N>> : public base_struct_builder<std::array<T, N>># Specialization of
struct_builder
for fixed-size one-dimensional STL arrays.See also
class
struct_builder
- Template Parameters:
T – type of the array elements
N – array size
Public Functions
-
inline struct_builder()#
-
template<typename T1, typename T2>
class struct_builder<std::pair<T1, T2>> : public base_struct_builder<std::pair<T1, T2>># Specialization of
struct_builder
for STL pairs.See also
class
struct_builder
- Template Parameters:
T1 – type of first member of the STL pair
T2 – type of second member of the STL pair
Public Functions
-
inline struct_builder()#
-
template<typename ...Ts>
class struct_builder<std::tuple<Ts...>> : public base_struct_builder<std::tuple<Ts...>># Specialization of
struct_builder
for STL tuples.See also
class
struct_builder
- Template Parameters:
Ts – parameter pack representing the types of the members of the STL tuple
Public Functions
-
inline struct_builder()#
-
template<typename T, std::size_t N0>
class struct_builder<T[N0]> : public base_struct_builder<T[N0]># Specialization of
struct_builder
for fixed-size one-dimensional C-style arrays.See also
class
struct_builder
- Template Parameters:
T – type of the array elements
N0 – array size
Public Functions
-
inline struct_builder()#
-
template<typename T, std::size_t N0, std::size_t N1>
class struct_builder<T[N0][N1]> : public base_struct_builder<T[N0][N1]># Specialization of
struct_builder
for fixed-size two-dimensional C-style arrays.See also
class
struct_builder
- Template Parameters:
T – type of the array elements
N0 – array size, first dimension
N1 – array size, second dimension
Public Functions
-
inline struct_builder()#
-
template<typename T, std::size_t N0, std::size_t N1, std::size_t N2>
class struct_builder<T[N0][N1][N2]> : public base_struct_builder<T[N0][N1][N2]># Specialization of
struct_builder
for fixed-size three-dimensional C-style arrays.See also
class
struct_builder
- Template Parameters:
T – type of the array elements
N0 – array size, first dimension
N1 – array size, second dimension
N2 – array size, third dimension
Public Functions
-
inline struct_builder()#
-
template<typename T, std::size_t N0, std::size_t N1, std::size_t N2, std::size_t N3>
class struct_builder<T[N0][N1][N2][N3]> : public base_struct_builder<T[N0][N1][N2][N3]># Specialization of
struct_builder
for fixed-size four-dimensional C-style arrays.See also
class
struct_builder
- Template Parameters:
T – type of the array elements
N0 – array size, first dimension
N1 – array size, second dimension
N2 – array size, third dimension
N3 – array size, fourth dimension
Public Functions
-
inline struct_builder()#
Template class struct_layout#
-
template<typename S>
class struct_layout# layout class for storing meta information about the public members of structures
- Template Parameters:
S – the struct or class type, the public members of which are managed
Public Functions
-
inline struct_layout ®ister_struct(const S &x)#
starts to register a struct type
- Parameters:
x – an instance of type
S
(the template parameter of classstruct_layout
)- Returns:
reference to this
struct_layout
object (allows chaining)
-
template<typename T>
inline struct_layout ®ister_element(T &x)# registers a struct member
- Parameters:
x – a member of an instance of type
S
(the template parameter of classstruct_layout
)- Returns:
reference to this
struct_layout
object (allows chaining)
Friends
- friend class base_struct_builder< S >