Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | // -*- C++ -*- |
Louis Dionne | 9bd9388 | 2021-11-17 16:25:01 -0500 | [diff] [blame] | 2 | //===----------------------------------------------------------------------===// |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3 | // |
Chandler Carruth | d201210 | 2019-01-19 10:56:40 +0000 | [diff] [blame] | 4 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 5 | // See https://llvm.org/LICENSE.txt for license information. |
| 6 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
Arthur O'Dwyer | 638e69a | 2021-04-04 17:39:50 -0400 | [diff] [blame] | 10 | #ifndef _LIBCPP_STREAMBUF |
| 11 | #define _LIBCPP_STREAMBUF |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 12 | |
| 13 | /* |
| 14 | streambuf synopsis |
| 15 | |
| 16 | namespace std |
| 17 | { |
| 18 | |
| 19 | template <class charT, class traits = char_traits<charT> > |
| 20 | class basic_streambuf |
| 21 | { |
| 22 | public: |
| 23 | // types: |
| 24 | typedef charT char_type; |
| 25 | typedef traits traits_type; |
| 26 | typedef typename traits_type::int_type int_type; |
| 27 | typedef typename traits_type::pos_type pos_type; |
| 28 | typedef typename traits_type::off_type off_type; |
| 29 | |
| 30 | virtual ~basic_streambuf(); |
| 31 | |
| 32 | // 27.6.2.2.1 locales: |
| 33 | locale pubimbue(const locale& loc); |
| 34 | locale getloc() const; |
| 35 | |
| 36 | // 27.6.2.2.2 buffer and positioning: |
| 37 | basic_streambuf* pubsetbuf(char_type* s, streamsize n); |
| 38 | pos_type pubseekoff(off_type off, ios_base::seekdir way, |
| 39 | ios_base::openmode which = ios_base::in | ios_base::out); |
| 40 | pos_type pubseekpos(pos_type sp, |
| 41 | ios_base::openmode which = ios_base::in | ios_base::out); |
| 42 | int pubsync(); |
| 43 | |
| 44 | // Get and put areas: |
| 45 | // 27.6.2.2.3 Get area: |
| 46 | streamsize in_avail(); |
| 47 | int_type snextc(); |
| 48 | int_type sbumpc(); |
| 49 | int_type sgetc(); |
| 50 | streamsize sgetn(char_type* s, streamsize n); |
| 51 | |
| 52 | // 27.6.2.2.4 Putback: |
| 53 | int_type sputbackc(char_type c); |
| 54 | int_type sungetc(); |
| 55 | |
| 56 | // 27.6.2.2.5 Put area: |
| 57 | int_type sputc(char_type c); |
| 58 | streamsize sputn(const char_type* s, streamsize n); |
| 59 | |
| 60 | protected: |
| 61 | basic_streambuf(); |
| 62 | basic_streambuf(const basic_streambuf& rhs); |
| 63 | basic_streambuf& operator=(const basic_streambuf& rhs); |
| 64 | void swap(basic_streambuf& rhs); |
| 65 | |
| 66 | // 27.6.2.3.2 Get area: |
| 67 | char_type* eback() const; |
| 68 | char_type* gptr() const; |
| 69 | char_type* egptr() const; |
| 70 | void gbump(int n); |
| 71 | void setg(char_type* gbeg, char_type* gnext, char_type* gend); |
| 72 | |
| 73 | // 27.6.2.3.3 Put area: |
| 74 | char_type* pbase() const; |
| 75 | char_type* pptr() const; |
| 76 | char_type* epptr() const; |
| 77 | void pbump(int n); |
| 78 | void setp(char_type* pbeg, char_type* pend); |
| 79 | |
| 80 | // 27.6.2.4 virtual functions: |
| 81 | // 27.6.2.4.1 Locales: |
| 82 | virtual void imbue(const locale& loc); |
| 83 | |
| 84 | // 27.6.2.4.2 Buffer management and positioning: |
| 85 | virtual basic_streambuf* setbuf(char_type* s, streamsize n); |
| 86 | virtual pos_type seekoff(off_type off, ios_base::seekdir way, |
| 87 | ios_base::openmode which = ios_base::in | ios_base::out); |
| 88 | virtual pos_type seekpos(pos_type sp, |
| 89 | ios_base::openmode which = ios_base::in | ios_base::out); |
| 90 | virtual int sync(); |
| 91 | |
| 92 | // 27.6.2.4.3 Get area: |
| 93 | virtual streamsize showmanyc(); |
| 94 | virtual streamsize xsgetn(char_type* s, streamsize n); |
| 95 | virtual int_type underflow(); |
| 96 | virtual int_type uflow(); |
| 97 | |
| 98 | // 27.6.2.4.4 Putback: |
| 99 | virtual int_type pbackfail(int_type c = traits_type::eof()); |
| 100 | |
| 101 | // 27.6.2.4.5 Put area: |
| 102 | virtual streamsize xsputn(const char_type* s, streamsize n); |
| 103 | virtual int_type overflow (int_type c = traits_type::eof()); |
| 104 | }; |
| 105 | |
| 106 | } // std |
| 107 | |
| 108 | */ |
| 109 | |
| 110 | #include <__config> |
Louis Dionne | 9c2a3205 | 2022-01-10 14:56:43 -0500 | [diff] [blame] | 111 | #include <cstdint> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 112 | #include <ios> |
Arthur O'Dwyer | ef18160 | 2021-05-19 11:57:04 -0400 | [diff] [blame] | 113 | #include <iosfwd> |
Mark de Wever | ce8f12c | 2021-12-22 18:14:14 +0100 | [diff] [blame] | 114 | #include <version> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 115 | |
Howard Hinnant | aaaa52b | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 116 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
Arthur O'Dwyer | 6eeaa00 | 2022-02-01 20:16:40 -0500 | [diff] [blame] | 117 | # pragma GCC system_header |
Howard Hinnant | aaaa52b | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 118 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 119 | |
Eric Fiselier | f4433a3 | 2017-05-31 22:07:49 +0000 | [diff] [blame] | 120 | _LIBCPP_PUSH_MACROS |
| 121 | #include <__undef_macros> |
| 122 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 123 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 124 | |
| 125 | template <class _CharT, class _Traits> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 126 | class _LIBCPP_TEMPLATE_VIS basic_streambuf |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 127 | { |
| 128 | public: |
| 129 | // types: |
| 130 | typedef _CharT char_type; |
| 131 | typedef _Traits traits_type; |
| 132 | typedef typename traits_type::int_type int_type; |
| 133 | typedef typename traits_type::pos_type pos_type; |
| 134 | typedef typename traits_type::off_type off_type; |
| 135 | |
Marshall Clow | d151d18 | 2018-02-01 03:55:27 +0000 | [diff] [blame] | 136 | static_assert((is_same<_CharT, typename traits_type::char_type>::value), |
| 137 | "traits_type::char_type must be the same type as CharT"); |
| 138 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 139 | virtual ~basic_streambuf(); |
| 140 | |
| 141 | // 27.6.2.2.1 locales: |
Louis Dionne | b4d05d7 | 2018-10-16 19:26:23 +0000 | [diff] [blame] | 142 | inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 |
Eric Fiselier | 815ed73 | 2016-09-16 00:00:48 +0000 | [diff] [blame] | 143 | locale pubimbue(const locale& __loc) { |
| 144 | imbue(__loc); |
| 145 | locale __r = __loc_; |
| 146 | __loc_ = __loc; |
| 147 | return __r; |
| 148 | } |
| 149 | |
Louis Dionne | b4d05d7 | 2018-10-16 19:26:23 +0000 | [diff] [blame] | 150 | inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 |
Eric Fiselier | 815ed73 | 2016-09-16 00:00:48 +0000 | [diff] [blame] | 151 | locale getloc() const { return __loc_; } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 152 | |
| 153 | // 27.6.2.2.2 buffer and positioning: |
Louis Dionne | b4d05d7 | 2018-10-16 19:26:23 +0000 | [diff] [blame] | 154 | inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 |
Eric Fiselier | 815ed73 | 2016-09-16 00:00:48 +0000 | [diff] [blame] | 155 | basic_streambuf* pubsetbuf(char_type* __s, streamsize __n) |
| 156 | { return setbuf(__s, __n); } |
| 157 | |
Louis Dionne | b4d05d7 | 2018-10-16 19:26:23 +0000 | [diff] [blame] | 158 | inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 159 | pos_type pubseekoff(off_type __off, ios_base::seekdir __way, |
Eric Fiselier | 815ed73 | 2016-09-16 00:00:48 +0000 | [diff] [blame] | 160 | ios_base::openmode __which = ios_base::in | ios_base::out) |
| 161 | { return seekoff(__off, __way, __which); } |
| 162 | |
Louis Dionne | b4d05d7 | 2018-10-16 19:26:23 +0000 | [diff] [blame] | 163 | inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 164 | pos_type pubseekpos(pos_type __sp, |
Eric Fiselier | 815ed73 | 2016-09-16 00:00:48 +0000 | [diff] [blame] | 165 | ios_base::openmode __which = ios_base::in | ios_base::out) |
| 166 | { return seekpos(__sp, __which); } |
| 167 | |
Louis Dionne | b4d05d7 | 2018-10-16 19:26:23 +0000 | [diff] [blame] | 168 | inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 |
Eric Fiselier | 815ed73 | 2016-09-16 00:00:48 +0000 | [diff] [blame] | 169 | int pubsync() { return sync(); } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 170 | |
| 171 | // Get and put areas: |
| 172 | // 27.6.2.2.3 Get area: |
Louis Dionne | b4d05d7 | 2018-10-16 19:26:23 +0000 | [diff] [blame] | 173 | inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 |
Eric Fiselier | 815ed73 | 2016-09-16 00:00:48 +0000 | [diff] [blame] | 174 | streamsize in_avail() { |
| 175 | if (__ninp_ < __einp_) |
| 176 | return static_cast<streamsize>(__einp_ - __ninp_); |
| 177 | return showmanyc(); |
| 178 | } |
| 179 | |
Louis Dionne | b4d05d7 | 2018-10-16 19:26:23 +0000 | [diff] [blame] | 180 | inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 |
Eric Fiselier | 815ed73 | 2016-09-16 00:00:48 +0000 | [diff] [blame] | 181 | int_type snextc() { |
| 182 | if (sbumpc() == traits_type::eof()) |
| 183 | return traits_type::eof(); |
| 184 | return sgetc(); |
| 185 | } |
| 186 | |
Louis Dionne | b4d05d7 | 2018-10-16 19:26:23 +0000 | [diff] [blame] | 187 | inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 |
Eric Fiselier | 815ed73 | 2016-09-16 00:00:48 +0000 | [diff] [blame] | 188 | int_type sbumpc() { |
| 189 | if (__ninp_ == __einp_) |
| 190 | return uflow(); |
| 191 | return traits_type::to_int_type(*__ninp_++); |
| 192 | } |
| 193 | |
Louis Dionne | b4d05d7 | 2018-10-16 19:26:23 +0000 | [diff] [blame] | 194 | inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 |
Eric Fiselier | 815ed73 | 2016-09-16 00:00:48 +0000 | [diff] [blame] | 195 | int_type sgetc() { |
| 196 | if (__ninp_ == __einp_) |
| 197 | return underflow(); |
| 198 | return traits_type::to_int_type(*__ninp_); |
| 199 | } |
| 200 | |
Louis Dionne | b4d05d7 | 2018-10-16 19:26:23 +0000 | [diff] [blame] | 201 | inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 |
Eric Fiselier | 815ed73 | 2016-09-16 00:00:48 +0000 | [diff] [blame] | 202 | streamsize sgetn(char_type* __s, streamsize __n) |
| 203 | { return xsgetn(__s, __n); } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 204 | |
| 205 | // 27.6.2.2.4 Putback: |
Louis Dionne | b4d05d7 | 2018-10-16 19:26:23 +0000 | [diff] [blame] | 206 | inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 |
Eric Fiselier | 815ed73 | 2016-09-16 00:00:48 +0000 | [diff] [blame] | 207 | int_type sputbackc(char_type __c) { |
| 208 | if (__binp_ == __ninp_ || !traits_type::eq(__c, __ninp_[-1])) |
| 209 | return pbackfail(traits_type::to_int_type(__c)); |
| 210 | return traits_type::to_int_type(*--__ninp_); |
| 211 | } |
| 212 | |
Louis Dionne | b4d05d7 | 2018-10-16 19:26:23 +0000 | [diff] [blame] | 213 | inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 |
Eric Fiselier | 815ed73 | 2016-09-16 00:00:48 +0000 | [diff] [blame] | 214 | int_type sungetc() { |
| 215 | if (__binp_ == __ninp_) |
| 216 | return pbackfail(); |
| 217 | return traits_type::to_int_type(*--__ninp_); |
| 218 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 219 | |
| 220 | // 27.6.2.2.5 Put area: |
Louis Dionne | b4d05d7 | 2018-10-16 19:26:23 +0000 | [diff] [blame] | 221 | inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 |
Eric Fiselier | 815ed73 | 2016-09-16 00:00:48 +0000 | [diff] [blame] | 222 | int_type sputc(char_type __c) { |
| 223 | if (__nout_ == __eout_) |
| 224 | return overflow(traits_type::to_int_type(__c)); |
| 225 | *__nout_++ = __c; |
| 226 | return traits_type::to_int_type(__c); |
| 227 | } |
| 228 | |
Louis Dionne | b4d05d7 | 2018-10-16 19:26:23 +0000 | [diff] [blame] | 229 | inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 |
Eric Fiselier | 815ed73 | 2016-09-16 00:00:48 +0000 | [diff] [blame] | 230 | streamsize sputn(const char_type* __s, streamsize __n) |
| 231 | { return xsputn(__s, __n); } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 232 | |
| 233 | protected: |
| 234 | basic_streambuf(); |
| 235 | basic_streambuf(const basic_streambuf& __rhs); |
| 236 | basic_streambuf& operator=(const basic_streambuf& __rhs); |
| 237 | void swap(basic_streambuf& __rhs); |
| 238 | |
| 239 | // 27.6.2.3.2 Get area: |
Louis Dionne | 16fe295 | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 240 | _LIBCPP_INLINE_VISIBILITY char_type* eback() const {return __binp_;} |
| 241 | _LIBCPP_INLINE_VISIBILITY char_type* gptr() const {return __ninp_;} |
| 242 | _LIBCPP_INLINE_VISIBILITY char_type* egptr() const {return __einp_;} |
Eric Fiselier | 815ed73 | 2016-09-16 00:00:48 +0000 | [diff] [blame] | 243 | |
Louis Dionne | b4d05d7 | 2018-10-16 19:26:23 +0000 | [diff] [blame] | 244 | inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 |
Eric Fiselier | 815ed73 | 2016-09-16 00:00:48 +0000 | [diff] [blame] | 245 | void gbump(int __n) { __ninp_ += __n; } |
| 246 | |
Louis Dionne | b4d05d7 | 2018-10-16 19:26:23 +0000 | [diff] [blame] | 247 | inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 |
Eric Fiselier | 815ed73 | 2016-09-16 00:00:48 +0000 | [diff] [blame] | 248 | void setg(char_type* __gbeg, char_type* __gnext, char_type* __gend) { |
| 249 | __binp_ = __gbeg; |
| 250 | __ninp_ = __gnext; |
| 251 | __einp_ = __gend; |
| 252 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 253 | |
| 254 | // 27.6.2.3.3 Put area: |
Louis Dionne | 16fe295 | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 255 | _LIBCPP_INLINE_VISIBILITY char_type* pbase() const {return __bout_;} |
| 256 | _LIBCPP_INLINE_VISIBILITY char_type* pptr() const {return __nout_;} |
| 257 | _LIBCPP_INLINE_VISIBILITY char_type* epptr() const {return __eout_;} |
Eric Fiselier | 815ed73 | 2016-09-16 00:00:48 +0000 | [diff] [blame] | 258 | |
Louis Dionne | b4d05d7 | 2018-10-16 19:26:23 +0000 | [diff] [blame] | 259 | inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 |
Eric Fiselier | 815ed73 | 2016-09-16 00:00:48 +0000 | [diff] [blame] | 260 | void pbump(int __n) { __nout_ += __n; } |
| 261 | |
Louis Dionne | 16fe295 | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 262 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 3393262 | 2017-09-12 15:00:43 +0000 | [diff] [blame] | 263 | void __pbump(streamsize __n) { __nout_ += __n; } |
| 264 | |
Louis Dionne | b4d05d7 | 2018-10-16 19:26:23 +0000 | [diff] [blame] | 265 | inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 |
Eric Fiselier | 815ed73 | 2016-09-16 00:00:48 +0000 | [diff] [blame] | 266 | void setp(char_type* __pbeg, char_type* __pend) { |
| 267 | __bout_ = __nout_ = __pbeg; |
| 268 | __eout_ = __pend; |
| 269 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 270 | |
| 271 | // 27.6.2.4 virtual functions: |
| 272 | // 27.6.2.4.1 Locales: |
| 273 | virtual void imbue(const locale& __loc); |
| 274 | |
| 275 | // 27.6.2.4.2 Buffer management and positioning: |
| 276 | virtual basic_streambuf* setbuf(char_type* __s, streamsize __n); |
| 277 | virtual pos_type seekoff(off_type __off, ios_base::seekdir __way, |
| 278 | ios_base::openmode __which = ios_base::in | ios_base::out); |
| 279 | virtual pos_type seekpos(pos_type __sp, |
| 280 | ios_base::openmode __which = ios_base::in | ios_base::out); |
| 281 | virtual int sync(); |
| 282 | |
| 283 | // 27.6.2.4.3 Get area: |
| 284 | virtual streamsize showmanyc(); |
| 285 | virtual streamsize xsgetn(char_type* __s, streamsize __n); |
| 286 | virtual int_type underflow(); |
| 287 | virtual int_type uflow(); |
| 288 | |
| 289 | // 27.6.2.4.4 Putback: |
| 290 | virtual int_type pbackfail(int_type __c = traits_type::eof()); |
| 291 | |
| 292 | // 27.6.2.4.5 Put area: |
| 293 | virtual streamsize xsputn(const char_type* __s, streamsize __n); |
| 294 | virtual int_type overflow(int_type __c = traits_type::eof()); |
| 295 | |
| 296 | private: |
| 297 | locale __loc_; |
| 298 | char_type* __binp_; |
| 299 | char_type* __ninp_; |
| 300 | char_type* __einp_; |
| 301 | char_type* __bout_; |
| 302 | char_type* __nout_; |
| 303 | char_type* __eout_; |
| 304 | }; |
| 305 | |
| 306 | template <class _CharT, class _Traits> |
| 307 | basic_streambuf<_CharT, _Traits>::~basic_streambuf() |
| 308 | { |
| 309 | } |
| 310 | |
| 311 | template <class _CharT, class _Traits> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 312 | basic_streambuf<_CharT, _Traits>::basic_streambuf() |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 313 | : __binp_(nullptr), |
| 314 | __ninp_(nullptr), |
| 315 | __einp_(nullptr), |
| 316 | __bout_(nullptr), |
| 317 | __nout_(nullptr), |
| 318 | __eout_(nullptr) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 319 | { |
| 320 | } |
| 321 | |
| 322 | template <class _CharT, class _Traits> |
| 323 | basic_streambuf<_CharT, _Traits>::basic_streambuf(const basic_streambuf& __sb) |
| 324 | : __loc_(__sb.__loc_), |
| 325 | __binp_(__sb.__binp_), |
| 326 | __ninp_(__sb.__ninp_), |
| 327 | __einp_(__sb.__einp_), |
| 328 | __bout_(__sb.__bout_), |
| 329 | __nout_(__sb.__nout_), |
| 330 | __eout_(__sb.__eout_) |
| 331 | { |
| 332 | } |
| 333 | |
| 334 | template <class _CharT, class _Traits> |
| 335 | basic_streambuf<_CharT, _Traits>& |
| 336 | basic_streambuf<_CharT, _Traits>::operator=(const basic_streambuf& __sb) |
| 337 | { |
| 338 | __loc_ = __sb.__loc_; |
| 339 | __binp_ = __sb.__binp_; |
| 340 | __ninp_ = __sb.__ninp_; |
| 341 | __einp_ = __sb.__einp_; |
| 342 | __bout_ = __sb.__bout_; |
| 343 | __nout_ = __sb.__nout_; |
| 344 | __eout_ = __sb.__eout_; |
| 345 | return *this; |
| 346 | } |
| 347 | |
| 348 | template <class _CharT, class _Traits> |
| 349 | void |
| 350 | basic_streambuf<_CharT, _Traits>::swap(basic_streambuf& __sb) |
| 351 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 352 | _VSTD::swap(__loc_, __sb.__loc_); |
| 353 | _VSTD::swap(__binp_, __sb.__binp_); |
| 354 | _VSTD::swap(__ninp_, __sb.__ninp_); |
| 355 | _VSTD::swap(__einp_, __sb.__einp_); |
| 356 | _VSTD::swap(__bout_, __sb.__bout_); |
| 357 | _VSTD::swap(__nout_, __sb.__nout_); |
| 358 | _VSTD::swap(__eout_, __sb.__eout_); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 359 | } |
| 360 | |
| 361 | template <class _CharT, class _Traits> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 362 | void |
| 363 | basic_streambuf<_CharT, _Traits>::imbue(const locale&) |
| 364 | { |
| 365 | } |
| 366 | |
| 367 | template <class _CharT, class _Traits> |
| 368 | basic_streambuf<_CharT, _Traits>* |
| 369 | basic_streambuf<_CharT, _Traits>::setbuf(char_type*, streamsize) |
| 370 | { |
| 371 | return this; |
| 372 | } |
| 373 | |
| 374 | template <class _CharT, class _Traits> |
| 375 | typename basic_streambuf<_CharT, _Traits>::pos_type |
Howard Hinnant | 28b2488 | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 376 | basic_streambuf<_CharT, _Traits>::seekoff(off_type, ios_base::seekdir, |
| 377 | ios_base::openmode) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 378 | { |
| 379 | return pos_type(off_type(-1)); |
| 380 | } |
| 381 | |
| 382 | template <class _CharT, class _Traits> |
| 383 | typename basic_streambuf<_CharT, _Traits>::pos_type |
Howard Hinnant | 28b2488 | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 384 | basic_streambuf<_CharT, _Traits>::seekpos(pos_type, ios_base::openmode) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 385 | { |
| 386 | return pos_type(off_type(-1)); |
| 387 | } |
| 388 | |
| 389 | template <class _CharT, class _Traits> |
| 390 | int |
| 391 | basic_streambuf<_CharT, _Traits>::sync() |
| 392 | { |
| 393 | return 0; |
| 394 | } |
| 395 | |
| 396 | template <class _CharT, class _Traits> |
| 397 | streamsize |
| 398 | basic_streambuf<_CharT, _Traits>::showmanyc() |
| 399 | { |
| 400 | return 0; |
| 401 | } |
| 402 | |
| 403 | template <class _CharT, class _Traits> |
| 404 | streamsize |
| 405 | basic_streambuf<_CharT, _Traits>::xsgetn(char_type* __s, streamsize __n) |
| 406 | { |
| 407 | const int_type __eof = traits_type::eof(); |
| 408 | int_type __c; |
| 409 | streamsize __i = 0; |
Evandro Menezes | 4ea8718 | 2016-06-10 16:00:29 +0000 | [diff] [blame] | 410 | while(__i < __n) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 411 | { |
| 412 | if (__ninp_ < __einp_) |
Evandro Menezes | 4ea8718 | 2016-06-10 16:00:29 +0000 | [diff] [blame] | 413 | { |
Marshall Clow | e30318f | 2017-07-24 14:05:10 +0000 | [diff] [blame] | 414 | const streamsize __len = _VSTD::min(static_cast<streamsize>(INT_MAX), |
| 415 | _VSTD::min(__einp_ - __ninp_, __n - __i)); |
Evandro Menezes | 4ea8718 | 2016-06-10 16:00:29 +0000 | [diff] [blame] | 416 | traits_type::copy(__s, __ninp_, __len); |
| 417 | __s += __len; |
| 418 | __i += __len; |
| 419 | this->gbump(__len); |
| 420 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 421 | else if ((__c = uflow()) != __eof) |
Evandro Menezes | 4ea8718 | 2016-06-10 16:00:29 +0000 | [diff] [blame] | 422 | { |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 423 | *__s = traits_type::to_char_type(__c); |
Evandro Menezes | 4ea8718 | 2016-06-10 16:00:29 +0000 | [diff] [blame] | 424 | ++__s; |
| 425 | ++__i; |
| 426 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 427 | else |
| 428 | break; |
| 429 | } |
| 430 | return __i; |
| 431 | } |
| 432 | |
| 433 | template <class _CharT, class _Traits> |
| 434 | typename basic_streambuf<_CharT, _Traits>::int_type |
| 435 | basic_streambuf<_CharT, _Traits>::underflow() |
| 436 | { |
| 437 | return traits_type::eof(); |
| 438 | } |
| 439 | |
| 440 | template <class _CharT, class _Traits> |
| 441 | typename basic_streambuf<_CharT, _Traits>::int_type |
| 442 | basic_streambuf<_CharT, _Traits>::uflow() |
| 443 | { |
| 444 | if (underflow() == traits_type::eof()) |
| 445 | return traits_type::eof(); |
| 446 | return traits_type::to_int_type(*__ninp_++); |
| 447 | } |
| 448 | |
| 449 | template <class _CharT, class _Traits> |
| 450 | typename basic_streambuf<_CharT, _Traits>::int_type |
| 451 | basic_streambuf<_CharT, _Traits>::pbackfail(int_type) |
| 452 | { |
| 453 | return traits_type::eof(); |
| 454 | } |
| 455 | |
| 456 | template <class _CharT, class _Traits> |
| 457 | streamsize |
| 458 | basic_streambuf<_CharT, _Traits>::xsputn(const char_type* __s, streamsize __n) |
| 459 | { |
| 460 | streamsize __i = 0; |
| 461 | int_type __eof = traits_type::eof(); |
Marshall Clow | 96c6262 | 2015-02-19 16:17:46 +0000 | [diff] [blame] | 462 | while( __i < __n) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 463 | { |
Marshall Clow | 96c6262 | 2015-02-19 16:17:46 +0000 | [diff] [blame] | 464 | if (__nout_ >= __eout_) |
| 465 | { |
| 466 | if (overflow(traits_type::to_int_type(*__s)) == __eof) |
| 467 | break; |
| 468 | ++__s; |
| 469 | ++__i; |
| 470 | } |
| 471 | else |
| 472 | { |
| 473 | streamsize __chunk_size = _VSTD::min(__eout_ - __nout_, __n - __i); |
| 474 | traits_type::copy(__nout_, __s, __chunk_size); |
| 475 | __nout_ += __chunk_size; |
| 476 | __s += __chunk_size; |
| 477 | __i += __chunk_size; |
| 478 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 479 | } |
| 480 | return __i; |
| 481 | } |
| 482 | |
| 483 | template <class _CharT, class _Traits> |
| 484 | typename basic_streambuf<_CharT, _Traits>::int_type |
Howard Hinnant | 28b2488 | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 485 | basic_streambuf<_CharT, _Traits>::overflow(int_type) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 486 | { |
| 487 | return traits_type::eof(); |
| 488 | } |
| 489 | |
Eric Fiselier | 1b57fa8 | 2016-09-15 22:27:07 +0000 | [diff] [blame] | 490 | _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_streambuf<char>) |
| 491 | _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_streambuf<wchar_t>) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 492 | |
Eric Fiselier | 1b57fa8 | 2016-09-15 22:27:07 +0000 | [diff] [blame] | 493 | _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ios<char>) |
| 494 | _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ios<wchar_t>) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 495 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 496 | _LIBCPP_END_NAMESPACE_STD |
| 497 | |
Eric Fiselier | f4433a3 | 2017-05-31 22:07:49 +0000 | [diff] [blame] | 498 | _LIBCPP_POP_MACROS |
| 499 | |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 500 | #endif // _LIBCPP_STREAMBUF |