#pragma once #if !defined(MIJIN_LOGGING_DEBUG_OUTPUT_SINK_HPP_INCLUDED) #define MIJIN_LOGGING_DEBUG_OUTPUT_SINK_HPP_INCLUDED 1 #include "./formatting.hpp" #include "../detect.hpp" #include "../util/traits.hpp" #if MIJIN_TARGET_OS == MIJIN_OS_WINDOWS #pragma comment(lib, "Kernel32.lib") extern "C" void OutputDebugStringA(const char* lpOutputString); extern "C" void OutputDebugStringW(const wchar_t* lpOutputString); namespace mijin { template requires(allocator_type>) class BaseDebugOutputSink : public BaseFormattingLogSink { public: using base_t = BaseFormattingLogSink; using typename base_t::char_t; using typename base_t::allocator_t; using typename base_t::formatter_ptr_t; using typename base_t::message_t; public: explicit BaseDebugOutputSink(formatter_ptr_t formatter, allocator_t allocator = {}) MIJIN_NOEXCEPT_IF(std::is_nothrow_move_constructible_v) : base_t(std::move(formatter), std::move(allocator)) {} void handleMessageFormatted(const message_t&, const char_t* formatted) MIJIN_NOEXCEPT override { if constexpr (std::is_same_v) { OutputDebugStringA(formatted); OutputDebugStringA("\n"); } else if constexpr (std::is_same_v) { OutputDebugStringW(formatted); OutputDebugStringW(L"\n"); } else if constexpr (sizeof(char_t) == sizeof(char)) { // char8_t etc. OutputDebugStringA(std::bit_cast(formatted)); OutputDebugStringA("\n"); } else { static_assert(always_false_v, "Character type not supported."); } } }; #define SINK_SET_ARGS(chr_type) chr_type, std::char_traits, TAllocator, TDeleter MIJIN_DEFINE_CHAR_VERSIONS_TMPL(DebugOutputSink, MIJIN_FORMATTING_SINK_COMMON_ARGS, SINK_SET_ARGS) #undef SINK_SET_ARGS } // namespace mijin #endif // MIJIN_TARGET_OS == MIJIN_OS_WINDOWS #endif // !defined(MIJIN_LOGGING_DEBUG_OUTPUT_SINK_HPP_INCLUDED)