diff --git a/plotjuggler_plugins/ParserROS/rosx_introspection/3rdparty/Fast-CDR/include/fastcdr/CdrEncoding.hpp b/plotjuggler_plugins/ParserROS/rosx_introspection/3rdparty/Fast-CDR/include/fastcdr/CdrEncoding.hpp new file mode 100644 index 000000000..6e128f555 --- /dev/null +++ b/plotjuggler_plugins/ParserROS/rosx_introspection/3rdparty/Fast-CDR/include/fastcdr/CdrEncoding.hpp @@ -0,0 +1,54 @@ +// Copyright 2023 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. + +#ifndef _FASTCDR_CDRENCODING_HPP_ +#define _FASTCDR_CDRENCODING_HPP_ + +#include + +namespace eprosima { +namespace fastcdr { + +//! @brief This enumeration represents the kinds of CDR serialization supported by eprosima::fastcdr::CDR. +typedef enum +{ + //! @brief Common CORBA CDR serialization. + CORBA_CDR = 0, + //! @brief DDS CDR serialization. + DDS_CDR = 1, + //! @brief XCDRv1 encoding defined by standard DDS X-Types 1.3 + XCDRv1 = 2, + //! @brief XCDRv2 encoding defined by standard DDS X-Types 1.3 + XCDRv2 = 3 +} CdrVersion; + +//! @brief This enumeration represents the supported XCDR encoding algorithms. +typedef enum : uint8_t +{ + //! @brief Specifies that the content is PLAIN_CDR. + PLAIN_CDR = 0x0, + //! @brief Specifies that the content is PL_CDR, + PL_CDR = 0x2, + //! @brief Specifies that the content is PLAIN_CDR2. + PLAIN_CDR2 = 0x6, + //! @brief Specifies that the content is DELIMIT_CDR2. + DELIMIT_CDR2 = 0x8, + //! @brief Specifies that the content is PL_CDR2. + PL_CDR2 = 0xa +} EncodingAlgorithmFlag; + +} // namespace fastcdr +} // namespace eprosima + +#endif // _FASTCDR_CDRENCODING_HPP_ diff --git a/plotjuggler_plugins/ParserROS/rosx_introspection/3rdparty/Fast-CDR/include/fastcdr/CdrSizeCalculator.hpp b/plotjuggler_plugins/ParserROS/rosx_introspection/3rdparty/Fast-CDR/include/fastcdr/CdrSizeCalculator.hpp new file mode 100644 index 000000000..423b32333 --- /dev/null +++ b/plotjuggler_plugins/ParserROS/rosx_introspection/3rdparty/Fast-CDR/include/fastcdr/CdrSizeCalculator.hpp @@ -0,0 +1,1270 @@ +// Copyright 2023 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. + +#ifndef _FASTCDR_CDRSIZECALCULATOR_HPP_ +#define _FASTCDR_CDRSIZECALCULATOR_HPP_ + +#include +#include +#include +#include +#include +#include + +#include "fastcdr_dll.h" + +#include "CdrEncoding.hpp" +#include "cdr/fixed_size_string.hpp" +#include "detail/container_recursive_inspector.hpp" +#include "exceptions/BadParamException.h" +#include "xcdr/external.hpp" +#include "xcdr/MemberId.hpp" +#include "xcdr/optional.hpp" + +namespace eprosima { +namespace fastcdr { + +class CdrSizeCalculator; + +template +extern size_t calculate_serialized_size( + CdrSizeCalculator&, + const _T&, + size_t&); + +/*! + * @brief This class offers an interface to calculate the encoded size of a type serialized using a support encoding + * algorithm. + * @ingroup FASTCDRAPIREFERENCE + */ +class CdrSizeCalculator +{ +public: + + /*! + * @brief Constructor. + * @param[in] cdr_version Represents the version of the encoding algorithm that will be used for the encoding. + * The default value is CdrVersion::XCDRv2. + */ + Cdr_DllAPI CdrSizeCalculator( + CdrVersion cdr_version); + + /*! + * @brief Retrieves the version of the encoding algorithm used by the instance. + * @return Configured CdrVersion. + */ + Cdr_DllAPI CdrVersion get_cdr_version() const; + + /*! + * @brief Retrieves the current encoding algorithm used by the instance. + * @return Configured EncodingAlgorithmFlag. + */ + Cdr_DllAPI EncodingAlgorithmFlag get_encoding() const; + + /*! + * @brief Generic template which calculates the encoded size of an instance of an unknown type. + * @tparam _T Instance's type. + * @param[in] data Reference to the instance. + * @param[inout] current_alignment Current alignment in the encoding. + * @return Encoded size of the instance. + */ + template::value>::type* = nullptr, typename = void> + size_t calculate_serialized_size( + const _T& data, + size_t& current_alignment) + { + return eprosima::fastcdr::calculate_serialized_size(*this, data, current_alignment); + } + + /*! + * @brief Template which calculates the encoded size of an instance of an enumeration of 32bits. + * @tparam _T Instance's type. + * @param[in] data Reference to the instance. + * @param[inout] current_alignment Current alignment in the encoding. + * @return Encoded size of the instance. + */ + template::value>::type* = nullptr, + typename std::enable_if::type, + int32_t>::value>::type* = nullptr> + size_t calculate_serialized_size( + const _T& data, + size_t& current_alignment) + { + return calculate_serialized_size(static_cast(data), current_alignment); + } + + /*! + * @brief Template which calculates the encoded size of an instance of an enumeration of unsigned 32bits. + * @tparam _T Instance's type. + * @param[in] data Reference to the instance. + * @param[inout] current_alignment Current alignment in the encoding. + * @return Encoded size of the instance. + */ + template::value>::type* = nullptr, + typename std::enable_if::type, + uint32_t>::value>::type* = nullptr> + size_t calculate_serialized_size( + const _T& data, + size_t& current_alignment) + { + return calculate_serialized_size(static_cast(data), current_alignment); + } + + /*! + * @brief Template which calculates the encoded size of an instance of an enumeration of 16bits. + * @tparam _T Instance's type. + * @param[in] data Reference to the instance. + * @param[inout] current_alignment Current alignment in the encoding. + * @return Encoded size of the instance. + */ + template::value>::type* = nullptr, + typename std::enable_if::type, + int16_t>::value>::type* = nullptr> + size_t calculate_serialized_size( + const _T& data, + size_t& current_alignment) + { + return calculate_serialized_size(static_cast(data), current_alignment); + } + + /*! + * @brief Template which calculates the encoded size of an instance of an enumeration of unsigned 16bits. + * @tparam _T Instance's type. + * @param[in] data Reference to the instance. + * @param[inout] current_alignment Current alignment in the encoding. + * @return Encoded size of the instance. + */ + template::value>::type* = nullptr, + typename std::enable_if::type, + uint16_t>::value>::type* = nullptr> + size_t calculate_serialized_size( + const _T& data, + size_t& current_alignment) + { + return calculate_serialized_size(static_cast(data), current_alignment); + } + + /*! + * @brief Template which calculates the encoded size of an instance of an enumeration of 8bits. + * @tparam _T Instance's type. + * @param[in] data Reference to the instance. + * @param[inout] current_alignment Current alignment in the encoding. + * @return Encoded size of the instance. + */ + template::value>::type* = nullptr, + typename std::enable_if::type, + int8_t>::value>::type* = nullptr> + size_t calculate_serialized_size( + const _T& data, + size_t& current_alignment) + { + return calculate_serialized_size(static_cast(data), current_alignment); + } + + /*! + * @brief Template which calculates the encoded size of an instance of an enumeration of unsigned 8bits. + * @tparam _T Instance's type. + * @param[in] data Reference to the instance. + * @param[inout] current_alignment Current alignment in the encoding. + * @return Encoded size of the instance. + */ + template::value>::type* = nullptr, + typename std::enable_if::type, + uint8_t>::value>::type* = nullptr> + size_t calculate_serialized_size( + const _T& data, + size_t& current_alignment) + { + return calculate_serialized_size(static_cast(data), current_alignment); + } + + /*! + * @brief Specific template which calculates the encoded size of an instance of an int8_t. + * @param[in] data Reference to the instance. + * @param[inout] current_alignment Current alignment in the encoding. + * @return Encoded size of the instance. + */ + TEMPLATE_SPEC + size_t calculate_serialized_size( + const int8_t& data, + size_t& current_alignment) + { + static_cast(data); + ++current_alignment; + return 1; + } + + /*! + * @brief Specific template which calculates the encoded size of an instance of an uint8_t. + * @param[in] data Reference to the instance. + * @param[inout] current_alignment Current alignment in the encoding. + * @return Encoded size of the instance. + */ + TEMPLATE_SPEC + size_t calculate_serialized_size( + const uint8_t& data, + size_t& current_alignment) + { + static_cast(data); + ++current_alignment; + return 1; + } + + /*! + * @brief Specific template which calculates the encoded size of an instance of a char. + * @param[in] data Reference to the instance. + * @param[inout] current_alignment Current alignment in the encoding. + * @return Encoded size of the instance. + */ + TEMPLATE_SPEC + size_t calculate_serialized_size( + const char& data, + size_t& current_alignment) + { + static_cast(data); + ++current_alignment; + return 1; + } + + /*! + * @brief Specific template which calculates the encoded size of an instance of a bool. + * @param[in] data Reference to the instance. + * @param[inout] current_alignment Current alignment in the encoding. + * @return Encoded size of the instance. + */ + TEMPLATE_SPEC + size_t calculate_serialized_size( + const bool& data, + size_t& current_alignment) + { + static_cast(data); + ++current_alignment; + return 1; + } + + /*! + * @brief Specific template which calculates the encoded size of an instance of a wchar. + * @param[in] data Reference to the instance. + * @param[inout] current_alignment Current alignment in the encoding. + * @return Encoded size of the instance. + */ + TEMPLATE_SPEC + size_t calculate_serialized_size( + const wchar_t& data, + size_t& current_alignment) + { + static_cast(data); + size_t calculated_size {2 + alignment(current_alignment, 2)}; + current_alignment += calculated_size; + return calculated_size; + } + + /*! + * @brief Specific template which calculates the encoded size of an instance of a int16_t. + * @param[in] data Reference to the instance. + * @param[inout] current_alignment Current alignment in the encoding. + * @return Encoded size of the instance. + */ + TEMPLATE_SPEC + size_t calculate_serialized_size( + const int16_t& data, + size_t& current_alignment) + { + static_cast(data); + size_t calculated_size {2 + alignment(current_alignment, 2)}; + current_alignment += calculated_size; + return calculated_size; + } + + /*! + * @brief Specific template which calculates the encoded size of an instance of a uint16_t. + * @param[in] data Reference to the instance. + * @param[inout] current_alignment Current alignment in the encoding. + * @return Encoded size of the instance. + */ + TEMPLATE_SPEC + size_t calculate_serialized_size( + const uint16_t& data, + size_t& current_alignment) + { + static_cast(data); + size_t calculated_size {2 + alignment(current_alignment, 2)}; + current_alignment += calculated_size; + return calculated_size; + } + + /*! + * @brief Specific template which calculates the encoded size of an instance of a int32_t. + * @param[in] data Reference to the instance. + * @param[inout] current_alignment Current alignment in the encoding. + * @return Encoded size of the instance. + */ + TEMPLATE_SPEC + size_t calculate_serialized_size( + const int32_t& data, + size_t& current_alignment) + { + static_cast(data); + size_t calculated_size {4 + alignment(current_alignment, 4)}; + current_alignment += calculated_size; + return calculated_size; + } + + /*! + * @brief Specific template which calculates the encoded size of an instance of a uint32_t. + * @param[in] data Reference to the instance. + * @param[inout] current_alignment Current alignment in the encoding. + * @return Encoded size of the instance. + */ + TEMPLATE_SPEC + size_t calculate_serialized_size( + const uint32_t& data, + size_t& current_alignment) + { + static_cast(data); + size_t calculated_size {4 + alignment(current_alignment, 4)}; + current_alignment += calculated_size; + return calculated_size; + } + + /*! + * @brief Specific template which calculates the encoded size of an instance of a int64_t. + * @param[in] data Reference to the instance. + * @param[inout] current_alignment Current alignment in the encoding. + * @return Encoded size of the instance. + */ + TEMPLATE_SPEC + size_t calculate_serialized_size( + const int64_t& data, + size_t& current_alignment) + { + static_cast(data); + size_t calculated_size {8 + alignment(current_alignment, align64_)}; + current_alignment += calculated_size; + return calculated_size; + } + + /*! + * @brief Specific template which calculates the encoded size of an instance of a uint64_t. + * @param[in] data Reference to the instance. + * @param[inout] current_alignment Current alignment in the encoding. + * @return Encoded size of the instance. + */ + TEMPLATE_SPEC + size_t calculate_serialized_size( + const uint64_t& data, + size_t& current_alignment) + { + static_cast(data); + size_t calculated_size {8 + alignment(current_alignment, align64_)}; + current_alignment += calculated_size; + return calculated_size; + } + + /*! + * @brief Specific template which calculates the encoded size of an instance of a float. + * @param[in] data Reference to the instance. + * @param[inout] current_alignment Current alignment in the encoding. + * @return Encoded size of the instance. + */ + TEMPLATE_SPEC + size_t calculate_serialized_size( + const float& data, + size_t& current_alignment) + { + static_cast(data); + size_t calculated_size {4 + alignment(current_alignment, 4)}; + current_alignment += calculated_size; + return calculated_size; + } + + /*! + * @brief Specific template which calculates the encoded size of an instance of a double. + * @param[in] data Reference to the instance. + * @param[inout] current_alignment Current alignment in the encoding. + * @return Encoded size of the instance. + */ + TEMPLATE_SPEC + size_t calculate_serialized_size( + const double& data, + size_t& current_alignment) + { + static_cast(data); + size_t calculated_size {8 + alignment(current_alignment, align64_)}; + current_alignment += calculated_size; + return calculated_size; + } + + /*! + * @brief Specific template which calculates the encoded size of an instance of a long double. + * @param[in] data Reference to the instance. + * @param[inout] current_alignment Current alignment in the encoding. + * @return Encoded size of the instance. + */ + TEMPLATE_SPEC + size_t calculate_serialized_size( + const long double& data, + size_t& current_alignment) + { + static_cast(data); + size_t calculated_size {16 + alignment(current_alignment, align64_)}; + current_alignment += calculated_size; + return calculated_size; + } + + /*! + * @brief Specific template which calculates the encoded size of an instance of a std::string. + * @param[in] data Reference to the instance. + * @param[inout] current_alignment Current alignment in the encoding. + * @return Encoded size of the instance. + */ + TEMPLATE_SPEC + size_t calculate_serialized_size( + const std::string& data, + size_t& current_alignment) + { + size_t calculated_size {4 + alignment(current_alignment, 4) + data.size() + 1}; + current_alignment += calculated_size; + serialized_member_size_ = SERIALIZED_MEMBER_SIZE; + + return calculated_size; + } + + /*! + * @brief Specific template which calculates the encoded size of an instance of a std::wstring. + * @param[in] data Reference to the instance. + * @param[inout] current_alignment Current alignment in the encoding. + * @return Encoded size of the instance. + */ + TEMPLATE_SPEC + size_t calculate_serialized_size( + const std::wstring& data, + size_t& current_alignment) + { + size_t calculated_size {4 + alignment(current_alignment, 4) + data.size() * 2}; + current_alignment += calculated_size; + + return calculated_size; + } + + /*! + * @brief Specific template which calculates the encoded size of an instance of a fixed_string. + * @param[in] data Reference to the instance. + * @param[inout] current_alignment Current alignment in the encoding. + * @return Encoded size of the instance. + */ + template + size_t calculate_serialized_size( + const fixed_string& data, + size_t& current_alignment) + { + size_t calculated_size {4 + alignment(current_alignment, 4) + data.size() + 1}; + current_alignment += calculated_size; + + return calculated_size; + } + + /*! + * @brief Specific template which calculates the encoded size of an instance of a sequence of non-primitives. + * @param[in] data Reference to the instance. + * @param[inout] current_alignment Current alignment in the encoding. + * @return Encoded size of the instance. + */ + template::value && + !std::is_arithmetic<_T>::value>::type* = nullptr> + size_t calculate_serialized_size( + const std::vector<_T>& data, + size_t& current_alignment) + { + size_t initial_alignment {current_alignment}; + + if (CdrVersion::XCDRv2 == cdr_version_) + { + // DHEADER + current_alignment += 4 + alignment(current_alignment, 4); + } + + current_alignment += 4 + alignment(current_alignment, 4); + + 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_) + { + // Inform DHEADER can be joined with NEXTINT + serialized_member_size_ = SERIALIZED_MEMBER_SIZE; + } + + return calculated_size; + } + + /*! + * @brief Specific template which calculates the encoded size of an instance of a sequence of primitives. + * @param[in] data Reference to the instance. + * @param[inout] current_alignment Current alignment in the encoding. + * @return Encoded size of the instance. + */ + template::value || + std::is_arithmetic<_T>::value>::type* = nullptr> + size_t calculate_serialized_size( + const std::vector<_T>& data, + size_t& current_alignment) + { + size_t initial_alignment {current_alignment}; + + current_alignment += 4 + alignment(current_alignment, 4); + + 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_) + { + serialized_member_size_ = get_serialized_member_size<_T>(); + } + + return calculated_size; + } + + /*! + * @brief Specific template which calculates the encoded size of an instance of a sequence of bool. + * @param[in] data Reference to the instance. + * @param[inout] current_alignment Current alignment in the encoding. + * @return Encoded size of the instance. + */ + TEMPLATE_SPEC + size_t calculate_serialized_size( + const std::vector& data, + size_t& current_alignment) + { + size_t calculated_size {data.size() + 4 + alignment(current_alignment, 4)}; + current_alignment += calculated_size; + + return calculated_size; + } + + /*! + * @brief Specific template which calculates the encoded size of an instance of an array. + * @param[in] data Reference to the instance. + * @param[inout] current_alignment Current alignment in the encoding. + * @return Encoded size of the instance. + */ + template + size_t calculate_serialized_size( + const std::array<_T, _Size>& data, + size_t& current_alignment) + { + size_t initial_alignment {current_alignment}; + + if (CdrVersion::XCDRv2 == cdr_version_ && + !is_multi_array_primitive(&data)) + { + // DHEADER + current_alignment += 4 + alignment(current_alignment, 4); + } + + 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_ && + !is_multi_array_primitive(&data)) + { + // Inform DHEADER can be joined with NEXTINT + serialized_member_size_ = SERIALIZED_MEMBER_SIZE; + } + + return calculated_size; + } + + /*! + * @brief Specific template which calculates the encoded size of an instance of a map of non-primitives. + * @param[in] data Reference to the instance. + * @param[inout] current_alignment Current alignment in the encoding. + * @return Encoded size of the instance. + */ + template::value && + !std::is_arithmetic<_V>::value>::type* = nullptr> + size_t calculate_serialized_size( + const std::map<_K, _V>& data, + size_t& current_alignment) + { + size_t initial_alignment {current_alignment}; + + if (CdrVersion::XCDRv2 == cdr_version_) + { + // DHEADER + current_alignment += 4 + alignment(current_alignment, 4); + } + + current_alignment += 4 + alignment(current_alignment, 4); + + 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); + calculated_size += calculate_serialized_size(it->second, current_alignment); + } + + if (CdrVersion::XCDRv2 == cdr_version_) + { + // Inform DHEADER can be joined with NEXTINT + serialized_member_size_ = SERIALIZED_MEMBER_SIZE; + } + + return calculated_size; + } + + /*! + * @brief Specific template which calculates the encoded size of an instance of a map of primitives. + * @param[in] data Reference to the instance. + * @param[inout] current_alignment Current alignment in the encoding. + * @return Encoded size of the instance. + */ + template::value || + std::is_arithmetic<_V>::value>::type* = nullptr> + size_t calculate_serialized_size( + const std::map<_K, _V>& data, + size_t& current_alignment) + { + size_t initial_alignment {current_alignment}; + + current_alignment += 4 + alignment(current_alignment, 4); + + 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); + calculated_size += calculate_serialized_size(it->second, current_alignment); + } + + return calculated_size; + } + + /*! + * @brief Specific template which calculates the encoded size of an instance of a bitset of 8bits. + * @param[in] data Reference to the instance. + * @param[inout] current_alignment Current alignment in the encoding. + * @return Encoded size of the instance. + */ + template ::type* = nullptr> + size_t calculate_serialized_size( + const std::bitset& data, + size_t& current_alignment) + { + static_cast(data); + ++current_alignment; + return 1; + } + + /*! + * @brief Specific template which calculates the encoded size of an instance of a bitset of 16bits. + * @param[in] data Reference to the instance. + * @param[inout] current_alignment Current alignment in the encoding. + * @return Encoded size of the instance. + */ + template ::type* = nullptr> + size_t calculate_serialized_size( + const std::bitset& data, + size_t& current_alignment) + { + static_cast(data); + size_t calculated_size {2 + alignment(current_alignment, 2)}; + current_alignment += calculated_size; + return calculated_size; + } + + /*! + * @brief Specific template which calculates the encoded size of an instance of a bitset of 32bits. + * @param[in] data Reference to the instance. + * @param[inout] current_alignment Current alignment in the encoding. + * @return Encoded size of the instance. + */ + template ::type* = nullptr> + size_t calculate_serialized_size( + const std::bitset& data, + size_t& current_alignment) + { + static_cast(data); + size_t calculated_size {4 + alignment(current_alignment, 4)}; + current_alignment += calculated_size; + return calculated_size; + } + + /*! + * @brief Specific template which calculates the encoded size of an instance of a bitset of 64bits. + * @param[in] data Reference to the instance. + * @param[inout] current_alignment Current alignment in the encoding. + * @return Encoded size of the instance. + */ + template ::type* = nullptr> + size_t calculate_serialized_size( + const std::bitset& data, + size_t& current_alignment) + { + static_cast(data); + size_t calculated_size {8 + alignment(current_alignment, align64_)}; + current_alignment += calculated_size; + return calculated_size; + } + + /*! + * @brief Specific template which calculates the encoded size of an instance of an optional type. + * @param[in] data Reference to the instance. + * @param[inout] current_alignment Current alignment in the encoding. + * @return Encoded size of the instance. + */ + template + size_t calculate_serialized_size( + const optional<_T>& data, + size_t& current_alignment) + { + size_t initial_alignment = current_alignment; + + if (CdrVersion::XCDRv2 == cdr_version_ && + EncodingAlgorithmFlag::PL_CDR2 != current_encoding_) + { + // Take into account the boolean is_present; + ++current_alignment; + } + + size_t calculated_size {current_alignment - initial_alignment}; + + if (data.has_value()) + { + calculated_size += calculate_serialized_size(data.value(), current_alignment); + } + + return calculated_size; + } + + /*! + * @brief Specific template which calculates the encoded size of an instance of an external type. + * @param[in] data Reference to the instance. + * @param[inout] current_alignment Current alignment in the encoding. + * @exception exception::BadParamException This exception is thrown when the external is null. + * @return Encoded size of the instance. + */ + template + size_t calculate_serialized_size( + const external<_T>& data, + size_t& current_alignment) + { + if (!data) + { + throw exception::BadParamException("External member is null"); + } + + return calculate_serialized_size(*data, current_alignment); + } + + /*! + * @brief Specific template which calculates the encoded size of an instance of an array of unknown type. + * @tparam _T Array's type. + * @param[in] data Reference to the array's instance. + * @param[in] num_elements Number of elements in the array. + * @param[inout] current_alignment Current alignment in the encoding. + * @return Encoded size of the instance. + */ + template + size_t calculate_array_serialized_size( + const _T* data, + size_t num_elements, + size_t& current_alignment) + { + size_t calculated_size {0}; + + for (size_t count = 0; count < num_elements; ++count) + { + calculated_size += calculate_serialized_size(data[count], current_alignment); + } + + return calculated_size; + } + + /*! + * @brief Specific template which calculates the encoded size of an instance of an array of int8_t. + * @param[in] data Reference to the array's instance. + * @param[in] num_elements Number of elements in the array. + * @param[inout] current_alignment Current alignment in the encoding. + * @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) + { + static_cast(data); + current_alignment += num_elements; + return num_elements; + } + + /*! + * @brief Specific template which calculates the encoded size of an instance of an array of uint8_t. + * @param[in] data Reference to the array's instance. + * @param[in] num_elements Number of elements in the array. + * @param[inout] current_alignment Current alignment in the encoding. + * @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) + { + static_cast(data); + current_alignment += num_elements; + return num_elements; + } + + /*! + * @brief Specific template which calculates the encoded size of an instance of an array of char. + * @param[in] data Reference to the array's instance. + * @param[in] num_elements Number of elements in the array. + * @param[inout] current_alignment Current alignment in the encoding. + * @return Encoded size of the instance. + */ + TEMPLATE_SPEC + size_t calculate_array_serialized_size( + const char* data, + size_t num_elements, + size_t& current_alignment) + { + static_cast(data); + current_alignment += num_elements; + return num_elements; + } + + /*! + * @brief Specific template which calculates the encoded size of an instance of an array of wchar. + * @param[in] data Reference to the array's instance. + * @param[in] num_elements Number of elements in the array. + * @param[inout] current_alignment Current alignment in the encoding. + * @return Encoded size of the instance. + */ + TEMPLATE_SPEC + size_t calculate_array_serialized_size( + const wchar_t* data, + size_t num_elements, + size_t& current_alignment) + { + static_cast(data); + size_t calculated_size {num_elements* 2 + alignment(current_alignment, 2)}; + current_alignment += calculated_size; + return calculated_size; + } + + /*! + * @brief Specific template which calculates the encoded size of an instance of an array of int16_t. + * @param[in] data Reference to the array's instance. + * @param[in] num_elements Number of elements in the array. + * @param[inout] current_alignment Current alignment in the encoding. + * @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) + { + static_cast(data); + size_t calculated_size {num_elements* 2 + alignment(current_alignment, 2)}; + current_alignment += calculated_size; + return calculated_size; + } + + /*! + * @brief Specific template which calculates the encoded size of an instance of an array of uint16_t. + * @param[in] data Reference to the array's instance. + * @param[in] num_elements Number of elements in the array. + * @param[inout] current_alignment Current alignment in the encoding. + * @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) + { + static_cast(data); + size_t calculated_size {num_elements* 2 + alignment(current_alignment, 2)}; + current_alignment += calculated_size; + return calculated_size; + } + + /*! + * @brief Specific template which calculates the encoded size of an instance of an array of int32_t. + * @param[in] data Reference to the array's instance. + * @param[in] num_elements Number of elements in the array. + * @param[inout] current_alignment Current alignment in the encoding. + * @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) + { + static_cast(data); + size_t calculated_size {num_elements* 4 + alignment(current_alignment, 4)}; + current_alignment += calculated_size; + return calculated_size; + } + + /*! + * @brief Specific template which calculates the encoded size of an instance of an array of uint32_t. + * @param[in] data Reference to the array's instance. + * @param[in] num_elements Number of elements in the array. + * @param[inout] current_alignment Current alignment in the encoding. + * @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) + { + static_cast(data); + size_t calculated_size {num_elements* 4 + alignment(current_alignment, 4)}; + current_alignment += calculated_size; + return calculated_size; + } + + /*! + * @brief Specific template which calculates the encoded size of an instance of an array of int64_t. + * @param[in] data Reference to the array's instance. + * @param[in] num_elements Number of elements in the array. + * @param[inout] current_alignment Current alignment in the encoding. + * @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) + { + static_cast(data); + size_t calculated_size {num_elements* 8 + alignment(current_alignment, align64_)}; + current_alignment += calculated_size; + return calculated_size; + } + + /*! + * @brief Specific template which calculates the encoded size of an instance of an array of uint64_t. + * @param[in] data Reference to the array's instance. + * @param[in] num_elements Number of elements in the array. + * @param[inout] current_alignment Current alignment in the encoding. + * @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) + { + static_cast(data); + size_t calculated_size {num_elements* 8 + alignment(current_alignment, align64_)}; + current_alignment += calculated_size; + return calculated_size; + } + + /*! + * @brief Specific template which calculates the encoded size of an instance of an array of float. + * @param[in] data Reference to the array's instance. + * @param[in] num_elements Number of elements in the array. + * @param[inout] current_alignment Current alignment in the encoding. + * @return Encoded size of the instance. + */ + TEMPLATE_SPEC + size_t calculate_array_serialized_size( + const float* data, + size_t num_elements, + size_t& current_alignment) + { + static_cast(data); + size_t calculated_size {num_elements* 4 + alignment(current_alignment, 4)}; + current_alignment += calculated_size; + return calculated_size; + } + + /*! + * @brief Specific template which calculates the encoded size of an instance of an array of double. + * @param[in] data Reference to the array's instance. + * @param[in] num_elements Number of elements in the array. + * @param[inout] current_alignment Current alignment in the encoding. + * @return Encoded size of the instance. + */ + TEMPLATE_SPEC + size_t calculate_array_serialized_size( + const double* data, + size_t num_elements, + size_t& current_alignment) + { + static_cast(data); + size_t calculated_size {num_elements* 8 + alignment(current_alignment, align64_)}; + current_alignment += calculated_size; + return calculated_size; + } + + /*! + * @brief Specific template which calculates the encoded size of an instance of an array of long double. + * @param[in] data Reference to the array's instance. + * @param[in] num_elements Number of elements in the array. + * @param[inout] current_alignment Current alignment in the encoding. + * @return Encoded size of the instance. + */ + TEMPLATE_SPEC + size_t calculate_array_serialized_size( + const long double* data, + size_t num_elements, + size_t& current_alignment) + { + static_cast(data); + size_t calculated_size {num_elements* 16 + alignment(current_alignment, align64_)}; + current_alignment += calculated_size; + return calculated_size; + } + + /*! + * @brief Specific template which calculates the encoded size of an instance of a multi-dimensional array. + * @param[in] data Reference to the array's instance. + * @param[in] num_elements Number of elements in the array. + * @param[inout] current_alignment Current alignment in the encoding. + * @return Encoded size of the instance. + */ + template + size_t calculate_array_serialized_size( + const std::array<_T, _N>* data, + size_t num_elements, + size_t& current_alignment) + { + return calculate_array_serialized_size(data->data(), num_elements * data->size(), current_alignment); + } + + /*! + * @brief Generic template which calculates the encoded size of the constructed type's member of a unknown type. + * @tparam _T Member's type. + * @param[in] id Member's identifier. + * @param[in] data Reference to the member's instance. + * @param[inout] current_alignment Current alignment in the encoding. + * @return Encoded size of the member's instance. + */ + template + size_t calculate_member_serialized_size( + const MemberId& id, + const _T& data, + size_t& current_alignment) + { + size_t initial_alignment {current_alignment}; + + if (EncodingAlgorithmFlag::PL_CDR == current_encoding_ || + EncodingAlgorithmFlag::PL_CDR2 == current_encoding_) + { + // Align to 4 for the XCDR header before calculating the data serialized size. + current_alignment += alignment(current_alignment, 4); + } + + size_t prev_size {current_alignment - initial_alignment}; + size_t extra_size {0}; + + if (EncodingAlgorithmFlag::PL_CDR == current_encoding_) + { + current_alignment = 0; + } + + size_t calculated_size {calculate_serialized_size(data, current_alignment)}; + + if (CdrVersion::XCDRv2 == cdr_version_ && EncodingAlgorithmFlag::PL_CDR2 == current_encoding_ && + 0 < calculated_size) + { + + if (8 < calculated_size) + { + extra_size = 8; // Long EMHEADER. + if (NO_SERIALIZED_MEMBER_SIZE != serialized_member_size_) + { + calculated_size -= 4; // Join NEXTINT and DHEADER. + } + } + else + { + extra_size = 4; // EMHEADER; + } + } + else if (CdrVersion::XCDRv1 == cdr_version_ && EncodingAlgorithmFlag::PL_CDR == current_encoding_ && + 0 < calculated_size) + { + extra_size = 4; // ShortMemberHeader + + if (0x3F00 < id.id || calculated_size > std::numeric_limits::max()) + { + extra_size += 8; // LongMemberHeader + } + + } + + calculated_size += prev_size + extra_size; + if (EncodingAlgorithmFlag::PL_CDR != current_encoding_) + { + current_alignment += extra_size; + } + + serialized_member_size_ = NO_SERIALIZED_MEMBER_SIZE; + + return calculated_size; + } + + /*! + * @brief Generic template which calculates the encoded size of the constructed type's member of type optional. + * @tparam _T Member's optional type. + * @param[in] id Member's identifier. + * @param[in] data Reference to the member's instance. + * @param[inout] current_alignment Current alignment in the encoding. + * @return Encoded size of the member's instance. + */ + template + size_t calculate_member_serialized_size( + const MemberId& id, + const optional<_T>& data, + size_t& current_alignment) + { + size_t initial_alignment = current_alignment; + + if (CdrVersion::XCDRv2 != cdr_version_ || + EncodingAlgorithmFlag::PL_CDR2 == current_encoding_) + { + if (data.has_value() || EncodingAlgorithmFlag::PLAIN_CDR == current_encoding_) + { + // Align to 4 for the XCDR header before calculating the data serialized size. + current_alignment += alignment(current_alignment, 4); + } + } + + size_t prev_size = {current_alignment - initial_alignment}; + size_t extra_size {0}; + + if (CdrVersion::XCDRv1 == cdr_version_ && + (data.has_value() || EncodingAlgorithmFlag::PLAIN_CDR == current_encoding_)) + { + current_alignment = 0; + } + + size_t calculated_size {calculate_serialized_size(data, current_alignment)}; + + if (CdrVersion::XCDRv2 == cdr_version_ && EncodingAlgorithmFlag::PL_CDR2 == current_encoding_ && + 0 < calculated_size) + { + if (8 < calculated_size) + { + extra_size = 8; // Long EMHEADER. + if (NO_SERIALIZED_MEMBER_SIZE != serialized_member_size_) + { + extra_size -= 4; // Join NEXTINT and DHEADER. + } + } + else + { + extra_size = 4; // EMHEADER; + } + } + else if (CdrVersion::XCDRv1 == cdr_version_ && + (0 < calculated_size || EncodingAlgorithmFlag::PLAIN_CDR == current_encoding_)) + { + extra_size = 4; // ShortMemberHeader + + if (0x3F00 < id.id || calculated_size > std::numeric_limits::max()) + { + extra_size += 8; // LongMemberHeader + } + + } + + calculated_size += prev_size + extra_size; + if (CdrVersion::XCDRv1 != cdr_version_) + { + current_alignment += extra_size; + } + + + return calculated_size; + } + + /*! + * @brief Indicates a new constructed type will be calculated. + * @param[in] new_encoding New encoding algorithm used for the constructed type. + * @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( + EncodingAlgorithmFlag new_encoding, + size_t& current_alignment); + + /*! + * @brief Indicates the ending of a constructed type. + * @param[in] new_encoding New encoding algorithm used after the constructed type. + * @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( + EncodingAlgorithmFlag new_encoding, + size_t& current_alignment); + +private: + + CdrSizeCalculator() = delete; + + CdrVersion cdr_version_ {CdrVersion::XCDRv2}; + + EncodingAlgorithmFlag current_encoding_ {EncodingAlgorithmFlag::PLAIN_CDR2}; + + enum SerializedMemberSizeForNextInt + { + NO_SERIALIZED_MEMBER_SIZE, + SERIALIZED_MEMBER_SIZE, + SERIALIZED_MEMBER_SIZE_4, + SERIALIZED_MEMBER_SIZE_8 + } + //! Specifies if a DHEADER was serialized. Used to calculate XCDRv2 member headers. + serialized_member_size_ {NO_SERIALIZED_MEMBER_SIZE}; + + //! Align for types equal or greater than 64bits. + size_t align64_ {4}; + + inline size_t alignment( + size_t current_alignment, + size_t data_size) const + { + return (data_size - (current_alignment % data_size)) & (data_size - 1); + } + + template::value || + std::is_arithmetic<_T>::value>::type* = nullptr> + constexpr SerializedMemberSizeForNextInt get_serialized_member_size() const + { + return (1 == sizeof(_T) ? SERIALIZED_MEMBER_SIZE : + (4 == sizeof(_T) ? SERIALIZED_MEMBER_SIZE_4 : + (8 == sizeof(_T) ? SERIALIZED_MEMBER_SIZE_8 : NO_SERIALIZED_MEMBER_SIZE))); + } + +}; + +} // namespace fastcdr +} // namespace eprosima + +#endif // _FASTCDR_CDRSIZECALCULATOR_HPP_ diff --git a/plotjuggler_plugins/ParserROS/rosx_introspection/3rdparty/Fast-CDR/include/fastcdr/cdr/fixed_size_string.hpp b/plotjuggler_plugins/ParserROS/rosx_introspection/3rdparty/Fast-CDR/include/fastcdr/cdr/fixed_size_string.hpp new file mode 100644 index 000000000..21bc800f1 --- /dev/null +++ b/plotjuggler_plugins/ParserROS/rosx_introspection/3rdparty/Fast-CDR/include/fastcdr/cdr/fixed_size_string.hpp @@ -0,0 +1,344 @@ +// Copyright 2023 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. + +/*! + * @file fixed_size_string.hpp + * + */ + +#ifndef FASTCDR_UTILS_FIXED_SIZE_STRING_HPP_ +#define FASTCDR_UTILS_FIXED_SIZE_STRING_HPP_ + +#include +#include + +#ifdef _WIN32 +#define MEMCCPY _memccpy +#else +#define MEMCCPY memccpy +#endif // ifdef _WIN32 + +namespace eprosima { +namespace fastcdr { + +/** + * @brief Template class for non-alloc strings. + * + * Will be truncated when assigned from a longer string. + * + * @tparam MAX_CHARS Maximum number of characters is specified as the template parameter. + * Space for an additional null terminator will be reserved. + */ +template +struct fixed_string +{ +public: + + //! @brief Maximum number of characters. + static constexpr size_t max_size = MAX_CHARS; + + //! @brief Default constructor. + fixed_string() noexcept + { + memset(string_data, 0, sizeof(string_data)); + string_len = 0; + } + + // We don't need to define copy/move constructors/assignment operators as the default ones would be enough + + /*! + * @brief Constructs from a char array + * @param[in] c_array Char array to be constructed from. + * @param[in] n_chars Number of characters of the Char array + */ + fixed_string( + const char* c_array, + size_t n_chars) noexcept + { + assign(c_array, n_chars); + } + + /*! + * @brief Assigns from a char array + * @param[in] c_array Char array to be assigned from. + * @param[in] n_chars Number of characters of the Char array. + * @return Reference of this instance. + */ + fixed_string& assign( + const char* c_array, + 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); + } + return *this; + } + + /*! + * @brief Constructs from a C string. + * @param[in] c_string Pointer to the C string. + */ + fixed_string ( + const char* c_string) noexcept + : fixed_string() + { + set(c_string != nullptr ? c_string : ""); + } + + /*! + * @brief Assigns from a C string. + * @param[in] c_string Pointer to the C string. + * @return Reference of this instance. + */ + fixed_string& operator = ( + const char* c_string) noexcept + { + set(c_string != nullptr ? c_string : ""); + return *this; + } + + /*! + * @brief Constructs from a std::string. + * @param[in] str Reference to the std::string. + */ + fixed_string ( + const std::string& str) noexcept + : fixed_string() + { + set(str.c_str()); + } + + /*! + * @brief Assigns from a std::string. + * @param[in] str Reference to the std::string. + * return Reference of this instance. + */ + fixed_string& operator = ( + const std::string& str) noexcept + { + set(str.c_str()); + return *this; + } + + /*! + * @brief Assigns from a fixed_string of any size. + * @param[in] rhs Reference to the fixed_string. + * return Reference of this instance. + */ + template fixed_string& operator = ( + const fixed_string& rhs) noexcept + { + set(rhs.c_str()); + return *this; + } + + /*! + * @brief Converts to C string. + * @return Pointer to the C string. + */ + const char* c_str() const noexcept + { + return string_data; + } + + /*! + * @brief Converts to std::string. + * @return Reference to the std::string. + */ + std::string to_string() const + { + return std::string(string_data); + } + + /*! + * @brief Compares equality with a C string. + * @param[in] rhs C string to be compared with. + * @return `true` if strings are equal. `false` otherwise. + */ + bool operator == ( + const char* rhs) const noexcept + { + return strncmp(string_data, rhs, MAX_CHARS) == 0; + } + + /*! + * @brief Compares equality with a std::string. + * @param[in] rhs std::string to be compared with. + * @return `true` if strings are equal. `false` otherwise. + */ + bool operator == ( + const std::string& rhs) const noexcept + { + return strncmp(string_data, rhs.c_str(), MAX_CHARS) == 0; + } + + /*! + * @brief Compares equality with a fixed_string of any size. + * @param[in] rhs fixed_string to be compared with. + * @return `true` if strings are equal. `false` otherwise. + */ + template bool operator == ( + const fixed_string& rhs) const noexcept + { + return strncmp(string_data, rhs.c_str(), MAX_CHARS) == 0; + } + + /*! + * @brief Compares inequality with a C string. + * @param[in] rhs C string to be compared with. + * @return `true` if strings are not equal. `false` otherwise. + */ + bool operator != ( + const char* rhs) const noexcept + { + return !(*this == rhs); + } + + /*! + * @brief Compares inequality with a std::string. + * @param[in] rhs std::string to be compared with. + * @return `true` if strings are not equal. `false` otherwise. + */ + bool operator != ( + const std::string& rhs) const noexcept + { + return !(*this == rhs); + } + + /*! + * @brief Compares inequality with a fixed_string of any size. + * @param[in] rhs fixed_string to be compared with. + * @return `true` if strings are not equal. `false` otherwise. + */ + template bool operator != ( + const fixed_string& rhs) const noexcept + { + return !(*this == rhs); + } + + /*! + * @brief Compares relational less than with a fixed_string of any size. + * @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 < ( + const fixed_string& rhs) const noexcept + { + return 0 > compare(rhs); + } + + /*! + * @brief Compares relational greater than with a fixed_string of any size. + * @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 > ( + const fixed_string& rhs) const noexcept + { + return 0 < compare(rhs); + } + + /*! + * @brief Compares relational less than with a std::string of any size. + * @param[in] rhs std::string to be compared with. + * @return `true` if this string is less than the provided one. `false` otherwise. + */ + bool operator < ( + const std::string& rhs) const noexcept + { + return 0 > compare(rhs); + } + + /*! + * @brief Compares relational greater than with a std::string of any size. + * @param[in] rhs std::string to be compared with. + * @return `true` if this string is greater than the provided one. `false` otherwise. + */ + bool operator > ( + const std::string& rhs) const noexcept + { + return 0 < compare(rhs); + } + + /*! + * @brief Casts to a C string. + */ + operator const char* () const noexcept { + return c_str(); + } + + /*! + * @brief Returns the size of the string. + * @return Length of the string. + */ + size_t size() const noexcept + { + return string_len; + } + + /*! + * @brief Compares with a C string. + * @param[in] str C string to be compared with. + * @return Integer value with the result of the comparison as described in `std::string::compare()`. + */ + int compare( + const char* str) const noexcept + { + return strncmp(string_data, str, MAX_CHARS); + } + + /*! + * @brief Compares with a std::string. + * @param[in] str std::string to be compared with. + * @return Integer value with the result of the comparison as described in `std::string::compare()`. + */ + int compare( + const std::string& str) const noexcept + { + return strncmp(string_data, str.c_str(), MAX_CHARS); + } + + /*! + * @brief Compares with a 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( + const fixed_string& str) const noexcept + { + return strncmp(string_data, str.c_str(), MAX_CHARS); + } + +private: + + 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; + } + + char string_data[MAX_CHARS + 1]; ///< Holds string data, including ending null character. + size_t string_len; ///< Holds current string length. +}; + +using string_255 = fixed_string<255>; + +} /* namespace fastcdr */ +} /* namespace eprosima */ + +#endif /* FASTCDR_UTILS_FIXED_SIZE_STRING_HPP_ */ diff --git a/plotjuggler_plugins/ParserROS/rosx_introspection/3rdparty/Fast-CDR/include/fastcdr/detail/container_recursive_inspector.hpp b/plotjuggler_plugins/ParserROS/rosx_introspection/3rdparty/Fast-CDR/include/fastcdr/detail/container_recursive_inspector.hpp new file mode 100644 index 000000000..6785c7fce --- /dev/null +++ b/plotjuggler_plugins/ParserROS/rosx_introspection/3rdparty/Fast-CDR/include/fastcdr/detail/container_recursive_inspector.hpp @@ -0,0 +1,53 @@ +// Copyright 2023 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. + +#ifndef _FASTCDR_DETAIL_CONTAINERRECURSIVEINSPECTOR_HPP_ +#define _FASTCDR_DETAIL_CONTAINERRECURSIVEINSPECTOR_HPP_ + +#include +#include +#include + +namespace eprosima { +namespace fastcdr { + +// Helpers to deduce multi-array of primitives. +/// Basis +constexpr bool is_multi_array_primitive( + ...) +{ + return false; +} + +/// Specializations +template ::value || + std::is_arithmetic<_T>::value>::type* = nullptr> +constexpr bool is_multi_array_primitive( + _T const*) +{ + return true; +} + +template +constexpr bool is_multi_array_primitive( + std::array<_T, _N> const*) +{ + return is_multi_array_primitive(static_cast<_T const*>(nullptr)); +} + +} // namespace fastcdr +} // namespace eprosima + +#endif // _FASTCDR_DETAIL_CONTAINERRECURSIVEINSPECTOR_HPP_ diff --git a/plotjuggler_plugins/ParserROS/rosx_introspection/3rdparty/Fast-CDR/include/fastcdr/xcdr/MemberId.hpp b/plotjuggler_plugins/ParserROS/rosx_introspection/3rdparty/Fast-CDR/include/fastcdr/xcdr/MemberId.hpp new file mode 100644 index 000000000..36693d52d --- /dev/null +++ b/plotjuggler_plugins/ParserROS/rosx_introspection/3rdparty/Fast-CDR/include/fastcdr/xcdr/MemberId.hpp @@ -0,0 +1,72 @@ +// Copyright 2023 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. +// +#ifndef _FASTCDR_XCDR_MEMBERID_HPP_ +#define _FASTCDR_XCDR_MEMBERID_HPP_ + +#include + +#include "../fastcdr_dll.h" + +namespace eprosima { +namespace fastcdr { + +class Cdr; + +class Cdr_DllAPI MemberId +{ +public: + + MemberId() = default; + + MemberId( + uint32_t id_value) + : id(id_value) + { + } + + bool operator ==( + uint32_t id_value) const + { + return id == id_value; + } + + bool operator ==( + const MemberId member_id) const + { + return id == member_id.id; + } + + bool operator !=( + const MemberId member_id) const + { + return !(member_id == *this); + } + + uint32_t id { member_id_invalid_value_ }; + + bool must_understand { false }; + +private: + + static constexpr uint32_t member_id_invalid_value_ = 0xFFFFFFFF; + +}; + +static const MemberId MEMBER_ID_INVALID {}; + +} // namespace fastcdr +} // namespace eprosima + +#endif //_FASTCDR_XCDR_MEMBERID_HPP_ diff --git a/plotjuggler_plugins/ParserROS/rosx_introspection/3rdparty/Fast-CDR/include/fastcdr/xcdr/detail/optional.hpp b/plotjuggler_plugins/ParserROS/rosx_introspection/3rdparty/Fast-CDR/include/fastcdr/xcdr/detail/optional.hpp new file mode 100644 index 000000000..f71474ec6 --- /dev/null +++ b/plotjuggler_plugins/ParserROS/rosx_introspection/3rdparty/Fast-CDR/include/fastcdr/xcdr/detail/optional.hpp @@ -0,0 +1,71 @@ +// Copyright 2023 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. +// +#ifndef _FASTCDR_XCDR_DETAIL_OPTIONAL_HPP_ +#define _FASTCDR_XCDR_DETAIL_OPTIONAL_HPP_ + +#include + +namespace eprosima { +namespace fastcdr { +namespace detail { +template +struct optional_storage +{ + union + { + char dummy_; + T val_; + }; + + bool engaged_ { false }; + + optional_storage() + { + } + + ~optional_storage() + { + if (engaged_) + { + val_.~T(); + } + } + +}; + +/* *INDENT-OFF* */ +template +struct optional_storage{}>::type> +{ + union + { + char dummy_; T val_; + }; + + bool engaged_ { false }; + + optional_storage() + { + } + + ~optional_storage() = default; +}; +/* *INDENT-ON* */ +} // namespace detail +} // namespace fastcdr +} // namespace eprosima + +#endif //_FASTCDR_XCDR_DETAIL_OPTIONAL_HPP_ + diff --git a/plotjuggler_plugins/ParserROS/rosx_introspection/3rdparty/Fast-CDR/include/fastcdr/xcdr/external.hpp b/plotjuggler_plugins/ParserROS/rosx_introspection/3rdparty/Fast-CDR/include/fastcdr/xcdr/external.hpp new file mode 100644 index 000000000..1c4b42a67 --- /dev/null +++ b/plotjuggler_plugins/ParserROS/rosx_introspection/3rdparty/Fast-CDR/include/fastcdr/xcdr/external.hpp @@ -0,0 +1,190 @@ +// Copyright 2023 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. +// +#ifndef _FASTCDR_XCDR_EXTERNAL_HPP_ +#define _FASTCDR_XCDR_EXTERNAL_HPP_ + +#include + +#include "../exceptions/LockedExternalAccessException.hpp" + +namespace eprosima { +namespace fastcdr { + +/*! + * @brief This class template manages an external member, a member declared to be external to the storage of a type. + */ +template +class external +{ +public: + + using type = T; + + //! Default constructor + external() = default; + + //! Constructor from a pointer. + external( + T* pointer, + bool locked = false) noexcept + : pointer_ {pointer} + , locked_ {locked} + { + } + + //! Constructor from a shared pointer. + external( + std::shared_ptr pointer) noexcept + : pointer_ {pointer} + { + } + + //! Copy constructor. + external( + const external& other) noexcept + : locked_ {other.locked_} + { + if (locked_) + { + pointer_ = std::make_shared(*other.pointer_); + } + else + { + pointer_ = other.pointer_; + } + } + + //! Assignment + external& operator =( + const external& other) + { + if (locked_) + { + throw exception::LockedExternalAccessException( + exception::LockedExternalAccessException::LOCKED_EXTERNAL_ACCESS_MESSAGE_DEFAULT); + } + + if (!other.pointer_) + { + pointer_.reset(); + } + else if (other.locked_) + { + if (!pointer_) + { + pointer_ = std::make_shared(*other.pointer_); + } + else + { + *pointer_ = *other.pointer_; + } + } + else + { + pointer_ = other.pointer_; + } + + return *this; + } + + //! Destructor + ~external() = default; + + //! Dereference object. + T& operator *() noexcept + { + return *pointer_; + } + + //! Dereference object. + const T& operator *() const noexcept + { + return *pointer_; + } + + //! Get pointer. + T* get() noexcept + { + return pointer_.get(); + } + + //! Get pointer. + const T* get() const noexcept + { + return pointer_.get(); + } + + //! Get shared pointer. + std::shared_ptr get_shared_ptr() noexcept + { + return pointer_; + } + + //! Dereference object member. + T* operator ->() noexcept + { + return pointer_.get(); + } + + //! Dereference object member. + const T* operator ->() const noexcept + { + return pointer_.get(); + } + + //! Compares they manage the same object or empty both. + bool operator ==( + const external& other) const + { + return pointer_.get() == other.pointer_.get(); + } + + //! Compares they don't manages the same object + bool operator !=( + const external& other) const + { + return !(*this == other); + } + + //! Checks if not null + operator bool() const noexcept + { + return nullptr != pointer_.get(); + } + + //! Checks if locked + bool is_locked() const noexcept + { + return locked_; + } + + //! Locks the managed object. + void lock() noexcept + { + locked_ = true; + } + +private: + + std::shared_ptr pointer_; + + bool locked_ {false}; + +}; + +} // namespace fastcdr +} // namespace eprosima + +#endif //_FASTCDR_XCDR_EXTERNAL_HPP_ diff --git a/plotjuggler_plugins/ParserROS/rosx_introspection/3rdparty/Fast-CDR/include/fastcdr/xcdr/optional.hpp b/plotjuggler_plugins/ParserROS/rosx_introspection/3rdparty/Fast-CDR/include/fastcdr/xcdr/optional.hpp new file mode 100644 index 000000000..a9c8b94d1 --- /dev/null +++ b/plotjuggler_plugins/ParserROS/rosx_introspection/3rdparty/Fast-CDR/include/fastcdr/xcdr/optional.hpp @@ -0,0 +1,356 @@ +// Copyright 2023 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. +// +#ifndef _FASTCDR_XCDR_OPTIONAL_HPP_ +#define _FASTCDR_XCDR_OPTIONAL_HPP_ + +#include +#include + +#include "detail/optional.hpp" +#include "../exceptions/BadOptionalAccessException.hpp" + +namespace eprosima { +namespace fastcdr { + +//! An empty class type used to indicate optional type with uninitialized state. +struct nullopt_t +{ + constexpr explicit nullopt_t( + int) + { + } + +}; + +/*! + * @brief nullopt is a constant of type nullopt_t that is used to indicate optional type with uninitialized state. + */ +static constexpr nullopt_t nullopt {0}; + +/*! + * @brief This class template manages an optional contained value, i.e. a value that may or may not be present. + */ +template +class optional +{ +public: + + using type = T; + + //! Default constructor + optional() = default; + + //! Copy constructor from an instance of the templated class. + optional( + const T& val) noexcept + { + ::new(&storage_.val_)T(val); + storage_.engaged_ = true; + } + + //! Move constructor from an instance of the templated class. + optional( + T&& val) noexcept + { + ::new(&storage_.val_)T(std::move(val)); + storage_.engaged_ = true; + } + + //! Copy constructor. + optional( + const optional& val) noexcept + { + ::new(&storage_.val_)T(val.storage_.val_); + storage_.engaged_ = val.storage_.engaged_; + } + + //! Move constructor. + optional( + optional&& val) noexcept + { + ::new(&storage_.val_)T(std::move(val.storage_.val_)); + storage_.engaged_ = val.storage_.engaged_; + } + + //! Destructor + ~optional() = default; + + /*! + * @brief Constructs the contained value in-place + * + * @param[in] _args The arguments to pass to the constructor. + */ + template void emplace( + Args&&... _args) + { + reset(); + storage_.val_.T(std::forward(_args)...); + storage_.engaged_ = true; + } + + /*! + * @brief Reset the state of the optional + * + * @param[in] initial_engaged True value initializes the state with a default instance of the templated class. + * False value leaves the optional in a uninitialized state. + */ + void reset( + bool initial_engaged = false) + { + if (storage_.engaged_) + { + storage_.val_.~T(); + } + storage_.engaged_ = initial_engaged; + if (storage_.engaged_) + { + ::new(&storage_.val_)T(); + } + } + + /*! + * @brief Returns the contained value. + * + * @return The contained value. + * @exception exception::BadOptionalAccessException This exception is thrown when the optional is uninitialized. + */ + T& value()& + { + if (!storage_.engaged_) + { + throw exception::BadOptionalAccessException( + exception::BadOptionalAccessException::BAD_OPTIONAL_ACCESS_MESSAGE_DEFAULT); + } + + return storage_.val_; + } + + /*! + * @brief Returns the contained value. + * + * @return The contained value. + * @exception exception::BadOptionalAccessException This exception is thrown when the optional is uninitialized. + */ + const T& value() const& + { + if (!storage_.engaged_) + { + throw exception::BadOptionalAccessException( + exception::BadOptionalAccessException::BAD_OPTIONAL_ACCESS_MESSAGE_DEFAULT); + } + + return storage_.val_; + } + + /*! + * @brief Returns the contained value. + * + * @return The contained value. + * @exception exception::BadOptionalAccessException This exception is thrown when the optional is uninitialized. + */ + T&& value() && + { + if (!storage_.engaged_) + { + throw exception::BadOptionalAccessException( + exception::BadOptionalAccessException::BAD_OPTIONAL_ACCESS_MESSAGE_DEFAULT); + } + + return std::move(storage_.val_); + } + + /*! + * @brief Returns the contained value. + * + * @return The contained value. + * @exception exception::BadOptionalAccessException This exception is thrown when the optional is uninitialized. + */ + const T&& value() const&& + { + if (!storage_.engaged_) + { + throw exception::BadOptionalAccessException( + exception::BadOptionalAccessException::BAD_OPTIONAL_ACCESS_MESSAGE_DEFAULT); + } + + return std::move(storage_.val_); + } + + /*! + * @brief Checks whether the optional contains a value. + * + * @return Whether the optional contains a value. + */ + bool has_value() const + { + return storage_.engaged_; + } + + //! Assigns content from an optional. + optional& operator =( + const optional& opt) + { + reset(); + storage_.engaged_ = opt.storage_.engaged_; + if (opt.storage_.engaged_) + { + ::new(&storage_.val_)T(opt.storage_.val_); + } + return *this; + } + + //! Assigns content from an optional. + optional& operator =( + optional&& opt) + { + reset(); + storage_.engaged_ = opt.storage_.engaged_; + if (opt.storage_.engaged_) + { + ::new(&storage_.val_)T(std::move(opt.storage_.val_)); + } + return *this; + } + + //! Assigns content from an instance of the templated class. + optional& operator =( + const T& val) + { + reset(); + ::new(&storage_.val_)T(val); + storage_.engaged_ = true; + return *this; + } + + //! Assigns content from an instance of the templated class. + optional& operator =( + T&& val) + { + reset(); + ::new(&storage_.val_)T(std::move(val)); + storage_.engaged_ = true; + return *this; + } + + //! Uninitialized the optional. + optional& operator = ( + nullopt_t) noexcept + { + reset(); + return *this; + } + + //! Compares optional values. + bool operator ==( + const optional& opt_val) const + { + return opt_val.storage_.engaged_ == storage_.engaged_ && + (storage_.engaged_ ? opt_val.storage_.val_ == storage_.val_ : true); + } + + //! Compares optional values. + bool operator !=( + const optional& opt_val) const + { + return !operator ==(opt_val); + } + + /*! + * @brief Accesses the contained value. + * + * The behavior is undefined if *this does not contain a value. + * + * @return The contained value. + */ + T& operator *() & noexcept + { + return storage_.val_; + } + + /*! + * @brief Accesses the contained value. + * + * The behavior is undefined if *this does not contain a value. + * + * @return The contained value. + */ + const T& operator *() const& noexcept + { + return storage_.val_; + } + + /*! + * @brief Accesses the contained value. + * + * The behavior is undefined if *this does not contain a value. + * + * @return The contained value. + */ + T&& operator *() && noexcept + { + return std::move(storage_.val_); + } + + /*! + * @brief Accesses the contained value. + * + * The behavior is undefined if *this does not contain a value. + * + * @return The contained value. + */ + const T&& operator *() const&& noexcept + { + return std::move(storage_.val_); + } + + /*! + * @brief Accesses the contained value. + * + * The behavior is undefined if *this does not contain a value. + * + * @return The contained value. + */ + T* operator ->() noexcept + { + return std::addressof(storage_.val_); + } + + /*! + * @brief Accesses the contained value. + * + * The behavior is undefined if *this does not contain a value. + * + * @return The contained value. + */ + const T* operator ->() const noexcept + { + return std::addressof(storage_.val_); + } + + //! Checks whether the optional contains a value. + explicit operator bool() const noexcept + { + return storage_.engaged_; + } + +private: + + detail::optional_storage storage_; +}; + +} // namespace fastcdr +} // namespace eprosima + +#endif //_FASTCDR_XCDR_OPTIONAL_HPP_