1.3.1. Convert

template<typename Type>
struct eprosima::is::utils::Convert

A utility to help with converting data between generic DynamicData field objects and middleware-specific data structures.

This struct will work as-is on primitive types (a.k.a. arithmetic types or strings), but a template specialization for converting to or from any complex class types should be created.

Public Types

using native_type = Type

Alias for the Type.

Public Static Functions

void from_xtype_field(const xtypes::ReadableDynamicDataRef &from, native_type &to)

Move data from a xTypes DynamicData field to a native middleware data structure.

Parameters
  • [in] from: A readable reference to the DynamicData field to be transferred.

  • [in] to: The destination native middleware data structure.

void to_xtype_field(const native_type &from, xtypes::WritableDynamicDataRef to)

Move data from a native middleware data structure to a xTypes DynamicData field.

Parameters
  • [in] from: A readable reference to the middleware native data structure to be transferred.

  • [in] to: A writable reference to the target DynamicData field.

Public Static Attributes

constexpr bool type_is_primitive = std::is_arithmetic<Type>::value || std::is_same<std::string, Type>::value || std::is_same<std::basic_string<char16_t>, Type>::value

Const expression to check if the type is primitive or not.

struct eprosima::is::utils::CharConvert

A class that helps create a Convert<> specialization for managing some char issues.

‘rosidl’ parse ‘char’ types as ‘signed’ values from ‘msg’ files and parse as ‘unsigned’ from idl files. This create a mismatched between types. This patch solves this issue when the native type differs from the DynamicData type for this specific case.

Note

This specialization can be removed safety if rosidl modifies its behavior.

Subclassed by eprosima::is::utils::Convert< char >

Public Types

using native_type = char

Alias for the Type.

Public Static Functions

void from_xtype_field(const xtypes::ReadableDynamicDataRef &from, native_type &to)

Documentation inherited from Convert.

void to_xtype_field(const native_type &from, xtypes::WritableDynamicDataRef to)

Documentation inherited from Convert.

template<typename ElementType, template<typename, typename> class NativeType, typename Allocator, std::size_t UpperBound, std::enable_if_t<std::is_base_of<std::vector<ElementType, Allocator>, NativeType<ElementType, Allocator>>::value, bool> = true>
struct eprosima::is::utils::ResizableUnboundedContainerConvert

A class that helps create a Convert<> specialization for resizable unbounded container message types.

To create a specialization for a native middleware message type, do the following:

namespace eprosima {
namespace is {
namespace utils {

template<typename ElementType, typename Allocator>
struct Convert<native::middleware::type<ElementType, Allocator> >
    : ResizableUnboundedContainerConvert<
        ElementType,
        native::middleware::type,
        Allocator,
        size_t::upperbound::limit
    > { };

} // namespace utils
} // namespace is
} // namespace eprosima

Note

The UpperBound limit could typically be calculated as

std::numeric_limits<typename native::middleware::type<ElementType, Allocator>::size_type>::max()

Public Static Functions

void from_xtype(const xtypes::ReadableDynamicDataRef &from, std::vector<bool>::reference to)

This template specialization is needed to deal with the edge case produced by vectors of bools. std::vector<bool> is specialized to be implemented as a bitmap, and as a result its operator[] cannot return its bool elements by reference. Instead it returns a “reference” proxy object.

void from_xtype_field(const xtypes::ReadableDynamicDataRef &from, native_type &to)

Documentation inherited from Convert.

void to_xtype_field(const native_type &from, xtypes::WritableDynamicDataRef to)

Documentation inherited from Convert.

template<typename ElementType, template<typename, std::size_t, typename> class NativeType, typename Allocator, std::size_t UpperBound>
struct eprosima::is::utils::ResizableBoundedContainerConvert

A class that helps create a Convert<> specialization for resizable bounded container message types.

To create a specialization for a native middleware message type, do the following:

namespace eprosima {
namespace is {
namespace utils {

template<typename ElementType, std::size_t N, typename Allocator, template<typename, std::size_t, typename> class VectorImpl>
struct Convert<VectorImpl<ElementType, N, Allocator> >
    : ResizableBoundedContainerConvert<
        ElementType,
        VectorImpl,
        Allocator,
        N
    > { };

} // namespace utils
} // namespace is
} // namespace eprosima

Public Static Functions

void from_xtype_field(const xtypes::ReadableDynamicDataRef &from, native_type &to)

Documentation inherited from Convert.

void to_xtype_field(const native_type &from, xtypes::WritableDynamicDataRef to)

Documentation inherited from Convert.

template<typename ElementType, template<typename, std::size_t> class NativeType, std::size_t UpperBound, std::enable_if_t<std::is_base_of<std::array<ElementType, UpperBound>, NativeType<ElementType, UpperBound>>::value || std::is_base_of<boost::array<ElementType, UpperBound>, NativeType<ElementType, UpperBound>>::value, bool> = true>
struct eprosima::is::utils::NonResizableContainerConvert

A class that helps create a Convert<> specialization for non resizable container message types.

To create a specialization for a native middleware message type, do the following:

namespace eprosima {
namespace is {
namespace utils {

template<template <typename, std::size_t> class Array, typename ElementType, std::size_t N>
struct Convert<Array<ElementType, N> >
    : NonResizableContainerConvert<
        ElementType,
        Array,
        N
    > { };

} // namespace utils
} // namespace is
} // namespace eprosima

Public Static Functions

void from_xtype_field(const xtypes::ReadableDynamicDataRef &from, native_type &to)

Documentation inherited from Convert.

void to_xtype_field(const native_type &from, xtypes::WritableDynamicDataRef to)

Documentation inherited from Convert.