1 // Copyright (c) 2012 Artyom Beilis (Tonkikh)
2 // Copyright (c) 2020 - 2021 Alexander Grund
4 // Distributed under the Boost Software License, Version 1.0.
5 // (See accompanying file LICENSE or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
8 #ifndef BOOST_NOWIDE_DETAIL_CONSOLE_BUFFER_HPP_INCLUDED
9 #define BOOST_NOWIDE_DETAIL_CONSOLE_BUFFER_HPP_INCLUDED
11 #include <boost/nowide/config.hpp>
12 #include <boost/nowide/utf/utf.hpp>
16 #include <boost/config/abi_prefix.hpp> // must be the last #include
18 // Internal header, not meant to be used outside of the implementation
24 class BOOST_NOWIDE_DECL console_output_buffer_base : public std::streambuf
28 int overflow(int c) override;
31 using decoder = utf::utf_traits<char>;
32 using encoder = utf::utf_traits<wchar_t>;
34 int write(const char* p, int n);
36 do_write(const wchar_t* buffer, std::size_t num_chars_to_write, std::size_t& num_chars_written) = 0;
38 static constexpr int buffer_size = 1024;
39 static constexpr int wbuffer_size = buffer_size * encoder::max_width;
40 char buffer_[buffer_size];
41 wchar_t wbuffer_[wbuffer_size];
46 #pragma warning(disable : 4251)
49 class BOOST_NOWIDE_DECL console_input_buffer_base : public std::streambuf
53 int pbackfail(int c) override;
54 int underflow() override;
57 using decoder = utf::utf_traits<wchar_t>;
58 using encoder = utf::utf_traits<char>;
61 virtual bool do_read(wchar_t* buffer, std::size_t num_chars_to_read, std::size_t& num_chars_read) = 0;
63 static constexpr size_t wbuffer_size = 1024;
64 static constexpr size_t buffer_size = wbuffer_size * encoder::max_width;
65 char buffer_[buffer_size];
66 wchar_t wbuffer_[wbuffer_size];
68 std::vector<char> pback_buffer_;
69 bool was_newline_ = true;
82 #include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas