Back to home page

EIC code displayed by LXR

 
 

    


Warning, /include/c++/v1/streambuf is written in an unsupported language. File is not indexed.

0001 // -*- C++ -*-
0002 //===----------------------------------------------------------------------===//
0003 //
0004 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0005 // See https://llvm.org/LICENSE.txt for license information.
0006 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0007 //
0008 //===----------------------------------------------------------------------===//
0009 
0010 #ifndef _LIBCPP_STREAMBUF
0011 #define _LIBCPP_STREAMBUF
0012 
0013 /*
0014     streambuf synopsis
0015 
0016 namespace std
0017 {
0018 
0019 template <class charT, class traits = char_traits<charT> >
0020 class basic_streambuf
0021 {
0022 public:
0023     // types:
0024     typedef charT char_type;
0025     typedef traits traits_type;
0026     typedef typename traits_type::int_type int_type;
0027     typedef typename traits_type::pos_type pos_type;
0028     typedef typename traits_type::off_type off_type;
0029 
0030     virtual ~basic_streambuf();
0031 
0032     // 27.6.2.2.1 locales:
0033     locale pubimbue(const locale& loc);
0034     locale getloc() const;
0035 
0036     // 27.6.2.2.2 buffer and positioning:
0037     basic_streambuf* pubsetbuf(char_type* s, streamsize n);
0038     pos_type pubseekoff(off_type off, ios_base::seekdir way,
0039                         ios_base::openmode which = ios_base::in | ios_base::out);
0040     pos_type pubseekpos(pos_type sp,
0041                         ios_base::openmode which = ios_base::in | ios_base::out);
0042     int pubsync();
0043 
0044     // Get and put areas:
0045     // 27.6.2.2.3 Get area:
0046     streamsize in_avail();
0047     int_type snextc();
0048     int_type sbumpc();
0049     int_type sgetc();
0050     streamsize sgetn(char_type* s, streamsize n);
0051 
0052     // 27.6.2.2.4 Putback:
0053     int_type sputbackc(char_type c);
0054     int_type sungetc();
0055 
0056     // 27.6.2.2.5 Put area:
0057     int_type sputc(char_type c);
0058     streamsize sputn(const char_type* s, streamsize n);
0059 
0060 protected:
0061     basic_streambuf();
0062     basic_streambuf(const basic_streambuf& rhs);
0063     basic_streambuf& operator=(const basic_streambuf& rhs);
0064     void swap(basic_streambuf& rhs);
0065 
0066     // 27.6.2.3.2 Get area:
0067     char_type* eback() const;
0068     char_type* gptr() const;
0069     char_type* egptr() const;
0070     void gbump(int n);
0071     void setg(char_type* gbeg, char_type* gnext, char_type* gend);
0072 
0073     // 27.6.2.3.3 Put area:
0074     char_type* pbase() const;
0075     char_type* pptr() const;
0076     char_type* epptr() const;
0077     void pbump(int n);
0078     void setp(char_type* pbeg, char_type* pend);
0079 
0080     // 27.6.2.4 virtual functions:
0081     // 27.6.2.4.1 Locales:
0082     virtual void imbue(const locale& loc);
0083 
0084     // 27.6.2.4.2 Buffer management and positioning:
0085     virtual basic_streambuf* setbuf(char_type* s, streamsize n);
0086     virtual pos_type seekoff(off_type off, ios_base::seekdir way,
0087                              ios_base::openmode which = ios_base::in | ios_base::out);
0088     virtual pos_type seekpos(pos_type sp,
0089                              ios_base::openmode which = ios_base::in | ios_base::out);
0090     virtual int sync();
0091 
0092     // 27.6.2.4.3 Get area:
0093     virtual streamsize showmanyc();
0094     virtual streamsize xsgetn(char_type* s, streamsize n);
0095     virtual int_type underflow();
0096     virtual int_type uflow();
0097 
0098     // 27.6.2.4.4 Putback:
0099     virtual int_type pbackfail(int_type c = traits_type::eof());
0100 
0101     // 27.6.2.4.5 Put area:
0102     virtual streamsize xsputn(const char_type* s, streamsize n);
0103     virtual int_type overflow (int_type c = traits_type::eof());
0104 };
0105 
0106 }  // std
0107 
0108 */
0109 
0110 #if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
0111 #  include <__cxx03/streambuf>
0112 #else
0113 #  include <__config>
0114 
0115 #  if _LIBCPP_HAS_LOCALIZATION
0116 
0117 #    include <__assert>
0118 #    include <__fwd/streambuf.h>
0119 #    include <__locale>
0120 #    include <__type_traits/is_same.h>
0121 #    include <__utility/is_valid_range.h>
0122 #    include <climits>
0123 #    include <ios>
0124 #    include <iosfwd>
0125 #    include <version>
0126 
0127 #    if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0128 #      pragma GCC system_header
0129 #    endif
0130 
0131 _LIBCPP_PUSH_MACROS
0132 #    include <__undef_macros>
0133 
0134 _LIBCPP_BEGIN_NAMESPACE_STD
0135 
0136 template <class _CharT, class _Traits>
0137 class _LIBCPP_TEMPLATE_VIS basic_streambuf {
0138 public:
0139   // types:
0140   typedef _CharT char_type;
0141   typedef _Traits traits_type;
0142   typedef typename traits_type::int_type int_type;
0143   typedef typename traits_type::pos_type pos_type;
0144   typedef typename traits_type::off_type off_type;
0145 
0146   static_assert(is_same<_CharT, typename traits_type::char_type>::value,
0147                 "traits_type::char_type must be the same type as CharT");
0148 
0149   virtual ~basic_streambuf() {}
0150 
0151   // 27.6.2.2.1 locales:
0152   inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 locale pubimbue(const locale& __loc) {
0153     imbue(__loc);
0154     locale __r = __loc_;
0155     __loc_     = __loc;
0156     return __r;
0157   }
0158 
0159   inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 locale getloc() const { return __loc_; }
0160 
0161   // 27.6.2.2.2 buffer and positioning:
0162   inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 basic_streambuf* pubsetbuf(char_type* __s, streamsize __n) {
0163     return setbuf(__s, __n);
0164   }
0165 
0166   inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 pos_type
0167   pubseekoff(off_type __off, ios_base::seekdir __way, ios_base::openmode __which = ios_base::in | ios_base::out) {
0168     return seekoff(__off, __way, __which);
0169   }
0170 
0171   inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 pos_type
0172   pubseekpos(pos_type __sp, ios_base::openmode __which = ios_base::in | ios_base::out) {
0173     return seekpos(__sp, __which);
0174   }
0175 
0176   inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 int pubsync() { return sync(); }
0177 
0178   // Get and put areas:
0179   // 27.6.2.2.3 Get area:
0180   inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 streamsize in_avail() {
0181     if (__ninp_ < __einp_)
0182       return static_cast<streamsize>(__einp_ - __ninp_);
0183     return showmanyc();
0184   }
0185 
0186   inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 int_type snextc() {
0187     if (sbumpc() == traits_type::eof())
0188       return traits_type::eof();
0189     return sgetc();
0190   }
0191 
0192   inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 int_type sbumpc() {
0193     if (__ninp_ == __einp_)
0194       return uflow();
0195     return traits_type::to_int_type(*__ninp_++);
0196   }
0197 
0198   inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 int_type sgetc() {
0199     if (__ninp_ == __einp_)
0200       return underflow();
0201     return traits_type::to_int_type(*__ninp_);
0202   }
0203 
0204   inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 streamsize sgetn(char_type* __s, streamsize __n) { return xsgetn(__s, __n); }
0205 
0206   // 27.6.2.2.4 Putback:
0207   inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 int_type sputbackc(char_type __c) {
0208     if (__binp_ == __ninp_ || !traits_type::eq(__c, __ninp_[-1]))
0209       return pbackfail(traits_type::to_int_type(__c));
0210     return traits_type::to_int_type(*--__ninp_);
0211   }
0212 
0213   inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 int_type sungetc() {
0214     if (__binp_ == __ninp_)
0215       return pbackfail();
0216     return traits_type::to_int_type(*--__ninp_);
0217   }
0218 
0219   // 27.6.2.2.5 Put area:
0220   inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 int_type sputc(char_type __c) {
0221     if (__nout_ == __eout_)
0222       return overflow(traits_type::to_int_type(__c));
0223     *__nout_++ = __c;
0224     return traits_type::to_int_type(__c);
0225   }
0226 
0227   inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 streamsize sputn(const char_type* __s, streamsize __n) {
0228     return xsputn(__s, __n);
0229   }
0230 
0231 protected:
0232   basic_streambuf() {}
0233   basic_streambuf(const basic_streambuf& __sb)
0234       : __loc_(__sb.__loc_),
0235         __binp_(__sb.__binp_),
0236         __ninp_(__sb.__ninp_),
0237         __einp_(__sb.__einp_),
0238         __bout_(__sb.__bout_),
0239         __nout_(__sb.__nout_),
0240         __eout_(__sb.__eout_) {}
0241 
0242   basic_streambuf& operator=(const basic_streambuf& __sb) {
0243     __loc_  = __sb.__loc_;
0244     __binp_ = __sb.__binp_;
0245     __ninp_ = __sb.__ninp_;
0246     __einp_ = __sb.__einp_;
0247     __bout_ = __sb.__bout_;
0248     __nout_ = __sb.__nout_;
0249     __eout_ = __sb.__eout_;
0250     return *this;
0251   }
0252 
0253   void swap(basic_streambuf& __sb) {
0254     std::swap(__loc_, __sb.__loc_);
0255     std::swap(__binp_, __sb.__binp_);
0256     std::swap(__ninp_, __sb.__ninp_);
0257     std::swap(__einp_, __sb.__einp_);
0258     std::swap(__bout_, __sb.__bout_);
0259     std::swap(__nout_, __sb.__nout_);
0260     std::swap(__eout_, __sb.__eout_);
0261   }
0262 
0263   // 27.6.2.3.2 Get area:
0264   _LIBCPP_HIDE_FROM_ABI char_type* eback() const { return __binp_; }
0265   _LIBCPP_HIDE_FROM_ABI char_type* gptr() const { return __ninp_; }
0266   _LIBCPP_HIDE_FROM_ABI char_type* egptr() const { return __einp_; }
0267 
0268   inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 void gbump(int __n) { __ninp_ += __n; }
0269 
0270   inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 void setg(char_type* __gbeg, char_type* __gnext, char_type* __gend) {
0271     _LIBCPP_ASSERT_VALID_INPUT_RANGE(std::__is_valid_range(__gbeg, __gnext), "[gbeg, gnext) must be a valid range");
0272     _LIBCPP_ASSERT_VALID_INPUT_RANGE(std::__is_valid_range(__gbeg, __gend), "[gbeg, gend) must be a valid range");
0273     _LIBCPP_ASSERT_VALID_INPUT_RANGE(std::__is_valid_range(__gnext, __gend), "[gnext, gend) must be a valid range");
0274     __binp_ = __gbeg;
0275     __ninp_ = __gnext;
0276     __einp_ = __gend;
0277   }
0278 
0279   // 27.6.2.3.3 Put area:
0280   _LIBCPP_HIDE_FROM_ABI char_type* pbase() const { return __bout_; }
0281   _LIBCPP_HIDE_FROM_ABI char_type* pptr() const { return __nout_; }
0282   _LIBCPP_HIDE_FROM_ABI char_type* epptr() const { return __eout_; }
0283 
0284   inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 void pbump(int __n) { __nout_ += __n; }
0285 
0286   _LIBCPP_HIDE_FROM_ABI void __pbump(streamsize __n) { __nout_ += __n; }
0287 
0288   inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 void setp(char_type* __pbeg, char_type* __pend) {
0289     _LIBCPP_ASSERT_VALID_INPUT_RANGE(std::__is_valid_range(__pbeg, __pend), "[pbeg, pend) must be a valid range");
0290     __bout_ = __nout_ = __pbeg;
0291     __eout_           = __pend;
0292   }
0293 
0294   // 27.6.2.4 virtual functions:
0295   // 27.6.2.4.1 Locales:
0296   virtual void imbue(const locale&) {}
0297 
0298   // 27.6.2.4.2 Buffer management and positioning:
0299   virtual basic_streambuf* setbuf(char_type*, streamsize) { return this; }
0300   virtual pos_type seekoff(off_type, ios_base::seekdir, ios_base::openmode = ios_base::in | ios_base::out) {
0301     return pos_type(off_type(-1));
0302   }
0303   virtual pos_type seekpos(pos_type, ios_base::openmode = ios_base::in | ios_base::out) {
0304     return pos_type(off_type(-1));
0305   }
0306   virtual int sync() { return 0; }
0307 
0308   // 27.6.2.4.3 Get area:
0309   virtual streamsize showmanyc() { return 0; }
0310 
0311   virtual streamsize xsgetn(char_type* __s, streamsize __n) {
0312     const int_type __eof = traits_type::eof();
0313     int_type __c;
0314     streamsize __i = 0;
0315     while (__i < __n) {
0316       if (__ninp_ < __einp_) {
0317         const streamsize __len = std::min(static_cast<streamsize>(INT_MAX), std::min(__einp_ - __ninp_, __n - __i));
0318         traits_type::copy(__s, __ninp_, __len);
0319         __s += __len;
0320         __i += __len;
0321         this->gbump(__len);
0322       } else if ((__c = uflow()) != __eof) {
0323         *__s = traits_type::to_char_type(__c);
0324         ++__s;
0325         ++__i;
0326       } else
0327         break;
0328     }
0329     return __i;
0330   }
0331 
0332   virtual int_type underflow() { return traits_type::eof(); }
0333   virtual int_type uflow() {
0334     if (underflow() == traits_type::eof())
0335       return traits_type::eof();
0336     return traits_type::to_int_type(*__ninp_++);
0337   }
0338 
0339   // 27.6.2.4.4 Putback:
0340   virtual int_type pbackfail(int_type = traits_type::eof()) { return traits_type::eof(); }
0341 
0342   // 27.6.2.4.5 Put area:
0343   virtual streamsize xsputn(const char_type* __s, streamsize __n) {
0344     streamsize __i = 0;
0345     int_type __eof = traits_type::eof();
0346     while (__i < __n) {
0347       if (__nout_ >= __eout_) {
0348         if (overflow(traits_type::to_int_type(*__s)) == __eof)
0349           break;
0350         ++__s;
0351         ++__i;
0352       } else {
0353         streamsize __chunk_size = std::min(__eout_ - __nout_, __n - __i);
0354         traits_type::copy(__nout_, __s, __chunk_size);
0355         __nout_ += __chunk_size;
0356         __s += __chunk_size;
0357         __i += __chunk_size;
0358       }
0359     }
0360     return __i;
0361   }
0362 
0363   virtual int_type overflow(int_type = traits_type::eof()) { return traits_type::eof(); }
0364 
0365 private:
0366   locale __loc_;
0367   char_type* __binp_ = nullptr;
0368   char_type* __ninp_ = nullptr;
0369   char_type* __einp_ = nullptr;
0370   char_type* __bout_ = nullptr;
0371   char_type* __nout_ = nullptr;
0372   char_type* __eout_ = nullptr;
0373 };
0374 
0375 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_streambuf<char>;
0376 
0377 #    if _LIBCPP_HAS_WIDE_CHARACTERS
0378 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_streambuf<wchar_t>;
0379 #    endif
0380 
0381 _LIBCPP_END_NAMESPACE_STD
0382 
0383 _LIBCPP_POP_MACROS
0384 
0385 #  endif // _LIBCPP_HAS_LOCALIZATION
0386 
0387 #  if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
0388 #    include <cstdint>
0389 #  endif
0390 #endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
0391 
0392 #endif // _LIBCPP_STREAMBUF