From aae4efd15d6933797b70ea6a44c2a1d180c3dfb4 Mon Sep 17 00:00:00 2001 From: Emilio Cuesta Date: Mon, 26 Oct 2026 15:39:11 +0100 Subject: [PATCH 1/6] Portability fixes for restricted standard libraries Every header now includes what it uses, and the C library names are written as C++ declares them: , , ... and std::uint32_t, std::size_t, std::memcpy... Each form is only guaranteed by its own header, so code mixing them ( with uint32_t) only builds with standard libraries that declare both, as GNU's does. , which is not standard, is replaced by . The C headers in config.h are for the code generated by Fast DDS Gen, which uses the C names without std::. Signed-off-by: Emilio Cuesta --- include/fastcdr/Cdr.h | 534 ++++++++-------- include/fastcdr/CdrEncoding.hpp | 4 +- include/fastcdr/CdrSizeCalculator.hpp | 450 +++++++------- include/fastcdr/FastBuffer.h | 46 +- include/fastcdr/FastCdr.h | 278 +++++---- include/fastcdr/cdr/fixed_size_string.hpp | 42 +- include/fastcdr/config.h.in | 5 + .../detail/container_recursive_inspector.hpp | 2 +- include/fastcdr/xcdr/MemberId.hpp | 8 +- include/fastcdr/xcdr/optional.hpp | 1 + src/cpp/Cdr.cpp | 580 +++++++++--------- src/cpp/CdrSizeCalculator.cpp | 12 +- src/cpp/FastBuffer.cpp | 22 +- src/cpp/FastCdr.cpp | 171 +++--- .../exceptions/BadOptionalAccessException.cpp | 2 + src/cpp/exceptions/BadParamException.cpp | 2 + src/cpp/exceptions/Exception.cpp | 2 + .../LockedExternalAccessException.cpp | 2 + .../exceptions/NotEnoughMemoryException.cpp | 2 + src/cpp/helpers/memory_helpers.hpp | 4 +- 20 files changed, 1088 insertions(+), 1081 deletions(-) diff --git a/include/fastcdr/Cdr.h b/include/fastcdr/Cdr.h index e4048df1..9a49cd46 100644 --- a/include/fastcdr/Cdr.h +++ b/include/fastcdr/Cdr.h @@ -43,11 +43,7 @@ #include "xcdr/MemberId.hpp" #include "xcdr/optional.hpp" -#if !__APPLE__ && !__FreeBSD__ && !__VXWORKS__ -#include -#else -#include -#endif // if !__APPLE__ && !__FreeBSD__ && !__VXWORKS__ +#include namespace eprosima { namespace fastcdr { @@ -75,7 +71,7 @@ class Cdr /*! * @brief This enumeration represents endianness types. */ - typedef enum : uint8_t + typedef enum : std::uint8_t { //! @brief Big endianness. BIG_ENDIANNESS = 0x0, @@ -139,13 +135,13 @@ class Cdr bool swap_bytes_ {false}; //! Stores the last datasize serialized/deserialized when the state was created. - size_t last_data_size_ {0}; + std::size_t last_data_size_ {0}; //! Not related with the state. Next member id which will be encoded. MemberId next_member_id_; //! Not related with the state. Used by encoding algorithms to set the encoded member size. - uint32_t member_size_ {0}; + std::uint32_t member_size_ {0}; //! Not related with the state. Used by encoding algorithms to store the selected member header version. XCdrHeaderSelection header_selection_ {XCdrHeaderSelection::AUTO_WITH_SHORT_HEADER_BY_DEFAULT}; @@ -231,14 +227,14 @@ class Cdr * @brief This function returns the option flags when the CDR type is eprosima::fastcdr::DDS_CDR. * @return The option flags. */ - Cdr_DllAPI std::array get_dds_cdr_options() const; + Cdr_DllAPI std::array get_dds_cdr_options() const; /*! * @brief This function sets the option flags when the CDR type is eprosima::fastcdr::DDS_CDR. * @param options New value for the option flags. */ Cdr_DllAPI void set_dds_cdr_options( - const std::array& options); + const std::array& options); /*! * @brief This function sets the current endianness used by the CDR type. @@ -265,7 +261,7 @@ class Cdr * @return True is returned when it works successfully. Otherwise, false is returned. */ Cdr_DllAPI bool jump( - size_t num_bytes); + std::size_t num_bytes); /*! * @brief This function resets the current position in the buffer to the beginning. @@ -288,7 +284,7 @@ class Cdr * @brief This function returns the length of the serialized data inside the stream. * @return The length of the serialized data. */ - Cdr_DllAPI size_t get_serialized_data_length() const; + Cdr_DllAPI std::size_t get_serialized_data_length() const; /*! * @brief Returns the number of bytes needed to align a position to certain data size. @@ -296,9 +292,9 @@ class Cdr * @param data_size Size of next data to process (should be power of two). * @return Number of required alignment bytes. */ - inline static size_t alignment( - size_t current_alignment, - size_t data_size) + inline static std::size_t alignment( + std::size_t current_alignment, + std::size_t data_size) { return (data_size - (current_alignment % data_size)) & (data_size - 1); } @@ -322,7 +318,7 @@ class Cdr * @return True If alignment was moved successfully. */ Cdr_DllAPI bool move_alignment_forward( - size_t num_bytes); + std::size_t num_bytes); /*! * @brief This function resets the alignment to the current position in the buffer. @@ -478,11 +474,11 @@ class Cdr template::value>::type* = nullptr, typename std::enable_if::type, - int32_t>::value>::type* = nullptr> + std::int32_t>::value>::type* = nullptr> Cdr& serialize( const _T& value) { - return serialize(static_cast(value)); + return serialize(static_cast(value)); } /*! @@ -496,11 +492,11 @@ class Cdr template::value>::type* = nullptr, typename std::enable_if::type, - uint32_t>::value>::type* = nullptr> + std::uint32_t>::value>::type* = nullptr> Cdr& serialize( const _T& value) { - return serialize(static_cast(value)); + return serialize(static_cast(value)); } /*! @@ -514,11 +510,11 @@ class Cdr template::value>::type* = nullptr, typename std::enable_if::type, - int16_t>::value>::type* = nullptr> + std::int16_t>::value>::type* = nullptr> Cdr& serialize( const _T& value) { - return serialize(static_cast(value)); + return serialize(static_cast(value)); } /*! @@ -532,11 +528,11 @@ class Cdr template::value>::type* = nullptr, typename std::enable_if::type, - uint16_t>::value>::type* = nullptr> + std::uint16_t>::value>::type* = nullptr> Cdr& serialize( const _T& value) { - return serialize(static_cast(value)); + return serialize(static_cast(value)); } /*! @@ -550,11 +546,11 @@ class Cdr template::value>::type* = nullptr, typename std::enable_if::type, - int8_t>::value>::type* = nullptr> + std::int8_t>::value>::type* = nullptr> Cdr& serialize( const _T& value) { - return serialize(static_cast(value)); + return serialize(static_cast(value)); } /*! @@ -568,11 +564,11 @@ class Cdr template::value>::type* = nullptr, typename std::enable_if::type, - uint8_t>::value>::type* = nullptr> + std::uint8_t>::value>::type* = nullptr> Cdr& serialize( const _T& value) { - return serialize(static_cast(value)); + return serialize(static_cast(value)); } /*! @@ -582,7 +578,7 @@ class Cdr * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. */ Cdr_DllAPI Cdr& serialize( - const uint8_t& octet_t); + const std::uint8_t& octet_t); /*! * @brief This function serializes a character. @@ -600,7 +596,7 @@ class Cdr * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. */ Cdr_DllAPI Cdr& serialize( - const int8_t int8); + const std::int8_t int8); /*! * @brief This function serializes an unsigned short. @@ -609,7 +605,7 @@ class Cdr * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. */ Cdr_DllAPI Cdr& serialize( - const uint16_t ushort_t); + const std::uint16_t ushort_t); /*! * @brief This function serializes a short. @@ -618,7 +614,7 @@ class Cdr * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. */ Cdr_DllAPI Cdr& serialize( - const int16_t short_t); + const std::int16_t short_t); /*! * @brief This function serializes an unsigned long. @@ -627,7 +623,7 @@ class Cdr * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. */ Cdr_DllAPI Cdr& serialize( - const uint32_t ulong_t); + const std::uint32_t ulong_t); /*! * @brief This function serializes a long. @@ -636,7 +632,7 @@ class Cdr * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. */ Cdr_DllAPI Cdr& serialize( - const int32_t long_t); + const std::int32_t long_t); /*! * @brief This function serializes a wide-char. @@ -654,7 +650,7 @@ class Cdr * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. */ Cdr_DllAPI Cdr& serialize( - const uint64_t ulonglong_t); + const std::uint64_t ulonglong_t); /*! * @brief This function serializes a long long. @@ -663,7 +659,7 @@ class Cdr * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. */ Cdr_DllAPI Cdr& serialize( - const int64_t longlong_t); + const std::int64_t longlong_t); /*! * @brief This function serializes a float. @@ -742,7 +738,7 @@ class Cdr { // Check there are no null characters in the string. const char* c_str = string_t.c_str(); - const auto str_len = strlen(c_str); + const auto str_len = std::strlen(c_str); if (string_t.size() > str_len) { throw exception::BadParamException("The string contains null characters"); @@ -771,7 +767,7 @@ class Cdr * @exception exception::NotEnoughMemoryException This exception is thrown when trying to encode into a buffer * position that exceeds the internal memory size. */ - template + template Cdr& serialize( const fixed_string& value) { @@ -784,7 +780,7 @@ class Cdr * @return Reference to the eprosima::fastcdr::Cdr object. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. */ - template + template Cdr& serialize( const std::array<_T, _Size>& array_t) { @@ -817,7 +813,7 @@ class Cdr { Cdr::state dheader_state {allocate_xcdrv2_dheader()}; - serialize(static_cast(vector_t.size())); + serialize(static_cast(vector_t.size())); try { @@ -847,7 +843,7 @@ class Cdr { state state_before_error(*this); - serialize(static_cast(vector_t.size())); + serialize(static_cast(vector_t.size())); try { @@ -893,7 +889,7 @@ class Cdr { Cdr::state dheader_state {allocate_xcdrv2_dheader()}; - serialize(static_cast(map_t.size())); + serialize(static_cast(map_t.size())); try { @@ -927,7 +923,7 @@ class Cdr { state state_(*this); - serialize(static_cast(map_t.size())); + serialize(static_cast(map_t.size())); try { @@ -954,32 +950,32 @@ class Cdr * @exception exception::NotEnoughMemoryException This exception is thrown when trying to encode into a buffer * position that exceeds the internal memory size. */ - template ::type* = nullptr> + template ::type* = nullptr> Cdr& serialize( const std::bitset& value) { - return serialize(static_cast(value.to_ulong())); + return serialize(static_cast(value.to_ulong())); } - template ::type* = nullptr> + template ::type* = nullptr> Cdr& serialize( const std::bitset& value) { - return serialize(static_cast(value.to_ulong())); + return serialize(static_cast(value.to_ulong())); } - template ::type* = nullptr> + template ::type* = nullptr> Cdr& serialize( const std::bitset& value) { - return serialize(static_cast(value.to_ulong())); + return serialize(static_cast(value.to_ulong())); } - template ::type* = nullptr> + template ::type* = nullptr> Cdr& serialize( const std::bitset& value) { - return serialize(static_cast(value.to_ullong())); + return serialize(static_cast(value.to_ullong())); } /*! @@ -996,9 +992,9 @@ class Cdr template Cdr& serialize_array( const _T* value, - size_t num_elements) + std::size_t num_elements) { - for (size_t count = 0; count < num_elements; ++count) + for (std::size_t count = 0; count < num_elements; ++count) { serialize(value[count]); } @@ -1016,7 +1012,7 @@ class Cdr template Cdr& serialize_array( const _T* type_t, - size_t num_elements, + std::size_t num_elements, Endianness endianness) { bool aux_swap = swap_bytes_; @@ -1046,8 +1042,8 @@ class Cdr */ TEMPLATE_SPEC Cdr& serialize_array( - const uint8_t* octet_t, - size_t num_elements) + const std::uint8_t* octet_t, + std::size_t num_elements) { return serialize_array(reinterpret_cast(octet_t), num_elements); } @@ -1061,7 +1057,7 @@ class Cdr */ Cdr_DllAPI Cdr& serialize_array( const char* char_t, - size_t num_elements); + std::size_t num_elements); /*! * @brief This function serializes an array of int8_t. @@ -1072,8 +1068,8 @@ class Cdr */ TEMPLATE_SPEC Cdr& serialize_array( - const int8_t* int8, - size_t num_elements) + const std::int8_t* int8, + std::size_t num_elements) { return serialize_array(reinterpret_cast(int8), num_elements); } @@ -1087,10 +1083,10 @@ class Cdr */ TEMPLATE_SPEC Cdr& serialize_array( - const uint16_t* ushort_t, - size_t num_elements) + const std::uint16_t* ushort_t, + std::size_t num_elements) { - return serialize_array(reinterpret_cast(ushort_t), num_elements); + return serialize_array(reinterpret_cast(ushort_t), num_elements); } /*! @@ -1101,8 +1097,8 @@ class Cdr * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. */ Cdr_DllAPI Cdr& serialize_array( - const int16_t* short_t, - size_t num_elements); + const std::int16_t* short_t, + std::size_t num_elements); /*! * @brief This function serializes an array of unsigned longs. @@ -1113,10 +1109,10 @@ class Cdr */ TEMPLATE_SPEC Cdr& serialize_array( - const uint32_t* ulong_t, - size_t num_elements) + const std::uint32_t* ulong_t, + std::size_t num_elements) { - return serialize_array(reinterpret_cast(ulong_t), num_elements); + return serialize_array(reinterpret_cast(ulong_t), num_elements); } /*! @@ -1127,8 +1123,8 @@ class Cdr * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. */ Cdr_DllAPI Cdr& serialize_array( - const int32_t* long_t, - size_t num_elements); + const std::int32_t* long_t, + std::size_t num_elements); /*! * @brief This function serializes an array of wide-chars. @@ -1139,7 +1135,7 @@ class Cdr */ Cdr_DllAPI Cdr& serialize_array( const wchar_t* wchar, - size_t num_elements); + std::size_t num_elements); /*! * @brief This function serializes an array of unsigned long longs. @@ -1150,10 +1146,10 @@ class Cdr */ TEMPLATE_SPEC Cdr& serialize_array( - const uint64_t* ulonglong_t, - size_t num_elements) + const std::uint64_t* ulonglong_t, + std::size_t num_elements) { - return serialize_array(reinterpret_cast(ulonglong_t), num_elements); + return serialize_array(reinterpret_cast(ulonglong_t), num_elements); } /*! @@ -1164,8 +1160,8 @@ class Cdr * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. */ Cdr_DllAPI Cdr& serialize_array( - const int64_t* longlong_t, - size_t num_elements); + const std::int64_t* longlong_t, + std::size_t num_elements); /*! * @brief This function serializes an array of floats. @@ -1176,7 +1172,7 @@ class Cdr */ Cdr_DllAPI Cdr& serialize_array( const float* float_t, - size_t num_elements); + std::size_t num_elements); /*! * @brief This function serializes an array of doubles. @@ -1187,7 +1183,7 @@ class Cdr */ Cdr_DllAPI Cdr& serialize_array( const double* double_t, - size_t num_elements); + std::size_t num_elements); /*! * @brief This function serializes an array of long doubles. @@ -1199,7 +1195,7 @@ class Cdr */ Cdr_DllAPI Cdr& serialize_array( const long double* ldouble_t, - size_t num_elements); + std::size_t num_elements); /*! * @brief This function serializes an array of booleans. @@ -1210,7 +1206,7 @@ class Cdr */ Cdr_DllAPI Cdr& serialize_array( const bool* bool_t, - size_t num_elements); + std::size_t num_elements); /*! * @brief This function serializes an array of strings. @@ -1222,9 +1218,9 @@ class Cdr TEMPLATE_SPEC Cdr& serialize_array( const std::string* string_t, - size_t num_elements) + std::size_t num_elements) { - for (size_t count = 0; count < num_elements; ++count) + for (std::size_t count = 0; count < num_elements; ++count) { serialize(string_t[count].c_str()); } @@ -1241,9 +1237,9 @@ class Cdr TEMPLATE_SPEC Cdr& serialize_array( const std::wstring* string_t, - size_t num_elements) + std::size_t num_elements) { - for (size_t count = 0; count < num_elements; ++count) + for (std::size_t count = 0; count < num_elements; ++count) { serialize(string_t[count].c_str()); } @@ -1258,12 +1254,12 @@ class Cdr * @exception exception::NotEnoughMemoryException This exception is thrown when trying to encode into a buffer * position that exceeds the internal memory size. */ - template + template Cdr& serialize_array( const fixed_string* value, - size_t num_elements) + std::size_t num_elements) { - for (size_t count = 0; count < num_elements; ++count) + for (std::size_t count = 0; count < num_elements; ++count) { serialize(value[count].c_str()); } @@ -1366,11 +1362,11 @@ class Cdr !std::is_arithmetic<_T>::value>::type* = nullptr> Cdr& serialize_sequence( const _T* sequence_t, - size_t num_elements) + std::size_t num_elements) { Cdr::state dheader_state {allocate_xcdrv2_dheader()}; - serialize(static_cast(num_elements)); + serialize(static_cast(num_elements)); try { @@ -1398,11 +1394,11 @@ class Cdr std::is_arithmetic<_T>::value>::type* = nullptr> Cdr& serialize_sequence( const _T* sequence_t, - size_t num_elements) + std::size_t num_elements) { state state_before_error(*this); - serialize(static_cast(num_elements)); + serialize(static_cast(num_elements)); try { @@ -1433,7 +1429,7 @@ class Cdr template Cdr& serialize_sequence( const _T* sequence_t, - size_t num_elements, + std::size_t num_elements, Endianness endianness) { bool aux_swap = swap_bytes_; @@ -1513,11 +1509,11 @@ class Cdr template::value>::type* = nullptr, typename std::enable_if::type, - int32_t>::value>::type* = nullptr> + std::int32_t>::value>::type* = nullptr> Cdr& deserialize( _T& value) { - int32_t decode_value {0}; + std::int32_t decode_value {0}; deserialize(decode_value); value = static_cast<_T>(decode_value); return *this; @@ -1533,11 +1529,11 @@ class Cdr template::value>::type* = nullptr, typename std::enable_if::type, - uint32_t>::value>::type* = nullptr> + std::uint32_t>::value>::type* = nullptr> Cdr& deserialize( _T& value) { - uint32_t decode_value {0}; + std::uint32_t decode_value {0}; deserialize(decode_value); value = static_cast<_T>(decode_value); return *this; @@ -1553,11 +1549,11 @@ class Cdr template::value>::type* = nullptr, typename std::enable_if::type, - int16_t>::value>::type* = nullptr> + std::int16_t>::value>::type* = nullptr> Cdr& deserialize( _T& value) { - int16_t decode_value {0}; + std::int16_t decode_value {0}; deserialize(decode_value); value = static_cast<_T>(decode_value); return *this; @@ -1573,11 +1569,11 @@ class Cdr template::value>::type* = nullptr, typename std::enable_if::type, - uint16_t>::value>::type* = nullptr> + std::uint16_t>::value>::type* = nullptr> Cdr& deserialize( _T& value) { - uint16_t decode_value {0}; + std::uint16_t decode_value {0}; deserialize(decode_value); value = static_cast<_T>(decode_value); return *this; @@ -1593,11 +1589,11 @@ class Cdr template::value>::type* = nullptr, typename std::enable_if::type, - int8_t>::value>::type* = nullptr> + std::int8_t>::value>::type* = nullptr> Cdr& deserialize( _T& value) { - int8_t decode_value {0}; + std::int8_t decode_value {0}; deserialize(decode_value); value = static_cast<_T>(decode_value); return *this; @@ -1613,11 +1609,11 @@ class Cdr template::value>::type* = nullptr, typename std::enable_if::type, - uint8_t>::value>::type* = nullptr> + std::uint8_t>::value>::type* = nullptr> Cdr& deserialize( _T& value) { - uint8_t decode_value {0}; + std::uint8_t decode_value {0}; deserialize(decode_value); value = static_cast<_T>(decode_value); return *this; @@ -1631,7 +1627,7 @@ class Cdr */ TEMPLATE_SPEC Cdr& deserialize( - uint8_t& octet_t) + std::uint8_t& octet_t) { return deserialize(reinterpret_cast(octet_t)); } @@ -1653,7 +1649,7 @@ class Cdr */ TEMPLATE_SPEC Cdr& deserialize( - int8_t& int8) + std::int8_t& int8) { return deserialize(reinterpret_cast(int8)); } @@ -1666,9 +1662,9 @@ class Cdr */ TEMPLATE_SPEC Cdr& deserialize( - uint16_t& ushort_t) + std::uint16_t& ushort_t) { - return deserialize(reinterpret_cast(ushort_t)); + return deserialize(reinterpret_cast(ushort_t)); } /*! @@ -1678,7 +1674,7 @@ class Cdr * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. */ Cdr_DllAPI Cdr& deserialize( - int16_t& short_t); + std::int16_t& short_t); /*! * @brief This function deserializes an unsigned long. @@ -1688,9 +1684,9 @@ class Cdr */ TEMPLATE_SPEC Cdr& deserialize( - uint32_t& ulong_t) + std::uint32_t& ulong_t) { - return deserialize(reinterpret_cast(ulong_t)); + return deserialize(reinterpret_cast(ulong_t)); } /*! @@ -1700,7 +1696,7 @@ class Cdr * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. */ Cdr_DllAPI Cdr& deserialize( - int32_t& long_t); + std::int32_t& long_t); /*! * @brief This function deserializes a wide-char. @@ -1712,7 +1708,7 @@ class Cdr Cdr& deserialize( wchar_t& wchar) { - uint16_t ret; + std::uint16_t ret; deserialize(ret); wchar = static_cast(ret); return *this; @@ -1726,9 +1722,9 @@ class Cdr */ TEMPLATE_SPEC Cdr& deserialize( - uint64_t& ulonglong_t) + std::uint64_t& ulonglong_t) { - return deserialize(reinterpret_cast(ulonglong_t)); + return deserialize(reinterpret_cast(ulonglong_t)); } /*! @@ -1738,7 +1734,7 @@ class Cdr * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. */ Cdr_DllAPI Cdr& deserialize( - int64_t& longlong_t); + std::int64_t& longlong_t); /*! * @brief This function deserializes a float. @@ -1816,7 +1812,7 @@ class Cdr Cdr_DllAPI Cdr& deserialize( char*& string_t, CdrTryConstructFlag consistency_flag, - uint32_t max_length); + std::uint32_t max_length); /*! * @brief This function deserializes a wide-string. @@ -1856,7 +1852,7 @@ class Cdr Cdr_DllAPI Cdr& deserialize( wchar_t*& string_t, CdrTryConstructFlag consistency_flag, - uint32_t max_length); + std::uint32_t max_length); /*! * @brief This function deserializes a std::string. @@ -1868,7 +1864,7 @@ class Cdr Cdr& deserialize( std::string& string_t) { - uint32_t length {(std::numeric_limits::max)()}; + std::uint32_t length {(std::numeric_limits::max)()}; const char* str = read_string(length, CdrTryConstructFlag::FAIL); string_t.assign(str, length); return *this; @@ -1898,9 +1894,9 @@ class Cdr Cdr& deserialize( std::string& string_t, CdrTryConstructFlag consistency_flag, - uint32_t max_length) + std::uint32_t max_length) { - uint32_t length {max_length}; + std::uint32_t length {max_length}; const char* str = read_string(length, consistency_flag); string_t.assign(str, length); return *this; @@ -1916,7 +1912,7 @@ class Cdr Cdr& deserialize( std::wstring& string_t) { - uint32_t length {(std::numeric_limits::max)()}; + std::uint32_t length {(std::numeric_limits::max)()}; string_t = read_wstring(length, CdrTryConstructFlag::FAIL); return *this; } @@ -1945,9 +1941,9 @@ class Cdr Cdr& deserialize( std::wstring& string_t, CdrTryConstructFlag consistency_flag, - uint32_t max_length) + std::uint32_t max_length) { - uint32_t length {max_length}; + std::uint32_t length {max_length}; string_t = read_wstring(length, consistency_flag); return *this; } @@ -1959,11 +1955,11 @@ class Cdr * @exception exception::NotEnoughMemoryException This exception is thrown when trying to decode from a buffer * position that exceeds the internal memory size. */ - template + template Cdr& deserialize( fixed_string& value) { - uint32_t length {MAX_CHARS}; + std::uint32_t length {MAX_CHARS}; const char* str = read_string(length, CdrTryConstructFlag::FAIL); value.assign(str, length); return *this; @@ -1992,12 +1988,12 @@ class Cdr * @exception exception::BadParamException This exception is thrown when @p consistency_flag is * @ref CdrTryConstructFlag::FAIL and the deserialized string does not fit in @c MAX_CHARS . */ - template + template Cdr& deserialize( fixed_string& value, CdrTryConstructFlag consistency_flag) { - uint32_t length {MAX_CHARS}; + std::uint32_t length {MAX_CHARS}; const char* str = read_string(length, consistency_flag); value.assign(str, length); return *this; @@ -2009,7 +2005,7 @@ class Cdr * @return Reference to the eprosima::fastcdr::Cdr object. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. */ - template + template Cdr& deserialize( std::array<_T, _Size>& array_t) { @@ -2017,7 +2013,7 @@ class Cdr if (CdrVersion::XCDRv2 == cdr_version_ && !is_multi_array_primitive(&array_t)) { - uint32_t dheader {0}; + std::uint32_t dheader {0}; deserialize_framing(dheader); if ((end_ - offset_) < dheader) @@ -2027,7 +2023,7 @@ class Cdr exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT); } - uint32_t count {0}; + std::uint32_t count {0}; auto last_offset = offset_; last_offset += dheader; @@ -2070,12 +2066,12 @@ class Cdr Cdr& deserialize( std::vector<_T>& vector_t) { - uint32_t sequence_length {0}; + std::uint32_t sequence_length {0}; state state_before_error(*this); if (CdrVersion::XCDRv2 == cdr_version_) { - uint32_t dheader {0}; + std::uint32_t dheader {0}; deserialize_framing(dheader); if (((end_ - offset_) < dheader) || (dheader < 4)) @@ -2107,7 +2103,7 @@ class Cdr { vector_t.resize(sequence_length); - uint32_t count {0}; + std::uint32_t count {0}; while (last_offset - offset_ > 0 && count < sequence_length) { deserialize(vector_t.data()[count]); @@ -2170,7 +2166,7 @@ class Cdr Cdr& deserialize( std::vector<_T>& vector_t) { - uint32_t sequence_length = 0; + std::uint32_t sequence_length = 0; state state_before_error(*this); deserialize_framing(sequence_length); @@ -2213,7 +2209,7 @@ class Cdr std::vector& vector_t) { return deserialize_bool_sequence(vector_t, CdrTryConstructFlag::FAIL, - (std::numeric_limits::max)()); + (std::numeric_limits::max)()); } /*! @@ -2241,9 +2237,9 @@ class Cdr Cdr& deserialize( std::vector<_T>& vector_t, CdrTryConstructFlag consistency_flag, - uint32_t max_length) + std::uint32_t max_length) { - uint32_t sequence_length = 0; + std::uint32_t sequence_length = 0; state state_before_error(*this); deserialize_framing(sequence_length); @@ -2262,7 +2258,7 @@ class Cdr exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT); } - uint32_t length_to_read {sequence_length}; + std::uint32_t length_to_read {sequence_length}; if (sequence_length > max_length) { @@ -2293,7 +2289,7 @@ class Cdr { fake_mode_scope discarding {*this, true}; - for (uint32_t count {length_to_read}; count < sequence_length; ++count) + for (std::uint32_t count {length_to_read}; count < sequence_length; ++count) { _T discarded; deserialize(discarded); @@ -2335,14 +2331,14 @@ class Cdr Cdr& deserialize( std::vector<_T>& vector_t, CdrTryConstructFlag consistency_flag, - uint32_t max_length) + std::uint32_t max_length) { - uint32_t sequence_length {0}; + std::uint32_t sequence_length {0}; state state_before_error(*this); if (CdrVersion::XCDRv2 == cdr_version_) { - uint32_t dheader {0}; + std::uint32_t dheader {0}; deserialize_framing(dheader); if (((end_ - offset_) < dheader) || (dheader < 4)) @@ -2358,14 +2354,14 @@ class Cdr vector_t.clear(); - if ((dheader - static_cast(offset_ - offset)) < sequence_length) + if ((dheader - static_cast(offset_ - offset)) < sequence_length) { set_state(state_before_error); throw exception::NotEnoughMemoryException( exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT); } - uint32_t length_to_read {sequence_length}; + std::uint32_t length_to_read {sequence_length}; if (sequence_length > max_length) { @@ -2384,7 +2380,7 @@ class Cdr } } - uint32_t count {0}; + std::uint32_t count {0}; try { @@ -2413,7 +2409,7 @@ class Cdr if (offset_ - offset < dheader) { - uint32_t remaining_bytes = dheader - static_cast(offset_ - offset); + std::uint32_t remaining_bytes = dheader - static_cast(offset_ - offset); if (!jump(remaining_bytes)) { set_state(state_before_error); @@ -2440,7 +2436,7 @@ class Cdr exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT); } - uint32_t length_to_read {sequence_length}; + std::uint32_t length_to_read {sequence_length}; if (sequence_length > max_length) { @@ -2471,7 +2467,7 @@ class Cdr { fake_mode_scope discarding {*this, true}; - for (uint32_t count {length_to_read}; count < sequence_length; ++count) + for (std::uint32_t count {length_to_read}; count < sequence_length; ++count) { _T discarded; deserialize(discarded); @@ -2492,7 +2488,7 @@ class Cdr Cdr& deserialize( std::vector& vector_t, CdrTryConstructFlag consistency_flag, - uint32_t max_length) + std::uint32_t max_length) { return deserialize_bool_sequence(vector_t, consistency_flag, max_length); } @@ -2514,7 +2510,7 @@ class Cdr if (CdrVersion::XCDRv2 == cdr_version_) { - uint32_t dheader {0}; + std::uint32_t dheader {0}; deserialize_framing(dheader); if (((end_ - offset_) < dheader) || (dheader < 4)) @@ -2527,12 +2523,12 @@ class Cdr auto last_offset = offset_; last_offset += dheader; - uint32_t map_length {0}; + std::uint32_t map_length {0}; deserialize_framing(map_length); try { - uint32_t count {0}; + std::uint32_t count {0}; while (last_offset - offset_ > 0 && count < map_length) { _K key; @@ -2557,13 +2553,13 @@ class Cdr } else { - uint32_t sequence_length = 0; + std::uint32_t sequence_length = 0; deserialize_framing(sequence_length); try { - for (uint32_t i = 0; i < sequence_length; ++i) + for (std::uint32_t i = 0; i < sequence_length; ++i) { _K key; _T value; @@ -2596,7 +2592,7 @@ class Cdr Cdr& deserialize( std::map<_K, _T>& map_t) { - uint32_t sequence_length = 0; + std::uint32_t sequence_length = 0; state state_(*this); std::map<_K, _T> map; @@ -2604,7 +2600,7 @@ class Cdr try { - for (uint32_t i = 0; i < sequence_length; ++i) + for (std::uint32_t i = 0; i < sequence_length; ++i) { _K key; _T value; @@ -2652,14 +2648,14 @@ class Cdr Cdr& deserialize( std::map<_K, _T>& map_t, CdrTryConstructFlag consistency_flag, - uint32_t max_length) + std::uint32_t max_length) { state state_before_error(*this); std::map<_K, _T> map; if (CdrVersion::XCDRv2 == cdr_version_) { - uint32_t dheader {0}; + std::uint32_t dheader {0}; deserialize_framing(dheader); if (((end_ - offset_) < dheader) || (dheader < 4)) @@ -2671,10 +2667,10 @@ class Cdr auto offset = offset_; - uint32_t map_length {0}; + std::uint32_t map_length {0}; deserialize_framing(map_length); - uint32_t length_to_read {map_length}; + std::uint32_t length_to_read {map_length}; if (map_length > max_length) { @@ -2693,7 +2689,7 @@ class Cdr } } - uint32_t count {0}; + std::uint32_t count {0}; try { @@ -2724,7 +2720,7 @@ class Cdr if (offset_ - offset < dheader) { - uint32_t remaining_bytes = dheader - static_cast(offset_ - offset); + std::uint32_t remaining_bytes = dheader - static_cast(offset_ - offset); if (!jump(remaining_bytes)) { set_state(state_before_error); @@ -2735,10 +2731,10 @@ class Cdr } else { - uint32_t map_length {0}; + std::uint32_t map_length {0}; deserialize_framing(map_length); - uint32_t length_to_read {map_length}; + std::uint32_t length_to_read {map_length}; if (map_length > max_length) { @@ -2759,7 +2755,7 @@ class Cdr try { - for (uint32_t i {0}; i < length_to_read; ++i) + for (std::uint32_t i {0}; i < length_to_read; ++i) { _K key; _T value; @@ -2774,7 +2770,7 @@ class Cdr { fake_mode_scope discarding {*this, true}; - for (uint32_t i {length_to_read}; i < map_length; ++i) + for (std::uint32_t i {length_to_read}; i < map_length; ++i) { _K key; _T value; @@ -2823,15 +2819,15 @@ class Cdr Cdr& deserialize( std::map<_K, _T>& map_t, CdrTryConstructFlag consistency_flag, - uint32_t max_length) + std::uint32_t max_length) { state state_before_error(*this); std::map<_K, _T> map; - uint32_t map_length {0}; + std::uint32_t map_length {0}; deserialize_framing(map_length); - uint32_t length_to_read {map_length}; + std::uint32_t length_to_read {map_length}; if (map_length > max_length) { @@ -2852,7 +2848,7 @@ class Cdr try { - for (uint32_t i {0}; i < length_to_read; ++i) + for (std::uint32_t i {0}; i < length_to_read; ++i) { _K key; _T value; @@ -2867,7 +2863,7 @@ class Cdr { fake_mode_scope discarding {*this, true}; - for (uint32_t i {length_to_read}; i < map_length; ++i) + for (std::uint32_t i {length_to_read}; i < map_length; ++i) { _K key; _T value; @@ -2894,41 +2890,41 @@ class Cdr * @exception exception::NotEnoughMemoryException This exception is thrown when trying to decode from a buffer * position that exceeds the internal memory size. */ - template ::type* = nullptr> + template ::type* = nullptr> Cdr& deserialize( std::bitset& value) { - uint8_t decode_value {0}; + std::uint8_t decode_value {0}; deserialize(decode_value); value = decode_value; return *this; } - template ::type* = nullptr> + template ::type* = nullptr> Cdr& deserialize( std::bitset& value) { - uint16_t decode_value {0}; + std::uint16_t decode_value {0}; deserialize(decode_value); value = decode_value; return *this; } - template ::type* = nullptr> + template ::type* = nullptr> Cdr& deserialize( std::bitset& value) { - uint32_t decode_value {0}; + std::uint32_t decode_value {0}; deserialize(decode_value); value = decode_value; return *this; } - template ::type* = nullptr> + template ::type* = nullptr> Cdr& deserialize( std::bitset& value) { - uint64_t decode_value {0}; + std::uint64_t decode_value {0}; deserialize(decode_value); value = decode_value; return *this; @@ -2948,9 +2944,9 @@ class Cdr template Cdr& deserialize_array( _T* value, - size_t num_elements) + std::size_t num_elements) { - for (size_t count = 0; count < num_elements; ++count) + for (std::size_t count = 0; count < num_elements; ++count) { deserialize(value[count]); } @@ -2968,7 +2964,7 @@ class Cdr template Cdr& deserialize_array( _T* type_t, - size_t num_elements, + std::size_t num_elements, Endianness endianness) { bool aux_swap = swap_bytes_; @@ -2998,8 +2994,8 @@ class Cdr */ TEMPLATE_SPEC Cdr& deserialize_array( - uint8_t* octet_t, - size_t num_elements) + std::uint8_t* octet_t, + std::size_t num_elements) { return deserialize_array(reinterpret_cast(octet_t), num_elements); } @@ -3013,7 +3009,7 @@ class Cdr */ Cdr_DllAPI Cdr& deserialize_array( char* char_t, - size_t num_elements); + std::size_t num_elements); /*! * @brief This function deserializes an array of int8_t. @@ -3024,8 +3020,8 @@ class Cdr */ TEMPLATE_SPEC Cdr& deserialize_array( - int8_t* int8, - size_t num_elements) + std::int8_t* int8, + std::size_t num_elements) { return deserialize_array(reinterpret_cast(int8), num_elements); } @@ -3039,10 +3035,10 @@ class Cdr */ TEMPLATE_SPEC Cdr& deserialize_array( - uint16_t* ushort_t, - size_t num_elements) + std::uint16_t* ushort_t, + std::size_t num_elements) { - return deserialize_array(reinterpret_cast(ushort_t), num_elements); + return deserialize_array(reinterpret_cast(ushort_t), num_elements); } /*! @@ -3053,8 +3049,8 @@ class Cdr * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. */ Cdr_DllAPI Cdr& deserialize_array( - int16_t* short_t, - size_t num_elements); + std::int16_t* short_t, + std::size_t num_elements); /*! * @brief This function deserializes an array of unsigned longs. @@ -3065,10 +3061,10 @@ class Cdr */ TEMPLATE_SPEC Cdr& deserialize_array( - uint32_t* ulong_t, - size_t num_elements) + std::uint32_t* ulong_t, + std::size_t num_elements) { - return deserialize_array(reinterpret_cast(ulong_t), num_elements); + return deserialize_array(reinterpret_cast(ulong_t), num_elements); } /*! @@ -3079,8 +3075,8 @@ class Cdr * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. */ Cdr_DllAPI Cdr& deserialize_array( - int32_t* long_t, - size_t num_elements); + std::int32_t* long_t, + std::size_t num_elements); /*! * @brief This function deserializes an array of wide-chars. @@ -3091,7 +3087,7 @@ class Cdr */ Cdr_DllAPI Cdr& deserialize_array( wchar_t* wchar, - size_t num_elements); + std::size_t num_elements); /*! * @brief This function deserializes an array of unsigned long longs. @@ -3102,10 +3098,10 @@ class Cdr */ TEMPLATE_SPEC Cdr& deserialize_array( - uint64_t* ulonglong_t, - size_t num_elements) + std::uint64_t* ulonglong_t, + std::size_t num_elements) { - return deserialize_array(reinterpret_cast(ulonglong_t), num_elements); + return deserialize_array(reinterpret_cast(ulonglong_t), num_elements); } /*! @@ -3116,8 +3112,8 @@ class Cdr * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. */ Cdr_DllAPI Cdr& deserialize_array( - int64_t* longlong_t, - size_t num_elements); + std::int64_t* longlong_t, + std::size_t num_elements); /*! * @brief This function deserializes an array of floats. @@ -3128,7 +3124,7 @@ class Cdr */ Cdr_DllAPI Cdr& deserialize_array( float* float_t, - size_t num_elements); + std::size_t num_elements); /*! * @brief This function deserializes an array of doubles. @@ -3139,7 +3135,7 @@ class Cdr */ Cdr_DllAPI Cdr& deserialize_array( double* double_t, - size_t num_elements); + std::size_t num_elements); /*! * @brief This function deserializes an array of long doubles. @@ -3151,7 +3147,7 @@ class Cdr */ Cdr_DllAPI Cdr& deserialize_array( long double* ldouble_t, - size_t num_elements); + std::size_t num_elements); /*! * @brief This function deserializes an array of booleans. @@ -3162,7 +3158,7 @@ class Cdr */ Cdr_DllAPI Cdr& deserialize_array( bool* bool_t, - size_t num_elements); + std::size_t num_elements); /*! * @brief Decodes an array of primitives on a std::vector. @@ -3203,7 +3199,7 @@ class Cdr if (CdrVersion::XCDRv2 == cdr_version_) { - uint32_t dheader {0}; + std::uint32_t dheader {0}; deserialize_framing(dheader); if ((end_ - offset_) < dheader) @@ -3213,7 +3209,7 @@ class Cdr exception::NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT); } - uint32_t count {0}; + std::uint32_t count {0}; auto last_offset = offset_; last_offset += dheader; try @@ -3310,14 +3306,14 @@ class Cdr !std::is_arithmetic<_T>::value>::type* = nullptr> Cdr& deserialize_sequence( _T*& sequence_t, - size_t& num_elements) + std::size_t& num_elements) { - uint32_t sequence_length {0}; + std::uint32_t sequence_length {0}; state state_before_error(*this); if (CdrVersion::XCDRv2 == cdr_version_) { - uint32_t dheader {0}; + std::uint32_t dheader {0}; deserialize_framing(dheader); if (((end_ - offset_) < dheader) || (dheader < 4)) @@ -3347,9 +3343,9 @@ class Cdr try { - sequence_t = reinterpret_cast<_T*>(calloc(sequence_length, sizeof(_T))); + sequence_t = reinterpret_cast<_T*>(std::calloc(sequence_length, sizeof(_T))); - uint32_t count {0}; + std::uint32_t count {0}; while (last_offset - offset_ > 0 && count < sequence_length) { deserialize(sequence_t[count]); @@ -3363,7 +3359,7 @@ class Cdr } catch (exception::Exception& ex) { - free(sequence_t); + std::free(sequence_t); sequence_t = NULL; set_state(state_before_error); ex.raise(); @@ -3382,12 +3378,12 @@ class Cdr try { - sequence_t = reinterpret_cast<_T*>(calloc(sequence_length, sizeof(_T))); + sequence_t = reinterpret_cast<_T*>(std::calloc(sequence_length, sizeof(_T))); deserialize_array(sequence_t, sequence_length); } catch (exception::Exception& ex) { - free(sequence_t); + std::free(sequence_t); sequence_t = NULL; set_state(state_before_error); ex.raise(); @@ -3411,21 +3407,21 @@ class Cdr std::is_arithmetic<_T>::value>::type* = nullptr> Cdr& deserialize_sequence( _T*& sequence_t, - size_t& num_elements) + std::size_t& num_elements) { - uint32_t sequence_length = 0; + std::uint32_t sequence_length = 0; state state_before_error(*this); deserialize_framing(sequence_length); try { - sequence_t = reinterpret_cast<_T*>(calloc(sequence_length, sizeof(_T))); + sequence_t = reinterpret_cast<_T*>(std::calloc(sequence_length, sizeof(_T))); deserialize_array(sequence_t, sequence_length); } catch (exception::Exception& ex) { - free(sequence_t); + std::free(sequence_t); sequence_t = NULL; set_state(state_before_error); ex.raise(); @@ -3448,7 +3444,7 @@ class Cdr template Cdr& deserialize_sequence( _T*& sequence_t, - size_t& num_elements, + std::size_t& num_elements, Endianness endianness) { bool aux_swap = swap_bytes_; @@ -3481,7 +3477,7 @@ class Cdr TEMPLATE_SPEC Cdr& deserialize_sequence( std::string*& sequence_t, - size_t& num_elements) + std::size_t& num_elements) { return deserialize_string_sequence(sequence_t, num_elements); } @@ -3498,7 +3494,7 @@ class Cdr TEMPLATE_SPEC Cdr& deserialize_sequence( std::wstring*& sequence_t, - size_t& num_elements) + std::size_t& num_elements) { return deserialize_wstring_sequence(sequence_t, num_elements); } @@ -3587,8 +3583,8 @@ class Cdr { deserialize(member_value); } - size_t member_size {current_state.member_size_}; - size_t diff {offset_ - prev_offset}; + std::size_t member_size {current_state.member_size_}; + std::size_t diff {offset_ - prev_offset}; if (member_size < diff) { throw exception::BadParamException( @@ -3632,8 +3628,8 @@ class Cdr { deserialize(member_value); } - size_t member_size {current_state.member_size_}; - size_t diff {offset_ - prev_offset}; + std::size_t member_size {current_state.member_size_}; + std::size_t diff {offset_ - prev_offset}; if (member_size < diff) { throw exception::BadParamException( @@ -3685,7 +3681,7 @@ class Cdr Cdr& deserialize_member( optional<_T>& member_value, CdrTryConstructFlag consistency_flag, - uint32_t max_length) + std::uint32_t max_length) { return deserialize_member_try_construct(member_value, consistency_flag, max_length); } @@ -3725,7 +3721,7 @@ class Cdr Cdr& deserialize_member( optional>& member_value, CdrTryConstructFlag consistency_flag, - uint32_t max_length) + std::uint32_t max_length) { return deserialize_member_try_construct(member_value, consistency_flag, max_length); } @@ -3931,7 +3927,7 @@ class Cdr Cdr& deserialize( optional<_T>& value, CdrTryConstructFlag consistency_flag, - uint32_t max_length) + std::uint32_t max_length) { return deserialize_try_construct(value, consistency_flag, max_length); } @@ -3969,7 +3965,7 @@ class Cdr Cdr& deserialize( external<_T>& value, CdrTryConstructFlag consistency_flag, - uint32_t max_length) + std::uint32_t max_length) { return deserialize_try_construct(value, consistency_flag, max_length); } @@ -4009,7 +4005,7 @@ class Cdr Cdr& deserialize( optional>& value, CdrTryConstructFlag consistency_flag, - uint32_t max_length) + std::uint32_t max_length) { return deserialize_try_construct(value, consistency_flag, max_length); } @@ -4054,8 +4050,8 @@ class Cdr { deserialize(member_value, consistency_flag, std::forward<_Args>(args)...); } - size_t member_size {current_state.member_size_}; - size_t diff {offset_ - prev_offset}; + std::size_t member_size {current_state.member_size_}; + std::size_t diff {offset_ - prev_offset}; if (member_size < diff) { throw exception::BadParamException( @@ -4099,8 +4095,8 @@ class Cdr { deserialize(member_value, consistency_flag, std::forward<_Args>(args)...); } - size_t member_size {current_state.member_size_}; - size_t diff {offset_ - prev_offset}; + std::size_t member_size {current_state.member_size_}; + std::size_t diff {offset_ - prev_offset}; if (member_size < diff) { throw exception::BadParamException( @@ -4210,15 +4206,15 @@ class Cdr Cdr_DllAPI Cdr& deserialize_bool_sequence( std::vector& vector_t, CdrTryConstructFlag consistency_flag, - uint32_t max_length); + std::uint32_t max_length); Cdr_DllAPI Cdr& deserialize_string_sequence( std::string*& sequence_t, - size_t& num_elements); + std::size_t& num_elements); Cdr_DllAPI Cdr& deserialize_wstring_sequence( std::wstring*& sequence_t, - size_t& num_elements); + std::size_t& num_elements); /*! * @brief Serializes the canonical @c uint8_t representation of @p bool_t. @@ -4237,10 +4233,10 @@ class Cdr * @return Reference to the eprosima::fastcdr::Cdr object. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize a position that exceeds the internal memory size. */ - template + template Cdr& serialize_array( const std::array<_T, _Size>* array_t, - size_t num_elements) + std::size_t num_elements) { if (num_elements == 0 || array_t == nullptr) { @@ -4256,10 +4252,10 @@ class Cdr * @return Reference to the eprosima::fastcdr::Cdr object. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. */ - template + template Cdr& deserialize_array( std::array<_T, _Size>* array_t, - size_t num_elements) + std::size_t num_elements) { if (num_elements == 0 || array_t == nullptr) { @@ -4276,10 +4272,10 @@ class Cdr * @return Reference to the eprosima::fastcdr::Cdr object. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize a position that exceeds the internal memory size. */ - template + template Cdr& deserialize_array( std::array<_T, _Size>* array_t, - size_t num_elements, + std::size_t num_elements, Endianness endianness) { if (num_elements == 0 || array_t == nullptr) @@ -4295,8 +4291,8 @@ class Cdr * @param data_size The size of the data that will be serialized. * @return The size needed for the alignment. */ - inline size_t alignment( - size_t data_size) const + inline std::size_t alignment( + std::size_t data_size) const { return data_size > last_data_size_ ? (data_size - ((offset_ - origin_) % data_size)) & (data_size - 1) : 0; } @@ -4306,7 +4302,7 @@ class Cdr * @param align The number of bytes to be skipped. */ inline void make_alignment( - size_t align) + std::size_t align) { offset_ += align; last_data_size_ = 0; @@ -4318,7 +4314,7 @@ class Cdr * @return True if the resize was succesful, false if it was not */ bool resize( - size_t min_size_inc); + std::size_t min_size_inc); /*! * @brief Sets @c fake_mode_ for the lifetime of the object, restoring its previous value on destruction @@ -4356,15 +4352,15 @@ class Cdr }; Cdr_DllAPI const char* read_string( - uint32_t& length); + std::uint32_t& length); Cdr_DllAPI const std::wstring read_wstring( - uint32_t& length); + std::uint32_t& length); Cdr_DllAPI const char* read_string( - uint32_t& length, + std::uint32_t& length, CdrTryConstructFlag consistency_flag); Cdr_DllAPI const std::wstring read_wstring( - uint32_t& length, + std::uint32_t& length, CdrTryConstructFlag consistency_flag); //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -4391,7 +4387,7 @@ class Cdr */ void xcdr1_end_short_member_header( const MemberId& member_id, - size_t member_serialized_size); + std::size_t member_serialized_size); /*! * @brief Encodes a long member header of a member according to XCDRv1. @@ -4411,7 +4407,7 @@ class Cdr */ void xcdr1_end_long_member_header( const MemberId& member_id, - size_t member_serialized_size); + std::size_t member_serialized_size); /*! * @brief Changes the previous encoded long header to a short header according to XCDRv1. @@ -4424,7 +4420,7 @@ class Cdr */ void xcdr1_change_to_short_member_header( const MemberId& member_id, - size_t member_serialized_size); + std::size_t member_serialized_size); /*! * @brief Changes the previous encoded short header to a long header according to XCDRv1. @@ -4435,7 +4431,7 @@ class Cdr */ void xcdr1_change_to_long_member_header( const MemberId& member_id, - size_t member_serialized_size); + std::size_t member_serialized_size); /*! * @brief Decodes a member header according to XCDRv1. @@ -4470,7 +4466,7 @@ class Cdr */ void xcdr2_end_short_member_header( const MemberId& member_id, - size_t member_serialized_size); + std::size_t member_serialized_size); /*! * @brief Encodes a long member header of a member according to XCDRv2. @@ -4492,7 +4488,7 @@ class Cdr */ void xcdr2_end_long_member_header( const MemberId& member_id, - size_t member_serialized_size); + std::size_t member_serialized_size); /*! * @brief Changes the previous encoded long header to a short header according to XCDRv2. @@ -4505,7 +4501,7 @@ class Cdr */ void xcdr2_change_to_short_member_header( const MemberId& member_id, - size_t member_serialized_size); + std::size_t member_serialized_size); /*! * @brief Changes the previous encoded long header to a short header according to XCDRv2. @@ -4517,7 +4513,7 @@ class Cdr */ void xcdr2_change_to_long_member_header( const MemberId& member_id, - size_t member_serialized_size); + std::size_t member_serialized_size); /*! * @brief Join the previous encoded long header with the next DHEADER which was serialized after. @@ -4807,16 +4803,16 @@ class Cdr EncodingAlgorithmFlag current_encoding_ {EncodingAlgorithmFlag::PLAIN_CDR2}; //! @brief This attribute stores the option flags when the CDR type is DDS_CDR; - std::array options_{{0}}; + std::array options_{{0}}; //! @brief The endianness that will be applied over the buffer. - uint8_t endianness_ {Endianness::LITTLE_ENDIANNESS}; + std::uint8_t endianness_ {Endianness::LITTLE_ENDIANNESS}; //! @brief This attribute specifies if it is needed to swap the bytes. bool swap_bytes_ {false}; //! @brief Stores the last datasize serialized/deserialized. It's used to optimize. - size_t last_data_size_ {0}; + std::size_t last_data_size_ {0}; //! @brief The current position in the serialization/deserialization process. FastBuffer::iterator offset_; @@ -4831,7 +4827,7 @@ class Cdr MemberId next_member_id_; //! Align for types equal or greater than 64bits. - size_t align64_ {4}; + std::size_t align64_ {4}; /*! * When serializing a member's type using XCDRv2, this enumerator is used to inform the type was serialized with a @@ -4859,11 +4855,11 @@ class Cdr //! Custom serialization context. std::shared_ptr context_; - uint32_t get_long_lc( + std::uint32_t get_long_lc( SerializedMemberSizeForNextInt serialized_member_size); - uint32_t get_short_lc( - size_t member_serialized_size); + std::uint32_t get_short_lc( + std::size_t member_serialized_size); template::value || std::is_arithmetic<_T>::value>::type* = nullptr> diff --git a/include/fastcdr/CdrEncoding.hpp b/include/fastcdr/CdrEncoding.hpp index ed00885e..949d0744 100644 --- a/include/fastcdr/CdrEncoding.hpp +++ b/include/fastcdr/CdrEncoding.hpp @@ -34,7 +34,7 @@ typedef enum } CdrVersion; //! @brief This enumeration represents the supported XCDR encoding algorithms. -typedef enum : uint8_t +typedef enum : std::uint8_t { //! @brief Specifies that the content is PLAIN_CDR. PLAIN_CDR = 0x0, @@ -49,7 +49,7 @@ typedef enum : uint8_t } EncodingAlgorithmFlag; //! @brief This enumeration represents Cdr's behavior when there is type inconsistency between the serialized data and the type used to deserialize the data. -enum class CdrTryConstructFlag : uint32_t +enum class CdrTryConstructFlag : std::uint32_t { //! @brief Cdr will fail deserialization if there is type inconsistency. FAIL = 0, diff --git a/include/fastcdr/CdrSizeCalculator.hpp b/include/fastcdr/CdrSizeCalculator.hpp index 3e6ac436..dfa09c6c 100644 --- a/include/fastcdr/CdrSizeCalculator.hpp +++ b/include/fastcdr/CdrSizeCalculator.hpp @@ -40,10 +40,10 @@ namespace fastcdr { class CdrSizeCalculator; template -extern size_t calculate_serialized_size( +extern std::size_t calculate_serialized_size( CdrSizeCalculator&, const _T&, - size_t&); + std::size_t&); /*! * @brief This class offers an interface to calculate the encoded size of a type serialized using a support encoding @@ -120,9 +120,9 @@ class CdrSizeCalculator * @return Encoded size of the instance. */ template::value>::type* = nullptr, typename = void> - size_t calculate_serialized_size( + std::size_t calculate_serialized_size( const _T& data, - size_t& current_alignment) + std::size_t& current_alignment) { return eprosima::fastcdr::calculate_serialized_size(*this, data, current_alignment); } @@ -137,12 +137,12 @@ class CdrSizeCalculator template::value>::type* = nullptr, typename std::enable_if::type, - int32_t>::value>::type* = nullptr> - size_t calculate_serialized_size( + std::int32_t>::value>::type* = nullptr> + std::size_t calculate_serialized_size( const _T& data, - size_t& current_alignment) + std::size_t& current_alignment) { - return calculate_serialized_size(static_cast(data), current_alignment); + return calculate_serialized_size(static_cast(data), current_alignment); } /*! @@ -155,12 +155,12 @@ class CdrSizeCalculator template::value>::type* = nullptr, typename std::enable_if::type, - uint32_t>::value>::type* = nullptr> - size_t calculate_serialized_size( + std::uint32_t>::value>::type* = nullptr> + std::size_t calculate_serialized_size( const _T& data, - size_t& current_alignment) + std::size_t& current_alignment) { - return calculate_serialized_size(static_cast(data), current_alignment); + return calculate_serialized_size(static_cast(data), current_alignment); } /*! @@ -173,12 +173,12 @@ class CdrSizeCalculator template::value>::type* = nullptr, typename std::enable_if::type, - int16_t>::value>::type* = nullptr> - size_t calculate_serialized_size( + std::int16_t>::value>::type* = nullptr> + std::size_t calculate_serialized_size( const _T& data, - size_t& current_alignment) + std::size_t& current_alignment) { - return calculate_serialized_size(static_cast(data), current_alignment); + return calculate_serialized_size(static_cast(data), current_alignment); } /*! @@ -191,12 +191,12 @@ class CdrSizeCalculator template::value>::type* = nullptr, typename std::enable_if::type, - uint16_t>::value>::type* = nullptr> - size_t calculate_serialized_size( + std::uint16_t>::value>::type* = nullptr> + std::size_t calculate_serialized_size( const _T& data, - size_t& current_alignment) + std::size_t& current_alignment) { - return calculate_serialized_size(static_cast(data), current_alignment); + return calculate_serialized_size(static_cast(data), current_alignment); } /*! @@ -209,12 +209,12 @@ class CdrSizeCalculator template::value>::type* = nullptr, typename std::enable_if::type, - int8_t>::value>::type* = nullptr> - size_t calculate_serialized_size( + std::int8_t>::value>::type* = nullptr> + std::size_t calculate_serialized_size( const _T& data, - size_t& current_alignment) + std::size_t& current_alignment) { - return calculate_serialized_size(static_cast(data), current_alignment); + return calculate_serialized_size(static_cast(data), current_alignment); } /*! @@ -227,12 +227,12 @@ class CdrSizeCalculator template::value>::type* = nullptr, typename std::enable_if::type, - uint8_t>::value>::type* = nullptr> - size_t calculate_serialized_size( + std::uint8_t>::value>::type* = nullptr> + std::size_t calculate_serialized_size( const _T& data, - size_t& current_alignment) + std::size_t& current_alignment) { - return calculate_serialized_size(static_cast(data), current_alignment); + return calculate_serialized_size(static_cast(data), current_alignment); } /*! @@ -242,9 +242,9 @@ class CdrSizeCalculator * @return Encoded size of the instance. */ TEMPLATE_SPEC - size_t calculate_serialized_size( - const int8_t& data, - size_t& current_alignment) + std::size_t calculate_serialized_size( + const std::int8_t& data, + std::size_t& current_alignment) { static_cast(data); ++current_alignment; @@ -258,9 +258,9 @@ class CdrSizeCalculator * @return Encoded size of the instance. */ TEMPLATE_SPEC - size_t calculate_serialized_size( - const uint8_t& data, - size_t& current_alignment) + std::size_t calculate_serialized_size( + const std::uint8_t& data, + std::size_t& current_alignment) { static_cast(data); ++current_alignment; @@ -274,9 +274,9 @@ class CdrSizeCalculator * @return Encoded size of the instance. */ TEMPLATE_SPEC - size_t calculate_serialized_size( + std::size_t calculate_serialized_size( const char& data, - size_t& current_alignment) + std::size_t& current_alignment) { static_cast(data); ++current_alignment; @@ -290,9 +290,9 @@ class CdrSizeCalculator * @return Encoded size of the instance. */ TEMPLATE_SPEC - size_t calculate_serialized_size( + std::size_t calculate_serialized_size( const bool& data, - size_t& current_alignment) + std::size_t& current_alignment) { static_cast(data); ++current_alignment; @@ -306,12 +306,12 @@ class CdrSizeCalculator * @return Encoded size of the instance. */ TEMPLATE_SPEC - size_t calculate_serialized_size( + std::size_t calculate_serialized_size( const wchar_t& data, - size_t& current_alignment) + std::size_t& current_alignment) { static_cast(data); - size_t calculated_size {2 + alignment(current_alignment, 2)}; + std::size_t calculated_size {2 + alignment(current_alignment, 2)}; current_alignment += calculated_size; return calculated_size; } @@ -323,12 +323,12 @@ class CdrSizeCalculator * @return Encoded size of the instance. */ TEMPLATE_SPEC - size_t calculate_serialized_size( - const int16_t& data, - size_t& current_alignment) + std::size_t calculate_serialized_size( + const std::int16_t& data, + std::size_t& current_alignment) { static_cast(data); - size_t calculated_size {2 + alignment(current_alignment, 2)}; + std::size_t calculated_size {2 + alignment(current_alignment, 2)}; current_alignment += calculated_size; return calculated_size; } @@ -340,12 +340,12 @@ class CdrSizeCalculator * @return Encoded size of the instance. */ TEMPLATE_SPEC - size_t calculate_serialized_size( - const uint16_t& data, - size_t& current_alignment) + std::size_t calculate_serialized_size( + const std::uint16_t& data, + std::size_t& current_alignment) { static_cast(data); - size_t calculated_size {2 + alignment(current_alignment, 2)}; + std::size_t calculated_size {2 + alignment(current_alignment, 2)}; current_alignment += calculated_size; return calculated_size; } @@ -357,12 +357,12 @@ class CdrSizeCalculator * @return Encoded size of the instance. */ TEMPLATE_SPEC - size_t calculate_serialized_size( - const int32_t& data, - size_t& current_alignment) + std::size_t calculate_serialized_size( + const std::int32_t& data, + std::size_t& current_alignment) { static_cast(data); - size_t calculated_size {4 + alignment(current_alignment, 4)}; + std::size_t calculated_size {4 + alignment(current_alignment, 4)}; current_alignment += calculated_size; return calculated_size; } @@ -374,12 +374,12 @@ class CdrSizeCalculator * @return Encoded size of the instance. */ TEMPLATE_SPEC - size_t calculate_serialized_size( - const uint32_t& data, - size_t& current_alignment) + std::size_t calculate_serialized_size( + const std::uint32_t& data, + std::size_t& current_alignment) { static_cast(data); - size_t calculated_size {4 + alignment(current_alignment, 4)}; + std::size_t calculated_size {4 + alignment(current_alignment, 4)}; current_alignment += calculated_size; return calculated_size; } @@ -391,12 +391,12 @@ class CdrSizeCalculator * @return Encoded size of the instance. */ TEMPLATE_SPEC - size_t calculate_serialized_size( - const int64_t& data, - size_t& current_alignment) + std::size_t calculate_serialized_size( + const std::int64_t& data, + std::size_t& current_alignment) { static_cast(data); - size_t calculated_size {8 + alignment(current_alignment, align64_)}; + std::size_t calculated_size {8 + alignment(current_alignment, align64_)}; current_alignment += calculated_size; return calculated_size; } @@ -408,12 +408,12 @@ class CdrSizeCalculator * @return Encoded size of the instance. */ TEMPLATE_SPEC - size_t calculate_serialized_size( - const uint64_t& data, - size_t& current_alignment) + std::size_t calculate_serialized_size( + const std::uint64_t& data, + std::size_t& current_alignment) { static_cast(data); - size_t calculated_size {8 + alignment(current_alignment, align64_)}; + std::size_t calculated_size {8 + alignment(current_alignment, align64_)}; current_alignment += calculated_size; return calculated_size; } @@ -425,12 +425,12 @@ class CdrSizeCalculator * @return Encoded size of the instance. */ TEMPLATE_SPEC - size_t calculate_serialized_size( + std::size_t calculate_serialized_size( const float& data, - size_t& current_alignment) + std::size_t& current_alignment) { static_cast(data); - size_t calculated_size {4 + alignment(current_alignment, 4)}; + std::size_t calculated_size {4 + alignment(current_alignment, 4)}; current_alignment += calculated_size; return calculated_size; } @@ -442,12 +442,12 @@ class CdrSizeCalculator * @return Encoded size of the instance. */ TEMPLATE_SPEC - size_t calculate_serialized_size( + std::size_t calculate_serialized_size( const double& data, - size_t& current_alignment) + std::size_t& current_alignment) { static_cast(data); - size_t calculated_size {8 + alignment(current_alignment, align64_)}; + std::size_t calculated_size {8 + alignment(current_alignment, align64_)}; current_alignment += calculated_size; return calculated_size; } @@ -459,12 +459,12 @@ class CdrSizeCalculator * @return Encoded size of the instance. */ TEMPLATE_SPEC - size_t calculate_serialized_size( + std::size_t calculate_serialized_size( const long double& data, - size_t& current_alignment) + std::size_t& current_alignment) { static_cast(data); - size_t calculated_size {16 + alignment(current_alignment, align64_)}; + std::size_t calculated_size {16 + alignment(current_alignment, align64_)}; current_alignment += calculated_size; return calculated_size; } @@ -476,11 +476,11 @@ class CdrSizeCalculator * @return Encoded size of the instance. */ TEMPLATE_SPEC - size_t calculate_serialized_size( + std::size_t calculate_serialized_size( const std::string& data, - size_t& current_alignment) + std::size_t& current_alignment) { - size_t calculated_size {4 + alignment(current_alignment, 4) + data.size() + 1}; + std::size_t calculated_size {4 + alignment(current_alignment, 4) + data.size() + 1}; current_alignment += calculated_size; serialized_member_size_ = SERIALIZED_MEMBER_SIZE; @@ -494,11 +494,11 @@ class CdrSizeCalculator * @return Encoded size of the instance. */ TEMPLATE_SPEC - size_t calculate_serialized_size( + std::size_t calculate_serialized_size( const std::wstring& data, - size_t& current_alignment) + std::size_t& current_alignment) { - size_t calculated_size {4 + alignment(current_alignment, 4) + data.size() * 2}; + std::size_t calculated_size {4 + alignment(current_alignment, 4) + data.size() * 2}; current_alignment += calculated_size; return calculated_size; @@ -510,12 +510,12 @@ class CdrSizeCalculator * @param[inout] current_alignment Current alignment in the encoding. * @return Encoded size of the instance. */ - template - size_t calculate_serialized_size( + template + std::size_t calculate_serialized_size( const fixed_string& data, - size_t& current_alignment) + std::size_t& current_alignment) { - size_t calculated_size {4 + alignment(current_alignment, 4) + data.size() + 1}; + std::size_t calculated_size {4 + alignment(current_alignment, 4) + data.size() + 1}; current_alignment += calculated_size; serialized_member_size_ = SERIALIZED_MEMBER_SIZE; @@ -530,11 +530,11 @@ class CdrSizeCalculator */ template::value && !std::is_arithmetic<_T>::value>::type* = nullptr> - size_t calculate_serialized_size( + std::size_t calculate_serialized_size( const std::vector<_T>& data, - size_t& current_alignment) + std::size_t& current_alignment) { - size_t initial_alignment {current_alignment}; + std::size_t initial_alignment {current_alignment}; if (CdrVersion::XCDRv2 == cdr_version_) { @@ -544,7 +544,7 @@ class CdrSizeCalculator current_alignment += 4 + alignment(current_alignment, 4); - size_t calculated_size {current_alignment - initial_alignment}; + std::size_t calculated_size {current_alignment - initial_alignment}; calculated_size += calculate_array_serialized_size(data.data(), data.size(), current_alignment); if (CdrVersion::XCDRv2 == cdr_version_) @@ -564,15 +564,15 @@ class CdrSizeCalculator */ template::value || std::is_arithmetic<_T>::value>::type* = nullptr> - size_t calculate_serialized_size( + std::size_t calculate_serialized_size( const std::vector<_T>& data, - size_t& current_alignment) + std::size_t& current_alignment) { - size_t initial_alignment {current_alignment}; + std::size_t initial_alignment {current_alignment}; current_alignment += 4 + alignment(current_alignment, 4); - size_t calculated_size {current_alignment - initial_alignment}; + std::size_t calculated_size {current_alignment - initial_alignment}; calculated_size += calculate_array_serialized_size(data.data(), data.size(), current_alignment); if (CdrVersion::XCDRv2 == cdr_version_) @@ -590,11 +590,11 @@ class CdrSizeCalculator * @return Encoded size of the instance. */ TEMPLATE_SPEC - size_t calculate_serialized_size( + std::size_t calculate_serialized_size( const std::vector& data, - size_t& current_alignment) + std::size_t& current_alignment) { - size_t calculated_size {data.size() + 4 + alignment(current_alignment, 4)}; + std::size_t calculated_size {data.size() + 4 + alignment(current_alignment, 4)}; current_alignment += calculated_size; return calculated_size; @@ -606,12 +606,12 @@ class CdrSizeCalculator * @param[inout] current_alignment Current alignment in the encoding. * @return Encoded size of the instance. */ - template - size_t calculate_serialized_size( + template + std::size_t calculate_serialized_size( const std::array<_T, _Size>& data, - size_t& current_alignment) + std::size_t& current_alignment) { - size_t initial_alignment {current_alignment}; + std::size_t initial_alignment {current_alignment}; if (CdrVersion::XCDRv2 == cdr_version_ && !is_multi_array_primitive(&data)) @@ -620,7 +620,7 @@ class CdrSizeCalculator current_alignment += 4 + alignment(current_alignment, 4); } - size_t calculated_size {current_alignment - initial_alignment}; + std::size_t calculated_size {current_alignment - initial_alignment}; calculated_size += calculate_array_serialized_size(data.data(), data.size(), current_alignment); if (CdrVersion::XCDRv2 == cdr_version_ && @@ -641,11 +641,11 @@ class CdrSizeCalculator */ template::value && !std::is_arithmetic<_V>::value>::type* = nullptr> - size_t calculate_serialized_size( + std::size_t calculate_serialized_size( const std::map<_K, _V>& data, - size_t& current_alignment) + std::size_t& current_alignment) { - size_t initial_alignment {current_alignment}; + std::size_t initial_alignment {current_alignment}; if (CdrVersion::XCDRv2 == cdr_version_) { @@ -655,7 +655,7 @@ class CdrSizeCalculator current_alignment += 4 + alignment(current_alignment, 4); - size_t calculated_size {current_alignment - initial_alignment}; + std::size_t calculated_size {current_alignment - initial_alignment}; for (auto it = data.begin(); it != data.end(); ++it) { calculated_size += calculate_serialized_size(it->first, current_alignment); @@ -679,15 +679,15 @@ class CdrSizeCalculator */ template::value || std::is_arithmetic<_V>::value>::type* = nullptr> - size_t calculate_serialized_size( + std::size_t calculate_serialized_size( const std::map<_K, _V>& data, - size_t& current_alignment) + std::size_t& current_alignment) { - size_t initial_alignment {current_alignment}; + std::size_t initial_alignment {current_alignment}; current_alignment += 4 + alignment(current_alignment, 4); - size_t calculated_size {current_alignment - initial_alignment}; + std::size_t calculated_size {current_alignment - initial_alignment}; for (auto it = data.begin(); it != data.end(); ++it) { calculated_size += calculate_serialized_size(it->first, current_alignment); @@ -703,10 +703,10 @@ class CdrSizeCalculator * @param[inout] current_alignment Current alignment in the encoding. * @return Encoded size of the instance. */ - template ::type* = nullptr> - size_t calculate_serialized_size( + template ::type* = nullptr> + std::size_t calculate_serialized_size( const std::bitset& data, - size_t& current_alignment) + std::size_t& current_alignment) { static_cast(data); ++current_alignment; @@ -719,13 +719,13 @@ class CdrSizeCalculator * @param[inout] current_alignment Current alignment in the encoding. * @return Encoded size of the instance. */ - template ::type* = nullptr> - size_t calculate_serialized_size( + template ::type* = nullptr> + std::size_t calculate_serialized_size( const std::bitset& data, - size_t& current_alignment) + std::size_t& current_alignment) { static_cast(data); - size_t calculated_size {2 + alignment(current_alignment, 2)}; + std::size_t calculated_size {2 + alignment(current_alignment, 2)}; current_alignment += calculated_size; return calculated_size; } @@ -736,13 +736,13 @@ class CdrSizeCalculator * @param[inout] current_alignment Current alignment in the encoding. * @return Encoded size of the instance. */ - template ::type* = nullptr> - size_t calculate_serialized_size( + template ::type* = nullptr> + std::size_t calculate_serialized_size( const std::bitset& data, - size_t& current_alignment) + std::size_t& current_alignment) { static_cast(data); - size_t calculated_size {4 + alignment(current_alignment, 4)}; + std::size_t calculated_size {4 + alignment(current_alignment, 4)}; current_alignment += calculated_size; return calculated_size; } @@ -753,13 +753,13 @@ class CdrSizeCalculator * @param[inout] current_alignment Current alignment in the encoding. * @return Encoded size of the instance. */ - template ::type* = nullptr> - size_t calculate_serialized_size( + template ::type* = nullptr> + std::size_t calculate_serialized_size( const std::bitset& data, - size_t& current_alignment) + std::size_t& current_alignment) { static_cast(data); - size_t calculated_size {8 + alignment(current_alignment, align64_)}; + std::size_t calculated_size {8 + alignment(current_alignment, align64_)}; current_alignment += calculated_size; return calculated_size; } @@ -771,11 +771,11 @@ class CdrSizeCalculator * @return Encoded size of the instance. */ template - size_t calculate_serialized_size( + std::size_t calculate_serialized_size( const optional<_T>& data, - size_t& current_alignment) + std::size_t& current_alignment) { - size_t initial_alignment = current_alignment; + std::size_t initial_alignment = current_alignment; if (CdrVersion::XCDRv2 == cdr_version_ && EncodingAlgorithmFlag::PL_CDR2 != current_encoding_) @@ -784,7 +784,7 @@ class CdrSizeCalculator ++current_alignment; } - size_t calculated_size {current_alignment - initial_alignment}; + std::size_t calculated_size {current_alignment - initial_alignment}; if (data.has_value()) { @@ -802,9 +802,9 @@ class CdrSizeCalculator * @return Encoded size of the instance. */ template - size_t calculate_serialized_size( + std::size_t calculate_serialized_size( const external<_T>& data, - size_t& current_alignment) + std::size_t& current_alignment) { if (!data) { @@ -823,14 +823,14 @@ class CdrSizeCalculator * @return Encoded size of the instance. */ template - size_t calculate_array_serialized_size( + std::size_t calculate_array_serialized_size( const _T* data, - size_t num_elements, - size_t& current_alignment) + std::size_t num_elements, + std::size_t& current_alignment) { - size_t calculated_size {0}; + std::size_t calculated_size {0}; - for (size_t count = 0; count < num_elements; ++count) + for (std::size_t count = 0; count < num_elements; ++count) { calculated_size += calculate_serialized_size(data[count], current_alignment); } @@ -846,10 +846,10 @@ class CdrSizeCalculator * @return Encoded size of the instance. */ TEMPLATE_SPEC - size_t calculate_array_serialized_size( - const int8_t* data, - size_t num_elements, - size_t& current_alignment) + std::size_t calculate_array_serialized_size( + const std::int8_t* data, + std::size_t num_elements, + std::size_t& current_alignment) { static_cast(data); current_alignment += num_elements; @@ -864,10 +864,10 @@ class CdrSizeCalculator * @return Encoded size of the instance. */ TEMPLATE_SPEC - size_t calculate_array_serialized_size( - const uint8_t* data, - size_t num_elements, - size_t& current_alignment) + std::size_t calculate_array_serialized_size( + const std::uint8_t* data, + std::size_t num_elements, + std::size_t& current_alignment) { static_cast(data); current_alignment += num_elements; @@ -882,10 +882,10 @@ class CdrSizeCalculator * @return Encoded size of the instance. */ TEMPLATE_SPEC - size_t calculate_array_serialized_size( + std::size_t calculate_array_serialized_size( const char* data, - size_t num_elements, - size_t& current_alignment) + std::size_t num_elements, + std::size_t& current_alignment) { static_cast(data); current_alignment += num_elements; @@ -900,13 +900,13 @@ class CdrSizeCalculator * @return Encoded size of the instance. */ TEMPLATE_SPEC - size_t calculate_array_serialized_size( + std::size_t calculate_array_serialized_size( const wchar_t* data, - size_t num_elements, - size_t& current_alignment) + std::size_t num_elements, + std::size_t& current_alignment) { static_cast(data); - size_t calculated_size {num_elements* 2 + alignment(current_alignment, 2)}; + std::size_t calculated_size {num_elements* 2 + alignment(current_alignment, 2)}; current_alignment += calculated_size; return calculated_size; } @@ -919,13 +919,13 @@ class CdrSizeCalculator * @return Encoded size of the instance. */ TEMPLATE_SPEC - size_t calculate_array_serialized_size( - const int16_t* data, - size_t num_elements, - size_t& current_alignment) + std::size_t calculate_array_serialized_size( + const std::int16_t* data, + std::size_t num_elements, + std::size_t& current_alignment) { static_cast(data); - size_t calculated_size {num_elements* 2 + alignment(current_alignment, 2)}; + std::size_t calculated_size {num_elements* 2 + alignment(current_alignment, 2)}; current_alignment += calculated_size; return calculated_size; } @@ -938,13 +938,13 @@ class CdrSizeCalculator * @return Encoded size of the instance. */ TEMPLATE_SPEC - size_t calculate_array_serialized_size( - const uint16_t* data, - size_t num_elements, - size_t& current_alignment) + std::size_t calculate_array_serialized_size( + const std::uint16_t* data, + std::size_t num_elements, + std::size_t& current_alignment) { static_cast(data); - size_t calculated_size {num_elements* 2 + alignment(current_alignment, 2)}; + std::size_t calculated_size {num_elements* 2 + alignment(current_alignment, 2)}; current_alignment += calculated_size; return calculated_size; } @@ -957,13 +957,13 @@ class CdrSizeCalculator * @return Encoded size of the instance. */ TEMPLATE_SPEC - size_t calculate_array_serialized_size( - const int32_t* data, - size_t num_elements, - size_t& current_alignment) + std::size_t calculate_array_serialized_size( + const std::int32_t* data, + std::size_t num_elements, + std::size_t& current_alignment) { static_cast(data); - size_t calculated_size {num_elements* 4 + alignment(current_alignment, 4)}; + std::size_t calculated_size {num_elements* 4 + alignment(current_alignment, 4)}; current_alignment += calculated_size; return calculated_size; } @@ -976,13 +976,13 @@ class CdrSizeCalculator * @return Encoded size of the instance. */ TEMPLATE_SPEC - size_t calculate_array_serialized_size( - const uint32_t* data, - size_t num_elements, - size_t& current_alignment) + std::size_t calculate_array_serialized_size( + const std::uint32_t* data, + std::size_t num_elements, + std::size_t& current_alignment) { static_cast(data); - size_t calculated_size {num_elements* 4 + alignment(current_alignment, 4)}; + std::size_t calculated_size {num_elements* 4 + alignment(current_alignment, 4)}; current_alignment += calculated_size; return calculated_size; } @@ -995,13 +995,13 @@ class CdrSizeCalculator * @return Encoded size of the instance. */ TEMPLATE_SPEC - size_t calculate_array_serialized_size( - const int64_t* data, - size_t num_elements, - size_t& current_alignment) + std::size_t calculate_array_serialized_size( + const std::int64_t* data, + std::size_t num_elements, + std::size_t& current_alignment) { static_cast(data); - size_t calculated_size {num_elements* 8 + alignment(current_alignment, align64_)}; + std::size_t calculated_size {num_elements* 8 + alignment(current_alignment, align64_)}; current_alignment += calculated_size; return calculated_size; } @@ -1014,13 +1014,13 @@ class CdrSizeCalculator * @return Encoded size of the instance. */ TEMPLATE_SPEC - size_t calculate_array_serialized_size( - const uint64_t* data, - size_t num_elements, - size_t& current_alignment) + std::size_t calculate_array_serialized_size( + const std::uint64_t* data, + std::size_t num_elements, + std::size_t& current_alignment) { static_cast(data); - size_t calculated_size {num_elements* 8 + alignment(current_alignment, align64_)}; + std::size_t calculated_size {num_elements* 8 + alignment(current_alignment, align64_)}; current_alignment += calculated_size; return calculated_size; } @@ -1033,13 +1033,13 @@ class CdrSizeCalculator * @return Encoded size of the instance. */ TEMPLATE_SPEC - size_t calculate_array_serialized_size( + std::size_t calculate_array_serialized_size( const float* data, - size_t num_elements, - size_t& current_alignment) + std::size_t num_elements, + std::size_t& current_alignment) { static_cast(data); - size_t calculated_size {num_elements* 4 + alignment(current_alignment, 4)}; + std::size_t calculated_size {num_elements* 4 + alignment(current_alignment, 4)}; current_alignment += calculated_size; return calculated_size; } @@ -1052,13 +1052,13 @@ class CdrSizeCalculator * @return Encoded size of the instance. */ TEMPLATE_SPEC - size_t calculate_array_serialized_size( + std::size_t calculate_array_serialized_size( const double* data, - size_t num_elements, - size_t& current_alignment) + std::size_t num_elements, + std::size_t& current_alignment) { static_cast(data); - size_t calculated_size {num_elements* 8 + alignment(current_alignment, align64_)}; + std::size_t calculated_size {num_elements* 8 + alignment(current_alignment, align64_)}; current_alignment += calculated_size; return calculated_size; } @@ -1071,13 +1071,13 @@ class CdrSizeCalculator * @return Encoded size of the instance. */ TEMPLATE_SPEC - size_t calculate_array_serialized_size( + std::size_t calculate_array_serialized_size( const long double* data, - size_t num_elements, - size_t& current_alignment) + std::size_t num_elements, + std::size_t& current_alignment) { static_cast(data); - size_t calculated_size {num_elements* 16 + alignment(current_alignment, align64_)}; + std::size_t calculated_size {num_elements* 16 + alignment(current_alignment, align64_)}; current_alignment += calculated_size; return calculated_size; } @@ -1089,11 +1089,11 @@ class CdrSizeCalculator * @param[inout] current_alignment Current alignment in the encoding. * @return Encoded size of the instance. */ - template - size_t calculate_array_serialized_size( + template + std::size_t calculate_array_serialized_size( const std::array<_T, _N>* data, - size_t num_elements, - size_t& current_alignment) + std::size_t num_elements, + std::size_t& current_alignment) { if (num_elements == 0 || data == nullptr) { @@ -1110,9 +1110,9 @@ class CdrSizeCalculator */ template::value || std::is_arithmetic<_T>::value>::type* = nullptr> - size_t calculate_array_serialized_size( + std::size_t calculate_array_serialized_size( const std::vector<_T>& data, - size_t& current_alignment) + std::size_t& current_alignment) { return calculate_array_serialized_size(data.data(), data.size(), current_alignment); } @@ -1125,11 +1125,11 @@ class CdrSizeCalculator */ template::value && !std::is_arithmetic<_T>::value>::type* = nullptr> - size_t calculate_array_serialized_size( + std::size_t calculate_array_serialized_size( const std::vector<_T>& data, - size_t& current_alignment) + std::size_t& current_alignment) { - size_t initial_alignment {current_alignment}; + std::size_t initial_alignment {current_alignment}; if (CdrVersion::XCDRv2 == cdr_version_) { @@ -1137,7 +1137,7 @@ class CdrSizeCalculator current_alignment += 4 + alignment(current_alignment, 4); } - size_t calculated_size {current_alignment - initial_alignment}; + std::size_t calculated_size {current_alignment - initial_alignment}; calculated_size += calculate_array_serialized_size(data.data(), data.size(), current_alignment); if (CdrVersion::XCDRv2 == cdr_version_) @@ -1156,9 +1156,9 @@ class CdrSizeCalculator * @return Encoded size of the instance. */ TEMPLATE_SPEC - size_t calculate_array_serialized_size( + std::size_t calculate_array_serialized_size( const std::vector& data, - size_t& current_alignment) + std::size_t& current_alignment) { current_alignment += data.size(); return data.size(); @@ -1173,12 +1173,12 @@ class CdrSizeCalculator * @return Encoded size of the member's instance. */ template - size_t calculate_member_serialized_size( + std::size_t calculate_member_serialized_size( const MemberId& id, const _T& data, - size_t& current_alignment) + std::size_t& current_alignment) { - size_t initial_alignment {current_alignment}; + std::size_t initial_alignment {current_alignment}; if (EncodingAlgorithmFlag::PL_CDR == current_encoding_ || EncodingAlgorithmFlag::PL_CDR2 == current_encoding_) @@ -1187,15 +1187,15 @@ class CdrSizeCalculator current_alignment += alignment(current_alignment, 4); } - size_t prev_size {current_alignment - initial_alignment}; - size_t extra_size {0}; + std::size_t prev_size {current_alignment - initial_alignment}; + std::size_t extra_size {0}; if (EncodingAlgorithmFlag::PL_CDR == current_encoding_) { current_alignment = 0; } - size_t calculated_size {calculate_serialized_size(data, current_alignment)}; + std::size_t calculated_size {calculate_serialized_size(data, current_alignment)}; if (CdrVersion::XCDRv2 == cdr_version_ && EncodingAlgorithmFlag::PL_CDR2 == current_encoding_ && 0 < calculated_size) @@ -1221,7 +1221,7 @@ class CdrSizeCalculator { extra_size = 4; // ShortMemberHeader - if (0x3F00 < id.id || calculated_size > std::numeric_limits::max()) + if (0x3F00 < id.id || calculated_size > std::numeric_limits::max()) { extra_size += 8; // LongMemberHeader } @@ -1248,12 +1248,12 @@ class CdrSizeCalculator * @return Encoded size of the member's instance. */ template - size_t calculate_member_serialized_size( + std::size_t calculate_member_serialized_size( const MemberId& id, const optional<_T>& data, - size_t& current_alignment) + std::size_t& current_alignment) { - size_t initial_alignment = current_alignment; + std::size_t initial_alignment = current_alignment; if (CdrVersion::XCDRv2 != cdr_version_ || EncodingAlgorithmFlag::PL_CDR2 == current_encoding_) @@ -1265,8 +1265,8 @@ class CdrSizeCalculator } } - size_t prev_size = {current_alignment - initial_alignment}; - size_t extra_size {0}; + std::size_t prev_size = {current_alignment - initial_alignment}; + std::size_t extra_size {0}; if (CdrVersion::XCDRv1 == cdr_version_ && (data.has_value() || EncodingAlgorithmFlag::PLAIN_CDR == current_encoding_)) @@ -1274,7 +1274,7 @@ class CdrSizeCalculator current_alignment = 0; } - size_t calculated_size {calculate_serialized_size(data, current_alignment)}; + std::size_t calculated_size {calculate_serialized_size(data, current_alignment)}; if (CdrVersion::XCDRv2 == cdr_version_ && EncodingAlgorithmFlag::PL_CDR2 == current_encoding_ && 0 < calculated_size) @@ -1299,7 +1299,7 @@ class CdrSizeCalculator { extra_size = 4; // ShortMemberHeader - if (0x3F00 < id.id || calculated_size > std::numeric_limits::max()) + if (0x3F00 < id.id || calculated_size > std::numeric_limits::max()) { extra_size += 8; // LongMemberHeader } @@ -1322,9 +1322,9 @@ class CdrSizeCalculator * @param[inout] current_alignment Current alignment in the encoding. * @return If new encoding algorithm encodes a header, return the encoded size of it. */ - Cdr_DllAPI size_t begin_calculate_type_serialized_size( + Cdr_DllAPI std::size_t begin_calculate_type_serialized_size( EncodingAlgorithmFlag new_encoding, - size_t& current_alignment); + std::size_t& current_alignment); /*! * @brief Indicates the ending of a constructed type. @@ -1332,9 +1332,9 @@ class CdrSizeCalculator * @param[inout] current_alignment Current alignment in the encoding. * @return If current encoding algorithm encodes a final mark, return the encoded size of it. */ - Cdr_DllAPI size_t end_calculate_type_serialized_size( + Cdr_DllAPI std::size_t end_calculate_type_serialized_size( EncodingAlgorithmFlag new_encoding, - size_t& current_alignment); + std::size_t& current_alignment); private: @@ -1355,14 +1355,14 @@ class CdrSizeCalculator serialized_member_size_ {NO_SERIALIZED_MEMBER_SIZE}; //! Align for types equal or greater than 64bits. - size_t align64_ {4}; + std::size_t align64_ {4}; //! Custom serialization context. std::shared_ptr context_; - inline size_t alignment( - size_t current_alignment, - size_t data_size) const + inline std::size_t alignment( + std::size_t current_alignment, + std::size_t data_size) const { return (data_size - (current_alignment % data_size)) & (data_size - 1); } diff --git a/include/fastcdr/FastBuffer.h b/include/fastcdr/FastBuffer.h index 6c85f46c..8db6e857 100644 --- a/include/fastcdr/FastBuffer.h +++ b/include/fastcdr/FastBuffer.h @@ -16,18 +16,18 @@ #define _FASTCDR_CDRBUFFER_H_ #include "fastcdr_dll.h" -#include +#include #include -#include +#include #include #include -inline uint32_t size_to_uint32( - size_t val) +inline std::uint32_t size_to_uint32( + std::size_t val) { #if defined(_WIN32) || !defined(FASTCDR_ARM32) // On 64 bit platforms and all Windows architectures (because of C4267), explicitly cast. - return static_cast(val); + return static_cast(val); #else // Skip useless cast on 32-bit builds. return val; @@ -57,7 +57,7 @@ class Cdr_DllAPI _FastBuffer_iterator */ explicit _FastBuffer_iterator( char* buffer, - size_t index) + std::size_t index) : buffer_(buffer) , current_position_(&buffer_[index]) { @@ -73,7 +73,7 @@ class Cdr_DllAPI _FastBuffer_iterator void operator <<( const _FastBuffer_iterator& iterator) { - ptrdiff_t diff = current_position_ - buffer_; + std::ptrdiff_t diff = current_position_ - buffer_; buffer_ = iterator.buffer_; current_position_ = buffer_ + diff; } @@ -87,7 +87,7 @@ class Cdr_DllAPI _FastBuffer_iterator void operator >>( const _FastBuffer_iterator& iterator) { - ptrdiff_t diff = iterator.current_position_ - iterator.buffer_; + std::ptrdiff_t diff = iterator.current_position_ - iterator.buffer_; current_position_ = buffer_ + diff; } @@ -101,7 +101,7 @@ class Cdr_DllAPI _FastBuffer_iterator void operator <<( const _T& data) { - memcpy(current_position_, &data, sizeof(_T)); + std::memcpy(current_position_, &data, sizeof(_T)); } /*! @@ -114,7 +114,7 @@ class Cdr_DllAPI _FastBuffer_iterator void operator >>( _T& data) { - memcpy(&data, current_position_, sizeof(_T)); + std::memcpy(&data, current_position_, sizeof(_T)); } /*! @@ -125,11 +125,11 @@ class Cdr_DllAPI _FastBuffer_iterator inline void memcopy( const void* src, - const size_t size) + const std::size_t size) { if (size > 0) { - memcpy(current_position_, src, size); + std::memcpy(current_position_, src, size); } } @@ -141,11 +141,11 @@ class Cdr_DllAPI _FastBuffer_iterator inline void rmemcopy( void* dst, - const size_t size) + const std::size_t size) { if (size > 0) { - memcpy(dst, current_position_, size); + std::memcpy(dst, current_position_, size); } } @@ -155,14 +155,14 @@ class Cdr_DllAPI _FastBuffer_iterator */ inline void operator +=( - size_t num_bytes) + std::size_t num_bytes) { current_position_ += num_bytes; } inline void operator -=( - size_t num_bytes) + std::size_t num_bytes) { current_position_ -= num_bytes; } @@ -173,10 +173,10 @@ class Cdr_DllAPI _FastBuffer_iterator * @return The result of subtract the current iterator's position and the source iterator's position. */ inline - size_t operator -( + std::size_t operator -( const _FastBuffer_iterator& it) const { - return static_cast(current_position_ - it.current_position_); + return static_cast(current_position_ - it.current_position_); } /*! @@ -262,7 +262,7 @@ class Cdr_DllAPI FastBuffer */ FastBuffer( char* const buffer, - const size_t bufferSize); + const std::size_t bufferSize); //! Move constructor FastBuffer( @@ -304,7 +304,7 @@ class Cdr_DllAPI FastBuffer * @brief This function returns the size of the allocated memory of the stream that the eprosima::fastcdr::FastBuffers uses to serialize data. * @return The size of the allocated memory of the stream used by the eprosima::fastcdr::FastBuffers to serialize data. */ - inline size_t getBufferSize() const + inline std::size_t getBufferSize() const { return size_; } @@ -335,7 +335,7 @@ class Cdr_DllAPI FastBuffer * @return True if the allocation suceeded. False if the raw buffer was set externally or is already allocated. */ bool reserve( - size_t size); + std::size_t size); /*! * @brief This function resizes the raw buffer. It will call the user's defined function for this purpose. @@ -343,7 +343,7 @@ class Cdr_DllAPI FastBuffer * @return True if the operation works. False if it does not. */ bool resize( - size_t min_size_inc); + std::size_t min_size_inc); private: @@ -357,7 +357,7 @@ class Cdr_DllAPI FastBuffer char* buffer_ { nullptr }; //! @brief The total size of the user's buffer. - size_t size_ { 0 }; + std::size_t size_ { 0 }; //! @brief This variable indicates if the managed buffer is internal or is from the user. bool m_internalBuffer { true }; diff --git a/include/fastcdr/FastCdr.h b/include/fastcdr/FastCdr.h index b762992c..dd566cbd 100644 --- a/include/fastcdr/FastCdr.h +++ b/include/fastcdr/FastCdr.h @@ -21,11 +21,7 @@ #include #include -#if !__APPLE__ && !__FreeBSD__ && !__VXWORKS__ -#include -#else -#include -#endif // if !__APPLE__ && !__FreeBSD__ && !__VXWORKS__ +#include #include "fastcdr_dll.h" #include "FastBuffer.h" @@ -87,7 +83,7 @@ class Cdr_DllAPI FastCdr * @return True is returned when the jump operation works successfully. Otherwise, false is returned. */ bool jump( - size_t num_bytes); + std::size_t num_bytes); /*! * @brief This function resets the current position in the buffer to the begining. @@ -104,7 +100,7 @@ class Cdr_DllAPI FastCdr * @brief This function returns the length of the serialized data inside the stream. * @return The length of the serialized data. */ - inline size_t get_serialized_data_length() const + inline std::size_t get_serialized_data_length() const { return current_position_ - cdr_buffer_.begin(); } @@ -129,7 +125,7 @@ class Cdr_DllAPI FastCdr * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size. */ inline FastCdr& operator <<( - const uint8_t octet_t) + const std::uint8_t octet_t) { return serialize(octet_t); } @@ -153,7 +149,7 @@ class Cdr_DllAPI FastCdr * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size. */ inline FastCdr& operator <<( - const int8_t int8) + const std::int8_t int8) { return serialize(int8); } @@ -165,7 +161,7 @@ class Cdr_DllAPI FastCdr * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size. */ inline FastCdr& operator <<( - const uint16_t ushort_t) + const std::uint16_t ushort_t) { return serialize(ushort_t); } @@ -177,7 +173,7 @@ class Cdr_DllAPI FastCdr * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size. */ inline FastCdr& operator <<( - const int16_t short_t) + const std::int16_t short_t) { return serialize(short_t); } @@ -189,7 +185,7 @@ class Cdr_DllAPI FastCdr * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size. */ inline FastCdr& operator <<( - const uint32_t ulong_t) + const std::uint32_t ulong_t) { return serialize(ulong_t); } @@ -201,7 +197,7 @@ class Cdr_DllAPI FastCdr * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size. */ inline FastCdr& operator <<( - const int32_t long_t) + const std::int32_t long_t) { return serialize(long_t); } @@ -225,7 +221,7 @@ class Cdr_DllAPI FastCdr * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size. */ inline FastCdr& operator <<( - const uint64_t ulonglong_t) + const std::uint64_t ulonglong_t) { return serialize(ulonglong_t); } @@ -237,7 +233,7 @@ class Cdr_DllAPI FastCdr * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size. */ inline FastCdr& operator <<( - const int64_t longlong_t) + const std::int64_t longlong_t) { return serialize(longlong_t); } @@ -344,7 +340,7 @@ class Cdr_DllAPI FastCdr * @return Reference to the eprosima::fastcdr::FastCdr object. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size. */ - template + template inline FastCdr& operator <<( const std::array<_T, _Size>& array_t) { @@ -385,7 +381,7 @@ class Cdr_DllAPI FastCdr * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size. */ inline FastCdr& operator >>( - uint8_t& octet_t) + std::uint8_t& octet_t) { return deserialize(octet_t); } @@ -409,7 +405,7 @@ class Cdr_DllAPI FastCdr * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size. */ inline FastCdr& operator >>( - int8_t& int8) + std::int8_t& int8) { return deserialize(int8); } @@ -421,7 +417,7 @@ class Cdr_DllAPI FastCdr * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size. */ inline FastCdr& operator >>( - uint16_t& ushort_t) + std::uint16_t& ushort_t) { return deserialize(ushort_t); } @@ -433,7 +429,7 @@ class Cdr_DllAPI FastCdr * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size. */ inline FastCdr& operator >>( - int16_t& short_t) + std::int16_t& short_t) { return deserialize(short_t); } @@ -445,7 +441,7 @@ class Cdr_DllAPI FastCdr * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size. */ inline FastCdr& operator >>( - uint32_t& ulong_t) + std::uint32_t& ulong_t) { return deserialize(ulong_t); } @@ -457,7 +453,7 @@ class Cdr_DllAPI FastCdr * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size. */ inline FastCdr& operator >>( - int32_t& long_t) + std::int32_t& long_t) { return deserialize(long_t); } @@ -481,7 +477,7 @@ class Cdr_DllAPI FastCdr * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size. */ inline FastCdr& operator >>( - uint64_t& ulonglong_t) + std::uint64_t& ulonglong_t) { return deserialize(ulonglong_t); } @@ -493,7 +489,7 @@ class Cdr_DllAPI FastCdr * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size. */ inline FastCdr& operator >>( - int64_t& longlong_t) + std::int64_t& longlong_t) { return deserialize(longlong_t); } @@ -592,7 +588,7 @@ class Cdr_DllAPI FastCdr * @return Reference to the eprosima::fastcdr::FastCdr object. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size. */ - template + template inline FastCdr& operator >>( std::array<_T, _Size>& array_t) { @@ -634,7 +630,7 @@ class Cdr_DllAPI FastCdr */ inline FastCdr& serialize( - const uint8_t octet_t) + const std::uint8_t octet_t) { return serialize(static_cast(octet_t)); } @@ -667,7 +663,7 @@ class Cdr_DllAPI FastCdr */ inline FastCdr& serialize( - const int8_t int8) + const std::int8_t int8) { return serialize(static_cast(int8)); } @@ -680,9 +676,9 @@ class Cdr_DllAPI FastCdr */ inline FastCdr& serialize( - const uint16_t ushort_t) + const std::uint16_t ushort_t) { - return serialize(static_cast(ushort_t)); + return serialize(static_cast(ushort_t)); } /*! @@ -693,7 +689,7 @@ class Cdr_DllAPI FastCdr */ inline FastCdr& serialize( - const int16_t short_t) + const std::int16_t short_t) { if (((last_position_ - current_position_) >= sizeof(short_t)) || resize(sizeof(short_t))) { @@ -715,9 +711,9 @@ class Cdr_DllAPI FastCdr */ inline FastCdr& serialize( - const uint32_t ulong_t) + const std::uint32_t ulong_t) { - return serialize(static_cast(ulong_t)); + return serialize(static_cast(ulong_t)); } /*! @@ -728,7 +724,7 @@ class Cdr_DllAPI FastCdr */ inline FastCdr& serialize( - const int32_t long_t) + const std::int32_t long_t) { if (((last_position_ - current_position_) >= sizeof(long_t)) || resize(sizeof(long_t))) { @@ -752,7 +748,7 @@ class Cdr_DllAPI FastCdr FastCdr& serialize( const wchar_t wchar) { - return serialize(static_cast(wchar)); + return serialize(static_cast(wchar)); } /*! @@ -763,9 +759,9 @@ class Cdr_DllAPI FastCdr */ inline FastCdr& serialize( - const uint64_t ulonglong_t) + const std::uint64_t ulonglong_t) { - return serialize(static_cast(ulonglong_t)); + return serialize(static_cast(ulonglong_t)); } /*! @@ -776,7 +772,7 @@ class Cdr_DllAPI FastCdr */ inline FastCdr& serialize( - const int64_t longlong_t) + const std::int64_t longlong_t) { if (((last_position_ - current_position_) >= sizeof(longlong_t)) || resize(sizeof(longlong_t))) { @@ -900,7 +896,7 @@ class Cdr_DllAPI FastCdr { // Check there are no null characters in the string. const char* c_str = string_t.c_str(); - const auto str_len = strlen(c_str); + const auto str_len = std::strlen(c_str); if (string_t.size() > str_len) { throw exception::BadParamException("The string contains null characters"); @@ -928,7 +924,7 @@ class Cdr_DllAPI FastCdr * @return Reference to the eprosima::fastcdr::FastCdr object. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size. */ - template + template inline FastCdr& serialize( const std::array<_T, _Size>& array_t) { @@ -960,7 +956,7 @@ class Cdr_DllAPI FastCdr { state state_before_error(*this); - *this << static_cast(vector_t.size()); + *this << static_cast(vector_t.size()); try { @@ -1014,8 +1010,8 @@ class Cdr_DllAPI FastCdr */ inline FastCdr& serialize_array( - const uint8_t* octet_t, - size_t num_elements) + const std::uint8_t* octet_t, + std::size_t num_elements) { return serialize_array(reinterpret_cast(octet_t), num_elements); } @@ -1029,7 +1025,7 @@ class Cdr_DllAPI FastCdr */ FastCdr& serialize_array( const char* char_t, - size_t num_elements); + std::size_t num_elements); /*! * @brief This function serializes an array of int8_t. @@ -1040,8 +1036,8 @@ class Cdr_DllAPI FastCdr */ inline FastCdr& serialize_array( - const int8_t* int8, - size_t num_elements) + const std::int8_t* int8, + std::size_t num_elements) { return serialize_array(reinterpret_cast(int8), num_elements); } @@ -1055,10 +1051,10 @@ class Cdr_DllAPI FastCdr */ inline FastCdr& serialize_array( - const uint16_t* ushort_t, - size_t num_elements) + const std::uint16_t* ushort_t, + std::size_t num_elements) { - return serialize_array(reinterpret_cast(ushort_t), num_elements); + return serialize_array(reinterpret_cast(ushort_t), num_elements); } /*! @@ -1069,8 +1065,8 @@ class Cdr_DllAPI FastCdr * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size. */ FastCdr& serialize_array( - const int16_t* short_t, - size_t num_elements); + const std::int16_t* short_t, + std::size_t num_elements); /*! * @brief This function serializes an array of unsigned longs. @@ -1081,10 +1077,10 @@ class Cdr_DllAPI FastCdr */ inline FastCdr& serialize_array( - const uint32_t* ulong_t, - size_t num_elements) + const std::uint32_t* ulong_t, + std::size_t num_elements) { - return serialize_array(reinterpret_cast(ulong_t), num_elements); + return serialize_array(reinterpret_cast(ulong_t), num_elements); } /*! @@ -1095,8 +1091,8 @@ class Cdr_DllAPI FastCdr * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size. */ FastCdr& serialize_array( - const int32_t* long_t, - size_t num_elements); + const std::int32_t* long_t, + std::size_t num_elements); /*! * @brief This function serializes an array of wide-chars. @@ -1107,7 +1103,7 @@ class Cdr_DllAPI FastCdr */ FastCdr& serialize_array( const wchar_t* wchar, - size_t num_elements); + std::size_t num_elements); /*! * @brief This function serializes an array of unsigned long longs. @@ -1118,10 +1114,10 @@ class Cdr_DllAPI FastCdr */ inline FastCdr& serialize_array( - const uint64_t* ulonglong_t, - size_t num_elements) + const std::uint64_t* ulonglong_t, + std::size_t num_elements) { - return serialize_array(reinterpret_cast(ulonglong_t), num_elements); + return serialize_array(reinterpret_cast(ulonglong_t), num_elements); } /*! @@ -1132,8 +1128,8 @@ class Cdr_DllAPI FastCdr * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size. */ FastCdr& serialize_array( - const int64_t* longlong_t, - size_t num_elements); + const std::int64_t* longlong_t, + std::size_t num_elements); /*! * @brief This function serializes an array of floats. @@ -1144,7 +1140,7 @@ class Cdr_DllAPI FastCdr */ FastCdr& serialize_array( const float* float_t, - size_t num_elements); + std::size_t num_elements); /*! * @brief This function serializes an array of doubles. @@ -1155,7 +1151,7 @@ class Cdr_DllAPI FastCdr */ FastCdr& serialize_array( const double* double_t, - size_t num_elements); + std::size_t num_elements); /*! * @brief This function serializes an array of long doubles. @@ -1166,7 +1162,7 @@ class Cdr_DllAPI FastCdr */ FastCdr& serialize_array( const long double* ldouble_t, - size_t num_elements); + std::size_t num_elements); /*! * @brief This function serializes an array of booleans. @@ -1177,7 +1173,7 @@ class Cdr_DllAPI FastCdr */ FastCdr& serialize_array( const bool* bool_t, - size_t num_elements); + std::size_t num_elements); /*! * @brief This function serializes an array of strings. @@ -1189,9 +1185,9 @@ class Cdr_DllAPI FastCdr inline FastCdr& serialize_array( const std::string* string_t, - size_t num_elements) + std::size_t num_elements) { - for (size_t count = 0; count < num_elements; ++count) + for (std::size_t count = 0; count < num_elements; ++count) { serialize(string_t[count].c_str()); } @@ -1208,9 +1204,9 @@ class Cdr_DllAPI FastCdr inline FastCdr& serialize_array( const std::wstring* string_t, - size_t num_elements) + std::size_t num_elements) { - for (size_t count = 0; count < num_elements; ++count) + for (std::size_t count = 0; count < num_elements; ++count) { serialize(string_t[count].c_str()); } @@ -1227,9 +1223,9 @@ class Cdr_DllAPI FastCdr template FastCdr& serialize_array( const std::vector<_T>* vector_t, - size_t num_elements) + std::size_t num_elements) { - for (size_t count = 0; count < num_elements; ++count) + for (std::size_t count = 0; count < num_elements; ++count) { serialize(vector_t[count]); } @@ -1246,9 +1242,9 @@ class Cdr_DllAPI FastCdr template FastCdr& serialize_array( const _T* type_t, - size_t num_elements) + std::size_t num_elements) { - for (size_t count = 0; count < num_elements; ++count) + for (std::size_t count = 0; count < num_elements; ++count) { type_t[count].serialize(*this); } @@ -1265,11 +1261,11 @@ class Cdr_DllAPI FastCdr template FastCdr& serialize_sequence( const _T* sequence_t, - size_t num_elements) + std::size_t num_elements) { state state_before_error(*this); - serialize(static_cast(num_elements)); + serialize(static_cast(num_elements)); try { @@ -1292,7 +1288,7 @@ class Cdr_DllAPI FastCdr */ inline FastCdr& deserialize( - uint8_t& octet_t) + std::uint8_t& octet_t) { return deserialize(reinterpret_cast(octet_t)); } @@ -1325,7 +1321,7 @@ class Cdr_DllAPI FastCdr */ inline FastCdr& deserialize( - int8_t& int8) + std::int8_t& int8) { return deserialize(reinterpret_cast(int8)); } @@ -1338,9 +1334,9 @@ class Cdr_DllAPI FastCdr */ inline FastCdr& deserialize( - uint16_t& ushort_t) + std::uint16_t& ushort_t) { - return deserialize(reinterpret_cast(ushort_t)); + return deserialize(reinterpret_cast(ushort_t)); } /*! @@ -1351,7 +1347,7 @@ class Cdr_DllAPI FastCdr */ inline FastCdr& deserialize( - int16_t& short_t) + std::int16_t& short_t) { if ((last_position_ - current_position_) >= sizeof(short_t)) { @@ -1373,9 +1369,9 @@ class Cdr_DllAPI FastCdr */ inline FastCdr& deserialize( - uint32_t& ulong_t) + std::uint32_t& ulong_t) { - return deserialize(reinterpret_cast(ulong_t)); + return deserialize(reinterpret_cast(ulong_t)); } /*! @@ -1386,7 +1382,7 @@ class Cdr_DllAPI FastCdr */ inline FastCdr& deserialize( - int32_t& long_t) + std::int32_t& long_t) { if ((last_position_ - current_position_) >= sizeof(long_t)) { @@ -1410,7 +1406,7 @@ class Cdr_DllAPI FastCdr FastCdr& deserialize( wchar_t& wchar) { - uint32_t ret; + std::uint32_t ret; deserialize(ret); wchar = static_cast(ret); return *this; @@ -1424,9 +1420,9 @@ class Cdr_DllAPI FastCdr */ inline FastCdr& deserialize( - uint64_t& ulonglong_t) + std::uint64_t& ulonglong_t) { - return deserialize(reinterpret_cast(ulonglong_t)); + return deserialize(reinterpret_cast(ulonglong_t)); } /*! @@ -1437,7 +1433,7 @@ class Cdr_DllAPI FastCdr */ inline FastCdr& deserialize( - int64_t& longlong_t) + std::int64_t& longlong_t) { if ((last_position_ - current_position_) >= sizeof(longlong_t)) { @@ -1564,7 +1560,7 @@ class Cdr_DllAPI FastCdr FastCdr& deserialize( std::string& string_t) { - uint32_t length = 0; + std::uint32_t length = 0; const char* str = read_string(length); string_t.assign(str, length); return *this; @@ -1580,7 +1576,7 @@ class Cdr_DllAPI FastCdr FastCdr& deserialize( std::wstring& string_t) { - uint32_t length = 0; + std::uint32_t length = 0; string_t = read_wstring(length); return *this; } @@ -1591,7 +1587,7 @@ class Cdr_DllAPI FastCdr * @return Reference to the eprosima::fastcdr::FastCdr object. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size. */ - template + template inline FastCdr& deserialize( std::array<_T, _Size>& array_t) { @@ -1621,7 +1617,7 @@ class Cdr_DllAPI FastCdr FastCdr& deserialize( std::vector<_T>& vector_t) { - uint32_t sequence_length = 0; + std::uint32_t sequence_length = 0; state state_before_error(*this); *this >> sequence_length; @@ -1679,8 +1675,8 @@ class Cdr_DllAPI FastCdr */ inline FastCdr& deserialize_array( - uint8_t* octet_t, - size_t num_elements) + std::uint8_t* octet_t, + std::size_t num_elements) { return deserialize_array(reinterpret_cast(octet_t), num_elements); } @@ -1694,7 +1690,7 @@ class Cdr_DllAPI FastCdr */ FastCdr& deserialize_array( char* char_t, - size_t num_elements); + std::size_t num_elements); /*! * @brief This function deserializes an array of int8_t. @@ -1705,8 +1701,8 @@ class Cdr_DllAPI FastCdr */ inline FastCdr& deserialize_array( - int8_t* int8, - size_t num_elements) + std::int8_t* int8, + std::size_t num_elements) { return deserialize_array(reinterpret_cast(int8), num_elements); } @@ -1720,10 +1716,10 @@ class Cdr_DllAPI FastCdr */ inline FastCdr& deserialize_array( - uint16_t* ushort_t, - size_t num_elements) + std::uint16_t* ushort_t, + std::size_t num_elements) { - return deserialize_array(reinterpret_cast(ushort_t), num_elements); + return deserialize_array(reinterpret_cast(ushort_t), num_elements); } /*! @@ -1734,8 +1730,8 @@ class Cdr_DllAPI FastCdr * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size. */ FastCdr& deserialize_array( - int16_t* short_t, - size_t num_elements); + std::int16_t* short_t, + std::size_t num_elements); /*! * @brief This function deserializes an array of unsigned longs. @@ -1746,10 +1742,10 @@ class Cdr_DllAPI FastCdr */ inline FastCdr& deserialize_array( - uint32_t* ulong_t, - size_t num_elements) + std::uint32_t* ulong_t, + std::size_t num_elements) { - return deserialize_array(reinterpret_cast(ulong_t), num_elements); + return deserialize_array(reinterpret_cast(ulong_t), num_elements); } /*! @@ -1760,8 +1756,8 @@ class Cdr_DllAPI FastCdr * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size. */ FastCdr& deserialize_array( - int32_t* long_t, - size_t num_elements); + std::int32_t* long_t, + std::size_t num_elements); /*! * @brief This function deserializes an array of wide-chars. @@ -1772,7 +1768,7 @@ class Cdr_DllAPI FastCdr */ FastCdr& deserialize_array( wchar_t* wchar, - size_t num_elements); + std::size_t num_elements); /*! * @brief This function deserializes an array of unsigned long longs. @@ -1783,10 +1779,10 @@ class Cdr_DllAPI FastCdr */ inline FastCdr& deserialize_array( - uint64_t* ulonglong_t, - size_t num_elements) + std::uint64_t* ulonglong_t, + std::size_t num_elements) { - return deserialize_array(reinterpret_cast(ulonglong_t), num_elements); + return deserialize_array(reinterpret_cast(ulonglong_t), num_elements); } /*! @@ -1797,8 +1793,8 @@ class Cdr_DllAPI FastCdr * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size. */ FastCdr& deserialize_array( - int64_t* longlong_t, - size_t num_elements); + std::int64_t* longlong_t, + std::size_t num_elements); /*! * @brief This function deserializes an array of floats. @@ -1809,7 +1805,7 @@ class Cdr_DllAPI FastCdr */ FastCdr& deserialize_array( float* float_t, - size_t num_elements); + std::size_t num_elements); /*! * @brief This function deserializes an array of doubles. @@ -1820,7 +1816,7 @@ class Cdr_DllAPI FastCdr */ FastCdr& deserialize_array( double* double_t, - size_t num_elements); + std::size_t num_elements); /*! * @brief This function deserializes an array of long doubles. @@ -1831,7 +1827,7 @@ class Cdr_DllAPI FastCdr */ FastCdr& deserialize_array( long double* ldouble_t, - size_t num_elements); + std::size_t num_elements); /*! * @brief This function deserializes an array of booleans. @@ -1842,7 +1838,7 @@ class Cdr_DllAPI FastCdr */ FastCdr& deserialize_array( bool* bool_t, - size_t num_elements); + std::size_t num_elements); /*! * @brief This function deserializes an array of strings. @@ -1854,9 +1850,9 @@ class Cdr_DllAPI FastCdr inline FastCdr& deserialize_array( std::string* string_t, - size_t num_elements) + std::size_t num_elements) { - for (size_t count = 0; count < num_elements; ++count) + for (std::size_t count = 0; count < num_elements; ++count) { deserialize(string_t[count]); } @@ -1873,9 +1869,9 @@ class Cdr_DllAPI FastCdr inline FastCdr& deserialize_array( std::wstring* string_t, - size_t num_elements) + std::size_t num_elements) { - for (size_t count = 0; count < num_elements; ++count) + for (std::size_t count = 0; count < num_elements; ++count) { deserialize(string_t[count]); } @@ -1892,9 +1888,9 @@ class Cdr_DllAPI FastCdr template FastCdr& deserialize_array( std::vector<_T>* vector_t, - size_t num_elements) + std::size_t num_elements) { - for (size_t count = 0; count < num_elements; ++count) + for (std::size_t count = 0; count < num_elements; ++count) { deserialize(vector_t[count]); } @@ -1911,9 +1907,9 @@ class Cdr_DllAPI FastCdr template FastCdr& deserialize_array( _T* type_t, - size_t num_elements) + std::size_t num_elements) { - for (size_t count = 0; count < num_elements; ++count) + for (std::size_t count = 0; count < num_elements; ++count) { type_t[count].deserialize(*this); } @@ -1932,7 +1928,7 @@ class Cdr_DllAPI FastCdr template FastCdr& deserialize_sequence( std::string*& sequence_t, - size_t& num_elements) + std::size_t& num_elements) { return deserialize_string_sequence(sequence_t, num_elements); } @@ -1949,7 +1945,7 @@ class Cdr_DllAPI FastCdr template FastCdr& deserialize_sequence( std::wstring*& sequence_t, - size_t& num_elements) + std::size_t& num_elements) { return deserialize_wstring_sequence(sequence_t, num_elements); } @@ -1966,21 +1962,21 @@ class Cdr_DllAPI FastCdr template FastCdr& deserialize_sequence( _T*& sequence_t, - size_t& num_elements) + std::size_t& num_elements) { - uint32_t sequence_length = 0; + std::uint32_t sequence_length = 0; state state_before_error(*this); deserialize(sequence_length); try { - sequence_t = reinterpret_cast<_T*>(calloc(sequence_length, sizeof(_T))); + sequence_t = reinterpret_cast<_T*>(std::calloc(sequence_length, sizeof(_T))); deserialize_array(sequence_t, sequence_length); } catch (eprosima::fastcdr::exception::Exception& ex) { - free(sequence_t); + std::free(sequence_t); sequence_t = NULL; set_state(state_before_error); ex.raise(); @@ -2003,7 +1999,7 @@ class Cdr_DllAPI FastCdr template<> FastCdr& deserialize_sequence( std::string*& sequence_t, - size_t& num_elements) + std::size_t& num_elements) { return deserialize_string_sequence(sequence_t, num_elements); } @@ -2020,7 +2016,7 @@ class Cdr_DllAPI FastCdr template<> FastCdr& deserialize_sequence( std::wstring*& sequence_t, - size_t& num_elements) + std::size_t& num_elements) { return deserialize_wstring_sequence(sequence_t, num_elements); } @@ -2053,11 +2049,11 @@ class Cdr_DllAPI FastCdr FastCdr& deserialize_string_sequence( std::string*& sequence_t, - size_t& num_elements); + std::size_t& num_elements); FastCdr& deserialize_wstring_sequence( std::wstring*& sequence_t, - size_t& num_elements); + std::size_t& num_elements); /*! * @brief This function template detects the content type of the STD container array and serializes the array. @@ -2066,10 +2062,10 @@ class Cdr_DllAPI FastCdr * @return Reference to the eprosima::fastcdr::FastCdr object. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to serialize in a position that exceeds the internal memory size. */ - template + template FastCdr& serialize_array( const std::array<_T, _Size>* array_t, - size_t num_elements) + std::size_t num_elements) { if (num_elements == 0 || array_t == nullptr) { @@ -2085,10 +2081,10 @@ class Cdr_DllAPI FastCdr * @return Reference to the eprosima::fastcdr::FastCdr object. * @exception exception::NotEnoughMemoryException This exception is thrown when trying to deserialize in a position that exceeds the internal memory size. */ - template + template FastCdr& deserialize_array( std::array<_T, _Size>* array_t, - size_t num_elements) + std::size_t num_elements) { if (num_elements == 0 || array_t == nullptr) { @@ -2098,13 +2094,13 @@ class Cdr_DllAPI FastCdr } bool resize( - size_t min_size_inc); + std::size_t min_size_inc); const char* read_string( - uint32_t& length); + std::uint32_t& length); std::wstring read_wstring( - uint32_t& length); + std::uint32_t& length); //! @brief Reference to the buffer that will be serialized/deserialized. FastBuffer& cdr_buffer_; diff --git a/include/fastcdr/cdr/fixed_size_string.hpp b/include/fastcdr/cdr/fixed_size_string.hpp index 022d68d7..ba2754a5 100644 --- a/include/fastcdr/cdr/fixed_size_string.hpp +++ b/include/fastcdr/cdr/fixed_size_string.hpp @@ -40,18 +40,18 @@ namespace fastcdr { * @tparam MAX_CHARS Maximum number of characters is specified as the template parameter. * Space for an additional null terminator will be reserved. */ -template +template struct fixed_string { public: //! @brief Maximum number of characters. - static constexpr size_t max_size = MAX_CHARS; + static constexpr std::size_t max_size = MAX_CHARS; //! @brief Default constructor. fixed_string() noexcept { - memset(string_data, 0, sizeof(string_data)); + std::memset(string_data, 0, sizeof(string_data)); string_len = 0; } @@ -64,7 +64,7 @@ struct fixed_string */ fixed_string( const char* c_array, - size_t n_chars) noexcept + std::size_t n_chars) noexcept { assign(c_array, n_chars); } @@ -77,13 +77,13 @@ struct fixed_string */ fixed_string& assign( const char* c_array, - size_t n_chars) noexcept + std::size_t n_chars) noexcept { string_len = (nullptr == c_array) ? 0 : (MAX_CHARS < n_chars) ? MAX_CHARS : n_chars; if (0 < string_len) { - memcpy(string_data, c_array, string_len); + std::memcpy(string_data, c_array, string_len); } string_data[string_len] = '\0'; return *this; @@ -140,7 +140,7 @@ struct fixed_string * @param[in] rhs Reference to the fixed_string. * return Reference of this instance. */ - template fixed_string& operator = ( + template fixed_string& operator = ( const fixed_string& rhs) noexcept { set(rhs.c_str()); @@ -173,7 +173,7 @@ struct fixed_string bool operator == ( const char* rhs) const noexcept { - return strncmp(string_data, rhs, MAX_CHARS) == 0; + return std::strncmp(string_data, rhs, MAX_CHARS) == 0; } /*! @@ -184,7 +184,7 @@ struct fixed_string bool operator == ( const std::string& rhs) const noexcept { - return strncmp(string_data, rhs.c_str(), MAX_CHARS) == 0; + return std::strncmp(string_data, rhs.c_str(), MAX_CHARS) == 0; } /*! @@ -192,10 +192,10 @@ struct fixed_string * @param[in] rhs fixed_string to be compared with. * @return `true` if strings are equal. `false` otherwise. */ - template bool operator == ( + template bool operator == ( const fixed_string& rhs) const noexcept { - return strncmp(string_data, rhs.c_str(), MAX_CHARS) == 0; + return std::strncmp(string_data, rhs.c_str(), MAX_CHARS) == 0; } /*! @@ -225,7 +225,7 @@ struct fixed_string * @param[in] rhs fixed_string to be compared with. * @return `true` if strings are not equal. `false` otherwise. */ - template bool operator != ( + template bool operator != ( const fixed_string& rhs) const noexcept { return !(*this == rhs); @@ -236,7 +236,7 @@ struct fixed_string * @param[in] rhs fixed_string to be compared with. * @return `true` if this string is less than the provided one. `false` otherwise. */ - template bool operator < ( + template bool operator < ( const fixed_string& rhs) const noexcept { return 0 > compare(rhs); @@ -247,7 +247,7 @@ struct fixed_string * @param[in] rhs fixed_string to be compared with. * @return `true` if this string is greater than the provided one. `false` otherwise. */ - template bool operator > ( + template bool operator > ( const fixed_string& rhs) const noexcept { return 0 < compare(rhs); @@ -286,7 +286,7 @@ struct fixed_string * @brief Returns the size of the string. * @return Length of the string. */ - size_t size() const noexcept + std::size_t size() const noexcept { return string_len; } @@ -299,7 +299,7 @@ struct fixed_string int compare( const char* str) const noexcept { - return strncmp(string_data, str, MAX_CHARS); + return std::strncmp(string_data, str, MAX_CHARS); } /*! @@ -310,7 +310,7 @@ struct fixed_string int compare( const std::string& str) const noexcept { - return strncmp(string_data, str.c_str(), MAX_CHARS); + return std::strncmp(string_data, str.c_str(), MAX_CHARS); } /*! @@ -318,10 +318,10 @@ struct fixed_string * @param[in] str fixed_string to be compared with. * @return Integer value with the result of the comparison as described in `std::string::compare()`. */ - template int compare( + template int compare( const fixed_string& str) const noexcept { - return strncmp(string_data, str.c_str(), MAX_CHARS); + return std::strncmp(string_data, str.c_str(), MAX_CHARS); } private: @@ -330,11 +330,11 @@ struct fixed_string const char* c_string) noexcept { char* result = static_cast(MEMCCPY(string_data, c_string, '\0', MAX_CHARS)); - string_len = (result == nullptr) ? MAX_CHARS : static_cast(result - string_data) - 1u; + string_len = (result == nullptr) ? MAX_CHARS : static_cast(result - string_data) - 1u; } char string_data[MAX_CHARS + 1]; ///< Holds string data, including ending null character. - size_t string_len; ///< Holds current string length. + std::size_t string_len; ///< Holds current string length. }; using string_255 = fixed_string<255>; diff --git a/include/fastcdr/config.h.in b/include/fastcdr/config.h.in index 83126de9..08eaa3d2 100644 --- a/include/fastcdr/config.h.in +++ b/include/fastcdr/config.h.in @@ -15,6 +15,11 @@ #ifndef _FASTCDR_CONFIG_H_ #define _FASTCDR_CONFIG_H_ +// The C names (size_t, uint32_t, memcpy...) that the code generated by Fast DDS Gen uses without std:: +#include +#include +#include + #define FASTCDR_VERSION_MAJOR @PROJECT_VERSION_MAJOR@ #define FASTCDR_VERSION_MINOR @PROJECT_VERSION_MINOR@ #define FASTCDR_VERSION_MICRO @PROJECT_VERSION_PATCH@ diff --git a/include/fastcdr/detail/container_recursive_inspector.hpp b/include/fastcdr/detail/container_recursive_inspector.hpp index 6785c7fc..72a1d6cb 100644 --- a/include/fastcdr/detail/container_recursive_inspector.hpp +++ b/include/fastcdr/detail/container_recursive_inspector.hpp @@ -40,7 +40,7 @@ constexpr bool is_multi_array_primitive( return true; } -template +template constexpr bool is_multi_array_primitive( std::array<_T, _N> const*) { diff --git a/include/fastcdr/xcdr/MemberId.hpp b/include/fastcdr/xcdr/MemberId.hpp index 36693d52..8df3ba7b 100644 --- a/include/fastcdr/xcdr/MemberId.hpp +++ b/include/fastcdr/xcdr/MemberId.hpp @@ -31,13 +31,13 @@ class Cdr_DllAPI MemberId MemberId() = default; MemberId( - uint32_t id_value) + std::uint32_t id_value) : id(id_value) { } bool operator ==( - uint32_t id_value) const + std::uint32_t id_value) const { return id == id_value; } @@ -54,13 +54,13 @@ class Cdr_DllAPI MemberId return !(member_id == *this); } - uint32_t id { member_id_invalid_value_ }; + std::uint32_t id { member_id_invalid_value_ }; bool must_understand { false }; private: - static constexpr uint32_t member_id_invalid_value_ = 0xFFFFFFFF; + static constexpr std::uint32_t member_id_invalid_value_ = 0xFFFFFFFF; }; diff --git a/include/fastcdr/xcdr/optional.hpp b/include/fastcdr/xcdr/optional.hpp index ab130cb9..6505a869 100644 --- a/include/fastcdr/xcdr/optional.hpp +++ b/include/fastcdr/xcdr/optional.hpp @@ -15,6 +15,7 @@ #ifndef _FASTCDR_XCDR_OPTIONAL_HPP_ #define _FASTCDR_XCDR_OPTIONAL_HPP_ +#include #include #include diff --git a/src/cpp/Cdr.cpp b/src/cpp/Cdr.cpp index 9743ca5e..97c6222b 100644 --- a/src/cpp/Cdr.cpp +++ b/src/cpp/Cdr.cpp @@ -32,29 +32,29 @@ const Cdr::Endianness Cdr::DEFAULT_ENDIAN = BIG_ENDIANNESS; const Cdr::Endianness Cdr::DEFAULT_ENDIAN = LITTLE_ENDIANNESS; #endif // if FASTCDR_IS_BIG_ENDIAN_TARGET -constexpr uint16_t PID_EXTENDED = 0x3F01; -constexpr uint16_t PID_EXTENDED_LENGTH = 0x8; -constexpr uint16_t PID_SENTINEL = 0x3F02; -constexpr uint16_t PID_SENTINEL_LENGTH = 0x0; +constexpr std::uint16_t PID_EXTENDED = 0x3F01; +constexpr std::uint16_t PID_EXTENDED_LENGTH = 0x8; +constexpr std::uint16_t PID_SENTINEL = 0x3F02; +constexpr std::uint16_t PID_SENTINEL_LENGTH = 0x0; -constexpr uint8_t operator ""_8u( +constexpr std::uint8_t operator ""_8u( unsigned long long int value) { - return static_cast(value); + return static_cast(value); } -inline size_t alignment_on_state( +inline std::size_t alignment_on_state( const FastBuffer::iterator& origin, const FastBuffer::iterator& offset, - size_t data_size) + std::size_t data_size) { return (data_size - ((offset - origin) % data_size)) & (data_size - 1); } -inline uint32_t Cdr::get_long_lc( +inline std::uint32_t Cdr::get_long_lc( SerializedMemberSizeForNextInt serialized_member_size) { - uint32_t lc {0x40000000}; + std::uint32_t lc {0x40000000}; switch (serialized_member_size) { @@ -74,10 +74,10 @@ inline uint32_t Cdr::get_long_lc( return lc; } -inline uint32_t Cdr::get_short_lc( - size_t member_serialized_size) +inline std::uint32_t Cdr::get_short_lc( + std::size_t member_serialized_size) { - uint32_t lc {0xFFFFFFFFu}; + std::uint32_t lc {0xFFFFFFFFu}; switch (member_serialized_size) { case 1: @@ -211,8 +211,8 @@ void Cdr::reset_callbacks() Cdr& Cdr::read_encapsulation() { - uint8_t dummy {0}; - uint8_t encapsulation {0}; + std::uint8_t dummy {0}; + std::uint8_t encapsulation {0}; state state_before_error(*this); try @@ -232,7 +232,7 @@ Cdr& Cdr::read_encapsulation() // If it is a different endianness, make changes. - const uint8_t endianness = encapsulation & 0x1_8u; + const std::uint8_t endianness = encapsulation & 0x1_8u; if (endianness_ != endianness) { swap_bytes_ = !swap_bytes_; @@ -240,7 +240,7 @@ Cdr& Cdr::read_encapsulation() } // Check encapsulationKind correctness - const uint8_t encoding_flag = encapsulation & static_cast(~0x1); + const std::uint8_t encoding_flag = encapsulation & static_cast(~0x1); switch (encoding_flag) { case EncodingAlgorithmFlag::PLAIN_CDR2: @@ -289,7 +289,7 @@ Cdr& Cdr::read_encapsulation() { deserialize(options_); - uint8_t option_align {static_cast(options_[1] & 0x3u)}; + std::uint8_t option_align {static_cast(options_[1] & 0x3u)}; if (0 < option_align) { @@ -316,8 +316,8 @@ Cdr& Cdr::read_encapsulation() Cdr& Cdr::serialize_encapsulation() { - uint8_t dummy = 0; - uint8_t encapsulation = 0; + std::uint8_t dummy = 0; + std::uint8_t encapsulation = 0; state state_before_error(*this); try @@ -387,13 +387,13 @@ bool Cdr::set_encoding_flag( return ret_value; } -std::array Cdr::get_dds_cdr_options() const +std::array Cdr::get_dds_cdr_options() const { return options_; } void Cdr::set_dds_cdr_options( - const std::array& options) + const std::array& options) { options_ = options; @@ -402,7 +402,7 @@ void Cdr::set_dds_cdr_options( { auto length {offset_ - cdr_buffer_.begin()}; auto alignment = ((length + 3u) & ~3u) - length; - options_[1] = static_cast(options_[1] & 0xC) + static_cast(alignment & 0x3); + options_[1] = static_cast(options_[1] & 0xC) + static_cast(alignment & 0x3); } if (encapsulation_serialized_ && CdrVersion::CORBA_CDR < cdr_version_) @@ -438,7 +438,7 @@ std::shared_ptr Cdr::get_context() const } bool Cdr::jump( - size_t num_bytes) + std::size_t num_bytes) { bool ret_value = false; @@ -462,7 +462,7 @@ char* Cdr::get_current_position() return &offset_; } -size_t Cdr::get_serialized_data_length() const +std::size_t Cdr::get_serialized_data_length() const { return offset_ - cdr_buffer_.begin(); } @@ -496,7 +496,7 @@ void Cdr::reset() } bool Cdr::move_alignment_forward( - size_t num_bytes) + std::size_t num_bytes) { bool ret_value = false; @@ -511,7 +511,7 @@ bool Cdr::move_alignment_forward( } bool Cdr::resize( - size_t min_size_inc) + std::size_t min_size_inc) { if (cdr_buffer_.resize(min_size_inc)) { @@ -525,7 +525,7 @@ bool Cdr::resize( } Cdr& Cdr::serialize( - const uint8_t& octet_t) + const std::uint8_t& octet_t) { return serialize(static_cast(octet_t)); } @@ -546,22 +546,22 @@ Cdr& Cdr::serialize( } Cdr& Cdr::serialize( - const int8_t int8) + const std::int8_t int8) { return serialize(static_cast(int8)); } Cdr& Cdr::serialize( - const uint16_t ushort_t) + const std::uint16_t ushort_t) { - return serialize(static_cast(ushort_t)); + return serialize(static_cast(ushort_t)); } Cdr& Cdr::serialize( - const int16_t short_t) + const std::int16_t short_t) { - size_t align = alignment(sizeof(short_t)); - size_t size_aligned = sizeof(short_t) + align; + std::size_t align = alignment(sizeof(short_t)); + std::size_t size_aligned = sizeof(short_t) + align; if (((end_ - offset_) >= size_aligned) || resize(size_aligned)) { @@ -589,16 +589,16 @@ Cdr& Cdr::serialize( } Cdr& Cdr::serialize( - const uint32_t ulong_t) + const std::uint32_t ulong_t) { - return serialize(static_cast(ulong_t)); + return serialize(static_cast(ulong_t)); } Cdr& Cdr::serialize( - const int32_t long_t) + const std::int32_t long_t) { - size_t align = alignment(sizeof(long_t)); - size_t size_aligned = sizeof(long_t) + align; + std::size_t align = alignment(sizeof(long_t)); + std::size_t size_aligned = sizeof(long_t) + align; if (((end_ - offset_) >= size_aligned) || resize(size_aligned)) { @@ -630,20 +630,20 @@ Cdr& Cdr::serialize( Cdr& Cdr::serialize( const wchar_t wchar) { - return serialize(static_cast(wchar)); + return serialize(static_cast(wchar)); } Cdr& Cdr::serialize( - const uint64_t ulonglong_t) + const std::uint64_t ulonglong_t) { - return serialize(static_cast(ulonglong_t)); + return serialize(static_cast(ulonglong_t)); } Cdr& Cdr::serialize( - const int64_t longlong_t) + const std::int64_t longlong_t) { - size_t align = alignment(align64_); - size_t size_aligned = sizeof(longlong_t) + align; + std::size_t align = alignment(align64_); + std::size_t size_aligned = sizeof(longlong_t) + align; if (((end_ - offset_) >= size_aligned) || resize(size_aligned)) { @@ -679,8 +679,8 @@ Cdr& Cdr::serialize( Cdr& Cdr::serialize( const float float_t) { - size_t align = alignment(sizeof(float_t)); - size_t size_aligned = sizeof(float_t) + align; + std::size_t align = alignment(sizeof(float_t)); + std::size_t size_aligned = sizeof(float_t) + align; if (((end_ - offset_) >= size_aligned) || resize(size_aligned)) { @@ -712,8 +712,8 @@ Cdr& Cdr::serialize( Cdr& Cdr::serialize( const double double_t) { - size_t align = alignment(align64_); - size_t size_aligned = sizeof(double_t) + align; + std::size_t align = alignment(align64_); + std::size_t size_aligned = sizeof(double_t) + align; if (((end_ - offset_) >= size_aligned) || resize(size_aligned)) { @@ -749,8 +749,8 @@ Cdr& Cdr::serialize( Cdr& Cdr::serialize( const long double ldouble_t) { - size_t align = alignment(align64_); - size_t size_aligned = sizeof(ldouble_t) + align; + std::size_t align = alignment(align64_); + std::size_t size_aligned = sizeof(ldouble_t) + align; if (((end_ - offset_) >= size_aligned) || resize(size_aligned)) { @@ -836,10 +836,10 @@ Cdr& Cdr::serialize( Cdr& Cdr::serialize( const bool bool_t) { - if (((end_ - offset_) >= sizeof(uint8_t)) || resize(sizeof(uint8_t))) + if (((end_ - offset_) >= sizeof(std::uint8_t)) || resize(sizeof(std::uint8_t))) { // Save last datasize. - last_data_size_ = sizeof(uint8_t); + last_data_size_ = sizeof(std::uint8_t); serialize_bool(bool_t); @@ -858,11 +858,11 @@ Cdr& Cdr::serialize( Cdr& Cdr::serialize( const char* string_t) { - uint32_t length = 0; + std::uint32_t length = 0; if (string_t != nullptr) { - length = size_to_uint32(strlen(string_t)) + 1; + length = size_to_uint32(std::strlen(string_t)) + 1; } if (length > 0) @@ -873,7 +873,7 @@ Cdr& Cdr::serialize( if (((end_ - offset_) >= length) || resize(length)) { // Save last datasize. - last_data_size_ = sizeof(uint8_t); + last_data_size_ = sizeof(std::uint8_t); offset_.memcopy(string_t, length); offset_ += length; @@ -897,12 +897,12 @@ Cdr& Cdr::serialize( Cdr& Cdr::serialize( const wchar_t* string_t) { - uint32_t bytes_length = 0; - size_t wstrlen = 0; + std::uint32_t bytes_length = 0; + std::size_t wstrlen = 0; if (string_t != nullptr) { - wstrlen = wcslen(string_t); + wstrlen = std::wcslen(string_t); bytes_length = size_to_uint32(wstrlen * 2); } @@ -931,16 +931,16 @@ Cdr& Cdr::serialize( Cdr& Cdr::serialize_array( const bool* bool_t, - size_t num_elements) + std::size_t num_elements) { - size_t total_size = sizeof(*bool_t) * num_elements; + std::size_t total_size = sizeof(*bool_t) * num_elements; if (((end_ - offset_) >= total_size) || resize(total_size)) { // Save last datasize. last_data_size_ = sizeof(*bool_t); - for (size_t count = 0; count < num_elements; ++count) + for (std::size_t count = 0; count < num_elements; ++count) { serialize_bool(bool_t[count]); } @@ -953,9 +953,9 @@ Cdr& Cdr::serialize_array( Cdr& Cdr::serialize_array( const char* char_t, - size_t num_elements) + std::size_t num_elements) { - size_t total_size = sizeof(*char_t) * num_elements; + std::size_t total_size = sizeof(*char_t) * num_elements; if (((end_ - offset_) >= total_size) || resize(total_size)) { @@ -971,17 +971,17 @@ Cdr& Cdr::serialize_array( } Cdr& Cdr::serialize_array( - const int16_t* short_t, - size_t num_elements) + const std::int16_t* short_t, + std::size_t num_elements) { if (num_elements == 0) { return *this; } - size_t align = alignment(sizeof(*short_t)); - size_t total_size = sizeof(*short_t) * num_elements; - size_t size_aligned = total_size + align; + std::size_t align = alignment(sizeof(*short_t)); + std::size_t total_size = sizeof(*short_t) * num_elements; + std::size_t size_aligned = total_size + align; if (((end_ - offset_) >= size_aligned) || resize(size_aligned)) { @@ -1013,17 +1013,17 @@ Cdr& Cdr::serialize_array( } Cdr& Cdr::serialize_array( - const int32_t* long_t, - size_t num_elements) + const std::int32_t* long_t, + std::size_t num_elements) { if (num_elements == 0) { return *this; } - size_t align = alignment(sizeof(*long_t)); - size_t total_size = sizeof(*long_t) * num_elements; - size_t size_aligned = total_size + align; + std::size_t align = alignment(sizeof(*long_t)); + std::size_t total_size = sizeof(*long_t) * num_elements; + std::size_t size_aligned = total_size + align; if (((end_ - offset_) >= size_aligned) || resize(size_aligned)) { @@ -1058,14 +1058,14 @@ Cdr& Cdr::serialize_array( Cdr& Cdr::serialize_array( const wchar_t* wchar, - size_t num_elements) + std::size_t num_elements) { if (num_elements == 0) { return *this; } - for (size_t count = 0; count < num_elements; ++count) + for (std::size_t count = 0; count < num_elements; ++count) { serialize(wchar[count]); } @@ -1073,17 +1073,17 @@ Cdr& Cdr::serialize_array( } Cdr& Cdr::serialize_array( - const int64_t* longlong_t, - size_t num_elements) + const std::int64_t* longlong_t, + std::size_t num_elements) { if (num_elements == 0) { return *this; } - size_t align = alignment(align64_); - size_t total_size = sizeof(*longlong_t) * num_elements; - size_t size_aligned = total_size + align; + std::size_t align = alignment(align64_); + std::size_t total_size = sizeof(*longlong_t) * num_elements; + std::size_t size_aligned = total_size + align; if (((end_ - offset_) >= size_aligned) || resize(size_aligned)) { @@ -1122,16 +1122,16 @@ Cdr& Cdr::serialize_array( Cdr& Cdr::serialize_array( const float* float_t, - size_t num_elements) + std::size_t num_elements) { if (num_elements == 0) { return *this; } - size_t align = alignment(sizeof(*float_t)); - size_t total_size = sizeof(*float_t) * num_elements; - size_t size_aligned = total_size + align; + std::size_t align = alignment(sizeof(*float_t)); + std::size_t total_size = sizeof(*float_t) * num_elements; + std::size_t size_aligned = total_size + align; if (((end_ - offset_) >= size_aligned) || resize(size_aligned)) { @@ -1166,16 +1166,16 @@ Cdr& Cdr::serialize_array( Cdr& Cdr::serialize_array( const double* double_t, - size_t num_elements) + std::size_t num_elements) { if (num_elements == 0) { return *this; } - size_t align = alignment(align64_); - size_t total_size = sizeof(*double_t) * num_elements; - size_t size_aligned = total_size + align; + std::size_t align = alignment(align64_); + std::size_t total_size = sizeof(*double_t) * num_elements; + std::size_t size_aligned = total_size + align; if (((end_ - offset_) >= size_aligned) || resize(size_aligned)) { @@ -1214,17 +1214,17 @@ Cdr& Cdr::serialize_array( Cdr& Cdr::serialize_array( const long double* ldouble_t, - size_t num_elements) + std::size_t num_elements) { if (num_elements == 0) { return *this; } - size_t align = alignment(align64_); + std::size_t align = alignment(align64_); // Fix for Windows ( long doubles only store 8 bytes ) - size_t total_size = 16 * num_elements; // sizeof(*ldouble_t) - size_t size_aligned = total_size + align; + std::size_t total_size = 16 * num_elements; // sizeof(*ldouble_t) + std::size_t size_aligned = total_size + align; if (((end_ - offset_) >= size_aligned) || resize(size_aligned)) { @@ -1235,7 +1235,7 @@ Cdr& Cdr::serialize_array( #if FASTCDR_HAVE_FLOAT128 && FASTCDR_SIZEOF_LONG_DOUBLE < 16 if (swap_bytes_) { - for (size_t i = 0; i < num_elements; ++i, ++ldouble_t) + for (std::size_t i = 0; i < num_elements; ++i, ++ldouble_t) { __float128 tmp = *ldouble_t; const char* dst = reinterpret_cast(&tmp); @@ -1259,7 +1259,7 @@ Cdr& Cdr::serialize_array( } else { - for (size_t i = 0; i < num_elements; ++i, ++ldouble_t) + for (std::size_t i = 0; i < num_elements; ++i, ++ldouble_t) { __float128 tmp = *ldouble_t; offset_ << tmp; @@ -1310,7 +1310,7 @@ Cdr& Cdr::serialize_array( offset_.memcopy(ldouble_t, total_size); offset_ += total_size; #else - for (size_t i = 0; i < num_elements; ++i) + for (std::size_t i = 0; i < num_elements; ++i) { offset_ << static_cast(0); offset_ += 8; @@ -1353,10 +1353,10 @@ Cdr& Cdr::deserialize( } Cdr& Cdr::deserialize( - int16_t& short_t) + std::int16_t& short_t) { - size_t align = alignment(sizeof(short_t)); - size_t size_aligned = sizeof(short_t) + align; + std::size_t align = alignment(sizeof(short_t)); + std::size_t size_aligned = sizeof(short_t) + align; if ((end_ - offset_) >= size_aligned) { @@ -1391,10 +1391,10 @@ Cdr& Cdr::deserialize( } Cdr& Cdr::deserialize( - int32_t& long_t) + std::int32_t& long_t) { - size_t align = alignment(sizeof(long_t)); - size_t size_aligned = sizeof(long_t) + align; + std::size_t align = alignment(sizeof(long_t)); + std::size_t size_aligned = sizeof(long_t) + align; if ((end_ - offset_) >= size_aligned) { @@ -1431,10 +1431,10 @@ Cdr& Cdr::deserialize( } Cdr& Cdr::deserialize( - int64_t& longlong_t) + std::int64_t& longlong_t) { - size_t align = alignment(align64_); - size_t size_aligned = sizeof(longlong_t) + align; + std::size_t align = alignment(align64_); + std::size_t size_aligned = sizeof(longlong_t) + align; if ((end_ - offset_) >= size_aligned) { @@ -1477,8 +1477,8 @@ Cdr& Cdr::deserialize( Cdr& Cdr::deserialize( float& float_t) { - size_t align = alignment(sizeof(float_t)); - size_t size_aligned = sizeof(float_t) + align; + std::size_t align = alignment(sizeof(float_t)); + std::size_t size_aligned = sizeof(float_t) + align; if ((end_ - offset_) >= size_aligned) { @@ -1517,8 +1517,8 @@ Cdr& Cdr::deserialize( Cdr& Cdr::deserialize( double& double_t) { - size_t align = alignment(align64_); - size_t size_aligned = sizeof(double_t) + align; + std::size_t align = alignment(align64_); + std::size_t size_aligned = sizeof(double_t) + align; if ((end_ - offset_) >= size_aligned) { @@ -1561,8 +1561,8 @@ Cdr& Cdr::deserialize( Cdr& Cdr::deserialize( long double& ldouble_t) { - size_t align = alignment(align64_); - size_t size_aligned = sizeof(ldouble_t) + align; + std::size_t align = alignment(align64_); + std::size_t size_aligned = sizeof(ldouble_t) + align; if ((end_ - offset_) >= size_aligned) { @@ -1657,12 +1657,12 @@ Cdr& Cdr::deserialize( Cdr& Cdr::deserialize( bool& bool_t) { - uint8_t value = 0; + std::uint8_t value = 0; - if ((end_ - offset_) >= sizeof(uint8_t)) + if ((end_ - offset_) >= sizeof(std::uint8_t)) { // Save last datasize. - last_data_size_ = sizeof(uint8_t); + last_data_size_ = sizeof(std::uint8_t); if (!fake_mode_) { @@ -1694,7 +1694,7 @@ Cdr& Cdr::deserialize( Cdr& Cdr::deserialize( char*& string_t) { - uint32_t length = 0; + std::uint32_t length = 0; Cdr::state state_before_error(*this); deserialize_framing(length); @@ -1707,15 +1707,15 @@ Cdr& Cdr::deserialize( else if ((end_ - offset_) >= length) { // Save last datasize. - last_data_size_ = sizeof(uint8_t); + last_data_size_ = sizeof(std::uint8_t); // Allocate memory. if (!fake_mode_) { string_t = - reinterpret_cast(calloc(length + ((&offset_)[length - 1] == '\0' ? 0 : 1), + reinterpret_cast(std::calloc(length + ((&offset_)[length - 1] == '\0' ? 0 : 1), sizeof(char))); - memcpy(string_t, &offset_, length); + std::memcpy(string_t, &offset_, length); } offset_ += length; return *this; @@ -1728,7 +1728,7 @@ Cdr& Cdr::deserialize( Cdr& Cdr::deserialize( wchar_t*& string_t) { - uint32_t length = 0; + std::uint32_t length = 0; Cdr::state state_before_error(*this); deserialize_framing(length); @@ -1741,12 +1741,12 @@ Cdr& Cdr::deserialize( else if ((end_ - offset_) >= (length * 2)) { // Save last datasize. - last_data_size_ = sizeof(uint16_t); + last_data_size_ = sizeof(std::uint16_t); if (!fake_mode_) { // Allocate memory. - string_t = reinterpret_cast(calloc(length + 1, sizeof(wchar_t))); // WStrings never serialize terminating zero + string_t = reinterpret_cast(std::calloc(length + 1, sizeof(wchar_t))); // WStrings never serialize terminating zero deserialize_array(string_t, length); } @@ -1765,9 +1765,9 @@ Cdr& Cdr::deserialize( Cdr& Cdr::deserialize( char*& string_t, CdrTryConstructFlag consistency_flag, - uint32_t max_length) + std::uint32_t max_length) { - uint32_t length {0}; + std::uint32_t length {0}; Cdr::state state_before_error(*this); deserialize_framing(length); @@ -1782,14 +1782,14 @@ Cdr& Cdr::deserialize( // Number of visible characters, i.e. excluding the terminating null character when the // encoder serialized one. The consistency policy is applied to this value because // `max_length` bounds the characters the destination type can hold. - uint32_t visible_length {length}; + std::uint32_t visible_length {length}; if ((&offset_)[length - 1] == '\0') { --visible_length; } - uint32_t length_to_read {visible_length}; + std::uint32_t length_to_read {visible_length}; if (visible_length > max_length) { @@ -1809,7 +1809,7 @@ Cdr& Cdr::deserialize( } // Save last datasize. - last_data_size_ = sizeof(uint8_t); + last_data_size_ = sizeof(std::uint8_t); if (!fake_mode_) { @@ -1817,8 +1817,8 @@ Cdr& Cdr::deserialize( // is zeroed by calloc, so the result is null-terminated whether or not the stream // carried a terminator and whether or not the string was trimmed. A string with no // characters to keep becomes an empty string, as with the std::string overload. - string_t = reinterpret_cast(calloc(length_to_read + 1, sizeof(char))); - memcpy(string_t, &offset_, length_to_read); + string_t = reinterpret_cast(std::calloc(length_to_read + 1, sizeof(char))); + std::memcpy(string_t, &offset_, length_to_read); } offset_ += length; return *this; @@ -1831,10 +1831,10 @@ Cdr& Cdr::deserialize( Cdr& Cdr::deserialize( wchar_t*& string_t, CdrTryConstructFlag consistency_flag, - uint32_t max_length) + std::uint32_t max_length) { - uint32_t length = 0; + std::uint32_t length = 0; Cdr::state state_before_error(*this); deserialize_framing(length); @@ -1846,7 +1846,7 @@ Cdr& Cdr::deserialize( } else if ((end_ - offset_) >= (length * 2)) { - uint32_t length_to_read {length}; + std::uint32_t length_to_read {length}; if (length > max_length) { @@ -1866,14 +1866,14 @@ Cdr& Cdr::deserialize( } // Save last datasize. - last_data_size_ = sizeof(uint16_t); + last_data_size_ = sizeof(std::uint16_t); if (!fake_mode_) { // Allocate memory. WStrings never serialize the terminating zero, so the extra // character zeroed by calloc terminates the result. A string with no characters to // keep becomes an empty string, as with the std::wstring overload. - string_t = reinterpret_cast(calloc(length_to_read + 1, sizeof(wchar_t))); + string_t = reinterpret_cast(std::calloc(length_to_read + 1, sizeof(wchar_t))); deserialize_array(string_t, length_to_read); @@ -1892,25 +1892,25 @@ Cdr& Cdr::deserialize( } const char* Cdr::read_string( - uint32_t& length) + std::uint32_t& length) { - length = (std::numeric_limits::max)(); + length = (std::numeric_limits::max)(); return read_string(length, CdrTryConstructFlag::FAIL); } const std::wstring Cdr::read_wstring( - uint32_t& length) + std::uint32_t& length) { - length = (std::numeric_limits::max)(); + length = (std::numeric_limits::max)(); return read_wstring(length, CdrTryConstructFlag::FAIL); } const char* Cdr::read_string( - uint32_t& length, + std::uint32_t& length, CdrTryConstructFlag consistency_flag) { const char* ret_value = ""; - uint32_t read_length {0}; + std::uint32_t read_length {0}; state state_before_error(*this); deserialize_framing(read_length); @@ -1925,14 +1925,14 @@ const char* Cdr::read_string( // Number of visible characters, i.e. excluding the terminating null character when the // encoder serialized one. The consistency policy is applied to this value because // `length` bounds the characters the destination type can hold. - uint32_t visible_length {read_length}; + std::uint32_t visible_length {read_length}; if ((&offset_)[read_length - 1] == '\0') { --visible_length; } - uint32_t length_to_read {visible_length}; + std::uint32_t length_to_read {visible_length}; if (visible_length > length) { @@ -1952,7 +1952,7 @@ const char* Cdr::read_string( } // Save last datasize. - last_data_size_ = sizeof(uint8_t); + last_data_size_ = sizeof(std::uint8_t); // In fake mode the stream is only consumed, so the returned pointer is left empty and the // reported length must be zero to stay consistent with it. @@ -1973,15 +1973,15 @@ const char* Cdr::read_string( } const std::wstring Cdr::read_wstring( - uint32_t& length, + std::uint32_t& length, CdrTryConstructFlag consistency_flag) { std::wstring ret_value = L""; - uint32_t read_length {0}; + std::uint32_t read_length {0}; state state_(*this); deserialize_framing(read_length); - uint32_t bytes_length = read_length * 2; + std::uint32_t bytes_length = read_length * 2; if (bytes_length == 0) { @@ -1989,7 +1989,7 @@ const std::wstring Cdr::read_wstring( } else if ((end_ - offset_) >= bytes_length) { - uint32_t length_to_read {read_length}; + std::uint32_t length_to_read {read_length}; if (read_length > length) { @@ -2009,7 +2009,7 @@ const std::wstring Cdr::read_wstring( } // Save last datasize. - last_data_size_ = sizeof(uint16_t); + last_data_size_ = sizeof(std::uint16_t); // In fake mode the stream is only consumed, so the returned string is left empty and the // reported length must be zero to stay consistent with it. @@ -2043,9 +2043,9 @@ const std::wstring Cdr::read_wstring( Cdr& Cdr::deserialize_array( bool* bool_t, - size_t num_elements) + std::size_t num_elements) { - size_t total_size = sizeof(*bool_t) * num_elements; + std::size_t total_size = sizeof(*bool_t) * num_elements; if ((end_ - offset_) >= total_size) { @@ -2054,9 +2054,9 @@ Cdr& Cdr::deserialize_array( if (!fake_mode_) { - for (size_t count = 0; count < num_elements; ++count) + for (std::size_t count = 0; count < num_elements; ++count) { - uint8_t value = 0; + std::uint8_t value = 0; offset_++ >> value; if (value == 1) @@ -2082,9 +2082,9 @@ Cdr& Cdr::deserialize_array( Cdr& Cdr::deserialize_array( char* char_t, - size_t num_elements) + std::size_t num_elements) { - size_t total_size = sizeof(*char_t) * num_elements; + std::size_t total_size = sizeof(*char_t) * num_elements; if ((end_ - offset_) >= total_size) { @@ -2103,17 +2103,17 @@ Cdr& Cdr::deserialize_array( } Cdr& Cdr::deserialize_array( - int16_t* short_t, - size_t num_elements) + std::int16_t* short_t, + std::size_t num_elements) { if (num_elements == 0) { return *this; } - size_t align = alignment(sizeof(*short_t)); - size_t total_size = sizeof(*short_t) * num_elements; - size_t size_aligned = total_size + align; + std::size_t align = alignment(sizeof(*short_t)); + std::size_t total_size = sizeof(*short_t) * num_elements; + std::size_t size_aligned = total_size + align; if ((end_ - offset_) >= size_aligned) { @@ -2152,17 +2152,17 @@ Cdr& Cdr::deserialize_array( } Cdr& Cdr::deserialize_array( - int32_t* long_t, - size_t num_elements) + std::int32_t* long_t, + std::size_t num_elements) { if (num_elements == 0) { return *this; } - size_t align = alignment(sizeof(*long_t)); - size_t total_size = sizeof(*long_t) * num_elements; - size_t size_aligned = total_size + align; + std::size_t align = alignment(sizeof(*long_t)); + std::size_t total_size = sizeof(*long_t) * num_elements; + std::size_t size_aligned = total_size + align; if ((end_ - offset_) >= size_aligned) { @@ -2204,15 +2204,15 @@ Cdr& Cdr::deserialize_array( Cdr& Cdr::deserialize_array( wchar_t* wchar, - size_t num_elements) + std::size_t num_elements) { if (num_elements == 0) { return *this; } - uint16_t value; - for (size_t count = 0; count < num_elements; ++count) + std::uint16_t value; + for (std::size_t count = 0; count < num_elements; ++count) { deserialize(value); wchar[count] = static_cast(value); @@ -2221,17 +2221,17 @@ Cdr& Cdr::deserialize_array( } Cdr& Cdr::deserialize_array( - int64_t* longlong_t, - size_t num_elements) + std::int64_t* longlong_t, + std::size_t num_elements) { if (num_elements == 0) { return *this; } - size_t align = alignment(align64_); - size_t total_size = sizeof(*longlong_t) * num_elements; - size_t size_aligned = total_size + align; + std::size_t align = alignment(align64_); + std::size_t total_size = sizeof(*longlong_t) * num_elements; + std::size_t size_aligned = total_size + align; if ((end_ - offset_) >= size_aligned) { @@ -2277,16 +2277,16 @@ Cdr& Cdr::deserialize_array( Cdr& Cdr::deserialize_array( float* float_t, - size_t num_elements) + std::size_t num_elements) { if (num_elements == 0) { return *this; } - size_t align = alignment(sizeof(*float_t)); - size_t total_size = sizeof(*float_t) * num_elements; - size_t size_aligned = total_size + align; + std::size_t align = alignment(sizeof(*float_t)); + std::size_t total_size = sizeof(*float_t) * num_elements; + std::size_t size_aligned = total_size + align; if ((end_ - offset_) >= size_aligned) { @@ -2328,16 +2328,16 @@ Cdr& Cdr::deserialize_array( Cdr& Cdr::deserialize_array( double* double_t, - size_t num_elements) + std::size_t num_elements) { if (num_elements == 0) { return *this; } - size_t align = alignment(align64_); - size_t total_size = sizeof(*double_t) * num_elements; - size_t size_aligned = total_size + align; + std::size_t align = alignment(align64_); + std::size_t total_size = sizeof(*double_t) * num_elements; + std::size_t size_aligned = total_size + align; if ((end_ - offset_) >= size_aligned) { @@ -2383,17 +2383,17 @@ Cdr& Cdr::deserialize_array( Cdr& Cdr::deserialize_array( long double* ldouble_t, - size_t num_elements) + std::size_t num_elements) { if (num_elements == 0) { return *this; } - size_t align = alignment(align64_); + std::size_t align = alignment(align64_); // Fix for Windows ( long doubles only store 8 bytes ) - size_t total_size = 16 * num_elements; - size_t size_aligned = total_size + align; + std::size_t total_size = 16 * num_elements; + std::size_t size_aligned = total_size + align; if ((end_ - offset_) >= size_aligned) { @@ -2406,7 +2406,7 @@ Cdr& Cdr::deserialize_array( #if FASTCDR_HAVE_FLOAT128 && FASTCDR_SIZEOF_LONG_DOUBLE < 16 if (swap_bytes_) { - for (size_t i = 0; i < num_elements; ++i) + for (std::size_t i = 0; i < num_elements; ++i) { __float128 tmp; char* dst = reinterpret_cast(&tmp); @@ -2431,7 +2431,7 @@ Cdr& Cdr::deserialize_array( } else { - for (size_t i = 0; i < num_elements; ++i) + for (std::size_t i = 0; i < num_elements; ++i) { __float128 tmp; offset_ >> tmp; @@ -2476,7 +2476,7 @@ Cdr& Cdr::deserialize_array( offset_.rmemcopy(ldouble_t, total_size); offset_ += total_size; #else - for (size_t i = 0; i < num_elements; ++i) + for (std::size_t i = 0; i < num_elements; ++i) { offset_ += 8; // ignore first 8 bytes offset_ >> ldouble_t[i]; @@ -2536,9 +2536,9 @@ inline void Cdr::serialize_bool( bool bool_t) { #if FASTCDR_STRICT_BOOL - offset_++ << static_cast(normalize_bool(bool_t)); + offset_++ << static_cast(normalize_bool(bool_t)); #else - offset_++ << (bool_t ? static_cast(1) : static_cast(0)); + offset_++ << (bool_t ? static_cast(1) : static_cast(0)); #endif // if FASTCDR_STRICT_BOOL } @@ -2547,14 +2547,14 @@ Cdr& Cdr::serialize_bool_array( { state state_before_error(*this); - size_t total_size = vector_t.size() * sizeof(bool); + std::size_t total_size = vector_t.size() * sizeof(bool); if (((end_ - offset_) >= total_size) || resize(total_size)) { // Save last datasize. last_data_size_ = sizeof(bool); - for (size_t count = 0; count < vector_t.size(); ++count) + for (std::size_t count = 0; count < vector_t.size(); ++count) { serialize_bool(vector_t[count]); } @@ -2573,16 +2573,16 @@ Cdr& Cdr::serialize_bool_sequence( { state state_before_error(*this); - *this << static_cast(vector_t.size()); + *this << static_cast(vector_t.size()); - size_t total_size = vector_t.size() * sizeof(bool); + std::size_t total_size = vector_t.size() * sizeof(bool); if (((end_ - offset_) >= total_size) || resize(total_size)) { // Save last datasize. last_data_size_ = sizeof(bool); - for (size_t count = 0; count < vector_t.size(); ++count) + for (std::size_t count = 0; count < vector_t.size(); ++count) { serialize_bool(vector_t[count]); } @@ -2606,16 +2606,16 @@ Cdr& Cdr::deserialize_bool_array( { state state_before_error(*this); - size_t total_size = vector_t.size() * sizeof(bool); + std::size_t total_size = vector_t.size() * sizeof(bool); if ((end_ - offset_) >= total_size) { // Save last datasize. last_data_size_ = sizeof(bool); - for (uint32_t count = 0; count < vector_t.size(); ++count) + for (std::uint32_t count = 0; count < vector_t.size(); ++count) { - uint8_t value = 0; + std::uint8_t value = 0; offset_++ >> value; if (value == 1) @@ -2644,20 +2644,20 @@ Cdr& Cdr::deserialize_bool_array( Cdr& Cdr::deserialize_bool_sequence( std::vector& vector_t, CdrTryConstructFlag consistency_flag, - uint32_t max_length) + std::uint32_t max_length) { - uint32_t sequence_length {0}; + std::uint32_t sequence_length {0}; state state_before_error(*this); deserialize_framing(sequence_length); vector_t.clear(); - size_t total_size = sequence_length * sizeof(bool); + std::size_t total_size = sequence_length * sizeof(bool); if ((end_ - offset_) >= total_size) { - uint32_t length_to_read {sequence_length}; + std::uint32_t length_to_read {sequence_length}; if (sequence_length > max_length) { @@ -2684,9 +2684,9 @@ Cdr& Cdr::deserialize_bool_sequence( // Save last datasize. last_data_size_ = sizeof(bool); - for (uint32_t count = 0; count < length_to_read; ++count) + for (std::uint32_t count = 0; count < length_to_read; ++count) { - uint8_t value = 0; + std::uint8_t value = 0; offset_++ >> value; if (value == 1) @@ -2717,13 +2717,13 @@ Cdr& Cdr::deserialize_bool_sequence( Cdr& Cdr::deserialize_string_sequence( std::string*& sequence_t, - size_t& num_elements) + std::size_t& num_elements) { - uint32_t sequence_length {0}; + std::uint32_t sequence_length {0}; if (CdrVersion::XCDRv2 == cdr_version_) { - uint32_t dheader {0}; + std::uint32_t dheader {0}; deserialize_framing(dheader); auto offset = offset_; @@ -2734,7 +2734,7 @@ Cdr& Cdr::deserialize_string_sequence( { sequence_t = new std::string[sequence_length]; - uint32_t count {0}; + std::uint32_t count {0}; while (offset_ - offset < dheader && count < sequence_length) { deserialize(sequence_t[count]); @@ -2779,13 +2779,13 @@ Cdr& Cdr::deserialize_string_sequence( Cdr& Cdr::deserialize_wstring_sequence( std::wstring*& sequence_t, - size_t& num_elements) + std::size_t& num_elements) { - uint32_t sequence_length {0}; + std::uint32_t sequence_length {0}; if (CdrVersion::XCDRv2 == cdr_version_) { - uint32_t dheader {0}; + std::uint32_t dheader {0}; deserialize_framing(dheader); auto offset = offset_; @@ -2796,7 +2796,7 @@ Cdr& Cdr::deserialize_wstring_sequence( { sequence_t = new std::wstring[sequence_length]; - uint32_t count {0}; + std::uint32_t count {0}; while (offset_ - offset < dheader && count < sequence_length) { deserialize(sequence_t[count]); @@ -2849,24 +2849,24 @@ void Cdr::xcdr1_serialize_short_member_header( make_alignment(alignment(4)); - uint16_t flags_and_member_id = static_cast(member_id.must_understand ? 0x4000 : 0x0) | - static_cast(member_id.id); + std::uint16_t flags_and_member_id = static_cast(member_id.must_understand ? 0x4000 : 0x0) | + static_cast(member_id.id); serialize(flags_and_member_id); - uint16_t size = 0; + std::uint16_t size = 0; serialize(size); reset_alignment(); } void Cdr::xcdr1_end_short_member_header( const MemberId& member_id, - size_t member_serialized_size) + std::size_t member_serialized_size) { static_cast(member_id); assert(0x3F00 >= member_id.id); - assert(std::numeric_limits::max() >= member_serialized_size ); + assert(std::numeric_limits::max() >= member_serialized_size ); make_alignment(alignment(4)); - jump(sizeof(uint16_t)); - uint16_t size = static_cast(member_serialized_size); + jump(sizeof(std::uint16_t)); + std::uint16_t size = static_cast(member_serialized_size); serialize(size); } @@ -2875,62 +2875,62 @@ void Cdr::xcdr1_serialize_long_member_header( { make_alignment(alignment(4)); - uint16_t flags_and_extended_pid = static_cast(member_id.must_understand ? 0x4000 : 0x0) | - static_cast(PID_EXTENDED); + std::uint16_t flags_and_extended_pid = static_cast(member_id.must_understand ? 0x4000 : 0x0) | + static_cast(PID_EXTENDED); serialize(flags_and_extended_pid); - uint16_t size = PID_EXTENDED_LENGTH; + std::uint16_t size = PID_EXTENDED_LENGTH; serialize(size); - uint32_t id = member_id.id; + std::uint32_t id = member_id.id; serialize(id); - uint32_t msize = 0; + std::uint32_t msize = 0; serialize(msize); reset_alignment(); } void Cdr::xcdr1_end_long_member_header( const MemberId&, - size_t member_serialized_size) + std::size_t member_serialized_size) { - jump(sizeof(uint16_t) + sizeof(uint16_t) + sizeof(uint32_t)); - uint32_t msize = static_cast(member_serialized_size); + jump(sizeof(std::uint16_t) + sizeof(std::uint16_t) + sizeof(std::uint32_t)); + std::uint32_t msize = static_cast(member_serialized_size); serialize(msize); } void Cdr::xcdr1_change_to_short_member_header( const MemberId& member_id, - size_t member_serialized_size) + std::size_t member_serialized_size) { assert(0x3F00 >= member_id.id); - assert(std::numeric_limits::max() >= member_serialized_size ); + assert(std::numeric_limits::max() >= member_serialized_size ); - uint16_t flags_and_member_id = static_cast(member_id.must_understand ? 0x4000 : 0x0) | - static_cast(member_id.id); + std::uint16_t flags_and_member_id = static_cast(member_id.must_understand ? 0x4000 : 0x0) | + static_cast(member_id.id); serialize(flags_and_member_id); - uint16_t size = static_cast(member_serialized_size); + std::uint16_t size = static_cast(member_serialized_size); serialize(size); - memmove(&offset_, &offset_ + 8, member_serialized_size); + std::memmove(&offset_, &offset_ + 8, member_serialized_size); } void Cdr::xcdr1_change_to_long_member_header( const MemberId& member_id, - size_t member_serialized_size) + std::size_t member_serialized_size) { if (0 < (end_ - offset_ - member_serialized_size - 11)) { - memmove(&offset_ + 12, &offset_ + 4, member_serialized_size); + std::memmove(&offset_ + 12, &offset_ + 4, member_serialized_size); } else { throw NotEnoughMemoryException(NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT); } - uint16_t flags_and_extended_pid = static_cast(member_id.must_understand ? 0x4000 : 0x0) | - static_cast(PID_EXTENDED); + std::uint16_t flags_and_extended_pid = static_cast(member_id.must_understand ? 0x4000 : 0x0) | + static_cast(PID_EXTENDED); serialize(flags_and_extended_pid); - uint16_t size = PID_EXTENDED_LENGTH; + std::uint16_t size = PID_EXTENDED_LENGTH; serialize(size); - uint32_t id = member_id.id; + std::uint32_t id = member_id.id; serialize(id); - uint32_t msize = static_cast(member_serialized_size); + std::uint32_t msize = static_cast(member_serialized_size); serialize(msize); } @@ -2940,16 +2940,16 @@ bool Cdr::xcdr1_deserialize_member_header( { bool ret_value = true; make_alignment(alignment(4)); - uint16_t flags_and_member_id = 0; + std::uint16_t flags_and_member_id = 0; deserialize_framing(flags_and_member_id); member_id.must_understand = (flags_and_member_id & 0x4000); - uint16_t id = (flags_and_member_id & 0x3FFF); + std::uint16_t id = (flags_and_member_id & 0x3FFF); if (PID_EXTENDED > id) { member_id.id = id; - uint16_t size = 0; + std::uint16_t size = 0; deserialize_framing(size); current_state.member_size_ = size; current_state.header_serialized_ = XCdrHeaderSelection::SHORT_HEADER; @@ -2957,13 +2957,13 @@ bool Cdr::xcdr1_deserialize_member_header( } else if (PID_EXTENDED == id) // PID_EXTENDED { - uint16_t size = 0; + std::uint16_t size = 0; deserialize_framing(size); if (PID_EXTENDED_LENGTH != size) { throw BadParamException("PID_EXTENDED comes with a size different than 8"); } - uint32_t mid = 0; + std::uint32_t mid = 0; deserialize_framing(mid); member_id.id = mid; deserialize_framing(current_state.member_size_); @@ -2972,7 +2972,7 @@ bool Cdr::xcdr1_deserialize_member_header( } else if (PID_SENTINEL == id) // PID_SENTINEL { - uint16_t size = 0; + std::uint16_t size = 0; deserialize_framing(size); if (0 != size) { @@ -2990,19 +2990,19 @@ void Cdr::xcdr2_serialize_short_member_header( { assert(0x10000000 > member_id.id); - uint32_t flags_and_member_id = (member_id.must_understand ? 0x80000000 : 0x0) | member_id.id; + std::uint32_t flags_and_member_id = (member_id.must_understand ? 0x80000000 : 0x0) | member_id.id; serialize(flags_and_member_id); } void Cdr::xcdr2_end_short_member_header( const MemberId& member_id, - size_t member_serialized_size) + std::size_t member_serialized_size) { assert(0x10000000 > member_id.id); assert(8 >= member_serialized_size); - uint32_t lc = get_short_lc(member_serialized_size); - uint32_t flags_and_member_id = (member_id.must_understand ? 0x80000000 : 0x0) | lc | member_id.id; + std::uint32_t lc = get_short_lc(member_serialized_size); + std::uint32_t flags_and_member_id = (member_id.must_understand ? 0x80000000 : 0x0) | lc | member_id.id; serialize(flags_and_member_id); } @@ -3011,59 +3011,59 @@ void Cdr::xcdr2_serialize_long_member_header( { assert(0x10000000 > member_id.id); - uint32_t flags_and_member_id = (member_id.must_understand ? 0x80000000 : 0x0) | member_id.id; + std::uint32_t flags_and_member_id = (member_id.must_understand ? 0x80000000 : 0x0) | member_id.id; serialize(flags_and_member_id); - uint32_t size = 0; + std::uint32_t size = 0; serialize(size); } void Cdr::xcdr2_end_long_member_header( const MemberId& member_id, - size_t member_serialized_size) + std::size_t member_serialized_size) { assert(0x10000000 > member_id.id); - uint32_t lc = 0 == member_serialized_size ? get_long_lc(serialized_member_size_) : 0x40000000; - uint32_t flags_and_member_id = (member_id.must_understand ? 0x80000000 : 0x0) | lc | member_id.id; + std::uint32_t lc = 0 == member_serialized_size ? get_long_lc(serialized_member_size_) : 0x40000000; + std::uint32_t flags_and_member_id = (member_id.must_understand ? 0x80000000 : 0x0) | lc | member_id.id; serialize(flags_and_member_id); if (0 < member_serialized_size) { - uint32_t size = static_cast(member_serialized_size); + std::uint32_t size = static_cast(member_serialized_size); serialize(size); } } void Cdr::xcdr2_change_to_short_member_header( const MemberId& member_id, - size_t member_serialized_size) + std::size_t member_serialized_size) { assert(0x10000000 > member_id.id); assert(8 >= member_serialized_size); - uint32_t lc = get_short_lc(member_serialized_size); - uint32_t flags_and_member_id = (member_id.must_understand ? 0x80000000 : 0x0) | lc | member_id.id; + std::uint32_t lc = get_short_lc(member_serialized_size); + std::uint32_t flags_and_member_id = (member_id.must_understand ? 0x80000000 : 0x0) | lc | member_id.id; serialize(flags_and_member_id); - memmove(&offset_, &offset_ + 4, member_serialized_size); + std::memmove(&offset_, &offset_ + 4, member_serialized_size); } void Cdr::xcdr2_change_to_long_member_header( const MemberId& member_id, - size_t member_serialized_size) + std::size_t member_serialized_size) { assert(0x10000000 > member_id.id); if (0 < (end_ - offset_ - member_serialized_size - 7)) { - memmove(&offset_ + 8, &offset_ + 4, member_serialized_size); + std::memmove(&offset_ + 8, &offset_ + 4, member_serialized_size); } else { throw NotEnoughMemoryException(NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT); } - uint32_t lc = get_long_lc(serialized_member_size_); - uint32_t flags_and_member_id = (member_id.must_understand ? 0x80000000 : 0x0) | lc | member_id.id; + std::uint32_t lc = get_long_lc(serialized_member_size_); + std::uint32_t flags_and_member_id = (member_id.must_understand ? 0x80000000 : 0x0) | lc | member_id.id; serialize(flags_and_member_id); - uint32_t size = static_cast(member_serialized_size); + std::uint32_t size = static_cast(member_serialized_size); serialize(size); } @@ -3073,9 +3073,9 @@ void Cdr::xcdr2_shrink_to_long_member_header( { assert(0x10000000 > member_id.id); - memmove(&offset_ + 4, &offset_ + 8, offset - offset_ - 8); - uint32_t lc = get_long_lc(serialized_member_size_); - uint32_t flags_and_member_id = (member_id.must_understand ? 0x80000000 : 0x0) | lc | member_id.id; + std::memmove(&offset_ + 4, &offset_ + 8, offset - offset_ - 8); + std::uint32_t lc = get_long_lc(serialized_member_size_); + std::uint32_t flags_and_member_id = (member_id.must_understand ? 0x80000000 : 0x0) | lc | member_id.id; serialize(flags_and_member_id); } @@ -3147,9 +3147,9 @@ Cdr& Cdr::xcdr1_end_serialize_member( auto member_origin = origin_; set_state(current_state); make_alignment(alignment(4)); - const size_t member_serialized_size = last_offset - offset_ - + const std::size_t member_serialized_size = last_offset - offset_ - (current_state.header_serialized_ == XCdrHeaderSelection::SHORT_HEADER ? 4 : 12); - if (member_serialized_size > std::numeric_limits::max()) + if (member_serialized_size > std::numeric_limits::max()) { switch (current_state.header_serialized_) { @@ -3271,9 +3271,9 @@ Cdr& Cdr::xcdr1_end_serialize_opt_member( auto member_origin = origin_; set_state(current_state); make_alignment(alignment(4)); - const size_t member_serialized_size = last_offset - offset_ - + const std::size_t member_serialized_size = last_offset - offset_ - (current_state.header_serialized_ == XCdrHeaderSelection::SHORT_HEADER ? 4 : 12); - if (member_serialized_size > std::numeric_limits::max()) + if (member_serialized_size > std::numeric_limits::max()) { switch (current_state.header_serialized_) { @@ -3383,10 +3383,10 @@ Cdr& Cdr::xcdr2_end_serialize_member( { auto last_offset = offset_; set_state(current_state); - make_alignment(alignment(sizeof(uint32_t))); + make_alignment(alignment(sizeof(std::uint32_t))); if (NO_SERIALIZED_MEMBER_SIZE == serialized_member_size_) { - const size_t member_serialized_size = last_offset - offset_ - + const std::size_t member_serialized_size = last_offset - offset_ - (current_state.header_serialized_ == XCdrHeaderSelection::SHORT_HEADER ? 4 : 8); if (8 < member_serialized_size || 0xFFFFFFFFu == get_short_lc(member_serialized_size)) { @@ -3452,7 +3452,7 @@ Cdr& Cdr::xcdr2_end_serialize_member( case XCdrHeaderSelection::LONG_HEADER: xcdr2_shrink_to_long_member_header(current_state.next_member_id_, last_offset); offset_ = last_offset; - offset_ -= sizeof(uint32_t); + offset_ -= sizeof(std::uint32_t); break; default: assert(false); // header_serialized_ must have only SHORT_HEADER or LONG_HEADER @@ -3472,11 +3472,11 @@ void Cdr::xcdr2_deserialize_member_header( MemberId& member_id, Cdr::state& current_state) { - uint32_t flags_and_member_id = 0; + std::uint32_t flags_and_member_id = 0; deserialize_framing(flags_and_member_id); member_id.must_understand = (flags_and_member_id & 0x80000000); - uint32_t mid = (flags_and_member_id & 0x0FFFFFFF); - uint32_t lc = (flags_and_member_id & 0x70000000) >> 28; + std::uint32_t mid = (flags_and_member_id & 0x0FFFFFFF); + std::uint32_t lc = (flags_and_member_id & 0x70000000) >> 28; member_id.id = mid; @@ -3503,18 +3503,18 @@ void Cdr::xcdr2_deserialize_member_header( } else if (4 == lc) { - uint32_t size = 0; + std::uint32_t size = 0; deserialize_framing(size); current_state.member_size_ = size; current_state.header_serialized_ = XCdrHeaderSelection::LONG_HEADER; } else { - uint32_t size = 0; + std::uint32_t size = 0; deserialize_framing(size); current_state.member_size_ = 4 + (size * (5 == lc ? 1 : (6 == lc ? 4 : 8))); current_state.header_serialized_ = XCdrHeaderSelection::SHORT_HEADER; // Avoid take into account DHEADER after. - offset_ -= sizeof(uint32_t); + offset_ -= sizeof(std::uint32_t); } } @@ -3563,7 +3563,7 @@ Cdr& Cdr::xcdr2_begin_serialize_type( EncodingAlgorithmFlag::PL_CDR2 == type_encoding); if (EncodingAlgorithmFlag::PLAIN_CDR2 != type_encoding) { - uint32_t dheader {0}; + std::uint32_t dheader {0}; serialize(dheader); } serialized_member_size_ = NO_SERIALIZED_MEMBER_SIZE; // Avoid error when serializing arrays, sequences, etc.. @@ -3582,8 +3582,8 @@ Cdr& Cdr::xcdr2_end_serialize_type( { auto last_offset = offset_; set_state(current_state); - const size_t member_serialized_size = last_offset - offset_ /*DHEADER ->*/ - 4 - alignment(4); - serialize(static_cast(member_serialized_size)); + const std::size_t member_serialized_size = last_offset - offset_ /*DHEADER ->*/ - 4 - alignment(4); + serialize(static_cast(member_serialized_size)); jump(member_serialized_size); serialized_member_size_ = SERIALIZED_MEMBER_SIZE; } @@ -3619,8 +3619,8 @@ Cdr& Cdr::xcdr1_deserialize_type( } } - size_t member_size {current_state.member_size_}; - size_t diff {offset_ - prev_offset}; + std::size_t member_size {current_state.member_size_}; + std::size_t diff {offset_ - prev_offset}; if (member_size < diff) { throw exception::BadParamException( @@ -3658,7 +3658,7 @@ Cdr& Cdr::xcdr2_deserialize_type( if (EncodingAlgorithmFlag::PLAIN_CDR2 != type_encoding) { - uint32_t dheader {0}; + std::uint32_t dheader {0}; deserialize_framing(dheader); Cdr::state current_state(*this); @@ -3693,7 +3693,7 @@ Cdr& Cdr::xcdr2_deserialize_type( 0 == offset_ - offset) && !(0 < current_state.member_size_ && current_state.member_size_ == offset_ - offset - - alignment_on_state(current_state.origin_, offset, sizeof(uint32_t)) - + alignment_on_state(current_state.origin_, offset, sizeof(std::uint32_t)) - (XCdrHeaderSelection::SHORT_HEADER == current_state.header_serialized_ ? 4 : 8))) { throw BadParamException( @@ -3711,7 +3711,7 @@ Cdr& Cdr::xcdr2_deserialize_type( { ++next_member_id_.id; } - size_t jump_size = dheader - (offset_ - current_state.offset_); + std::size_t jump_size = dheader - (offset_ - current_state.offset_); jump(jump_size); next_member_id_ = current_state.next_member_id_; @@ -3798,7 +3798,7 @@ Cdr::state Cdr::allocate_xcdrv2_dheader() if (CdrVersion::XCDRv2 == cdr_version_) { // Serialize DHEADER - uint32_t dheader {0}; + std::uint32_t dheader {0}; serialize(dheader); } @@ -3813,8 +3813,8 @@ void Cdr::set_xcdrv2_dheader( auto offset = offset_; Cdr::state state_after(*this); set_state(dheader_state); - size_t dheader = offset - offset_ - (4 + alignment(sizeof(uint32_t))); /* DHEADER */ - serialize(static_cast(dheader)); + std::size_t dheader = offset - offset_ - (4 + alignment(sizeof(std::uint32_t))); /* DHEADER */ + serialize(static_cast(dheader)); set_state(state_after); serialized_member_size_ = SERIALIZED_MEMBER_SIZE; } diff --git a/src/cpp/CdrSizeCalculator.cpp b/src/cpp/CdrSizeCalculator.cpp index c354c2ad..1b805087 100644 --- a/src/cpp/CdrSizeCalculator.cpp +++ b/src/cpp/CdrSizeCalculator.cpp @@ -72,11 +72,11 @@ std::shared_ptr CdrSizeCalculator::get_context() const return context_; } -size_t CdrSizeCalculator::begin_calculate_type_serialized_size( +std::size_t CdrSizeCalculator::begin_calculate_type_serialized_size( EncodingAlgorithmFlag new_encoding, - size_t& current_alignment) + std::size_t& current_alignment) { - size_t calculated_size {0}; + std::size_t calculated_size {0}; current_encoding_ = new_encoding; if (CdrVersion::XCDRv2 == cdr_version_ && EncodingAlgorithmFlag::PLAIN_CDR2 != current_encoding_) @@ -91,11 +91,11 @@ size_t CdrSizeCalculator::begin_calculate_type_serialized_size( return calculated_size; } -size_t CdrSizeCalculator::end_calculate_type_serialized_size( +std::size_t CdrSizeCalculator::end_calculate_type_serialized_size( EncodingAlgorithmFlag new_encoding, - size_t& current_alignment) + std::size_t& current_alignment) { - size_t calculated_size {0}; + std::size_t calculated_size {0}; if (CdrVersion::XCDRv1 == cdr_version_ && EncodingAlgorithmFlag::PL_CDR == current_encoding_) { diff --git a/src/cpp/FastBuffer.cpp b/src/cpp/FastBuffer.cpp index 7f730ade..e5dcd88b 100644 --- a/src/cpp/FastBuffer.cpp +++ b/src/cpp/FastBuffer.cpp @@ -14,11 +14,7 @@ #include -#if !__APPLE__ && !__FreeBSD__ && !__VXWORKS__ -#include -#else -#include -#endif // if !__APPLE__ && !__FreeBSD__ && !__VXWORKS__ +#include #define BUFFER_START_LENGTH 200 @@ -26,7 +22,7 @@ using namespace eprosima::fastcdr; FastBuffer::FastBuffer( char* const buffer, - const size_t bufferSize) + const std::size_t bufferSize) : buffer_(buffer) , size_(bufferSize) , m_internalBuffer(false) @@ -37,16 +33,16 @@ FastBuffer::~FastBuffer() { if (m_internalBuffer && buffer_ != nullptr) { - free(buffer_); + std::free(buffer_); } } bool FastBuffer::reserve( - size_t size) + std::size_t size) { if (m_internalBuffer && buffer_ == NULL) { - buffer_ = reinterpret_cast(malloc(size)); + buffer_ = reinterpret_cast(std::malloc(size)); if (buffer_) { size_ = size; @@ -57,9 +53,9 @@ bool FastBuffer::reserve( } bool FastBuffer::resize( - size_t min_size_inc) + std::size_t min_size_inc) { - size_t incBufferSize = BUFFER_START_LENGTH; + std::size_t incBufferSize = BUFFER_START_LENGTH; if (m_internalBuffer) { @@ -72,7 +68,7 @@ bool FastBuffer::resize( { size_ = incBufferSize; - buffer_ = reinterpret_cast(malloc(size_)); + buffer_ = reinterpret_cast(std::malloc(size_)); if (buffer_ != NULL) { @@ -83,7 +79,7 @@ bool FastBuffer::resize( { size_ += incBufferSize; - buffer_ = reinterpret_cast(realloc(buffer_, size_)); + buffer_ = reinterpret_cast(std::realloc(buffer_, size_)); if (buffer_ != NULL) { diff --git a/src/cpp/FastCdr.cpp b/src/cpp/FastCdr.cpp index 0b2b7f9e..0fc9c27f 100644 --- a/src/cpp/FastCdr.cpp +++ b/src/cpp/FastCdr.cpp @@ -14,7 +14,8 @@ #include #include -#include +#include +#include #include "helpers/memory_helpers.hpp" using namespace eprosima::fastcdr; @@ -41,7 +42,7 @@ FastCdr::FastCdr( } bool FastCdr::jump( - size_t num_bytes) + std::size_t num_bytes) { bool ret_value = false; @@ -76,7 +77,7 @@ void FastCdr::reset() } bool FastCdr::resize( - size_t min_size_inc) + std::size_t min_size_inc) { if (cdr_buffer_.resize(min_size_inc)) { @@ -91,7 +92,7 @@ bool FastCdr::resize( FastCdr& FastCdr::serialize( const bool bool_t) { - if (((last_position_ - current_position_) >= sizeof(uint8_t)) || resize(sizeof(uint8_t))) + if (((last_position_ - current_position_) >= sizeof(std::uint8_t)) || resize(sizeof(std::uint8_t))) { serialize_bool(bool_t); @@ -104,11 +105,11 @@ FastCdr& FastCdr::serialize( FastCdr& FastCdr::serialize( const char* string_t) { - uint32_t length = 0; + std::uint32_t length = 0; if (string_t != nullptr) { - length = size_to_uint32(strlen(string_t)) + 1; + length = size_to_uint32(std::strlen(string_t)) + 1; } if (length > 0) @@ -138,12 +139,12 @@ FastCdr& FastCdr::serialize( FastCdr& FastCdr::serialize( const wchar_t* string_t) { - uint32_t bytes_length = 0; - size_t wstrlen = 0; + std::uint32_t bytes_length = 0; + std::size_t wstrlen = 0; if (string_t != nullptr) { - wstrlen = wcslen(string_t); + wstrlen = std::wcslen(string_t); bytes_length = size_to_uint32(wstrlen * 4); } @@ -177,13 +178,13 @@ FastCdr& FastCdr::serialize( FastCdr& FastCdr::serialize_array( const bool* bool_t, - size_t num_elements) + std::size_t num_elements) { - size_t total_size = sizeof(*bool_t) * num_elements; + std::size_t total_size = sizeof(*bool_t) * num_elements; if (((last_position_ - current_position_) >= total_size) || resize(total_size)) { - for (size_t count = 0; count < num_elements; ++count) + for (std::size_t count = 0; count < num_elements; ++count) { serialize_bool(bool_t[count]); } @@ -196,9 +197,9 @@ FastCdr& FastCdr::serialize_array( FastCdr& FastCdr::serialize_array( const char* char_t, - size_t num_elements) + std::size_t num_elements) { - size_t total_size = sizeof(*char_t) * num_elements; + std::size_t total_size = sizeof(*char_t) * num_elements; if (((last_position_ - current_position_) >= total_size) || resize(total_size)) { @@ -211,10 +212,10 @@ FastCdr& FastCdr::serialize_array( } FastCdr& FastCdr::serialize_array( - const int16_t* short_t, - size_t num_elements) + const std::int16_t* short_t, + std::size_t num_elements) { - size_t total_size = sizeof(*short_t) * num_elements; + std::size_t total_size = sizeof(*short_t) * num_elements; if (((last_position_ - current_position_) >= total_size) || resize(total_size)) { @@ -228,10 +229,10 @@ FastCdr& FastCdr::serialize_array( } FastCdr& FastCdr::serialize_array( - const int32_t* long_t, - size_t num_elements) + const std::int32_t* long_t, + std::size_t num_elements) { - size_t total_size = sizeof(*long_t) * num_elements; + std::size_t total_size = sizeof(*long_t) * num_elements; if (((last_position_ - current_position_) >= total_size) || resize(total_size)) { @@ -246,9 +247,9 @@ FastCdr& FastCdr::serialize_array( FastCdr& FastCdr::serialize_array( const wchar_t* wchar, - size_t num_elements) + std::size_t num_elements) { - for (size_t count = 0; count < num_elements; ++count) + for (std::size_t count = 0; count < num_elements; ++count) { serialize(wchar[count]); } @@ -256,10 +257,10 @@ FastCdr& FastCdr::serialize_array( } FastCdr& FastCdr::serialize_array( - const int64_t* longlong_t, - size_t num_elements) + const std::int64_t* longlong_t, + std::size_t num_elements) { - size_t total_size = sizeof(*longlong_t) * num_elements; + std::size_t total_size = sizeof(*longlong_t) * num_elements; if (((last_position_ - current_position_) >= total_size) || resize(total_size)) { @@ -274,9 +275,9 @@ FastCdr& FastCdr::serialize_array( FastCdr& FastCdr::serialize_array( const float* float_t, - size_t num_elements) + std::size_t num_elements) { - size_t total_size = sizeof(*float_t) * num_elements; + std::size_t total_size = sizeof(*float_t) * num_elements; if (((last_position_ - current_position_) >= total_size) || resize(total_size)) { @@ -291,9 +292,9 @@ FastCdr& FastCdr::serialize_array( FastCdr& FastCdr::serialize_array( const double* double_t, - size_t num_elements) + std::size_t num_elements) { - size_t total_size = sizeof(*double_t) * num_elements; + std::size_t total_size = sizeof(*double_t) * num_elements; if (((last_position_ - current_position_) >= total_size) || resize(total_size)) { @@ -308,14 +309,14 @@ FastCdr& FastCdr::serialize_array( FastCdr& FastCdr::serialize_array( const long double* ldouble_t, - size_t num_elements) + std::size_t num_elements) { - size_t total_size = 16 * num_elements; + std::size_t total_size = 16 * num_elements; if (((last_position_ - current_position_) >= total_size) || resize(total_size)) { #if FASTCDR_HAVE_FLOAT128 && FASTCDR_SIZEOF_LONG_DOUBLE < 16 - for (size_t idx = 0; idx < num_elements; ++idx) + for (std::size_t idx = 0; idx < num_elements; ++idx) { __float128 tmp = ldouble_t[idx]; current_position_ << tmp; @@ -327,7 +328,7 @@ FastCdr& FastCdr::serialize_array( current_position_ += total_size; #else #if FASTCDR_SIZEOF_LONG_DOUBLE == 8 - for (size_t idx = 0; idx < num_elements; ++idx) + for (std::size_t idx = 0; idx < num_elements; ++idx) { current_position_ << static_cast(0); current_position_ += 8; @@ -349,9 +350,9 @@ FastCdr& FastCdr::serialize_array( FastCdr& FastCdr::deserialize( bool& bool_t) { - uint8_t value = 0; + std::uint8_t value = 0; - if ((last_position_ - current_position_) >= sizeof(uint8_t)) + if ((last_position_ - current_position_) >= sizeof(std::uint8_t)) { current_position_++ >> value; @@ -375,7 +376,7 @@ FastCdr& FastCdr::deserialize( FastCdr& FastCdr::deserialize( char*& string_t) { - uint32_t length = 0; + std::uint32_t length = 0; FastCdr::state state_before_error(*this); deserialize(length); @@ -389,9 +390,9 @@ FastCdr& FastCdr::deserialize( { // Allocate memory. string_t = - reinterpret_cast(calloc(length + ((¤t_position_)[length - 1] == '\0' ? 0 : 1), + reinterpret_cast(std::calloc(length + ((¤t_position_)[length - 1] == '\0' ? 0 : 1), sizeof(char))); - memcpy(string_t, ¤t_position_, length); + std::memcpy(string_t, ¤t_position_, length); current_position_ += length; return *this; } @@ -403,7 +404,7 @@ FastCdr& FastCdr::deserialize( FastCdr& FastCdr::deserialize( wchar_t*& string_t) { - uint32_t length = 0; + std::uint32_t length = 0; FastCdr::state state_before_error(*this); deserialize(length); @@ -416,18 +417,18 @@ FastCdr& FastCdr::deserialize( else if ((last_position_ - current_position_) >= length) { // Allocate memory. - string_t = reinterpret_cast(calloc(length + 1, sizeof(wchar_t))); // WStrings never serialize terminating zero + string_t = reinterpret_cast(std::calloc(length + 1, sizeof(wchar_t))); // WStrings never serialize terminating zero #if defined(_WIN32) - for (size_t idx = 0; idx < length; ++idx) + for (std::size_t idx = 0; idx < length; ++idx) { - uint32_t temp; + std::uint32_t temp; current_position_ >> temp; string_t[idx] = static_cast(temp); current_position_ += 4; } #else - memcpy(string_t, ¤t_position_, length * sizeof(wchar_t)); + std::memcpy(string_t, ¤t_position_, length * sizeof(wchar_t)); current_position_ += length * sizeof(wchar_t); #endif // if defined(_WIN32) @@ -439,7 +440,7 @@ FastCdr& FastCdr::deserialize( } const char* FastCdr::read_string( - uint32_t& length) + std::uint32_t& length) { const char* ret_value = ""; state state_before_error(*this); @@ -467,13 +468,13 @@ const char* FastCdr::read_string( } std::wstring FastCdr::read_wstring( - uint32_t& length) + std::uint32_t& length) { std::wstring ret_value = L""; state state_(*this); *this >> length; - uint32_t bytes_length = length * 4; + std::uint32_t bytes_length = length * 4; if (bytes_length == 0) { @@ -499,15 +500,15 @@ std::wstring FastCdr::read_wstring( FastCdr& FastCdr::deserialize_array( bool* bool_t, - size_t num_elements) + std::size_t num_elements) { - size_t total_size = sizeof(*bool_t) * num_elements; + std::size_t total_size = sizeof(*bool_t) * num_elements; if ((last_position_ - current_position_) >= total_size) { - for (size_t count = 0; count < num_elements; ++count) + for (std::size_t count = 0; count < num_elements; ++count) { - uint8_t value = 0; + std::uint8_t value = 0; current_position_++ >> value; if (value == 1) @@ -528,9 +529,9 @@ FastCdr& FastCdr::deserialize_array( FastCdr& FastCdr::deserialize_array( char* char_t, - size_t num_elements) + std::size_t num_elements) { - size_t total_size = sizeof(*char_t) * num_elements; + std::size_t total_size = sizeof(*char_t) * num_elements; if ((last_position_ - current_position_) >= total_size) { @@ -543,10 +544,10 @@ FastCdr& FastCdr::deserialize_array( } FastCdr& FastCdr::deserialize_array( - int16_t* short_t, - size_t num_elements) + std::int16_t* short_t, + std::size_t num_elements) { - size_t total_size = sizeof(*short_t) * num_elements; + std::size_t total_size = sizeof(*short_t) * num_elements; if ((last_position_ - current_position_) >= total_size) { @@ -560,10 +561,10 @@ FastCdr& FastCdr::deserialize_array( } FastCdr& FastCdr::deserialize_array( - int32_t* long_t, - size_t num_elements) + std::int32_t* long_t, + std::size_t num_elements) { - size_t total_size = sizeof(*long_t) * num_elements; + std::size_t total_size = sizeof(*long_t) * num_elements; if ((last_position_ - current_position_) >= total_size) { @@ -578,10 +579,10 @@ FastCdr& FastCdr::deserialize_array( FastCdr& FastCdr::deserialize_array( wchar_t* wchar, - size_t num_elements) + std::size_t num_elements) { - uint32_t value = 0; - for (size_t count = 0; count < num_elements; ++count) + std::uint32_t value = 0; + for (std::size_t count = 0; count < num_elements; ++count) { deserialize(value); wchar[count] = static_cast(value); @@ -590,10 +591,10 @@ FastCdr& FastCdr::deserialize_array( } FastCdr& FastCdr::deserialize_array( - int64_t* longlong_t, - size_t num_elements) + std::int64_t* longlong_t, + std::size_t num_elements) { - size_t total_size = sizeof(*longlong_t) * num_elements; + std::size_t total_size = sizeof(*longlong_t) * num_elements; if ((last_position_ - current_position_) >= total_size) { @@ -608,9 +609,9 @@ FastCdr& FastCdr::deserialize_array( FastCdr& FastCdr::deserialize_array( float* float_t, - size_t num_elements) + std::size_t num_elements) { - size_t total_size = sizeof(*float_t) * num_elements; + std::size_t total_size = sizeof(*float_t) * num_elements; if ((last_position_ - current_position_) >= total_size) { @@ -625,9 +626,9 @@ FastCdr& FastCdr::deserialize_array( FastCdr& FastCdr::deserialize_array( double* double_t, - size_t num_elements) + std::size_t num_elements) { - size_t total_size = sizeof(*double_t) * num_elements; + std::size_t total_size = sizeof(*double_t) * num_elements; if ((last_position_ - current_position_) >= total_size) { @@ -642,14 +643,14 @@ FastCdr& FastCdr::deserialize_array( FastCdr& FastCdr::deserialize_array( long double* ldouble_t, - size_t num_elements) + std::size_t num_elements) { - size_t total_size = 16 * num_elements; + std::size_t total_size = 16 * num_elements; if ((last_position_ - current_position_) >= total_size) { #if FASTCDR_HAVE_FLOAT128 && FASTCDR_SIZEOF_LONG_DOUBLE < 16 - for (size_t idx = 0; idx < num_elements; ++idx) + for (std::size_t idx = 0; idx < num_elements; ++idx) { __float128 tmp; current_position_ >> tmp; @@ -662,7 +663,7 @@ FastCdr& FastCdr::deserialize_array( current_position_ += total_size; #else #if FASTCDR_SIZEOF_LONG_DOUBLE == 8 - for (size_t idx = 0; idx < num_elements; ++idx) + for (std::size_t idx = 0; idx < num_elements; ++idx) { current_position_ += 8; current_position_ >> ldouble_t[idx]; @@ -684,9 +685,9 @@ inline void FastCdr::serialize_bool( bool bool_t) { #if FASTCDR_STRICT_BOOL - current_position_++ << static_cast(normalize_bool(bool_t)); + current_position_++ << static_cast(normalize_bool(bool_t)); #else - current_position_++ << (bool_t ? static_cast(1) : static_cast(0)); + current_position_++ << (bool_t ? static_cast(1) : static_cast(0)); #endif // if FASTCDR_STRICT_BOOL } @@ -695,13 +696,13 @@ FastCdr& FastCdr::serialize_bool_sequence( { state state_before_error(*this); - *this << static_cast(vector_t.size()); + *this << static_cast(vector_t.size()); - size_t total_size = vector_t.size() * sizeof(bool); + std::size_t total_size = vector_t.size() * sizeof(bool); if (((last_position_ - current_position_) >= total_size) || resize(total_size)) { - for (size_t count = 0; count < vector_t.size(); ++count) + for (std::size_t count = 0; count < vector_t.size(); ++count) { serialize_bool(vector_t[count]); } @@ -718,19 +719,19 @@ FastCdr& FastCdr::serialize_bool_sequence( FastCdr& FastCdr::deserialize_bool_sequence( std::vector& vector_t) { - uint32_t sequence_length = 0; + std::uint32_t sequence_length = 0; state state_before_error(*this); *this >> sequence_length; - size_t total_size = sequence_length * sizeof(bool); + std::size_t total_size = sequence_length * sizeof(bool); if ((last_position_ - current_position_) >= total_size) { vector_t.resize(sequence_length); - for (uint32_t count = 0; count < sequence_length; ++count) + for (std::uint32_t count = 0; count < sequence_length; ++count) { - uint8_t value = 0; + std::uint8_t value = 0; current_position_++ >> value; if (value == 1) @@ -754,9 +755,9 @@ FastCdr& FastCdr::deserialize_bool_sequence( FastCdr& FastCdr::deserialize_string_sequence( std::string*& sequence_t, - size_t& num_elements) + std::size_t& num_elements) { - uint32_t sequence_length = 0; + std::uint32_t sequence_length = 0; state state_before_error(*this); deserialize(sequence_length); @@ -780,9 +781,9 @@ FastCdr& FastCdr::deserialize_string_sequence( FastCdr& FastCdr::deserialize_wstring_sequence( std::wstring*& sequence_t, - size_t& num_elements) + std::size_t& num_elements) { - uint32_t sequence_length = 0; + std::uint32_t sequence_length = 0; state state_before_error(*this); deserialize(sequence_length); diff --git a/src/cpp/exceptions/BadOptionalAccessException.cpp b/src/cpp/exceptions/BadOptionalAccessException.cpp index 36df17ee..2f7687db 100644 --- a/src/cpp/exceptions/BadOptionalAccessException.cpp +++ b/src/cpp/exceptions/BadOptionalAccessException.cpp @@ -14,6 +14,8 @@ #include +#include + using namespace eprosima::fastcdr::exception; const char* const BadOptionalAccessException::BAD_OPTIONAL_ACCESS_MESSAGE_DEFAULT = diff --git a/src/cpp/exceptions/BadParamException.cpp b/src/cpp/exceptions/BadParamException.cpp index 3510487d..664a3444 100644 --- a/src/cpp/exceptions/BadParamException.cpp +++ b/src/cpp/exceptions/BadParamException.cpp @@ -14,6 +14,8 @@ #include +#include + using namespace eprosima::fastcdr::exception; const char* const BadParamException::BAD_PARAM_MESSAGE_DEFAULT = "Bad parameter"; diff --git a/src/cpp/exceptions/Exception.cpp b/src/cpp/exceptions/Exception.cpp index b1d0d9ad..4b741e49 100644 --- a/src/cpp/exceptions/Exception.cpp +++ b/src/cpp/exceptions/Exception.cpp @@ -14,6 +14,8 @@ #include +#include + using namespace eprosima::fastcdr::exception; Exception::Exception( diff --git a/src/cpp/exceptions/LockedExternalAccessException.cpp b/src/cpp/exceptions/LockedExternalAccessException.cpp index ff1d7f64..bf89489f 100644 --- a/src/cpp/exceptions/LockedExternalAccessException.cpp +++ b/src/cpp/exceptions/LockedExternalAccessException.cpp @@ -14,6 +14,8 @@ #include +#include + using namespace eprosima::fastcdr::exception; const char* const LockedExternalAccessException::LOCKED_EXTERNAL_ACCESS_MESSAGE_DEFAULT = diff --git a/src/cpp/exceptions/NotEnoughMemoryException.cpp b/src/cpp/exceptions/NotEnoughMemoryException.cpp index 4aaab9eb..49d8891a 100644 --- a/src/cpp/exceptions/NotEnoughMemoryException.cpp +++ b/src/cpp/exceptions/NotEnoughMemoryException.cpp @@ -14,6 +14,8 @@ #include +#include + using namespace eprosima::fastcdr::exception; const char* const NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT = diff --git a/src/cpp/helpers/memory_helpers.hpp b/src/cpp/helpers/memory_helpers.hpp index e02211af..14911c92 100644 --- a/src/cpp/helpers/memory_helpers.hpp +++ b/src/cpp/helpers/memory_helpers.hpp @@ -15,6 +15,8 @@ #ifndef _SRC_CPP_HELPERS_MEMORYHELPERS_HPP_ #define _SRC_CPP_HELPERS_MEMORYHELPERS_HPP_ +#include + #include #include #include @@ -148,7 +150,7 @@ inline void do_not_optimize( inline bool normalize_bool( bool b) noexcept { - uint8_t raw; + std::uint8_t raw; std::memcpy(&raw, &b, 1); do_not_optimize(raw); return static_cast(raw); From e54928dff1c6782dce7ea57697c346c3bd07a0a7 Mon Sep 17 00:00:00 2001 From: Emilio Cuesta Date: Thu, 29 Oct 2026 12:01:03 +0100 Subject: [PATCH 2/6] Standard C++ instead of memccpy, and only where it is used fixed_string copies with a bounded loop and std::memcpy instead of memccpy (_memccpy on Windows), which is POSIX and not standard C++, with the same result: the terminator is copied when it fits. The MEMCCPY macro is removed. memory_helpers.hpp includes only for MSVC, the only compiler whose clobber_memory() uses it, so that the other compilers do not need the header. Signed-off-by: Emilio Cuesta --- include/fastcdr/cdr/fixed_size_string.hpp | 17 +++++++-------- src/cpp/helpers/memory_helpers.hpp | 25 +++++++++++++---------- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/include/fastcdr/cdr/fixed_size_string.hpp b/include/fastcdr/cdr/fixed_size_string.hpp index ba2754a5..f16e9545 100644 --- a/include/fastcdr/cdr/fixed_size_string.hpp +++ b/include/fastcdr/cdr/fixed_size_string.hpp @@ -23,12 +23,6 @@ #include #include -#ifdef _WIN32 -#define MEMCCPY _memccpy -#else -#define MEMCCPY memccpy -#endif // ifdef _WIN32 - namespace eprosima { namespace fastcdr { @@ -329,8 +323,15 @@ struct fixed_string void set( const char* c_string) noexcept { - char* result = static_cast(MEMCCPY(string_data, c_string, '\0', MAX_CHARS)); - string_len = (result == nullptr) ? MAX_CHARS : static_cast(result - string_data) - 1u; + // As memccpy(string_data, c_string, '\0', MAX_CHARS), which is not standard C++: the terminator is copied + // when it fits. + std::size_t len = 0; + while (len < MAX_CHARS && '\0' != c_string[len]) + { + ++len; + } + std::memcpy(string_data, c_string, len < MAX_CHARS ? len + 1u : len); + string_len = len; } char string_data[MAX_CHARS + 1]; ///< Holds string data, including ending null character. diff --git a/src/cpp/helpers/memory_helpers.hpp b/src/cpp/helpers/memory_helpers.hpp index 14911c92..375379a5 100644 --- a/src/cpp/helpers/memory_helpers.hpp +++ b/src/cpp/helpers/memory_helpers.hpp @@ -17,11 +17,19 @@ #include -#include #include #include #include +#if (!defined(__GNUC__) && !defined(__clang__)) || defined(__pnacl__) || \ + defined(__EMSCRIPTEN__) +#define HAS_NO_INLINE_ASSEMBLY +#endif // if (!defined(__GNUC__) && !defined(__clang__)) || defined(__pnacl__) || defined(__EMSCRIPTEN__) + +#if defined(HAS_NO_INLINE_ASSEMBLY) && defined(_MSC_VER) +#include +#endif // if defined(HAS_NO_INLINE_ASSEMBLY) && defined(_MSC_VER) + namespace eprosima { namespace fastcdr { @@ -30,16 +38,6 @@ void use_char_pointer( char const volatile *const v); } // namespace internal -#if (!defined(__GNUC__) && !defined(__clang__)) || defined(__pnacl__) || \ - defined(__EMSCRIPTEN__) -#define HAS_NO_INLINE_ASSEMBLY -#endif // if (!defined(__GNUC__) && !defined(__clang__)) || defined(__pnacl__) || defined(__EMSCRIPTEN__) - -inline void clobber_memory() -{ - std::atomic_signal_fence(std::memory_order_acq_rel); -} - #ifndef HAS_NO_INLINE_ASSEMBLY #if !defined(__GNUC__) || defined(__llvm__) || defined(__INTEL_COMPILER) template @@ -104,6 +102,11 @@ do_not_optimize( #endif // if !defined(__GNUC__) || defined(__llvm__) || defined(__INTEL_COMPILER) #elif defined(_MSC_VER) +inline void clobber_memory() +{ + std::atomic_signal_fence(std::memory_order_acq_rel); +} + template inline void do_not_optimize( Tp& value) From 080677889dbf757ac06dd34e028288adcbf8e412 Mon Sep 17 00:00:00 2001 From: Emilio Cuesta Date: Fri, 30 Oct 2026 18:11:57 +0100 Subject: [PATCH 3/6] Keep the MEMCCPY macro, defined as a standard C++ memccpy MEMCCPY is defined by a public header, so code that includes Fast CDR may use it. It is kept, and now names eprosima::fastcdr::detail::memccpy, a standard C++ copy with memccpy's semantics, instead of POSIX's memccpy (_memccpy on Windows), which is not standard C++. fixed_string::set uses it again. Signed-off-by: Emilio Cuesta --- include/fastcdr/cdr/fixed_size_string.hpp | 47 ++++++++++++++++++----- 1 file changed, 38 insertions(+), 9 deletions(-) diff --git a/include/fastcdr/cdr/fixed_size_string.hpp b/include/fastcdr/cdr/fixed_size_string.hpp index f16e9545..116d4031 100644 --- a/include/fastcdr/cdr/fixed_size_string.hpp +++ b/include/fastcdr/cdr/fixed_size_string.hpp @@ -23,6 +23,42 @@ #include #include +namespace eprosima { +namespace fastcdr { +namespace detail { + +/** + * @brief Copies bytes from @c src to @c dest until @c c is copied or @c n bytes are copied, as POSIX's memccpy, which + * is not standard C++. + * + * @return A pointer to the byte after @c c in @c dest, or @c nullptr if @c c was not found in the first @c n bytes. + */ +inline void* memccpy( + void* dest, + const void* src, + int c, + std::size_t n) noexcept +{ + unsigned char* d = static_cast(dest); + const unsigned char* s = static_cast(src); + const unsigned char uc = static_cast(c); + for (std::size_t i = 0; i < n; ++i) + { + d[i] = s[i]; + if (uc == s[i]) + { + return d + i + 1; + } + } + return nullptr; +} + +} // namespace detail +} // namespace fastcdr +} // namespace eprosima + +#define MEMCCPY eprosima::fastcdr::detail::memccpy + namespace eprosima { namespace fastcdr { @@ -323,15 +359,8 @@ struct fixed_string void set( const char* c_string) noexcept { - // As memccpy(string_data, c_string, '\0', MAX_CHARS), which is not standard C++: the terminator is copied - // when it fits. - std::size_t len = 0; - while (len < MAX_CHARS && '\0' != c_string[len]) - { - ++len; - } - std::memcpy(string_data, c_string, len < MAX_CHARS ? len + 1u : len); - string_len = len; + char* result = static_cast(MEMCCPY(string_data, c_string, '\0', MAX_CHARS)); + string_len = (result == nullptr) ? MAX_CHARS : static_cast(result - string_data) - 1u; } char string_data[MAX_CHARS + 1]; ///< Holds string data, including ending null character. From c614617015a413571670635ebebefbc2d8f7a308 Mon Sep 17 00:00:00 2001 From: Emilio Cuesta Date: Tue, 3 Nov 2026 14:12:18 +0100 Subject: [PATCH 4/6] Uncrustify Signed-off-by: Emilio Cuesta --- include/fastcdr/cdr/fixed_size_string.hpp | 2 +- include/fastcdr/detail/container_recursive_inspector.hpp | 4 ++-- src/cpp/helpers/memory_helpers.hpp | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/include/fastcdr/cdr/fixed_size_string.hpp b/include/fastcdr/cdr/fixed_size_string.hpp index 116d4031..c4757dbd 100644 --- a/include/fastcdr/cdr/fixed_size_string.hpp +++ b/include/fastcdr/cdr/fixed_size_string.hpp @@ -70,7 +70,7 @@ namespace fastcdr { * @tparam MAX_CHARS Maximum number of characters is specified as the template parameter. * Space for an additional null terminator will be reserved. */ -template +template struct fixed_string { public: diff --git a/include/fastcdr/detail/container_recursive_inspector.hpp b/include/fastcdr/detail/container_recursive_inspector.hpp index 72a1d6cb..54b74cef 100644 --- a/include/fastcdr/detail/container_recursive_inspector.hpp +++ b/include/fastcdr/detail/container_recursive_inspector.hpp @@ -31,7 +31,7 @@ constexpr bool is_multi_array_primitive( } /// Specializations -template ::value || std::is_arithmetic<_T>::value>::type* = nullptr> constexpr bool is_multi_array_primitive( @@ -40,7 +40,7 @@ constexpr bool is_multi_array_primitive( return true; } -template +template constexpr bool is_multi_array_primitive( std::array<_T, _N> const*) { diff --git a/src/cpp/helpers/memory_helpers.hpp b/src/cpp/helpers/memory_helpers.hpp index 375379a5..8084062a 100644 --- a/src/cpp/helpers/memory_helpers.hpp +++ b/src/cpp/helpers/memory_helpers.hpp @@ -64,7 +64,7 @@ inline void do_not_optimize( #elif (__GNUC__ >= 5) template -inline typename std::enable_if::value&& +inline typename std::enable_if::value && (sizeof(Tp) <= sizeof(Tp*))>::type do_not_optimize( Tp& value) @@ -82,7 +82,7 @@ do_not_optimize( } template -inline typename std::enable_if::value&& +inline typename std::enable_if::value && (sizeof(Tp) <= sizeof(Tp*))>::type do_not_optimize( Tp&& value) From 57f361eaa70963ddfc2bdf4e3fc6d96f70c0e896 Mon Sep 17 00:00:00 2001 From: Emilio Cuesta Date: Tue, 3 Nov 2026 16:44:17 +0100 Subject: [PATCH 5/6] No C headers in config.h config.h included , and for the code generated by Fast DDS Gen, which used size_t, uint32_t and memcpy without std::. The generated code now includes what it uses and writes the std:: names (eProsima/Fast-DDS-Gen-Pro#49), and config.h uses none of them, so they are removed. Signed-off-by: Emilio Cuesta --- include/fastcdr/config.h.in | 5 ----- 1 file changed, 5 deletions(-) diff --git a/include/fastcdr/config.h.in b/include/fastcdr/config.h.in index 08eaa3d2..83126de9 100644 --- a/include/fastcdr/config.h.in +++ b/include/fastcdr/config.h.in @@ -15,11 +15,6 @@ #ifndef _FASTCDR_CONFIG_H_ #define _FASTCDR_CONFIG_H_ -// The C names (size_t, uint32_t, memcpy...) that the code generated by Fast DDS Gen uses without std:: -#include -#include -#include - #define FASTCDR_VERSION_MAJOR @PROJECT_VERSION_MAJOR@ #define FASTCDR_VERSION_MINOR @PROJECT_VERSION_MINOR@ #define FASTCDR_VERSION_MICRO @PROJECT_VERSION_PATCH@ From b67b75b29c18062e97a5de43b0a5f7a0e5ee757b Mon Sep 17 00:00:00 2001 From: Emilio Cuesta Date: Tue, 3 Nov 2026 16:44:17 +0100 Subject: [PATCH 6/6] FACE check of the C++11 General Purpose capability set utils/face/check_face.py compiles Fast CDR as the FACE Conformance Test Suite compiles a Unit of Conformance: each public header alone and each source, with the compiler flags of the CTS toolchain and only the gold standard headers of the profile. Then the functions the objects use must be defined by the gold standard libraries, built from their CTS sources, the default allowed definitions of the CTS, or allowed_symbols.txt (the C++ exception runtime). It lists every issue where it is, with the files that run into it, and fails when there is any. Only the gold standard files are fetched from the CTS 3.2.3 archive, with HTTP range requests (10 MB), and checked against their SHA-256. It runs in a job of the Ubuntu CI of its own, independent of the build and test matrix: it only needs the configured sources (for config.h). The job runs utils/face/check_face.py directly, which is also how it runs by hand. It fails until wide strings can be left out (eProsima/Fast-CDR#352): the profile excludes them. Signed-off-by: Emilio Cuesta --- .github/workflows/ubuntu-ci.yml | 25 ++ utils/face/allowed_symbols.txt | 14 ++ utils/face/check_face.py | 391 ++++++++++++++++++++++++++++++++ 3 files changed, 430 insertions(+) create mode 100644 utils/face/allowed_symbols.txt create mode 100644 utils/face/check_face.py diff --git a/.github/workflows/ubuntu-ci.yml b/.github/workflows/ubuntu-ci.yml index 8145e973..1727dbab 100644 --- a/.github/workflows/ubuntu-ci.yml +++ b/.github/workflows/ubuntu-ci.yml @@ -73,3 +73,28 @@ jobs: (github.event.pull_request.head.repo.full_name == github.repository) && (!contains(github.event.pull_request.labels.*.name, 'skip-ci')) && true || false }} + + # Fast CDR compiled as the FACE CTS compiles a Unit of Conformance (utils/face/check_face.py), apart from the build + # and test matrix: it only needs the configured sources, and fetches the gold standard files of the CTS + face-check: + if: ${{ !(github.event_name == 'pull_request') || + (!contains(github.event.pull_request.labels.*.name, 'conflicts') && + !contains(github.event.pull_request.labels.*.name, 'skip-ci')) }} + runs-on: ubuntu-22.04 + steps: + - name: Sync eProsima/Fast-CDR repository + uses: eProsima/eProsima-CI/external/checkout@v0 + with: + path: src/fastcdr + ref: ${{ inputs.fastcdr-branch || github.ref }} + + - name: Configure Fast CDR + run: cmake -S src/fastcdr -B build/fastcdr + + - name: FACE check (C++11 General Purpose capability set) + run: | + python3 src/fastcdr/utils/face/check_face.py \ + --source-dir src/fastcdr \ + --build-dir build/fastcdr \ + --work-dir build/face \ + --define FASTCDR_SOURCE diff --git a/utils/face/allowed_symbols.txt b/utils/face/allowed_symbols.txt new file mode 100644 index 00000000..aaf54e9c --- /dev/null +++ b/utils/face/allowed_symbols.txt @@ -0,0 +1,14 @@ +# Symbols the Fast CDR objects may use besides those the gold standard libraries and the default allowed definitions +# of the FACE CTS define. One per line, mangled. + +# GCC C++ ABI runtime (libsupc++), called by the code the compiler generates for throw and catch. The General Purpose +# C++11 capability set allows exceptions thrown and caught within a UoC (FACE Technical Standard 3.2, 4.2.3.3.2), but +# the default allowed definitions of the CTS only provide the personality routine and _Unwind_Resume. +__cxa_allocate_exception +__cxa_free_exception +__cxa_throw +__cxa_begin_catch +__cxa_end_catch + +# Defined by the linker for position-independent code. +_GLOBAL_OFFSET_TABLE_ diff --git a/utils/face/check_face.py b/utils/face/check_face.py new file mode 100644 index 00000000..c5e83d40 --- /dev/null +++ b/utils/face/check_face.py @@ -0,0 +1,391 @@ +#!/usr/bin/env python3 +# Copyright 2026 Proyectos y Sistemas de Mantenimiento SL (eProsima). +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +"""Checks Fast CDR against the C++11 General Purpose capability set of the FACE Technical Standard, Edition 3.2. + +Fast CDR is compiled as the FACE Conformance Test Suite (CTS) compiles a Unit of Conformance: with the compiler flags +of its toolchain (-nostdinc -nostdinc++ ...) and only the gold standard headers of the profile, which declare just what +the profile allows, each in the form the C++ standard guarantees for its header. Then the functions the objects use +must be defined by the gold standard libraries, or by the allowed definitions of the toolchain. + +* Each public header is compiled alone, so that it includes what it uses. +* Each source is compiled to an object, with the definitions of the library build. +* The undefined symbols of the objects must be defined by the gold standard libraries (built from their CTS sources), + the default allowed definitions of the CTS, or allowed_symbols.txt. + +Only the gold standard files of the capability set are fetched from the CTS archive published by The Open Group +(Distribution Statement A, unlimited), with HTTP range requests, and checked against GOLD_SHA256. A local CTS +installation can be given instead (--cts-dir). + +The result is the list of issues: each compiler error, or function outside the profile, at the place in Fast CDR where +it is, with the checked files that run into it. The first error of a file is marked: the later ones may be its +consequences. + +Exit code: 0 when there is no issue; 1 when there is any; 2 when the check could not run. +""" +import argparse +import collections +import concurrent.futures +import hashlib +import io +import os +import re +import shutil +import subprocess +import sys +import urllib.request +import zipfile + +CTS_VERSION = '3.2.3' +CTS_URL = 'https://www.opengroup.org/sites/default/files/Linux_CTS_{}_Distribution.zip'.format(CTS_VERSION) +CTS_ROOT = 'FACEConformanceTestSuite_{}/'.format(CTS_VERSION) +# The gold standard headers and libraries of the C++11 General Purpose capability set, and the default allowed +# definitions of the CTS toolchains. +GOLD_DIR = 'goldStandardLibraries/C++/src/OSS/libstdc++_v11/general/' +ALLOWED_DEFINITIONS = 'datafiles/sourcefiles/default_allowed_definitions.cpp' +# SHA-256 of the fetched files (see files_sha256) +GOLD_SHA256 = '8e60fa509b5b4643d7632eaf6bc08b7af3bcca1d51bd6baa9320b1e8f29955fb' + +# The compiler flags of the CTS C++11 General Purpose toolchain +FACE_FLAGS = ['-fno-builtin', '-nostdinc', '-nostdinc++', '-DFACE_GENERAL_PURPOSE_PROFILE', '-std=c++11'] + +# The headers the CTS generates for each toolchain, which the gold standard headers and the allowed definitions +# include: the exact-width types of the compiler, the null pointer constant, and the declarations of the allowed +# definitions (none with GCC on Linux: the CTS sample toolchain only declares atexit for MinGW and Cygwin). +TOOLCHAIN_HEADERS = { + 'allowed_definitions.hpp': '''\ +#ifndef CTS_ALLOWED_DEFINITIONS_HPP +#define CTS_ALLOWED_DEFINITIONS_HPP +#endif +''', + 'CONFORMANCE_TEST_FACE_EXACT_TYPES.h': '''\ +#ifndef CONFORMANCE_TEST_FACE_EXACT_TYPES_H +#define CONFORMANCE_TEST_FACE_EXACT_TYPES_H +typedef __INT8_TYPE__ FACE_int8_t; +typedef __INT16_TYPE__ FACE_int16_t; +typedef __INT32_TYPE__ FACE_int32_t; +typedef __INT64_TYPE__ FACE_int64_t; +typedef __UINT8_TYPE__ FACE_uint8_t; +typedef __UINT16_TYPE__ FACE_uint16_t; +typedef __UINT32_TYPE__ FACE_uint32_t; +typedef __UINT64_TYPE__ FACE_uint64_t; +typedef __SIZE_TYPE__ FACE_size_t; +#endif +''', + 'CONFORMANCE_TEST_FACE_NULL.h': '''\ +#ifndef CONFORMANCE_TEST_FACE_NULL_H +#define CONFORMANCE_TEST_FACE_NULL_H +#ifdef __cplusplus +#define FACE_NULL 0 +#else +#define FACE_NULL ((void*) 0) +#endif +#endif +''', +} + +# A compiler error: file, line, column, message +ERROR = re.compile(r'^(.+?):(\d+):(\d+): (?:fatal )?error: (.*)$') + + +class HttpRangeFile(io.RawIOBase): + """A remote file read with HTTP range requests, so that zipfile reads only the entries it needs.""" + + def __init__(self, url): + self.url = url + self.pos = 0 + with urllib.request.urlopen(urllib.request.Request(url, method='HEAD'), timeout=60) as response: + if response.headers.get('Accept-Ranges') != 'bytes': + raise RuntimeError('{} does not accept range requests'.format(url)) + self.size = int(response.headers['Content-Length']) + + def readable(self): + return True + + def seekable(self): + return True + + def tell(self): + return self.pos + + def seek(self, offset, whence=io.SEEK_SET): + self.pos = {io.SEEK_SET: 0, io.SEEK_CUR: self.pos, io.SEEK_END: self.size}[whence] + offset + return self.pos + + def readinto(self, buffer): + if self.pos >= self.size or len(buffer) == 0: + return 0 + end = min(self.pos + len(buffer), self.size) - 1 + request = urllib.request.Request(self.url, headers={'Range': 'bytes={}-{}'.format(self.pos, end)}) + with urllib.request.urlopen(request, timeout=60) as response: + data = response.read() + buffer[:len(data)] = data + self.pos += len(data) + return len(data) + + +def files_sha256(directory): + """SHA-256 of the relative paths and contents of every file under a directory, in a fixed order.""" + digest = hashlib.sha256() + for root, dirs, files in os.walk(directory): + dirs.sort() + for name in sorted(files): + path = os.path.join(root, name) + digest.update(os.path.relpath(path, directory).replace(os.sep, '/').encode() + b'\0') + with open(path, 'rb') as f: + digest.update(hashlib.sha256(f.read()).digest()) + return digest.hexdigest() + + +def fetch_cts(destination): + """Fetches the gold standard files and the allowed definitions into destination, unless they are already there.""" + if os.path.isdir(destination) and files_sha256(destination) == GOLD_SHA256: + return + shutil.rmtree(destination, ignore_errors=True) + print('Fetching the gold standard files of FACE CTS {} from {}'.format(CTS_VERSION, CTS_URL), flush=True) + with zipfile.ZipFile(io.BufferedReader(HttpRangeFile(CTS_URL), buffer_size=1 << 20)) as archive: + for name in archive.namelist(): + relative = name[len(CTS_ROOT):] if name.startswith(CTS_ROOT) else None + if name.endswith('/') or relative is None or not ( + relative.startswith(GOLD_DIR) or relative == ALLOWED_DEFINITIONS): + continue + path = os.path.join(destination, *relative.split('/')) + os.makedirs(os.path.dirname(path), exist_ok=True) + with open(path, 'wb') as f: + f.write(archive.read(name)) + actual = files_sha256(destination) + if actual != GOLD_SHA256: + raise RuntimeError('The fetched files do not match GOLD_SHA256 (got {}): the published CTS may have changed; ' + 'check {} and update GOLD_SHA256'.format(actual, CTS_URL)) + + +def compile_file(cxx, flags, source, output): + """Compiles a file; returns whether it compiled, and the compiler output.""" + command = [cxx] + flags + (['-fsyntax-only'] if output is None else ['-c', '-o', output]) + [source] + result = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True) + return result.returncode == 0, result.stdout + + +def run(command, **kwargs): + return subprocess.run(command, stdout=subprocess.PIPE, universal_newlines=True, check=True, **kwargs).stdout + + +def symbols(nm, objects, defined): + """The symbols that objects define, or the undefined ones.""" + if not objects: + return set() + flag = '--defined-only' if defined else '--undefined-only' + output = run([nm, flag, '--format=just-symbols'] + objects) + return {line.strip() for line in output.splitlines() if line.strip() and not line.endswith(':')} + + +def demangle(name): + try: + return run(['c++filt', name]).strip() + except (OSError, subprocess.CalledProcessError): + return name + + +def call_sites(obj, names): + """The source lines of an object (built with -g) that refer to each of the names: {name: {'file:line'}}.""" + sites = collections.defaultdict(set) + try: + relocations = run(['readelf', '-rW', obj]) + except (OSError, subprocess.CalledProcessError): + return sites + section = None + offsets = collections.defaultdict(list) # section: [(offset, name)] + for line in relocations.splitlines(): + header = re.match(r"Relocation section '\.rela?(\S+)'", line) + if header: + section = header.group(1) + continue + fields = line.split() + if section and len(fields) >= 5 and re.match(r'^[0-9a-f]+$', fields[0]): + name = fields[4].split('@')[0] + if name in names: + offsets[section].append((fields[0], name)) + for section, entries in offsets.items(): + try: + lines = run(['addr2line', '-e', obj, '-j', section] + [offset for offset, _ in entries]).splitlines() + except (OSError, subprocess.CalledProcessError): + continue + for (_, name), location in zip(entries, lines): + if not location.startswith('??'): + sites[name].add(location.split(' ')[0]) + return sites + + +def read_list(path): + """The non-empty lines of a file, without comments.""" + lines = [] + with open(path) as f: + for line in f: + line = line.split('#', 1)[0].strip() + if line: + lines.append(line) + return lines + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + parser = argparse.ArgumentParser(description=__doc__.split('\n\n')[0]) + parser.add_argument('--source-dir', required=True, help='Fast CDR sources') + parser.add_argument('--build-dir', required=True, help='Fast CDR build, for its generated headers') + parser.add_argument('--work-dir', required=True, help='Directory for the fetched files and the objects') + parser.add_argument('--cts-dir', help='A local CTS installation, instead of fetching its files') + parser.add_argument('--cxx', default='g++', help='GCC C++ compiler (default: g++)') + parser.add_argument('--nm', default='nm', help='nm (default: nm)') + parser.add_argument('--define', action='append', default=[], help='Definition of the library sources') + parser.add_argument('--allowed-symbols', default=os.path.join(here, 'allowed_symbols.txt'), + help='Symbols allowed besides those of the CTS (default: allowed_symbols.txt)') + parser.add_argument('--jobs', type=int, default=os.cpu_count() or 1) + args = parser.parse_args() + + source_dir = os.path.abspath(args.source_dir) + build_dir = os.path.abspath(args.build_dir) + work_dir = os.path.abspath(args.work_dir) + + # The CTS files and the toolchain headers + try: + if args.cts_dir: + cts_dir = os.path.abspath(args.cts_dir) + else: + cts_dir = os.path.join(work_dir, 'cts') + fetch_cts(cts_dir) + except (OSError, RuntimeError, zipfile.BadZipFile) as error: + print('Could not get the CTS files: {}'.format(error), file=sys.stderr) + return 2 + gold_dir = os.path.join(cts_dir, *GOLD_DIR.split('/')) + toolchain_dir = os.path.join(work_dir, 'toolchain') + os.makedirs(toolchain_dir, exist_ok=True) + for name, contents in TOOLCHAIN_HEADERS.items(): + with open(os.path.join(toolchain_dir, name), 'w') as f: + f.write(contents) + face_flags = FACE_FLAGS + ['-I' + gold_dir, '-I' + toolchain_dir] + + # The gold standard libraries and the allowed definitions + objects_dir = os.path.join(work_dir, 'objects') + shutil.rmtree(objects_dir, ignore_errors=True) + os.makedirs(os.path.join(objects_dir, 'gold')) + os.makedirs(os.path.join(objects_dir, 'fastcdr')) + gold_sources = sorted(os.path.join(root, name) for root, _, files in os.walk(gold_dir) + for name in files if name.endswith('.cpp')) + gold_sources.append(os.path.join(cts_dir, *ALLOWED_DEFINITIONS.split('/'))) + gold_objects = [os.path.join(objects_dir, 'gold', '{}.o'.format(i)) for i in range(len(gold_sources))] + + # Fast CDR: each public header alone, and each source (with debug information, to locate the calls) + headers = sorted(os.path.relpath(os.path.join(root, name), source_dir) for root, _, files in + os.walk(os.path.join(source_dir, 'include')) for name in files if name.endswith(('.h', '.hpp'))) + sources = sorted(os.path.relpath(os.path.join(root, name), source_dir) for root, _, files in + os.walk(os.path.join(source_dir, 'src', 'cpp')) for name in files if name.endswith('.cpp')) + fastcdr_flags = face_flags + ['-I' + os.path.join(source_dir, 'include'), '-I' + os.path.join(build_dir, 'include')] + source_flags = fastcdr_flags + ['-g', '-I' + os.path.join(source_dir, 'src', 'cpp')] + \ + ['-D' + d for d in args.define] + units_dir = os.path.join(work_dir, 'units') + os.makedirs(units_dir, exist_ok=True) + + jobs = [] # (checked file, compiler flags, file to compile, object or None) + for header in headers: + unit = os.path.join(units_dir, header.replace(os.sep, '_') + '.cpp') + with open(unit, 'w') as f: + f.write('#include <{}>\n'.format(os.path.relpath(header, 'include').replace(os.sep, '/'))) + jobs.append((header, fastcdr_flags, unit, None)) + for i, source in enumerate(sources): + jobs.append((source, source_flags, os.path.join(source_dir, source), + os.path.join(objects_dir, 'fastcdr', '{}.o'.format(i)))) + + with concurrent.futures.ThreadPoolExecutor(max(1, args.jobs)) as pool: + gold_results = list(pool.map(lambda job: compile_file(args.cxx, face_flags, *job), + zip(gold_sources, gold_objects))) + results = list(pool.map(lambda job: compile_file(args.cxx, job[1], job[2], job[3]), jobs)) + gold_failures = [(source, output) for source, (ok, output) in zip(gold_sources, gold_results) if not ok] + if gold_failures: + for source, output in gold_failures: + print('Gold standard source {} does not compile:\n{}'.format(source, output), file=sys.stderr) + return 2 + + def where(path): + """A path as reported: relative to the Fast CDR sources or build, or to the CTS.""" + path = os.path.normpath(os.path.join(source_dir, path)) + for base, prefix in ((units_dir, ''), (source_dir, ''), (build_dir, '/'), (cts_dir, '/')): + if path.startswith(base + os.sep): + return prefix + os.path.relpath(path, base) + return path + + # The issues: {(location, message): {checked file: whether it is its first error}} + issues = collections.defaultdict(dict) + logs_dir = os.path.join(work_dir, 'logs') + shutil.rmtree(logs_dir, ignore_errors=True) + os.makedirs(logs_dir) + for (checked, _, _, _), (ok, output) in zip(jobs, results): + if ok: + continue + with open(os.path.join(logs_dir, checked.replace(os.sep, '_') + '.log'), 'w') as f: + f.write(output) + errors = [ERROR.match(line) for line in output.splitlines()] + errors = [e for e in errors if e] + if not errors: + issues[(checked, 'does not compile (see the log)')][checked] = True + for index, error in enumerate(errors): + location = '{}:{}:{}'.format(where(error.group(1)), error.group(2), error.group(3)) + key = (location, error.group(4)) + issues[key][checked] = issues[key].get(checked, False) or index == 0 + + # The functions each object of Fast CDR uses from outside Fast CDR, against those of the CTS and + # allowed_symbols.txt + fastcdr_objects = [job[3] for job, (ok, _) in zip(jobs, results) if job[3] is not None and ok] + allowed = (symbols(args.nm, gold_objects, True) | symbols(args.nm, fastcdr_objects, True) | + set(read_list(args.allowed_symbols))) + for (checked, _, _, obj), (ok, _) in zip(jobs, results): + if obj is None or not ok: + continue + outside = symbols(args.nm, [obj], False) - allowed + sites = call_sites(obj, outside) + for name in sorted(outside): + message = 'uses {}, which is not in the profile'.format(demangle(name)) + for site in sorted(sites.get(name)) or [checked]: + issues[(where(site), message)][checked] = True + + # Report + def sort_key(item): + (location, _), _ = item + parts = location.split(':') + return (parts[0],) + tuple(int(p) if p.isdigit() else 0 for p in parts[1:]) + + failed = {checked for found_in in issues.values() for checked in found_in} + first_errors = [item for item in sorted(issues.items(), key=sort_key) if any(item[1].values())] + if first_errors: + print('First error of each failing file (later errors may be their consequences):') + for (location, message), found_in in first_errors: + print(' {}: {}'.format(location, message)) + print(' in: ' + ', '.join(sorted(c for c, is_first in found_in.items() if is_first))) + print('\nAll issues:') + for (location, message), found_in in sorted(issues.items(), key=sort_key): + print('{}: {}'.format(location, message)) + first = sorted(checked for checked, is_first in found_in.items() if is_first) + later = sorted(checked for checked, is_first in found_in.items() if not is_first) + if first: + print(' first error of: ' + ', '.join(first)) + if later: + print(' also in: ' + ', '.join(later)) + print('\n{} issues in {} of {} checked files ({} headers, {} sources).'.format( + len(issues), len(failed), len(jobs), len(headers), len(sources))) + if failed: + print('Compiler output: {}'.format(logs_dir)) + return 1 if issues else 0 + + +if __name__ == '__main__': + sys.exit(main())