Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-17 08:40:31

0001 #ifndef BOOST_PARSER_DETAIL_VS_OUTPUT_STREAM_HPP
0002 #define BOOST_PARSER_DETAIL_VS_OUTPUT_STREAM_HPP
0003 
0004 #include <array>
0005 #include <functional>
0006 #include <iostream>
0007 #include <sstream>
0008 
0009 #include <Windows.h>
0010 
0011 
0012 namespace boost::parser::detail {
0013 
0014     template<class CharT, class TraitsT = std::char_traits<CharT>>
0015     class basic_debugbuf : public std::basic_stringbuf<CharT, TraitsT>
0016     {
0017     public:
0018         virtual ~basic_debugbuf() { sync_impl(); }
0019 
0020     protected:
0021         int sync_impl()
0022         {
0023             output_debug_string(this->str().c_str());
0024             this->str(std::basic_string<CharT>()); // Clear the string buffer
0025             return 0;
0026         }
0027 
0028         int sync() override { return sync_impl(); }
0029 
0030         void output_debug_string(const CharT * text);
0031     };
0032 
0033     template<>
0034     inline void basic_debugbuf<char>::output_debug_string(const char * text)
0035     {
0036         // Save in-memory logging buffer to a log file on error (from MSDN
0037         // example).
0038         std::wstring dest;
0039         int convert_result = MultiByteToWideChar(
0040             CP_UTF8, 0, text, static_cast<int>(std::strlen(text)), nullptr, 0);
0041         if (convert_result <= 0) {
0042             // cannot convert to wide-char -> use ANSI API
0043             ::OutputDebugStringA(text);
0044         } else {
0045             dest.resize(convert_result + 10);
0046             convert_result = MultiByteToWideChar(
0047                 CP_UTF8,
0048                 0,
0049                 text,
0050                 static_cast<int>(std::strlen(text)),
0051                 dest.data(),
0052                 static_cast<int>(dest.size()));
0053             if (convert_result <= 0) {
0054                 // cannot convert to wide-char -> use ANSI API
0055                 ::OutputDebugStringA(text);
0056             } else {
0057                 ::OutputDebugStringW(dest.c_str());
0058             }
0059         }
0060     }
0061 
0062     template<class CharT, class TraitsT = std::char_traits<CharT>>
0063     class basic_debug_ostream : public std::basic_ostream<CharT, TraitsT>
0064     {
0065     public:
0066         basic_debug_ostream() :
0067             std::basic_ostream<CharT, TraitsT>(
0068                 new basic_debugbuf<CharT, TraitsT>())
0069         {}
0070         ~basic_debug_ostream() { delete this->rdbuf(); }
0071     };
0072 
0073     inline basic_debug_ostream<char> vs_cout;
0074     //
0075 }
0076 
0077 #endif