diff --git a/iceoryx_hoofs/include/iceoryx_hoofs/cxx/string.hpp b/iceoryx_hoofs/include/iceoryx_hoofs/cxx/string.hpp index f1d30cd623..120866b0b7 100644 --- a/iceoryx_hoofs/include/iceoryx_hoofs/cxx/string.hpp +++ b/iceoryx_hoofs/include/iceoryx_hoofs/cxx/string.hpp @@ -231,7 +231,7 @@ class string final /// @endcode // TruncateToCapacity_t is a compile time variable to distinguish between constructors // NOLINTNEXTLINE(hicpp-named-parameter, readability-named-parameter) - string(TruncateToCapacity_t, const char* const other) noexcept(false); + string(TruncateToCapacity_t, const char* const other) noexcept; /// @brief conversion constructor for std::string to string which truncates characters if the std::string size is /// greater than the string capacity @@ -275,7 +275,7 @@ class string final /// @endcode // TruncateToCapacity_t is a compile time variable to distinguish between constructors // NOLINTNEXTLINE(hicpp-named-parameter, readability-named-parameter) - string(TruncateToCapacity_t, const char* const other, const uint64_t count) noexcept(false); + string(TruncateToCapacity_t, const char* const other, const uint64_t count) noexcept; /// @brief assigns a char array to string with compile time check if the array size is less than or equal /// to the string capacity @@ -402,7 +402,9 @@ class string final /// @brief converts the string to a std::string /// /// @return a std::string with data equivalent to those stored in the string - // NOLINTNEXTLINE(hicpp-explicit-conversions) todo #1196 remove this conversion and implement toStdString method + + // @todo iox-#260 remove this conversion and implement toStdString method + // NOLINTNEXTLINE(hicpp-explicit-conversions) operator std::string() const noexcept; /// @brief since there are two valid options for what should happen when appending a string larger than this' @@ -570,6 +572,15 @@ class string final uint64_t m_rawstringSize{0U}; }; +/// @brief outputs the fixed string on stream +/// +/// @param [in] stream is the output stream +/// @param [in] str is the fixed string +/// +/// @return the stream output of the fixed string +template +inline std::ostream& operator<<(std::ostream& stream, const string& str) noexcept; + // AXIVION DISABLE STYLE AutosarC++19_03-A13.5.5: Comparison with std::string, char array or // char is also intended /// @brief checks if a lhs std::string, char array or char is equal to a rhs iox::cxx::string @@ -625,65 +636,57 @@ IsStdStringOrCharArrayOrChar operator>(const T& lhs, const string IsStdStringOrCharArrayOrChar operator>=(const T& lhs, const string& rhs) noexcept; -/// @brief outputs the fixed string on stream -/// -/// @param [in] stream is the output stream -/// @param [in] str is the fixed string -/// -/// @return the stream output of the fixed string -template -inline std::ostream& operator<<(std::ostream& stream, const string& str) noexcept(false); - -/// @brief checks if self is equal to rhs +/// @brief checks if lhs is equal to rhs /// -/// @param [in] rhs is the iox::cxx::string, std::string, char array or char to compare with self +/// @param [in] lhs is the iox::cxx::string +/// @param [in] rhs is the iox::cxx::string, std::string, char array or char to compare with lhs /// /// @return true if both strings are equal, otherwise false template IsStringOrCharArrayOrChar operator==(const string& lhs, const T& rhs) noexcept; -/// @brief checks if self is not equal to rhs +/// @brief checks if lhs is not equal to rhs /// /// @param [in] lhs is the iox::cxx::string -/// @param [in] rhs is the iox::cxx::string, std::string, char array or char to compare with self +/// @param [in] rhs is the iox::cxx::string, std::string, char array or char to compare with lhs /// /// @return true if both strings are not equal, otherwise false template IsStringOrCharArrayOrChar operator!=(const string& lhs, const T& rhs) noexcept; -/// @brief checks if self is less than rhs, in lexicographical order +/// @brief checks if lhs is less than rhs, in lexicographical order /// /// @param [in] lhs is the iox::cxx::string -/// @param [in] rhs is the iox::cxx::string, std::string, char array or char to compare with self +/// @param [in] rhs is the iox::cxx::string, std::string, char array or char to compare with lhs /// -/// @return true if self is less than rhs, otherwise false +/// @return true if lhs is less than rhs, otherwise false template IsStringOrCharArrayOrChar operator<(const string& lhs, const T& rhs) noexcept; -/// @brief checks if self is less than or equal to rhs, in lexicographical order +/// @brief checks if lhs is less than or equal to rhs, in lexicographical order /// /// @param [in] lhs is the iox::cxx::string -/// @param [in] rhs is the iox::cxx::string, std::string, char array or char to compare with self +/// @param [in] rhs is the iox::cxx::string, std::string, char array or char to compare with lhs /// -/// @return true if self is less than or equal to rhs, otherwise false +/// @return true if lhs is less than or equal to rhs, otherwise false template IsStringOrCharArrayOrChar operator<=(const string& lhs, const T& rhs) noexcept; -/// @brief checks if self is greater than rhs, in lexicographical order +/// @brief checks if lhs is greater than rhs, in lexicographical order /// /// @param [in] lhs is the iox::cxx::string -/// @param [in] rhs is the iox::cxx::string, std::string, char array or char to compare with self +/// @param [in] rhs is the iox::cxx::string, std::string, char array or char to compare with lhs /// -/// @return true if self is greater than rhs, otherwise false +/// @return true if lhs is greater than rhs, otherwise false template IsStringOrCharArrayOrChar operator>(const string& lhs, const T& rhs) noexcept; -/// @brief checks if self is greater than or equal to rhs, in lexicographical order +/// @brief checks if lhs is greater than or equal to rhs, in lexicographical order /// /// @param [in] lhs is the iox::cxx::string -/// @param [in] rhs is the iox::cxx::string, std::string, char array or char to compare with self +/// @param [in] rhs is the iox::cxx::string, std::string, char array or char to compare with lhs /// -/// @return true if self is greater than or equal to rhs, otherwise false +/// @return true if lhs is greater than or equal to rhs, otherwise false template IsStringOrCharArrayOrChar operator>=(const string& lhs, const T& rhs) noexcept; // AXIVION ENABLE STYLE AutosarC++19_03-A13.5.5 diff --git a/iceoryx_hoofs/include/iceoryx_hoofs/internal/cxx/string.inl b/iceoryx_hoofs/include/iceoryx_hoofs/internal/cxx/string.inl index 1136c8069c..664936dffd 100644 --- a/iceoryx_hoofs/include/iceoryx_hoofs/internal/cxx/string.inl +++ b/iceoryx_hoofs/include/iceoryx_hoofs/internal/cxx/string.inl @@ -98,6 +98,7 @@ inline string& string::operator=(string&& rhs) noexcept template template +// AXIVION Next Construct AutosarC++19_03-A18.1.1 : C-array type usage is intentional // NOLINTNEXTLINE(hicpp-avoid-c-arrays, cppcoreguidelines-avoid-c-arrays) cxx::string wraps char array inline string::string(const char (&other)[N]) noexcept { @@ -106,7 +107,7 @@ inline string::string(const char (&other)[N]) noexcept template // NOLINTNEXTLINE(hicpp-named-parameter, readability-named-parameter) justification in header -inline string::string(TruncateToCapacity_t, const char* const other) noexcept(false) +inline string::string(TruncateToCapacity_t, const char* const other) noexcept : string(TruncateToCapacity, other, [&other]() -> uint64_t { return (other != nullptr) ? strnlen(other, Capacity) : 0U; }()) @@ -124,7 +125,7 @@ inline string::string(TruncateToCapacity_t, const std::string& other) template // TruncateToCapacity_t is a compile time variable to distinguish between constructors // NOLINTNEXTLINE(hicpp-named-parameter, readability-named-parameter) -inline string::string(TruncateToCapacity_t, const char* const other, const uint64_t count) noexcept(false) +inline string::string(TruncateToCapacity_t, const char* const other, const uint64_t count) noexcept { if (other == nullptr) { @@ -132,7 +133,8 @@ inline string::string(TruncateToCapacity_t, const char* const other, c } else if (Capacity < count) { -// AXIVION DISABLE STYLE AutosarC++19_03-A16.0.1: conditional compilation is required for setting gcc diagnostics +// AXIVION DISABLE STYLE AutosarC++19_03-A16.0.1: conditional compilation is required for setting gcc diagnostics, since +// gcc 8 incorrectly warns here about out of bounds array access #if (defined(__GNUC__) && (__GNUC__ == 8)) && (__GNUC_MINOR__ == 3) #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Warray-bounds" @@ -158,6 +160,7 @@ inline string::string(TruncateToCapacity_t, const char* const other, c template template +// AXIVION Next Construct AutosarC++19_03-A18.1.1 : C-array type usage is intentional // NOLINTNEXTLINE(hicpp-avoid-c-arrays, cppcoreguidelines-avoid-c-arrays) cxx::string wraps char array inline string& string::operator=(const char (&rhs)[N]) noexcept { @@ -195,6 +198,7 @@ inline string& string::assign(const string& str) noexcept template template +// AXIVION Next Construct AutosarC++19_03-A18.1.1 : C-array type usage is intentional // NOLINTNEXTLINE(hicpp-avoid-c-arrays, cppcoreguidelines-avoid-c-arrays) cxx::string wraps char array inline string& string::assign(const char (&str)[N]) noexcept { @@ -333,10 +337,11 @@ inline string& string::move(string&& rhs) noexcept rhs.clear(); return *this; } -// AXIVION DISABLE Style AutosarC++19_03-M5.17.1: Only need to support streaming output +// AXIVION Next Construct AutosarC++19_03-M5.17.1: This is not used as shift operator but as stream operator and does +// not require to implement '<<=' template -inline std::ostream& operator<<(std::ostream& stream, const string& str) noexcept(false) +inline std::ostream& operator<<(std::ostream& stream, const string& str) noexcept { stream << str.c_str(); return stream; @@ -375,9 +380,9 @@ concatenate(const T1& str1, const T2& str2, const Targs&... targs) noexcept return concatenate(concatenate(str1, str2), targs...); } +template // AXIVION Next Construct AutosarC++19_03-M17.0.3 : operator+ is defined within iox::cxx namespace which prevents easy // misuse -template inline IsCxxStringAndCxxStringOrCharArrayOrChar::value>> operator+(const T1& str1, const T2& str2) noexcept { @@ -578,7 +583,6 @@ inline constexpr char& string::at(const uint64_t pos) noexcept template inline constexpr const char& string::at(const uint64_t pos) const noexcept { - // AXIVION Next Construct AutosarC++19_03-M5.3.1 : operand of logical operator is non-bool, enhances readability ExpectsWithMsg((pos < size()), "Out of bounds access!"); return m_rawstring[pos]; } @@ -668,7 +672,7 @@ inline IsStringOrCharArrayOrChar operator>=(const string& lhs { return (lhs.compare(rhs) >= 0); } -// AXIVION ENABLE Style AutosarC++19_03-M5.17.1 +// AXIVION ENABLE Style AutosarC++19_03-A13.5.5 } // namespace cxx } // namespace iox