xref: /freebsd/contrib/llvm-project/libcxx/include/__cxx03/streambuf (revision 700637cbb5e582861067a11aaca4d053546871d2)
1*700637cbSDimitry Andric// -*- C++ -*-
2*700637cbSDimitry Andric//===----------------------------------------------------------------------===//
3*700637cbSDimitry Andric//
4*700637cbSDimitry Andric// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5*700637cbSDimitry Andric// See https://llvm.org/LICENSE.txt for license information.
6*700637cbSDimitry Andric// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7*700637cbSDimitry Andric//
8*700637cbSDimitry Andric//===----------------------------------------------------------------------===//
9*700637cbSDimitry Andric
10*700637cbSDimitry Andric#ifndef _LIBCPP___CXX03_STREAMBUF
11*700637cbSDimitry Andric#define _LIBCPP___CXX03_STREAMBUF
12*700637cbSDimitry Andric
13*700637cbSDimitry Andric/*
14*700637cbSDimitry Andric    streambuf synopsis
15*700637cbSDimitry Andric
16*700637cbSDimitry Andricnamespace std
17*700637cbSDimitry Andric{
18*700637cbSDimitry Andric
19*700637cbSDimitry Andrictemplate <class charT, class traits = char_traits<charT> >
20*700637cbSDimitry Andricclass basic_streambuf
21*700637cbSDimitry Andric{
22*700637cbSDimitry Andricpublic:
23*700637cbSDimitry Andric    // types:
24*700637cbSDimitry Andric    typedef charT char_type;
25*700637cbSDimitry Andric    typedef traits traits_type;
26*700637cbSDimitry Andric    typedef typename traits_type::int_type int_type;
27*700637cbSDimitry Andric    typedef typename traits_type::pos_type pos_type;
28*700637cbSDimitry Andric    typedef typename traits_type::off_type off_type;
29*700637cbSDimitry Andric
30*700637cbSDimitry Andric    virtual ~basic_streambuf();
31*700637cbSDimitry Andric
32*700637cbSDimitry Andric    // 27.6.2.2.1 locales:
33*700637cbSDimitry Andric    locale pubimbue(const locale& loc);
34*700637cbSDimitry Andric    locale getloc() const;
35*700637cbSDimitry Andric
36*700637cbSDimitry Andric    // 27.6.2.2.2 buffer and positioning:
37*700637cbSDimitry Andric    basic_streambuf* pubsetbuf(char_type* s, streamsize n);
38*700637cbSDimitry Andric    pos_type pubseekoff(off_type off, ios_base::seekdir way,
39*700637cbSDimitry Andric                        ios_base::openmode which = ios_base::in | ios_base::out);
40*700637cbSDimitry Andric    pos_type pubseekpos(pos_type sp,
41*700637cbSDimitry Andric                        ios_base::openmode which = ios_base::in | ios_base::out);
42*700637cbSDimitry Andric    int pubsync();
43*700637cbSDimitry Andric
44*700637cbSDimitry Andric    // Get and put areas:
45*700637cbSDimitry Andric    // 27.6.2.2.3 Get area:
46*700637cbSDimitry Andric    streamsize in_avail();
47*700637cbSDimitry Andric    int_type snextc();
48*700637cbSDimitry Andric    int_type sbumpc();
49*700637cbSDimitry Andric    int_type sgetc();
50*700637cbSDimitry Andric    streamsize sgetn(char_type* s, streamsize n);
51*700637cbSDimitry Andric
52*700637cbSDimitry Andric    // 27.6.2.2.4 Putback:
53*700637cbSDimitry Andric    int_type sputbackc(char_type c);
54*700637cbSDimitry Andric    int_type sungetc();
55*700637cbSDimitry Andric
56*700637cbSDimitry Andric    // 27.6.2.2.5 Put area:
57*700637cbSDimitry Andric    int_type sputc(char_type c);
58*700637cbSDimitry Andric    streamsize sputn(const char_type* s, streamsize n);
59*700637cbSDimitry Andric
60*700637cbSDimitry Andricprotected:
61*700637cbSDimitry Andric    basic_streambuf();
62*700637cbSDimitry Andric    basic_streambuf(const basic_streambuf& rhs);
63*700637cbSDimitry Andric    basic_streambuf& operator=(const basic_streambuf& rhs);
64*700637cbSDimitry Andric    void swap(basic_streambuf& rhs);
65*700637cbSDimitry Andric
66*700637cbSDimitry Andric    // 27.6.2.3.2 Get area:
67*700637cbSDimitry Andric    char_type* eback() const;
68*700637cbSDimitry Andric    char_type* gptr() const;
69*700637cbSDimitry Andric    char_type* egptr() const;
70*700637cbSDimitry Andric    void gbump(int n);
71*700637cbSDimitry Andric    void setg(char_type* gbeg, char_type* gnext, char_type* gend);
72*700637cbSDimitry Andric
73*700637cbSDimitry Andric    // 27.6.2.3.3 Put area:
74*700637cbSDimitry Andric    char_type* pbase() const;
75*700637cbSDimitry Andric    char_type* pptr() const;
76*700637cbSDimitry Andric    char_type* epptr() const;
77*700637cbSDimitry Andric    void pbump(int n);
78*700637cbSDimitry Andric    void setp(char_type* pbeg, char_type* pend);
79*700637cbSDimitry Andric
80*700637cbSDimitry Andric    // 27.6.2.4 virtual functions:
81*700637cbSDimitry Andric    // 27.6.2.4.1 Locales:
82*700637cbSDimitry Andric    virtual void imbue(const locale& loc);
83*700637cbSDimitry Andric
84*700637cbSDimitry Andric    // 27.6.2.4.2 Buffer management and positioning:
85*700637cbSDimitry Andric    virtual basic_streambuf* setbuf(char_type* s, streamsize n);
86*700637cbSDimitry Andric    virtual pos_type seekoff(off_type off, ios_base::seekdir way,
87*700637cbSDimitry Andric                             ios_base::openmode which = ios_base::in | ios_base::out);
88*700637cbSDimitry Andric    virtual pos_type seekpos(pos_type sp,
89*700637cbSDimitry Andric                             ios_base::openmode which = ios_base::in | ios_base::out);
90*700637cbSDimitry Andric    virtual int sync();
91*700637cbSDimitry Andric
92*700637cbSDimitry Andric    // 27.6.2.4.3 Get area:
93*700637cbSDimitry Andric    virtual streamsize showmanyc();
94*700637cbSDimitry Andric    virtual streamsize xsgetn(char_type* s, streamsize n);
95*700637cbSDimitry Andric    virtual int_type underflow();
96*700637cbSDimitry Andric    virtual int_type uflow();
97*700637cbSDimitry Andric
98*700637cbSDimitry Andric    // 27.6.2.4.4 Putback:
99*700637cbSDimitry Andric    virtual int_type pbackfail(int_type c = traits_type::eof());
100*700637cbSDimitry Andric
101*700637cbSDimitry Andric    // 27.6.2.4.5 Put area:
102*700637cbSDimitry Andric    virtual streamsize xsputn(const char_type* s, streamsize n);
103*700637cbSDimitry Andric    virtual int_type overflow (int_type c = traits_type::eof());
104*700637cbSDimitry Andric};
105*700637cbSDimitry Andric
106*700637cbSDimitry Andric}  // std
107*700637cbSDimitry Andric
108*700637cbSDimitry Andric*/
109*700637cbSDimitry Andric
110*700637cbSDimitry Andric#include <__cxx03/__assert>
111*700637cbSDimitry Andric#include <__cxx03/__config>
112*700637cbSDimitry Andric#include <__cxx03/__fwd/streambuf.h>
113*700637cbSDimitry Andric#include <__cxx03/__locale>
114*700637cbSDimitry Andric#include <__cxx03/__type_traits/is_same.h>
115*700637cbSDimitry Andric#include <__cxx03/__utility/is_valid_range.h>
116*700637cbSDimitry Andric#include <__cxx03/climits>
117*700637cbSDimitry Andric#include <__cxx03/ios>
118*700637cbSDimitry Andric#include <__cxx03/iosfwd>
119*700637cbSDimitry Andric#include <__cxx03/version>
120*700637cbSDimitry Andric
121*700637cbSDimitry Andric#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
122*700637cbSDimitry Andric#  pragma GCC system_header
123*700637cbSDimitry Andric#endif
124*700637cbSDimitry Andric
125*700637cbSDimitry Andric_LIBCPP_PUSH_MACROS
126*700637cbSDimitry Andric#include <__cxx03/__undef_macros>
127*700637cbSDimitry Andric
128*700637cbSDimitry Andric_LIBCPP_BEGIN_NAMESPACE_STD
129*700637cbSDimitry Andric
130*700637cbSDimitry Andrictemplate <class _CharT, class _Traits>
131*700637cbSDimitry Andricclass _LIBCPP_TEMPLATE_VIS basic_streambuf {
132*700637cbSDimitry Andricpublic:
133*700637cbSDimitry Andric  // types:
134*700637cbSDimitry Andric  typedef _CharT char_type;
135*700637cbSDimitry Andric  typedef _Traits traits_type;
136*700637cbSDimitry Andric  typedef typename traits_type::int_type int_type;
137*700637cbSDimitry Andric  typedef typename traits_type::pos_type pos_type;
138*700637cbSDimitry Andric  typedef typename traits_type::off_type off_type;
139*700637cbSDimitry Andric
140*700637cbSDimitry Andric  static_assert(is_same<_CharT, typename traits_type::char_type>::value,
141*700637cbSDimitry Andric                "traits_type::char_type must be the same type as CharT");
142*700637cbSDimitry Andric
143*700637cbSDimitry Andric  virtual ~basic_streambuf();
144*700637cbSDimitry Andric
145*700637cbSDimitry Andric  // 27.6.2.2.1 locales:
146*700637cbSDimitry Andric  inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 locale pubimbue(const locale& __loc) {
147*700637cbSDimitry Andric    imbue(__loc);
148*700637cbSDimitry Andric    locale __r = __loc_;
149*700637cbSDimitry Andric    __loc_     = __loc;
150*700637cbSDimitry Andric    return __r;
151*700637cbSDimitry Andric  }
152*700637cbSDimitry Andric
153*700637cbSDimitry Andric  inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 locale getloc() const { return __loc_; }
154*700637cbSDimitry Andric
155*700637cbSDimitry Andric  // 27.6.2.2.2 buffer and positioning:
156*700637cbSDimitry Andric  inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 basic_streambuf* pubsetbuf(char_type* __s, streamsize __n) {
157*700637cbSDimitry Andric    return setbuf(__s, __n);
158*700637cbSDimitry Andric  }
159*700637cbSDimitry Andric
160*700637cbSDimitry Andric  inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 pos_type
161*700637cbSDimitry Andric  pubseekoff(off_type __off, ios_base::seekdir __way, ios_base::openmode __which = ios_base::in | ios_base::out) {
162*700637cbSDimitry Andric    return seekoff(__off, __way, __which);
163*700637cbSDimitry Andric  }
164*700637cbSDimitry Andric
165*700637cbSDimitry Andric  inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 pos_type
166*700637cbSDimitry Andric  pubseekpos(pos_type __sp, ios_base::openmode __which = ios_base::in | ios_base::out) {
167*700637cbSDimitry Andric    return seekpos(__sp, __which);
168*700637cbSDimitry Andric  }
169*700637cbSDimitry Andric
170*700637cbSDimitry Andric  inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 int pubsync() { return sync(); }
171*700637cbSDimitry Andric
172*700637cbSDimitry Andric  // Get and put areas:
173*700637cbSDimitry Andric  // 27.6.2.2.3 Get area:
174*700637cbSDimitry Andric  inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 streamsize in_avail() {
175*700637cbSDimitry Andric    if (__ninp_ < __einp_)
176*700637cbSDimitry Andric      return static_cast<streamsize>(__einp_ - __ninp_);
177*700637cbSDimitry Andric    return showmanyc();
178*700637cbSDimitry Andric  }
179*700637cbSDimitry Andric
180*700637cbSDimitry Andric  inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 int_type snextc() {
181*700637cbSDimitry Andric    if (sbumpc() == traits_type::eof())
182*700637cbSDimitry Andric      return traits_type::eof();
183*700637cbSDimitry Andric    return sgetc();
184*700637cbSDimitry Andric  }
185*700637cbSDimitry Andric
186*700637cbSDimitry Andric  inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 int_type sbumpc() {
187*700637cbSDimitry Andric    if (__ninp_ == __einp_)
188*700637cbSDimitry Andric      return uflow();
189*700637cbSDimitry Andric    return traits_type::to_int_type(*__ninp_++);
190*700637cbSDimitry Andric  }
191*700637cbSDimitry Andric
192*700637cbSDimitry Andric  inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 int_type sgetc() {
193*700637cbSDimitry Andric    if (__ninp_ == __einp_)
194*700637cbSDimitry Andric      return underflow();
195*700637cbSDimitry Andric    return traits_type::to_int_type(*__ninp_);
196*700637cbSDimitry Andric  }
197*700637cbSDimitry Andric
198*700637cbSDimitry Andric  inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 streamsize sgetn(char_type* __s, streamsize __n) { return xsgetn(__s, __n); }
199*700637cbSDimitry Andric
200*700637cbSDimitry Andric  // 27.6.2.2.4 Putback:
201*700637cbSDimitry Andric  inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 int_type sputbackc(char_type __c) {
202*700637cbSDimitry Andric    if (__binp_ == __ninp_ || !traits_type::eq(__c, __ninp_[-1]))
203*700637cbSDimitry Andric      return pbackfail(traits_type::to_int_type(__c));
204*700637cbSDimitry Andric    return traits_type::to_int_type(*--__ninp_);
205*700637cbSDimitry Andric  }
206*700637cbSDimitry Andric
207*700637cbSDimitry Andric  inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 int_type sungetc() {
208*700637cbSDimitry Andric    if (__binp_ == __ninp_)
209*700637cbSDimitry Andric      return pbackfail();
210*700637cbSDimitry Andric    return traits_type::to_int_type(*--__ninp_);
211*700637cbSDimitry Andric  }
212*700637cbSDimitry Andric
213*700637cbSDimitry Andric  // 27.6.2.2.5 Put area:
214*700637cbSDimitry Andric  inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 int_type sputc(char_type __c) {
215*700637cbSDimitry Andric    if (__nout_ == __eout_)
216*700637cbSDimitry Andric      return overflow(traits_type::to_int_type(__c));
217*700637cbSDimitry Andric    *__nout_++ = __c;
218*700637cbSDimitry Andric    return traits_type::to_int_type(__c);
219*700637cbSDimitry Andric  }
220*700637cbSDimitry Andric
221*700637cbSDimitry Andric  inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 streamsize sputn(const char_type* __s, streamsize __n) {
222*700637cbSDimitry Andric    return xsputn(__s, __n);
223*700637cbSDimitry Andric  }
224*700637cbSDimitry Andric
225*700637cbSDimitry Andricprotected:
226*700637cbSDimitry Andric  basic_streambuf();
227*700637cbSDimitry Andric  basic_streambuf(const basic_streambuf& __rhs);
228*700637cbSDimitry Andric  basic_streambuf& operator=(const basic_streambuf& __rhs);
229*700637cbSDimitry Andric  void swap(basic_streambuf& __rhs);
230*700637cbSDimitry Andric
231*700637cbSDimitry Andric  // 27.6.2.3.2 Get area:
232*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI char_type* eback() const { return __binp_; }
233*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI char_type* gptr() const { return __ninp_; }
234*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI char_type* egptr() const { return __einp_; }
235*700637cbSDimitry Andric
236*700637cbSDimitry Andric  inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 void gbump(int __n) { __ninp_ += __n; }
237*700637cbSDimitry Andric
238*700637cbSDimitry Andric  inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 void setg(char_type* __gbeg, char_type* __gnext, char_type* __gend) {
239*700637cbSDimitry Andric    _LIBCPP_ASSERT_VALID_INPUT_RANGE(std::__is_valid_range(__gbeg, __gnext), "[gbeg, gnext) must be a valid range");
240*700637cbSDimitry Andric    _LIBCPP_ASSERT_VALID_INPUT_RANGE(std::__is_valid_range(__gbeg, __gend), "[gbeg, gend) must be a valid range");
241*700637cbSDimitry Andric    _LIBCPP_ASSERT_VALID_INPUT_RANGE(std::__is_valid_range(__gnext, __gend), "[gnext, gend) must be a valid range");
242*700637cbSDimitry Andric    __binp_ = __gbeg;
243*700637cbSDimitry Andric    __ninp_ = __gnext;
244*700637cbSDimitry Andric    __einp_ = __gend;
245*700637cbSDimitry Andric  }
246*700637cbSDimitry Andric
247*700637cbSDimitry Andric  // 27.6.2.3.3 Put area:
248*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI char_type* pbase() const { return __bout_; }
249*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI char_type* pptr() const { return __nout_; }
250*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI char_type* epptr() const { return __eout_; }
251*700637cbSDimitry Andric
252*700637cbSDimitry Andric  inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 void pbump(int __n) { __nout_ += __n; }
253*700637cbSDimitry Andric
254*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void __pbump(streamsize __n) { __nout_ += __n; }
255*700637cbSDimitry Andric
256*700637cbSDimitry Andric  inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 void setp(char_type* __pbeg, char_type* __pend) {
257*700637cbSDimitry Andric    _LIBCPP_ASSERT_VALID_INPUT_RANGE(std::__is_valid_range(__pbeg, __pend), "[pbeg, pend) must be a valid range");
258*700637cbSDimitry Andric    __bout_ = __nout_ = __pbeg;
259*700637cbSDimitry Andric    __eout_           = __pend;
260*700637cbSDimitry Andric  }
261*700637cbSDimitry Andric
262*700637cbSDimitry Andric  // 27.6.2.4 virtual functions:
263*700637cbSDimitry Andric  // 27.6.2.4.1 Locales:
264*700637cbSDimitry Andric  virtual void imbue(const locale& __loc);
265*700637cbSDimitry Andric
266*700637cbSDimitry Andric  // 27.6.2.4.2 Buffer management and positioning:
267*700637cbSDimitry Andric  virtual basic_streambuf* setbuf(char_type* __s, streamsize __n);
268*700637cbSDimitry Andric  virtual pos_type
269*700637cbSDimitry Andric  seekoff(off_type __off, ios_base::seekdir __way, ios_base::openmode __which = ios_base::in | ios_base::out);
270*700637cbSDimitry Andric  virtual pos_type seekpos(pos_type __sp, ios_base::openmode __which = ios_base::in | ios_base::out);
271*700637cbSDimitry Andric  virtual int sync();
272*700637cbSDimitry Andric
273*700637cbSDimitry Andric  // 27.6.2.4.3 Get area:
274*700637cbSDimitry Andric  virtual streamsize showmanyc();
275*700637cbSDimitry Andric  virtual streamsize xsgetn(char_type* __s, streamsize __n);
276*700637cbSDimitry Andric  virtual int_type underflow();
277*700637cbSDimitry Andric  virtual int_type uflow();
278*700637cbSDimitry Andric
279*700637cbSDimitry Andric  // 27.6.2.4.4 Putback:
280*700637cbSDimitry Andric  virtual int_type pbackfail(int_type __c = traits_type::eof());
281*700637cbSDimitry Andric
282*700637cbSDimitry Andric  // 27.6.2.4.5 Put area:
283*700637cbSDimitry Andric  virtual streamsize xsputn(const char_type* __s, streamsize __n);
284*700637cbSDimitry Andric  virtual int_type overflow(int_type __c = traits_type::eof());
285*700637cbSDimitry Andric
286*700637cbSDimitry Andricprivate:
287*700637cbSDimitry Andric  locale __loc_;
288*700637cbSDimitry Andric  char_type* __binp_;
289*700637cbSDimitry Andric  char_type* __ninp_;
290*700637cbSDimitry Andric  char_type* __einp_;
291*700637cbSDimitry Andric  char_type* __bout_;
292*700637cbSDimitry Andric  char_type* __nout_;
293*700637cbSDimitry Andric  char_type* __eout_;
294*700637cbSDimitry Andric};
295*700637cbSDimitry Andric
296*700637cbSDimitry Andrictemplate <class _CharT, class _Traits>
297*700637cbSDimitry Andricbasic_streambuf<_CharT, _Traits>::~basic_streambuf() {}
298*700637cbSDimitry Andric
299*700637cbSDimitry Andrictemplate <class _CharT, class _Traits>
300*700637cbSDimitry Andricbasic_streambuf<_CharT, _Traits>::basic_streambuf()
301*700637cbSDimitry Andric    : __binp_(nullptr), __ninp_(nullptr), __einp_(nullptr), __bout_(nullptr), __nout_(nullptr), __eout_(nullptr) {}
302*700637cbSDimitry Andric
303*700637cbSDimitry Andrictemplate <class _CharT, class _Traits>
304*700637cbSDimitry Andricbasic_streambuf<_CharT, _Traits>::basic_streambuf(const basic_streambuf& __sb)
305*700637cbSDimitry Andric    : __loc_(__sb.__loc_),
306*700637cbSDimitry Andric      __binp_(__sb.__binp_),
307*700637cbSDimitry Andric      __ninp_(__sb.__ninp_),
308*700637cbSDimitry Andric      __einp_(__sb.__einp_),
309*700637cbSDimitry Andric      __bout_(__sb.__bout_),
310*700637cbSDimitry Andric      __nout_(__sb.__nout_),
311*700637cbSDimitry Andric      __eout_(__sb.__eout_) {}
312*700637cbSDimitry Andric
313*700637cbSDimitry Andrictemplate <class _CharT, class _Traits>
314*700637cbSDimitry Andricbasic_streambuf<_CharT, _Traits>& basic_streambuf<_CharT, _Traits>::operator=(const basic_streambuf& __sb) {
315*700637cbSDimitry Andric  __loc_  = __sb.__loc_;
316*700637cbSDimitry Andric  __binp_ = __sb.__binp_;
317*700637cbSDimitry Andric  __ninp_ = __sb.__ninp_;
318*700637cbSDimitry Andric  __einp_ = __sb.__einp_;
319*700637cbSDimitry Andric  __bout_ = __sb.__bout_;
320*700637cbSDimitry Andric  __nout_ = __sb.__nout_;
321*700637cbSDimitry Andric  __eout_ = __sb.__eout_;
322*700637cbSDimitry Andric  return *this;
323*700637cbSDimitry Andric}
324*700637cbSDimitry Andric
325*700637cbSDimitry Andrictemplate <class _CharT, class _Traits>
326*700637cbSDimitry Andricvoid basic_streambuf<_CharT, _Traits>::swap(basic_streambuf& __sb) {
327*700637cbSDimitry Andric  std::swap(__loc_, __sb.__loc_);
328*700637cbSDimitry Andric  std::swap(__binp_, __sb.__binp_);
329*700637cbSDimitry Andric  std::swap(__ninp_, __sb.__ninp_);
330*700637cbSDimitry Andric  std::swap(__einp_, __sb.__einp_);
331*700637cbSDimitry Andric  std::swap(__bout_, __sb.__bout_);
332*700637cbSDimitry Andric  std::swap(__nout_, __sb.__nout_);
333*700637cbSDimitry Andric  std::swap(__eout_, __sb.__eout_);
334*700637cbSDimitry Andric}
335*700637cbSDimitry Andric
336*700637cbSDimitry Andrictemplate <class _CharT, class _Traits>
337*700637cbSDimitry Andricvoid basic_streambuf<_CharT, _Traits>::imbue(const locale&) {}
338*700637cbSDimitry Andric
339*700637cbSDimitry Andrictemplate <class _CharT, class _Traits>
340*700637cbSDimitry Andricbasic_streambuf<_CharT, _Traits>* basic_streambuf<_CharT, _Traits>::setbuf(char_type*, streamsize) {
341*700637cbSDimitry Andric  return this;
342*700637cbSDimitry Andric}
343*700637cbSDimitry Andric
344*700637cbSDimitry Andrictemplate <class _CharT, class _Traits>
345*700637cbSDimitry Andrictypename basic_streambuf<_CharT, _Traits>::pos_type
346*700637cbSDimitry Andricbasic_streambuf<_CharT, _Traits>::seekoff(off_type, ios_base::seekdir, ios_base::openmode) {
347*700637cbSDimitry Andric  return pos_type(off_type(-1));
348*700637cbSDimitry Andric}
349*700637cbSDimitry Andric
350*700637cbSDimitry Andrictemplate <class _CharT, class _Traits>
351*700637cbSDimitry Andrictypename basic_streambuf<_CharT, _Traits>::pos_type
352*700637cbSDimitry Andricbasic_streambuf<_CharT, _Traits>::seekpos(pos_type, ios_base::openmode) {
353*700637cbSDimitry Andric  return pos_type(off_type(-1));
354*700637cbSDimitry Andric}
355*700637cbSDimitry Andric
356*700637cbSDimitry Andrictemplate <class _CharT, class _Traits>
357*700637cbSDimitry Andricint basic_streambuf<_CharT, _Traits>::sync() {
358*700637cbSDimitry Andric  return 0;
359*700637cbSDimitry Andric}
360*700637cbSDimitry Andric
361*700637cbSDimitry Andrictemplate <class _CharT, class _Traits>
362*700637cbSDimitry Andricstreamsize basic_streambuf<_CharT, _Traits>::showmanyc() {
363*700637cbSDimitry Andric  return 0;
364*700637cbSDimitry Andric}
365*700637cbSDimitry Andric
366*700637cbSDimitry Andrictemplate <class _CharT, class _Traits>
367*700637cbSDimitry Andricstreamsize basic_streambuf<_CharT, _Traits>::xsgetn(char_type* __s, streamsize __n) {
368*700637cbSDimitry Andric  const int_type __eof = traits_type::eof();
369*700637cbSDimitry Andric  int_type __c;
370*700637cbSDimitry Andric  streamsize __i = 0;
371*700637cbSDimitry Andric  while (__i < __n) {
372*700637cbSDimitry Andric    if (__ninp_ < __einp_) {
373*700637cbSDimitry Andric      const streamsize __len = std::min(static_cast<streamsize>(INT_MAX), std::min(__einp_ - __ninp_, __n - __i));
374*700637cbSDimitry Andric      traits_type::copy(__s, __ninp_, __len);
375*700637cbSDimitry Andric      __s += __len;
376*700637cbSDimitry Andric      __i += __len;
377*700637cbSDimitry Andric      this->gbump(__len);
378*700637cbSDimitry Andric    } else if ((__c = uflow()) != __eof) {
379*700637cbSDimitry Andric      *__s = traits_type::to_char_type(__c);
380*700637cbSDimitry Andric      ++__s;
381*700637cbSDimitry Andric      ++__i;
382*700637cbSDimitry Andric    } else
383*700637cbSDimitry Andric      break;
384*700637cbSDimitry Andric  }
385*700637cbSDimitry Andric  return __i;
386*700637cbSDimitry Andric}
387*700637cbSDimitry Andric
388*700637cbSDimitry Andrictemplate <class _CharT, class _Traits>
389*700637cbSDimitry Andrictypename basic_streambuf<_CharT, _Traits>::int_type basic_streambuf<_CharT, _Traits>::underflow() {
390*700637cbSDimitry Andric  return traits_type::eof();
391*700637cbSDimitry Andric}
392*700637cbSDimitry Andric
393*700637cbSDimitry Andrictemplate <class _CharT, class _Traits>
394*700637cbSDimitry Andrictypename basic_streambuf<_CharT, _Traits>::int_type basic_streambuf<_CharT, _Traits>::uflow() {
395*700637cbSDimitry Andric  if (underflow() == traits_type::eof())
396*700637cbSDimitry Andric    return traits_type::eof();
397*700637cbSDimitry Andric  return traits_type::to_int_type(*__ninp_++);
398*700637cbSDimitry Andric}
399*700637cbSDimitry Andric
400*700637cbSDimitry Andrictemplate <class _CharT, class _Traits>
401*700637cbSDimitry Andrictypename basic_streambuf<_CharT, _Traits>::int_type basic_streambuf<_CharT, _Traits>::pbackfail(int_type) {
402*700637cbSDimitry Andric  return traits_type::eof();
403*700637cbSDimitry Andric}
404*700637cbSDimitry Andric
405*700637cbSDimitry Andrictemplate <class _CharT, class _Traits>
406*700637cbSDimitry Andricstreamsize basic_streambuf<_CharT, _Traits>::xsputn(const char_type* __s, streamsize __n) {
407*700637cbSDimitry Andric  streamsize __i = 0;
408*700637cbSDimitry Andric  int_type __eof = traits_type::eof();
409*700637cbSDimitry Andric  while (__i < __n) {
410*700637cbSDimitry Andric    if (__nout_ >= __eout_) {
411*700637cbSDimitry Andric      if (overflow(traits_type::to_int_type(*__s)) == __eof)
412*700637cbSDimitry Andric        break;
413*700637cbSDimitry Andric      ++__s;
414*700637cbSDimitry Andric      ++__i;
415*700637cbSDimitry Andric    } else {
416*700637cbSDimitry Andric      streamsize __chunk_size = std::min(__eout_ - __nout_, __n - __i);
417*700637cbSDimitry Andric      traits_type::copy(__nout_, __s, __chunk_size);
418*700637cbSDimitry Andric      __nout_ += __chunk_size;
419*700637cbSDimitry Andric      __s += __chunk_size;
420*700637cbSDimitry Andric      __i += __chunk_size;
421*700637cbSDimitry Andric    }
422*700637cbSDimitry Andric  }
423*700637cbSDimitry Andric  return __i;
424*700637cbSDimitry Andric}
425*700637cbSDimitry Andric
426*700637cbSDimitry Andrictemplate <class _CharT, class _Traits>
427*700637cbSDimitry Andrictypename basic_streambuf<_CharT, _Traits>::int_type basic_streambuf<_CharT, _Traits>::overflow(int_type) {
428*700637cbSDimitry Andric  return traits_type::eof();
429*700637cbSDimitry Andric}
430*700637cbSDimitry Andric
431*700637cbSDimitry Andricextern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_streambuf<char>;
432*700637cbSDimitry Andric
433*700637cbSDimitry Andric#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
434*700637cbSDimitry Andricextern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_streambuf<wchar_t>;
435*700637cbSDimitry Andric#endif
436*700637cbSDimitry Andric
437*700637cbSDimitry Andric_LIBCPP_END_NAMESPACE_STD
438*700637cbSDimitry Andric
439*700637cbSDimitry Andric_LIBCPP_POP_MACROS
440*700637cbSDimitry Andric
441*700637cbSDimitry Andric#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES)
442*700637cbSDimitry Andric#  include <__cxx03/cstdint>
443*700637cbSDimitry Andric#endif
444*700637cbSDimitry Andric
445*700637cbSDimitry Andric#endif // _LIBCPP___CXX03_STREAMBUF
446