]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/nowide/src/console_buffer.hpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / libs / nowide / src / console_buffer.hpp
1 // Copyright (c) 2012 Artyom Beilis (Tonkikh)
2 // Copyright (c) 2020 - 2021 Alexander Grund
3 //
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)
7
8 #ifndef BOOST_NOWIDE_DETAIL_CONSOLE_BUFFER_HPP_INCLUDED
9 #define BOOST_NOWIDE_DETAIL_CONSOLE_BUFFER_HPP_INCLUDED
10
11 #include <boost/nowide/config.hpp>
12 #include <boost/nowide/utf/utf.hpp>
13 #include <streambuf>
14 #include <vector>
15
16 #include <boost/config/abi_prefix.hpp> // must be the last #include
17
18 // Internal header, not meant to be used outside of the implementation
19 namespace boost {
20 namespace nowide {
21 namespace detail {
22
23 /// \cond INTERNAL
24 class BOOST_NOWIDE_DECL console_output_buffer_base : public std::streambuf
25 {
26 protected:
27 int sync() override;
28 int overflow(int c) override;
29
30 private:
31 using decoder = utf::utf_traits<char>;
32 using encoder = utf::utf_traits<wchar_t>;
33
34 int write(const char* p, int n);
35 virtual bool
36 do_write(const wchar_t* buffer, std::size_t num_chars_to_write, std::size_t& num_chars_written) = 0;
37
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];
42 };
43
44 #ifdef BOOST_MSVC
45 #pragma warning(push)
46 #pragma warning(disable : 4251)
47 #endif
48
49 class BOOST_NOWIDE_DECL console_input_buffer_base : public std::streambuf
50 {
51 protected:
52 int sync() override;
53 int pbackfail(int c) override;
54 int underflow() override;
55
56 private:
57 using decoder = utf::utf_traits<wchar_t>;
58 using encoder = utf::utf_traits<char>;
59
60 size_t read();
61 virtual bool do_read(wchar_t* buffer, std::size_t num_chars_to_read, std::size_t& num_chars_read) = 0;
62
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];
67 size_t wsize_ = 0;
68 std::vector<char> pback_buffer_;
69 bool was_newline_ = true;
70 };
71
72 #ifdef BOOST_MSVC
73 #pragma warning(pop)
74 #endif
75
76 /// \endcond
77
78 } // namespace detail
79 } // namespace nowide
80 } // namespace boost
81
82 #include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
83
84 #endif