10b57cec5SDimitry Andric// -*- C++ -*- 2349cc55cSDimitry Andric//===----------------------------------------------------------------------===// 30b57cec5SDimitry Andric// 40b57cec5SDimitry Andric// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 50b57cec5SDimitry Andric// See https://llvm.org/LICENSE.txt for license information. 60b57cec5SDimitry Andric// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 70b57cec5SDimitry Andric// 80b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 90b57cec5SDimitry Andric 10fe6060f1SDimitry Andric#ifndef _LIBCPP_STREAMBUF 11fe6060f1SDimitry Andric#define _LIBCPP_STREAMBUF 120b57cec5SDimitry Andric 130b57cec5SDimitry Andric/* 140b57cec5SDimitry Andric streambuf synopsis 150b57cec5SDimitry Andric 160b57cec5SDimitry Andricnamespace std 170b57cec5SDimitry Andric{ 180b57cec5SDimitry Andric 190b57cec5SDimitry Andrictemplate <class charT, class traits = char_traits<charT> > 200b57cec5SDimitry Andricclass basic_streambuf 210b57cec5SDimitry Andric{ 220b57cec5SDimitry Andricpublic: 230b57cec5SDimitry Andric // types: 240b57cec5SDimitry Andric typedef charT char_type; 250b57cec5SDimitry Andric typedef traits traits_type; 260b57cec5SDimitry Andric typedef typename traits_type::int_type int_type; 270b57cec5SDimitry Andric typedef typename traits_type::pos_type pos_type; 280b57cec5SDimitry Andric typedef typename traits_type::off_type off_type; 290b57cec5SDimitry Andric 300b57cec5SDimitry Andric virtual ~basic_streambuf(); 310b57cec5SDimitry Andric 320b57cec5SDimitry Andric // 27.6.2.2.1 locales: 330b57cec5SDimitry Andric locale pubimbue(const locale& loc); 340b57cec5SDimitry Andric locale getloc() const; 350b57cec5SDimitry Andric 360b57cec5SDimitry Andric // 27.6.2.2.2 buffer and positioning: 370b57cec5SDimitry Andric basic_streambuf* pubsetbuf(char_type* s, streamsize n); 380b57cec5SDimitry Andric pos_type pubseekoff(off_type off, ios_base::seekdir way, 390b57cec5SDimitry Andric ios_base::openmode which = ios_base::in | ios_base::out); 400b57cec5SDimitry Andric pos_type pubseekpos(pos_type sp, 410b57cec5SDimitry Andric ios_base::openmode which = ios_base::in | ios_base::out); 420b57cec5SDimitry Andric int pubsync(); 430b57cec5SDimitry Andric 440b57cec5SDimitry Andric // Get and put areas: 450b57cec5SDimitry Andric // 27.6.2.2.3 Get area: 460b57cec5SDimitry Andric streamsize in_avail(); 470b57cec5SDimitry Andric int_type snextc(); 480b57cec5SDimitry Andric int_type sbumpc(); 490b57cec5SDimitry Andric int_type sgetc(); 500b57cec5SDimitry Andric streamsize sgetn(char_type* s, streamsize n); 510b57cec5SDimitry Andric 520b57cec5SDimitry Andric // 27.6.2.2.4 Putback: 530b57cec5SDimitry Andric int_type sputbackc(char_type c); 540b57cec5SDimitry Andric int_type sungetc(); 550b57cec5SDimitry Andric 560b57cec5SDimitry Andric // 27.6.2.2.5 Put area: 570b57cec5SDimitry Andric int_type sputc(char_type c); 580b57cec5SDimitry Andric streamsize sputn(const char_type* s, streamsize n); 590b57cec5SDimitry Andric 600b57cec5SDimitry Andricprotected: 610b57cec5SDimitry Andric basic_streambuf(); 620b57cec5SDimitry Andric basic_streambuf(const basic_streambuf& rhs); 630b57cec5SDimitry Andric basic_streambuf& operator=(const basic_streambuf& rhs); 640b57cec5SDimitry Andric void swap(basic_streambuf& rhs); 650b57cec5SDimitry Andric 660b57cec5SDimitry Andric // 27.6.2.3.2 Get area: 670b57cec5SDimitry Andric char_type* eback() const; 680b57cec5SDimitry Andric char_type* gptr() const; 690b57cec5SDimitry Andric char_type* egptr() const; 700b57cec5SDimitry Andric void gbump(int n); 710b57cec5SDimitry Andric void setg(char_type* gbeg, char_type* gnext, char_type* gend); 720b57cec5SDimitry Andric 730b57cec5SDimitry Andric // 27.6.2.3.3 Put area: 740b57cec5SDimitry Andric char_type* pbase() const; 750b57cec5SDimitry Andric char_type* pptr() const; 760b57cec5SDimitry Andric char_type* epptr() const; 770b57cec5SDimitry Andric void pbump(int n); 780b57cec5SDimitry Andric void setp(char_type* pbeg, char_type* pend); 790b57cec5SDimitry Andric 800b57cec5SDimitry Andric // 27.6.2.4 virtual functions: 810b57cec5SDimitry Andric // 27.6.2.4.1 Locales: 820b57cec5SDimitry Andric virtual void imbue(const locale& loc); 830b57cec5SDimitry Andric 840b57cec5SDimitry Andric // 27.6.2.4.2 Buffer management and positioning: 850b57cec5SDimitry Andric virtual basic_streambuf* setbuf(char_type* s, streamsize n); 860b57cec5SDimitry Andric virtual pos_type seekoff(off_type off, ios_base::seekdir way, 870b57cec5SDimitry Andric ios_base::openmode which = ios_base::in | ios_base::out); 880b57cec5SDimitry Andric virtual pos_type seekpos(pos_type sp, 890b57cec5SDimitry Andric ios_base::openmode which = ios_base::in | ios_base::out); 900b57cec5SDimitry Andric virtual int sync(); 910b57cec5SDimitry Andric 920b57cec5SDimitry Andric // 27.6.2.4.3 Get area: 930b57cec5SDimitry Andric virtual streamsize showmanyc(); 940b57cec5SDimitry Andric virtual streamsize xsgetn(char_type* s, streamsize n); 950b57cec5SDimitry Andric virtual int_type underflow(); 960b57cec5SDimitry Andric virtual int_type uflow(); 970b57cec5SDimitry Andric 980b57cec5SDimitry Andric // 27.6.2.4.4 Putback: 990b57cec5SDimitry Andric virtual int_type pbackfail(int_type c = traits_type::eof()); 1000b57cec5SDimitry Andric 1010b57cec5SDimitry Andric // 27.6.2.4.5 Put area: 1020b57cec5SDimitry Andric virtual streamsize xsputn(const char_type* s, streamsize n); 1030b57cec5SDimitry Andric virtual int_type overflow (int_type c = traits_type::eof()); 1040b57cec5SDimitry Andric}; 1050b57cec5SDimitry Andric 1060b57cec5SDimitry Andric} // std 1070b57cec5SDimitry Andric 1080b57cec5SDimitry Andric*/ 1090b57cec5SDimitry Andric 110*0fca6ea1SDimitry Andric#include <__assert> 1110b57cec5SDimitry Andric#include <__config> 11206c3fb27SDimitry Andric#include <__fwd/streambuf.h> 113*0fca6ea1SDimitry Andric#include <__locale> 114*0fca6ea1SDimitry Andric#include <__type_traits/is_same.h> 115*0fca6ea1SDimitry Andric#include <__utility/is_valid_range.h> 1165f757f3fSDimitry Andric#include <climits> 1170b57cec5SDimitry Andric#include <ios> 118fe6060f1SDimitry Andric#include <iosfwd> 11904eeddc0SDimitry Andric#include <version> 1200b57cec5SDimitry Andric 1210b57cec5SDimitry Andric#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 1220b57cec5SDimitry Andric# pragma GCC system_header 1230b57cec5SDimitry Andric#endif 1240b57cec5SDimitry Andric 1250b57cec5SDimitry Andric_LIBCPP_PUSH_MACROS 1260b57cec5SDimitry Andric#include <__undef_macros> 1270b57cec5SDimitry Andric 1280b57cec5SDimitry Andric_LIBCPP_BEGIN_NAMESPACE_STD 1290b57cec5SDimitry Andric 1300b57cec5SDimitry Andrictemplate <class _CharT, class _Traits> 131cb14a3feSDimitry Andricclass _LIBCPP_TEMPLATE_VIS basic_streambuf { 1320b57cec5SDimitry Andricpublic: 1330b57cec5SDimitry Andric // types: 1340b57cec5SDimitry Andric typedef _CharT char_type; 1350b57cec5SDimitry Andric typedef _Traits traits_type; 1360b57cec5SDimitry Andric typedef typename traits_type::int_type int_type; 1370b57cec5SDimitry Andric typedef typename traits_type::pos_type pos_type; 1380b57cec5SDimitry Andric typedef typename traits_type::off_type off_type; 1390b57cec5SDimitry Andric 140*0fca6ea1SDimitry Andric static_assert(is_same<_CharT, typename traits_type::char_type>::value, 1410b57cec5SDimitry Andric "traits_type::char_type must be the same type as CharT"); 1420b57cec5SDimitry Andric 1430b57cec5SDimitry Andric virtual ~basic_streambuf(); 1440b57cec5SDimitry Andric 1450b57cec5SDimitry Andric // 27.6.2.2.1 locales: 146cb14a3feSDimitry Andric inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 locale pubimbue(const locale& __loc) { 1470b57cec5SDimitry Andric imbue(__loc); 1480b57cec5SDimitry Andric locale __r = __loc_; 1490b57cec5SDimitry Andric __loc_ = __loc; 1500b57cec5SDimitry Andric return __r; 1510b57cec5SDimitry Andric } 1520b57cec5SDimitry Andric 153cb14a3feSDimitry Andric inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 locale getloc() const { return __loc_; } 1540b57cec5SDimitry Andric 1550b57cec5SDimitry Andric // 27.6.2.2.2 buffer and positioning: 156cb14a3feSDimitry Andric inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 basic_streambuf* pubsetbuf(char_type* __s, streamsize __n) { 157cb14a3feSDimitry Andric return setbuf(__s, __n); 158cb14a3feSDimitry Andric } 1590b57cec5SDimitry Andric 160cb14a3feSDimitry Andric inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 pos_type 161cb14a3feSDimitry Andric pubseekoff(off_type __off, ios_base::seekdir __way, ios_base::openmode __which = ios_base::in | ios_base::out) { 162cb14a3feSDimitry Andric return seekoff(__off, __way, __which); 163cb14a3feSDimitry Andric } 1640b57cec5SDimitry Andric 165cb14a3feSDimitry Andric inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 pos_type 166cb14a3feSDimitry Andric pubseekpos(pos_type __sp, ios_base::openmode __which = ios_base::in | ios_base::out) { 167cb14a3feSDimitry Andric return seekpos(__sp, __which); 168cb14a3feSDimitry Andric } 1690b57cec5SDimitry Andric 170cb14a3feSDimitry Andric inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 int pubsync() { return sync(); } 1710b57cec5SDimitry Andric 1720b57cec5SDimitry Andric // Get and put areas: 1730b57cec5SDimitry Andric // 27.6.2.2.3 Get area: 174cb14a3feSDimitry Andric inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 streamsize in_avail() { 1750b57cec5SDimitry Andric if (__ninp_ < __einp_) 1760b57cec5SDimitry Andric return static_cast<streamsize>(__einp_ - __ninp_); 1770b57cec5SDimitry Andric return showmanyc(); 1780b57cec5SDimitry Andric } 1790b57cec5SDimitry Andric 180cb14a3feSDimitry Andric inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 int_type snextc() { 1810b57cec5SDimitry Andric if (sbumpc() == traits_type::eof()) 1820b57cec5SDimitry Andric return traits_type::eof(); 1830b57cec5SDimitry Andric return sgetc(); 1840b57cec5SDimitry Andric } 1850b57cec5SDimitry Andric 186cb14a3feSDimitry Andric inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 int_type sbumpc() { 1870b57cec5SDimitry Andric if (__ninp_ == __einp_) 1880b57cec5SDimitry Andric return uflow(); 1890b57cec5SDimitry Andric return traits_type::to_int_type(*__ninp_++); 1900b57cec5SDimitry Andric } 1910b57cec5SDimitry Andric 192cb14a3feSDimitry Andric inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 int_type sgetc() { 1930b57cec5SDimitry Andric if (__ninp_ == __einp_) 1940b57cec5SDimitry Andric return underflow(); 1950b57cec5SDimitry Andric return traits_type::to_int_type(*__ninp_); 1960b57cec5SDimitry Andric } 1970b57cec5SDimitry Andric 198cb14a3feSDimitry Andric inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 streamsize sgetn(char_type* __s, streamsize __n) { return xsgetn(__s, __n); } 1990b57cec5SDimitry Andric 2000b57cec5SDimitry Andric // 27.6.2.2.4 Putback: 201cb14a3feSDimitry Andric inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 int_type sputbackc(char_type __c) { 2020b57cec5SDimitry Andric if (__binp_ == __ninp_ || !traits_type::eq(__c, __ninp_[-1])) 2030b57cec5SDimitry Andric return pbackfail(traits_type::to_int_type(__c)); 2040b57cec5SDimitry Andric return traits_type::to_int_type(*--__ninp_); 2050b57cec5SDimitry Andric } 2060b57cec5SDimitry Andric 207cb14a3feSDimitry Andric inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 int_type sungetc() { 2080b57cec5SDimitry Andric if (__binp_ == __ninp_) 2090b57cec5SDimitry Andric return pbackfail(); 2100b57cec5SDimitry Andric return traits_type::to_int_type(*--__ninp_); 2110b57cec5SDimitry Andric } 2120b57cec5SDimitry Andric 2130b57cec5SDimitry Andric // 27.6.2.2.5 Put area: 214cb14a3feSDimitry Andric inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 int_type sputc(char_type __c) { 2150b57cec5SDimitry Andric if (__nout_ == __eout_) 2160b57cec5SDimitry Andric return overflow(traits_type::to_int_type(__c)); 2170b57cec5SDimitry Andric *__nout_++ = __c; 2180b57cec5SDimitry Andric return traits_type::to_int_type(__c); 2190b57cec5SDimitry Andric } 2200b57cec5SDimitry Andric 221cb14a3feSDimitry Andric inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 streamsize sputn(const char_type* __s, streamsize __n) { 222cb14a3feSDimitry Andric return xsputn(__s, __n); 223cb14a3feSDimitry Andric } 2240b57cec5SDimitry Andric 2250b57cec5SDimitry Andricprotected: 2260b57cec5SDimitry Andric basic_streambuf(); 2270b57cec5SDimitry Andric basic_streambuf(const basic_streambuf& __rhs); 2280b57cec5SDimitry Andric basic_streambuf& operator=(const basic_streambuf& __rhs); 2290b57cec5SDimitry Andric void swap(basic_streambuf& __rhs); 2300b57cec5SDimitry Andric 2310b57cec5SDimitry Andric // 27.6.2.3.2 Get area: 2325f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI char_type* eback() const { return __binp_; } 2335f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI char_type* gptr() const { return __ninp_; } 2345f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI char_type* egptr() const { return __einp_; } 2350b57cec5SDimitry Andric 236cb14a3feSDimitry Andric inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 void gbump(int __n) { __ninp_ += __n; } 2370b57cec5SDimitry Andric 238cb14a3feSDimitry Andric inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 void setg(char_type* __gbeg, char_type* __gnext, char_type* __gend) { 239*0fca6ea1SDimitry Andric _LIBCPP_ASSERT_VALID_INPUT_RANGE(std::__is_valid_range(__gbeg, __gnext), "[gbeg, gnext) must be a valid range"); 240*0fca6ea1SDimitry Andric _LIBCPP_ASSERT_VALID_INPUT_RANGE(std::__is_valid_range(__gbeg, __gend), "[gbeg, gend) must be a valid range"); 241*0fca6ea1SDimitry Andric _LIBCPP_ASSERT_VALID_INPUT_RANGE(std::__is_valid_range(__gnext, __gend), "[gnext, gend) must be a valid range"); 2420b57cec5SDimitry Andric __binp_ = __gbeg; 2430b57cec5SDimitry Andric __ninp_ = __gnext; 2440b57cec5SDimitry Andric __einp_ = __gend; 2450b57cec5SDimitry Andric } 2460b57cec5SDimitry Andric 2470b57cec5SDimitry Andric // 27.6.2.3.3 Put area: 2485f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI char_type* pbase() const { return __bout_; } 2495f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI char_type* pptr() const { return __nout_; } 2505f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI char_type* epptr() const { return __eout_; } 2510b57cec5SDimitry Andric 252cb14a3feSDimitry Andric inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 void pbump(int __n) { __nout_ += __n; } 2530b57cec5SDimitry Andric 254cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI void __pbump(streamsize __n) { __nout_ += __n; } 2550b57cec5SDimitry Andric 256cb14a3feSDimitry Andric inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 void setp(char_type* __pbeg, char_type* __pend) { 257*0fca6ea1SDimitry Andric _LIBCPP_ASSERT_VALID_INPUT_RANGE(std::__is_valid_range(__pbeg, __pend), "[pbeg, pend) must be a valid range"); 2580b57cec5SDimitry Andric __bout_ = __nout_ = __pbeg; 2590b57cec5SDimitry Andric __eout_ = __pend; 2600b57cec5SDimitry Andric } 2610b57cec5SDimitry Andric 2620b57cec5SDimitry Andric // 27.6.2.4 virtual functions: 2630b57cec5SDimitry Andric // 27.6.2.4.1 Locales: 2640b57cec5SDimitry Andric virtual void imbue(const locale& __loc); 2650b57cec5SDimitry Andric 2660b57cec5SDimitry Andric // 27.6.2.4.2 Buffer management and positioning: 2670b57cec5SDimitry Andric virtual basic_streambuf* setbuf(char_type* __s, streamsize __n); 268cb14a3feSDimitry Andric virtual pos_type 269cb14a3feSDimitry Andric seekoff(off_type __off, ios_base::seekdir __way, ios_base::openmode __which = ios_base::in | ios_base::out); 270cb14a3feSDimitry Andric virtual pos_type seekpos(pos_type __sp, ios_base::openmode __which = ios_base::in | ios_base::out); 2710b57cec5SDimitry Andric virtual int sync(); 2720b57cec5SDimitry Andric 2730b57cec5SDimitry Andric // 27.6.2.4.3 Get area: 2740b57cec5SDimitry Andric virtual streamsize showmanyc(); 2750b57cec5SDimitry Andric virtual streamsize xsgetn(char_type* __s, streamsize __n); 2760b57cec5SDimitry Andric virtual int_type underflow(); 2770b57cec5SDimitry Andric virtual int_type uflow(); 2780b57cec5SDimitry Andric 2790b57cec5SDimitry Andric // 27.6.2.4.4 Putback: 2800b57cec5SDimitry Andric virtual int_type pbackfail(int_type __c = traits_type::eof()); 2810b57cec5SDimitry Andric 2820b57cec5SDimitry Andric // 27.6.2.4.5 Put area: 2830b57cec5SDimitry Andric virtual streamsize xsputn(const char_type* __s, streamsize __n); 2840b57cec5SDimitry Andric virtual int_type overflow(int_type __c = traits_type::eof()); 2850b57cec5SDimitry Andric 2860b57cec5SDimitry Andricprivate: 2870b57cec5SDimitry Andric locale __loc_; 2880b57cec5SDimitry Andric char_type* __binp_; 2890b57cec5SDimitry Andric char_type* __ninp_; 2900b57cec5SDimitry Andric char_type* __einp_; 2910b57cec5SDimitry Andric char_type* __bout_; 2920b57cec5SDimitry Andric char_type* __nout_; 2930b57cec5SDimitry Andric char_type* __eout_; 2940b57cec5SDimitry Andric}; 2950b57cec5SDimitry Andric 2960b57cec5SDimitry Andrictemplate <class _CharT, class _Traits> 297cb14a3feSDimitry Andricbasic_streambuf<_CharT, _Traits>::~basic_streambuf() {} 2980b57cec5SDimitry Andric 2990b57cec5SDimitry Andrictemplate <class _CharT, class _Traits> 3000b57cec5SDimitry Andricbasic_streambuf<_CharT, _Traits>::basic_streambuf() 301cb14a3feSDimitry Andric : __binp_(nullptr), __ninp_(nullptr), __einp_(nullptr), __bout_(nullptr), __nout_(nullptr), __eout_(nullptr) {} 3020b57cec5SDimitry Andric 3030b57cec5SDimitry Andrictemplate <class _CharT, class _Traits> 3040b57cec5SDimitry Andricbasic_streambuf<_CharT, _Traits>::basic_streambuf(const basic_streambuf& __sb) 3050b57cec5SDimitry Andric : __loc_(__sb.__loc_), 3060b57cec5SDimitry Andric __binp_(__sb.__binp_), 3070b57cec5SDimitry Andric __ninp_(__sb.__ninp_), 3080b57cec5SDimitry Andric __einp_(__sb.__einp_), 3090b57cec5SDimitry Andric __bout_(__sb.__bout_), 3100b57cec5SDimitry Andric __nout_(__sb.__nout_), 311cb14a3feSDimitry Andric __eout_(__sb.__eout_) {} 3120b57cec5SDimitry Andric 3130b57cec5SDimitry Andrictemplate <class _CharT, class _Traits> 314cb14a3feSDimitry Andricbasic_streambuf<_CharT, _Traits>& basic_streambuf<_CharT, _Traits>::operator=(const basic_streambuf& __sb) { 3150b57cec5SDimitry Andric __loc_ = __sb.__loc_; 3160b57cec5SDimitry Andric __binp_ = __sb.__binp_; 3170b57cec5SDimitry Andric __ninp_ = __sb.__ninp_; 3180b57cec5SDimitry Andric __einp_ = __sb.__einp_; 3190b57cec5SDimitry Andric __bout_ = __sb.__bout_; 3200b57cec5SDimitry Andric __nout_ = __sb.__nout_; 3210b57cec5SDimitry Andric __eout_ = __sb.__eout_; 3220b57cec5SDimitry Andric return *this; 3230b57cec5SDimitry Andric} 3240b57cec5SDimitry Andric 3250b57cec5SDimitry Andrictemplate <class _CharT, class _Traits> 326cb14a3feSDimitry Andricvoid basic_streambuf<_CharT, _Traits>::swap(basic_streambuf& __sb) { 3275f757f3fSDimitry Andric std::swap(__loc_, __sb.__loc_); 3285f757f3fSDimitry Andric std::swap(__binp_, __sb.__binp_); 3295f757f3fSDimitry Andric std::swap(__ninp_, __sb.__ninp_); 3305f757f3fSDimitry Andric std::swap(__einp_, __sb.__einp_); 3315f757f3fSDimitry Andric std::swap(__bout_, __sb.__bout_); 3325f757f3fSDimitry Andric std::swap(__nout_, __sb.__nout_); 3335f757f3fSDimitry Andric std::swap(__eout_, __sb.__eout_); 3340b57cec5SDimitry Andric} 3350b57cec5SDimitry Andric 3360b57cec5SDimitry Andrictemplate <class _CharT, class _Traits> 337cb14a3feSDimitry Andricvoid basic_streambuf<_CharT, _Traits>::imbue(const locale&) {} 3380b57cec5SDimitry Andric 3390b57cec5SDimitry Andrictemplate <class _CharT, class _Traits> 340cb14a3feSDimitry Andricbasic_streambuf<_CharT, _Traits>* basic_streambuf<_CharT, _Traits>::setbuf(char_type*, streamsize) { 3410b57cec5SDimitry Andric return this; 3420b57cec5SDimitry Andric} 3430b57cec5SDimitry Andric 3440b57cec5SDimitry Andrictemplate <class _CharT, class _Traits> 3450b57cec5SDimitry Andrictypename basic_streambuf<_CharT, _Traits>::pos_type 346cb14a3feSDimitry Andricbasic_streambuf<_CharT, _Traits>::seekoff(off_type, ios_base::seekdir, ios_base::openmode) { 3470b57cec5SDimitry Andric return pos_type(off_type(-1)); 3480b57cec5SDimitry Andric} 3490b57cec5SDimitry Andric 3500b57cec5SDimitry Andrictemplate <class _CharT, class _Traits> 3510b57cec5SDimitry Andrictypename basic_streambuf<_CharT, _Traits>::pos_type 352cb14a3feSDimitry Andricbasic_streambuf<_CharT, _Traits>::seekpos(pos_type, ios_base::openmode) { 3530b57cec5SDimitry Andric return pos_type(off_type(-1)); 3540b57cec5SDimitry Andric} 3550b57cec5SDimitry Andric 3560b57cec5SDimitry Andrictemplate <class _CharT, class _Traits> 357cb14a3feSDimitry Andricint basic_streambuf<_CharT, _Traits>::sync() { 3580b57cec5SDimitry Andric return 0; 3590b57cec5SDimitry Andric} 3600b57cec5SDimitry Andric 3610b57cec5SDimitry Andrictemplate <class _CharT, class _Traits> 362cb14a3feSDimitry Andricstreamsize basic_streambuf<_CharT, _Traits>::showmanyc() { 3630b57cec5SDimitry Andric return 0; 3640b57cec5SDimitry Andric} 3650b57cec5SDimitry Andric 3660b57cec5SDimitry Andrictemplate <class _CharT, class _Traits> 367cb14a3feSDimitry Andricstreamsize basic_streambuf<_CharT, _Traits>::xsgetn(char_type* __s, streamsize __n) { 3680b57cec5SDimitry Andric const int_type __eof = traits_type::eof(); 3690b57cec5SDimitry Andric int_type __c; 3700b57cec5SDimitry Andric streamsize __i = 0; 371cb14a3feSDimitry Andric while (__i < __n) { 372cb14a3feSDimitry Andric if (__ninp_ < __einp_) { 373cb14a3feSDimitry Andric const streamsize __len = std::min(static_cast<streamsize>(INT_MAX), std::min(__einp_ - __ninp_, __n - __i)); 3740b57cec5SDimitry Andric traits_type::copy(__s, __ninp_, __len); 3750b57cec5SDimitry Andric __s += __len; 3760b57cec5SDimitry Andric __i += __len; 3770b57cec5SDimitry Andric this->gbump(__len); 378cb14a3feSDimitry Andric } else if ((__c = uflow()) != __eof) { 3790b57cec5SDimitry Andric *__s = traits_type::to_char_type(__c); 3800b57cec5SDimitry Andric ++__s; 3810b57cec5SDimitry Andric ++__i; 382cb14a3feSDimitry Andric } else 3830b57cec5SDimitry Andric break; 3840b57cec5SDimitry Andric } 3850b57cec5SDimitry Andric return __i; 3860b57cec5SDimitry Andric} 3870b57cec5SDimitry Andric 3880b57cec5SDimitry Andrictemplate <class _CharT, class _Traits> 389cb14a3feSDimitry Andrictypename basic_streambuf<_CharT, _Traits>::int_type basic_streambuf<_CharT, _Traits>::underflow() { 3900b57cec5SDimitry Andric return traits_type::eof(); 3910b57cec5SDimitry Andric} 3920b57cec5SDimitry Andric 3930b57cec5SDimitry Andrictemplate <class _CharT, class _Traits> 394cb14a3feSDimitry Andrictypename basic_streambuf<_CharT, _Traits>::int_type basic_streambuf<_CharT, _Traits>::uflow() { 3950b57cec5SDimitry Andric if (underflow() == traits_type::eof()) 3960b57cec5SDimitry Andric return traits_type::eof(); 3970b57cec5SDimitry Andric return traits_type::to_int_type(*__ninp_++); 3980b57cec5SDimitry Andric} 3990b57cec5SDimitry Andric 4000b57cec5SDimitry Andrictemplate <class _CharT, class _Traits> 401cb14a3feSDimitry Andrictypename basic_streambuf<_CharT, _Traits>::int_type basic_streambuf<_CharT, _Traits>::pbackfail(int_type) { 4020b57cec5SDimitry Andric return traits_type::eof(); 4030b57cec5SDimitry Andric} 4040b57cec5SDimitry Andric 4050b57cec5SDimitry Andrictemplate <class _CharT, class _Traits> 406cb14a3feSDimitry Andricstreamsize basic_streambuf<_CharT, _Traits>::xsputn(const char_type* __s, streamsize __n) { 4070b57cec5SDimitry Andric streamsize __i = 0; 4080b57cec5SDimitry Andric int_type __eof = traits_type::eof(); 409cb14a3feSDimitry Andric while (__i < __n) { 410cb14a3feSDimitry Andric if (__nout_ >= __eout_) { 4110b57cec5SDimitry Andric if (overflow(traits_type::to_int_type(*__s)) == __eof) 4120b57cec5SDimitry Andric break; 4130b57cec5SDimitry Andric ++__s; 4140b57cec5SDimitry Andric ++__i; 415cb14a3feSDimitry Andric } else { 4165f757f3fSDimitry Andric streamsize __chunk_size = std::min(__eout_ - __nout_, __n - __i); 4170b57cec5SDimitry Andric traits_type::copy(__nout_, __s, __chunk_size); 4180b57cec5SDimitry Andric __nout_ += __chunk_size; 4190b57cec5SDimitry Andric __s += __chunk_size; 4200b57cec5SDimitry Andric __i += __chunk_size; 4210b57cec5SDimitry Andric } 4220b57cec5SDimitry Andric } 4230b57cec5SDimitry Andric return __i; 4240b57cec5SDimitry Andric} 4250b57cec5SDimitry Andric 4260b57cec5SDimitry Andrictemplate <class _CharT, class _Traits> 427cb14a3feSDimitry Andrictypename basic_streambuf<_CharT, _Traits>::int_type basic_streambuf<_CharT, _Traits>::overflow(int_type) { 4280b57cec5SDimitry Andric return traits_type::eof(); 4290b57cec5SDimitry Andric} 4300b57cec5SDimitry Andric 43181ad6265SDimitry Andricextern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_streambuf<char>; 432bdd1243dSDimitry Andric 433bdd1243dSDimitry Andric#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS 434bdd1243dSDimitry Andricextern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_streambuf<wchar_t>; 435bdd1243dSDimitry Andric#endif 4360b57cec5SDimitry Andric 4370b57cec5SDimitry Andric_LIBCPP_END_NAMESPACE_STD 4380b57cec5SDimitry Andric 4390b57cec5SDimitry Andric_LIBCPP_POP_MACROS 4400b57cec5SDimitry Andric 4415f757f3fSDimitry Andric#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20 4425f757f3fSDimitry Andric# include <cstdint> 4435f757f3fSDimitry Andric#endif 4445f757f3fSDimitry Andric 445fe6060f1SDimitry Andric#endif // _LIBCPP_STREAMBUF 446