Skip to content
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
18 changes: 9 additions & 9 deletions src/main/cpp/asyncbuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@

#include <log4cxx/helpers/asyncbuffer.h>
#include <log4cxx/helpers/transcoder.h>
#if defined(__cpp_concepts) && 202002 <= __cpp_concepts
#if LOG4CXX_CONCEPTS
#include <variant>
#endif // defined(__cpp_concepts) && 202002 <= __cpp_concepts
#endif // LOG4CXX_CONCEPTS

namespace LOG4CXX_NS
{
Expand All @@ -29,7 +29,7 @@ namespace helpers

struct AsyncBuffer::Private
{
#if defined(__cpp_concepts) && 202002 <= __cpp_concepts && LOG4CXX_WCHAR_T_API
#if LOG4CXX_CONCEPTS && LOG4CXX_WCHAR_T_API
using value_t = std::variant<MessageBufferAppender, WideMessageBufferAppender>;
#else // !(defined(__cpp_concepts) && 202002 <= __cpp_concepts && LOG4CXX_WCHAR_T_API)
using value_t = MessageBufferAppender;
Expand Down Expand Up @@ -135,7 +135,7 @@ void AsyncBuffer::renderMessage(LogCharMessageBuffer& msg) const
if (m_priv)
{
for (auto& renderer : m_priv->data)
#if defined(__cpp_concepts) && 202002 <= __cpp_concepts && LOG4CXX_WCHAR_T_API
#if LOG4CXX_CONCEPTS && LOG4CXX_WCHAR_T_API
{
#if LOG4CXX_LOGCHAR_IS_UTF8
if (auto pRenderer = std::get_if<MessageBufferAppender>(&renderer))
Expand All @@ -159,9 +159,9 @@ void AsyncBuffer::renderMessage(LogCharMessageBuffer& msg) const
}
#endif // !LOG4CXX_LOGCHAR_IS_UTF8
}
#else // !(defined(__cpp_concepts) && 202002 <= __cpp_concepts && LOG4CXX_WCHAR_T_API)
#else // !LOG4CXX_CONCEPTS
renderer(msg);
#endif // !(defined(__cpp_concepts) && 202002 <= __cpp_concepts && LOG4CXX_WCHAR_T_API)
#endif // !LOG4CXX_CONCEPTS

#if LOG4CXX_ASYNC_BUFFER_SUPPORTS_FMT
#if LOG4CXX_LOGCHAR_IS_UTF8
Expand Down Expand Up @@ -206,7 +206,7 @@ void AsyncBuffer::clear()
}
}

#if defined(__cpp_concepts) && 202002 <= __cpp_concepts
#if LOG4CXX_CONCEPTS
/**
* Append \c function to this buffer.
*/
Expand All @@ -230,7 +230,7 @@ void AsyncBuffer::append(const WideMessageBufferAppender& f)
m_priv->data.push_back(f);
}
#endif // LOG4CXX_WCHAR_T_API
#else // !(defined(__cpp_concepts) && 202002 <= __cpp_concepts
#else // !LOG4CXX_CONCEPTS
/**
* Append \c function to this buffer.
*/
Expand All @@ -241,7 +241,7 @@ void AsyncBuffer::append(const MessageBufferAppender& f)
else
m_priv->data.push_back(f);
}
#endif // !(defined(__cpp_concepts) && 202002 <= __cpp_concepts
#endif // !LOG4CXX_CONCEPTS

} // namespace helpers
} // namespace LOG4CXX_NS
Expand Down
30 changes: 20 additions & 10 deletions src/main/include/log4cxx/helpers/asyncbuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,17 @@
#include <fmt/xchar.h>
#endif // LOG4CXX_WCHAR_T_API || LOG4CXX_LOGCHAR_IS_WCHAR
#endif // LOG4CXX_ASYNC_BUFFER_SUPPORTS_FMT
#if defined(__cpp_concepts) && 202002 <= __cpp_concepts

#if defined(__cpp_concepts) && 202002 <= __cpp_concepts && defined(__GNUC__) && __GNUC__ <= 12
// GCC 12 has broken concepts
#define LOG4CXX_CONCEPTS 0
#elif defined(__cpp_concepts) && 202002 <= __cpp_concepts
#define LOG4CXX_CONCEPTS 1
#else
#define LOG4CXX_CONCEPTS 0
#endif

#if LOG4CXX_CONCEPTS
#include <concepts>
#endif

Expand Down Expand Up @@ -65,7 +75,7 @@ class LOG4CXX_EXPORT AsyncBuffer
template <typename T>
AsyncBuffer& operator<<(const T& value)
{
#if defined(__cpp_concepts) && 202002 <= __cpp_concepts
#if LOG4CXX_CONCEPTS
#if LOG4CXX_LOGCHAR_IS_UTF8
if constexpr (requires(std::ostream& buf, T v) { buf << v; })
{
Expand Down Expand Up @@ -103,12 +113,12 @@ class LOG4CXX_EXPORT AsyncBuffer
else
static_assert(false, "operator<<(std::wostream&) overload must be provided");
#endif // !LOG4CXX_LOGCHAR_IS_UTF8
#else // !(defined(__cpp_concepts) && 202002 <= __cpp_concepts)
#else // !LOG4CXX_CONCEPTS
append([value](LogCharMessageBuffer& msgBuf)
{
msgBuf << value;
});
#endif // !(defined(__cpp_concepts) && 202002 <= __cpp_concepts)
#endif // !LOG4CXX_CONCEPTS
return *this;
}

Expand All @@ -120,7 +130,7 @@ class LOG4CXX_EXPORT AsyncBuffer
template <typename T>
AsyncBuffer& operator<<(const T&& rvalue)
{
#if defined(__cpp_concepts) && 202002 <= __cpp_concepts
#if LOG4CXX_CONCEPTS
#if LOG4CXX_LOGCHAR_IS_UTF8
if constexpr (requires(std::ostream& buf, T v) { buf << v; })
{
Expand Down Expand Up @@ -158,12 +168,12 @@ class LOG4CXX_EXPORT AsyncBuffer
else
static_assert(false, "operator<<(std::wostream&) overload must be provided");
#endif // !LOG4CXX_LOGCHAR_IS_UTF8
#else // !(defined(__cpp_concepts) && 202002 <= __cpp_concepts)
#else // !LOG4CXX_CONCEPTS
append([value = std::move(rvalue)](LogCharMessageBuffer& msgBuf)
{
msgBuf << value;
});
#endif // !(defined(__cpp_concepts) && 202002 <= __cpp_concepts)
#endif // !LOG4CXX_CONCEPTS
return *this;
}

Expand Down Expand Up @@ -215,7 +225,7 @@ class LOG4CXX_EXPORT AsyncBuffer
AsyncBuffer& operator=(const AsyncBuffer&) = delete;

LOG4CXX_DECLARE_PRIVATE_MEMBER_PTR(Private, m_priv)
#if defined(__cpp_concepts) && 202002 <= __cpp_concepts
#if LOG4CXX_CONCEPTS
using MessageBufferAppender = std::function<void(CharMessageBuffer&)>;

/**
Expand All @@ -231,14 +241,14 @@ class LOG4CXX_EXPORT AsyncBuffer
*/
void append(const WideMessageBufferAppender& f);
#endif // LOG4CXX_WCHAR_T_API
#else // !(defined(__cpp_concepts) && 202002 <= __cpp_concepts)
#else // !LOG4CXX_CONCEPTS
using MessageBufferAppender = std::function<void(LogCharMessageBuffer&)>;

/**
* Append \c f to this buffer.
*/
void append(const MessageBufferAppender& f);
#endif // !(defined(__cpp_concepts) && 202002 <= __cpp_concepts)
#endif // !LOG4CXX_CONCEPTS

#if LOG4CXX_ASYNC_BUFFER_SUPPORTS_FMT
void initializeForFmt(StringViewType&& format_string, FmtArgStore&& args);
Expand Down
4 changes: 2 additions & 2 deletions src/test/cpp/asyncappendertestcase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,10 +253,10 @@ class AsyncAppenderTestCase : public AppenderSkeletonTestCase
#if !LOG4CXX_LOGCHAR_IS_UTF8 || LOG4CXX_WCHAR_T_API
LOG4CXX_INFO(root, otherStr << 42);
++expectedEventCount;
#if defined(__cpp_concepts) && 202002 <= __cpp_concepts
#if LOG4CXX_CONCEPTS
LOG4CXX_INFO_ASYNC(root, otherStr << 42);
++expectedEventCount;
#endif // defined(__cpp_concepts) && 202002 <= __cpp_concepts
#endif // LOG4CXX_CONCEPTS
#endif // !LOG4CXX_LOGCHAR_IS_UTF8 || LOG4CXX_WCHAR_T_API

// Check all messages were received
Expand Down
Loading