Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iox-#1755 Distinct overloads for arithmetic types for logstream #2022

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ inline constexpr const char* logFormatDec() noexcept
return nullptr;
}
template <>
inline constexpr const char* logFormatDec<char>() noexcept
{
return "%c";
}
template <>
inline constexpr const char* logFormatDec<signed char>() noexcept
{
return "%hhi";
Expand Down
126 changes: 102 additions & 24 deletions iceoryx_hoofs/reporting/include/iox/detail/log/logstream.inl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright (c) 2019 - 2021 by Robert Bosch GmbH. All rights reserved.
// Copyright (c) 2021 - 2022 by Apex.AI Inc. All rights reserved.
// Copyright (c) 2023 by Mathias Kraus <elboberido@m-hias.de>. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -108,45 +109,132 @@ inline LogStream& LogStream::self() noexcept
return *this;
}

// AXIVION Next Construct AutosarC++19_03-A3.9.1 : See at declaration in header
// AXIVION Next Construct AutosarC++19_03-M5.17.1 : This is not used as shift operator but as stream operator and does
// AXIVION DISABLE STYLE AutosarC++19_03-M5.17.1 : This is not used as shift operator but as stream operator and does
// not require to implement '<<='

// AXIVION Next Construct AutosarC++19_03-A3.9.1 : See at declaration in header
inline LogStream& LogStream::operator<<(const char* cstr) noexcept
{
m_logger.logString(cstr);
m_isFlushed = false;
return *this;
}

// 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 '<<='
inline LogStream& LogStream::operator<<(const std::string& str) noexcept
{
m_logger.logString(str.c_str());
m_isFlushed = false;
return *this;
}

// 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 '<<='
inline LogStream& LogStream::operator<<(const bool val) noexcept
{
m_logger.logBool(val);
return *this;
}

// 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 <typename T, typename std::enable_if_t<std::is_arithmetic<T>::value, bool>>
inline LogStream& LogStream::operator<<(const T val) noexcept
// AXIVION DISABLE STYLE AutosarC++19_03-A3.9.1 : See at declaration in header

inline LogStream& LogStream::operator<<(const char val) noexcept
{
m_logger.logDec(val);
m_isFlushed = false;
return *this;
}

// 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 '<<='
inline LogStream& LogStream::operator<<(const signed char val) noexcept
{
m_logger.logDec(val);
m_isFlushed = false;
return *this;
}

inline LogStream& LogStream::operator<<(const unsigned char val) noexcept
{
m_logger.logDec(val);
m_isFlushed = false;
return *this;
}

inline LogStream& LogStream::operator<<(const short val) noexcept
{
m_logger.logDec(val);
m_isFlushed = false;
return *this;
}

inline LogStream& LogStream::operator<<(const unsigned short val) noexcept
{
m_logger.logDec(val);
m_isFlushed = false;
return *this;
}

inline LogStream& LogStream::operator<<(const int val) noexcept
{
m_logger.logDec(val);
m_isFlushed = false;
return *this;
}

inline LogStream& LogStream::operator<<(const unsigned int val) noexcept
{
m_logger.logDec(val);
m_isFlushed = false;
return *this;
}

inline LogStream& LogStream::operator<<(const long val) noexcept
{
m_logger.logDec(val);
m_isFlushed = false;
return *this;
}

inline LogStream& LogStream::operator<<(const unsigned long val) noexcept
{
m_logger.logDec(val);
m_isFlushed = false;
return *this;
}

inline LogStream& LogStream::operator<<(const long long val) noexcept
{
m_logger.logDec(val);
m_isFlushed = false;
return *this;
}

inline LogStream& LogStream::operator<<(const unsigned long long val) noexcept
{
m_logger.logDec(val);
m_isFlushed = false;
return *this;
}

inline LogStream& LogStream::operator<<(const float val) noexcept
{
m_logger.logDec(val);
m_isFlushed = false;
return *this;
}

inline LogStream& LogStream::operator<<(const double val) noexcept
{
m_logger.logDec(val);
m_isFlushed = false;
return *this;
}

inline LogStream& LogStream::operator<<(const long double val) noexcept
{
m_logger.logDec(val);
m_isFlushed = false;
return *this;
}

// AXIVION ENABLE STYLE AutosarC++19_03-A3.9.1

template <typename T, typename std::enable_if_t<std::is_integral<T>::value, bool>>
inline LogStream& LogStream::operator<<(const LogHex<T> val) noexcept
{
Expand All @@ -156,8 +244,6 @@ inline LogStream& LogStream::operator<<(const LogHex<T> val) noexcept
return *this;
}

// 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 <typename T, typename std::enable_if_t<std::is_floating_point<T>::value, bool>>
inline LogStream& LogStream::operator<<(const LogHex<T> val) noexcept
{
Expand All @@ -166,17 +252,13 @@ inline LogStream& LogStream::operator<<(const LogHex<T> val) noexcept
return *this;
}

// 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 '<<='
inline LogStream& LogStream::operator<<(const LogHex<const void* const> val) noexcept
{
m_logger.logHex(val.m_value);
m_isFlushed = false;
return *this;
}

// 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 <typename T, typename std::enable_if_t<std::is_integral<T>::value, bool>>
inline LogStream& LogStream::operator<<(const LogOct<T> val) noexcept
{
Expand All @@ -186,16 +268,12 @@ inline LogStream& LogStream::operator<<(const LogOct<T> val) noexcept
return *this;
}

// 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 <typename Callable, typename>
inline LogStream& LogStream::operator<<(const Callable& c) noexcept
{
return c(*this);
}

// 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 '<<='
inline LogStream& LogStream::operator<<(const LogLevel value) noexcept
{
m_logger.logString(asStringLiteral(value));
Expand All @@ -214,15 +292,15 @@ inline LogStreamOff& LogStreamOff::self() noexcept
return *this;
}

// 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 <typename T>
inline LogStreamOff& LogStreamOff::operator<<(T&&) noexcept
{
return *this;
}
} // namespace internal

// AXIVION ENABLE STYLE AutosarC++19_03-M5.17.1

} // namespace log
} // namespace iox

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ namespace internal
template <typename T>
constexpr const char* logFormatDec() noexcept;
template <>
constexpr const char* logFormatDec<char>() noexcept;
template <>
constexpr const char* logFormatDec<signed char>() noexcept;
template <>
constexpr const char* logFormatDec<unsigned char>() noexcept;
Expand Down
82 changes: 75 additions & 7 deletions iceoryx_hoofs/reporting/include/iox/log/logstream.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright (c) 2019 - 2021 by Robert Bosch GmbH. All rights reserved.
// Copyright (c) 2021 - 2022 by Apex.AI Inc. All rights reserved.
// Copyright (c) 2023 by Mathias Kraus <elboberido@m-hias.de>. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -156,17 +157,84 @@ class LogStream
/// and avoid the std::string dependency; alternatively this could be implemented as free function
LogStream& operator<<(const std::string& str) noexcept;

/// @brief Logging support for boolean
/// @param[in] val is the boolean to log
/// @brief Logging support for 'boolean'
/// @param[in] val is the 'boolean' to log
/// @return a reference to the LogStream instance
LogStream& operator<<(const bool val) noexcept;

/// @brief Logging support for arithmetic numbers in decimal format
/// @tparam[in] T is the arithmetic data type of the value to log
/// @param[in] val is the number to log
// AXIVION DISABLE STYLE AutosarC++19_03-A3.9.1 : Basic numeric types are used in order to cover als basic numeric types, independent of the type alias

/// @brief Logging support for 'char'
/// @param[in] val is the 'char' to log
/// @return a reference to the LogStream instance
LogStream& operator<<(const char val) noexcept;

/// @brief Logging support for 'signed char'
/// @param[in] val is the 'signed char' to log
/// @return a reference to the LogStream instance
LogStream& operator<<(const signed char val) noexcept;

/// @brief Logging support for 'unsigned char'
/// @param[in] val is the 'unsigned char' to log
/// @return a reference to the LogStream instance
LogStream& operator<<(const unsigned char val) noexcept;

/// @brief Logging support for 'short'
/// @param[in] val is the 'short' to log
/// @return a reference to the LogStream instance
template <typename T, typename std::enable_if_t<std::is_arithmetic<T>::value, bool> = 0>
LogStream& operator<<(const T val) noexcept;
LogStream& operator<<(const short val) noexcept;

/// @brief Logging support for 'unsigned short'
/// @param[in] val is the 'unsigned short' to log
/// @return a reference to the LogStream instance
LogStream& operator<<(const unsigned short val) noexcept;

/// @brief Logging support for 'int'
/// @param[in] val is the 'int' to log
/// @return a reference to the LogStream instance
LogStream& operator<<(const int val) noexcept;

/// @brief Logging support for 'unsigned int'
/// @param[in] val is the 'unsigned int' to log
/// @return a reference to the LogStream instance
LogStream& operator<<(const unsigned int val) noexcept;

/// @brief Logging support for 'long'
/// @param[in] val is the 'long' to log
/// @return a reference to the LogStream instance
LogStream& operator<<(const long val) noexcept;

/// @brief Logging support for 'unsigned long'
/// @param[in] val is the 'unsigned long' to log
/// @return a reference to the LogStream instance
LogStream& operator<<(const unsigned long val) noexcept;

/// @brief Logging support for 'long long'
/// @param[in] val is the 'long long' to log
/// @return a reference to the LogStream instance
LogStream& operator<<(const long long val) noexcept;

/// @brief Logging support for 'unsigned long long'
/// @param[in] val is the 'unsigned long long' to log
/// @return a reference to the LogStream instance
LogStream& operator<<(const unsigned long long val) noexcept;

/// @brief Logging support for 'float'
/// @param[in] val is the 'float' to log
/// @return a reference to the LogStream instance
LogStream& operator<<(const float val) noexcept;

/// @brief Logging support for 'double'
/// @param[in] val is the 'double' to log
/// @return a reference to the LogStream instance
LogStream& operator<<(const double val) noexcept;

/// @brief Logging support for 'long double'
/// @param[in] val is the 'long double' to log
/// @return a reference to the LogStream instance
LogStream& operator<<(const long double val) noexcept;

// AXIVION ENABLE STYLE AutosarC++19_03-A3.9.1

/// @brief Logging support for integral numbers in hexadecimal format
/// @tparam[in] T is the integral data type of the value to log
Expand Down
Loading
Loading