Warning, /include/c++/v1/__cxx03/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___CXX03_STREAMBUF
0011 #define _LIBCPP___CXX03_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 #include <__cxx03/__assert>
0111 #include <__cxx03/__config>
0112 #include <__cxx03/__fwd/streambuf.h>
0113 #include <__cxx03/__locale>
0114 #include <__cxx03/__type_traits/is_same.h>
0115 #include <__cxx03/__utility/is_valid_range.h>
0116 #include <__cxx03/climits>
0117 #include <__cxx03/ios>
0118 #include <__cxx03/iosfwd>
0119 #include <__cxx03/version>
0120
0121 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0122 # pragma GCC system_header
0123 #endif
0124
0125 _LIBCPP_PUSH_MACROS
0126 #include <__cxx03/__undef_macros>
0127
0128 _LIBCPP_BEGIN_NAMESPACE_STD
0129
0130 template <class _CharT, class _Traits>
0131 class _LIBCPP_TEMPLATE_VIS basic_streambuf {
0132 public:
0133 // types:
0134 typedef _CharT char_type;
0135 typedef _Traits traits_type;
0136 typedef typename traits_type::int_type int_type;
0137 typedef typename traits_type::pos_type pos_type;
0138 typedef typename traits_type::off_type off_type;
0139
0140 static_assert(is_same<_CharT, typename traits_type::char_type>::value,
0141 "traits_type::char_type must be the same type as CharT");
0142
0143 virtual ~basic_streambuf();
0144
0145 // 27.6.2.2.1 locales:
0146 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 locale pubimbue(const locale& __loc) {
0147 imbue(__loc);
0148 locale __r = __loc_;
0149 __loc_ = __loc;
0150 return __r;
0151 }
0152
0153 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 locale getloc() const { return __loc_; }
0154
0155 // 27.6.2.2.2 buffer and positioning:
0156 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 basic_streambuf* pubsetbuf(char_type* __s, streamsize __n) {
0157 return setbuf(__s, __n);
0158 }
0159
0160 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 pos_type
0161 pubseekoff(off_type __off, ios_base::seekdir __way, ios_base::openmode __which = ios_base::in | ios_base::out) {
0162 return seekoff(__off, __way, __which);
0163 }
0164
0165 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 pos_type
0166 pubseekpos(pos_type __sp, ios_base::openmode __which = ios_base::in | ios_base::out) {
0167 return seekpos(__sp, __which);
0168 }
0169
0170 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 int pubsync() { return sync(); }
0171
0172 // Get and put areas:
0173 // 27.6.2.2.3 Get area:
0174 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 streamsize in_avail() {
0175 if (__ninp_ < __einp_)
0176 return static_cast<streamsize>(__einp_ - __ninp_);
0177 return showmanyc();
0178 }
0179
0180 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 int_type snextc() {
0181 if (sbumpc() == traits_type::eof())
0182 return traits_type::eof();
0183 return sgetc();
0184 }
0185
0186 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 int_type sbumpc() {
0187 if (__ninp_ == __einp_)
0188 return uflow();
0189 return traits_type::to_int_type(*__ninp_++);
0190 }
0191
0192 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 int_type sgetc() {
0193 if (__ninp_ == __einp_)
0194 return underflow();
0195 return traits_type::to_int_type(*__ninp_);
0196 }
0197
0198 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 streamsize sgetn(char_type* __s, streamsize __n) { return xsgetn(__s, __n); }
0199
0200 // 27.6.2.2.4 Putback:
0201 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 int_type sputbackc(char_type __c) {
0202 if (__binp_ == __ninp_ || !traits_type::eq(__c, __ninp_[-1]))
0203 return pbackfail(traits_type::to_int_type(__c));
0204 return traits_type::to_int_type(*--__ninp_);
0205 }
0206
0207 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 int_type sungetc() {
0208 if (__binp_ == __ninp_)
0209 return pbackfail();
0210 return traits_type::to_int_type(*--__ninp_);
0211 }
0212
0213 // 27.6.2.2.5 Put area:
0214 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 int_type sputc(char_type __c) {
0215 if (__nout_ == __eout_)
0216 return overflow(traits_type::to_int_type(__c));
0217 *__nout_++ = __c;
0218 return traits_type::to_int_type(__c);
0219 }
0220
0221 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 streamsize sputn(const char_type* __s, streamsize __n) {
0222 return xsputn(__s, __n);
0223 }
0224
0225 protected:
0226 basic_streambuf();
0227 basic_streambuf(const basic_streambuf& __rhs);
0228 basic_streambuf& operator=(const basic_streambuf& __rhs);
0229 void swap(basic_streambuf& __rhs);
0230
0231 // 27.6.2.3.2 Get area:
0232 _LIBCPP_HIDE_FROM_ABI char_type* eback() const { return __binp_; }
0233 _LIBCPP_HIDE_FROM_ABI char_type* gptr() const { return __ninp_; }
0234 _LIBCPP_HIDE_FROM_ABI char_type* egptr() const { return __einp_; }
0235
0236 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 void gbump(int __n) { __ninp_ += __n; }
0237
0238 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 void setg(char_type* __gbeg, char_type* __gnext, char_type* __gend) {
0239 _LIBCPP_ASSERT_VALID_INPUT_RANGE(std::__is_valid_range(__gbeg, __gnext), "[gbeg, gnext) must be a valid range");
0240 _LIBCPP_ASSERT_VALID_INPUT_RANGE(std::__is_valid_range(__gbeg, __gend), "[gbeg, gend) must be a valid range");
0241 _LIBCPP_ASSERT_VALID_INPUT_RANGE(std::__is_valid_range(__gnext, __gend), "[gnext, gend) must be a valid range");
0242 __binp_ = __gbeg;
0243 __ninp_ = __gnext;
0244 __einp_ = __gend;
0245 }
0246
0247 // 27.6.2.3.3 Put area:
0248 _LIBCPP_HIDE_FROM_ABI char_type* pbase() const { return __bout_; }
0249 _LIBCPP_HIDE_FROM_ABI char_type* pptr() const { return __nout_; }
0250 _LIBCPP_HIDE_FROM_ABI char_type* epptr() const { return __eout_; }
0251
0252 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 void pbump(int __n) { __nout_ += __n; }
0253
0254 _LIBCPP_HIDE_FROM_ABI void __pbump(streamsize __n) { __nout_ += __n; }
0255
0256 inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 void setp(char_type* __pbeg, char_type* __pend) {
0257 _LIBCPP_ASSERT_VALID_INPUT_RANGE(std::__is_valid_range(__pbeg, __pend), "[pbeg, pend) must be a valid range");
0258 __bout_ = __nout_ = __pbeg;
0259 __eout_ = __pend;
0260 }
0261
0262 // 27.6.2.4 virtual functions:
0263 // 27.6.2.4.1 Locales:
0264 virtual void imbue(const locale& __loc);
0265
0266 // 27.6.2.4.2 Buffer management and positioning:
0267 virtual basic_streambuf* setbuf(char_type* __s, streamsize __n);
0268 virtual pos_type
0269 seekoff(off_type __off, ios_base::seekdir __way, ios_base::openmode __which = ios_base::in | ios_base::out);
0270 virtual pos_type seekpos(pos_type __sp, ios_base::openmode __which = ios_base::in | ios_base::out);
0271 virtual int sync();
0272
0273 // 27.6.2.4.3 Get area:
0274 virtual streamsize showmanyc();
0275 virtual streamsize xsgetn(char_type* __s, streamsize __n);
0276 virtual int_type underflow();
0277 virtual int_type uflow();
0278
0279 // 27.6.2.4.4 Putback:
0280 virtual int_type pbackfail(int_type __c = traits_type::eof());
0281
0282 // 27.6.2.4.5 Put area:
0283 virtual streamsize xsputn(const char_type* __s, streamsize __n);
0284 virtual int_type overflow(int_type __c = traits_type::eof());
0285
0286 private:
0287 locale __loc_;
0288 char_type* __binp_;
0289 char_type* __ninp_;
0290 char_type* __einp_;
0291 char_type* __bout_;
0292 char_type* __nout_;
0293 char_type* __eout_;
0294 };
0295
0296 template <class _CharT, class _Traits>
0297 basic_streambuf<_CharT, _Traits>::~basic_streambuf() {}
0298
0299 template <class _CharT, class _Traits>
0300 basic_streambuf<_CharT, _Traits>::basic_streambuf()
0301 : __binp_(nullptr), __ninp_(nullptr), __einp_(nullptr), __bout_(nullptr), __nout_(nullptr), __eout_(nullptr) {}
0302
0303 template <class _CharT, class _Traits>
0304 basic_streambuf<_CharT, _Traits>::basic_streambuf(const basic_streambuf& __sb)
0305 : __loc_(__sb.__loc_),
0306 __binp_(__sb.__binp_),
0307 __ninp_(__sb.__ninp_),
0308 __einp_(__sb.__einp_),
0309 __bout_(__sb.__bout_),
0310 __nout_(__sb.__nout_),
0311 __eout_(__sb.__eout_) {}
0312
0313 template <class _CharT, class _Traits>
0314 basic_streambuf<_CharT, _Traits>& basic_streambuf<_CharT, _Traits>::operator=(const basic_streambuf& __sb) {
0315 __loc_ = __sb.__loc_;
0316 __binp_ = __sb.__binp_;
0317 __ninp_ = __sb.__ninp_;
0318 __einp_ = __sb.__einp_;
0319 __bout_ = __sb.__bout_;
0320 __nout_ = __sb.__nout_;
0321 __eout_ = __sb.__eout_;
0322 return *this;
0323 }
0324
0325 template <class _CharT, class _Traits>
0326 void basic_streambuf<_CharT, _Traits>::swap(basic_streambuf& __sb) {
0327 std::swap(__loc_, __sb.__loc_);
0328 std::swap(__binp_, __sb.__binp_);
0329 std::swap(__ninp_, __sb.__ninp_);
0330 std::swap(__einp_, __sb.__einp_);
0331 std::swap(__bout_, __sb.__bout_);
0332 std::swap(__nout_, __sb.__nout_);
0333 std::swap(__eout_, __sb.__eout_);
0334 }
0335
0336 template <class _CharT, class _Traits>
0337 void basic_streambuf<_CharT, _Traits>::imbue(const locale&) {}
0338
0339 template <class _CharT, class _Traits>
0340 basic_streambuf<_CharT, _Traits>* basic_streambuf<_CharT, _Traits>::setbuf(char_type*, streamsize) {
0341 return this;
0342 }
0343
0344 template <class _CharT, class _Traits>
0345 typename basic_streambuf<_CharT, _Traits>::pos_type
0346 basic_streambuf<_CharT, _Traits>::seekoff(off_type, ios_base::seekdir, ios_base::openmode) {
0347 return pos_type(off_type(-1));
0348 }
0349
0350 template <class _CharT, class _Traits>
0351 typename basic_streambuf<_CharT, _Traits>::pos_type
0352 basic_streambuf<_CharT, _Traits>::seekpos(pos_type, ios_base::openmode) {
0353 return pos_type(off_type(-1));
0354 }
0355
0356 template <class _CharT, class _Traits>
0357 int basic_streambuf<_CharT, _Traits>::sync() {
0358 return 0;
0359 }
0360
0361 template <class _CharT, class _Traits>
0362 streamsize basic_streambuf<_CharT, _Traits>::showmanyc() {
0363 return 0;
0364 }
0365
0366 template <class _CharT, class _Traits>
0367 streamsize basic_streambuf<_CharT, _Traits>::xsgetn(char_type* __s, streamsize __n) {
0368 const int_type __eof = traits_type::eof();
0369 int_type __c;
0370 streamsize __i = 0;
0371 while (__i < __n) {
0372 if (__ninp_ < __einp_) {
0373 const streamsize __len = std::min(static_cast<streamsize>(INT_MAX), std::min(__einp_ - __ninp_, __n - __i));
0374 traits_type::copy(__s, __ninp_, __len);
0375 __s += __len;
0376 __i += __len;
0377 this->gbump(__len);
0378 } else if ((__c = uflow()) != __eof) {
0379 *__s = traits_type::to_char_type(__c);
0380 ++__s;
0381 ++__i;
0382 } else
0383 break;
0384 }
0385 return __i;
0386 }
0387
0388 template <class _CharT, class _Traits>
0389 typename basic_streambuf<_CharT, _Traits>::int_type basic_streambuf<_CharT, _Traits>::underflow() {
0390 return traits_type::eof();
0391 }
0392
0393 template <class _CharT, class _Traits>
0394 typename basic_streambuf<_CharT, _Traits>::int_type basic_streambuf<_CharT, _Traits>::uflow() {
0395 if (underflow() == traits_type::eof())
0396 return traits_type::eof();
0397 return traits_type::to_int_type(*__ninp_++);
0398 }
0399
0400 template <class _CharT, class _Traits>
0401 typename basic_streambuf<_CharT, _Traits>::int_type basic_streambuf<_CharT, _Traits>::pbackfail(int_type) {
0402 return traits_type::eof();
0403 }
0404
0405 template <class _CharT, class _Traits>
0406 streamsize basic_streambuf<_CharT, _Traits>::xsputn(const char_type* __s, streamsize __n) {
0407 streamsize __i = 0;
0408 int_type __eof = traits_type::eof();
0409 while (__i < __n) {
0410 if (__nout_ >= __eout_) {
0411 if (overflow(traits_type::to_int_type(*__s)) == __eof)
0412 break;
0413 ++__s;
0414 ++__i;
0415 } else {
0416 streamsize __chunk_size = std::min(__eout_ - __nout_, __n - __i);
0417 traits_type::copy(__nout_, __s, __chunk_size);
0418 __nout_ += __chunk_size;
0419 __s += __chunk_size;
0420 __i += __chunk_size;
0421 }
0422 }
0423 return __i;
0424 }
0425
0426 template <class _CharT, class _Traits>
0427 typename basic_streambuf<_CharT, _Traits>::int_type basic_streambuf<_CharT, _Traits>::overflow(int_type) {
0428 return traits_type::eof();
0429 }
0430
0431 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_streambuf<char>;
0432
0433 #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
0434 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_streambuf<wchar_t>;
0435 #endif
0436
0437 _LIBCPP_END_NAMESPACE_STD
0438
0439 _LIBCPP_POP_MACROS
0440
0441 #if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
0442 # include <__cxx03/cstdint>
0443 #endif
0444
0445 #endif // _LIBCPP___CXX03_STREAMBUF