37#pragma GCC system_header
39namespace std _GLIBCXX_VISIBILITY(default)
41_GLIBCXX_BEGIN_NAMESPACE_VERSION
43 template <
class _CharT,
class _Traits,
class _Alloc>
44 typename basic_stringbuf<_CharT, _Traits, _Alloc>::int_type
48 int_type __ret = traits_type::eof();
49 if (this->eback() < this->gptr())
53 const bool __testeof = traits_type::eq_int_type(__c, __ret);
56 const bool __testeq = traits_type::eq(traits_type::
60 if (__testeq || __testout)
64 *this->gptr() = traits_type::to_char_type(__c);
71 __ret = traits_type::not_eof(__c);
77 template <
class _CharT,
class _Traits,
class _Alloc>
78 typename basic_stringbuf<_CharT, _Traits, _Alloc>::int_type
83 if (__builtin_expect(!__testout,
false))
84 return traits_type::eof();
86 const bool __testeof = traits_type::eq_int_type(__c, traits_type::eof());
87 if (__builtin_expect(__testeof,
false))
88 return traits_type::not_eof(__c);
90 const __size_type __capacity = _M_string.capacity();
92#if _GLIBCXX_USE_CXX11_ABI
93 if (
size_t(this->epptr() - this->pbase()) < __capacity)
96 char_type* __base =
const_cast<char_type*
>(_M_string.data());
97 _M_pbump(__base, __base + __capacity, this->pptr() - this->pbase());
100 const __size_type __nget = this->gptr() - this->eback();
101 const __size_type __eget = this->egptr() - this->eback();
102 this->setg(__base, __base + __nget, __base + __eget + 1);
104 *this->pptr() = traits_type::to_char_type(__c);
110 const __size_type __max_size = _M_string.max_size();
111 const bool __testput = this->pptr() < this->epptr();
112 if (__builtin_expect(!__testput && __capacity == __max_size,
false))
113 return traits_type::eof();
117 const char_type __conv = traits_type::to_char_type(__c);
129 const __size_type __opt_len =
std::max(__size_type(2 * __capacity),
131 const __size_type __len =
std::min(__opt_len, __max_size);
135 __tmp.
assign(this->pbase(), this->epptr() - this->pbase());
137 _M_string.swap(__tmp);
138 _M_sync(
const_cast<char_type*
>(_M_string.data()),
139 this->gptr() - this->eback(), this->pptr() - this->pbase());
142 *this->pptr() = __conv;
147 template <
class _CharT,
class _Traits,
class _Alloc>
148 typename basic_stringbuf<_CharT, _Traits, _Alloc>::int_type
152 int_type __ret = traits_type::eof();
159 if (this->gptr() < this->egptr())
160 __ret = traits_type::to_int_type(*this->gptr());
165 template <
class _CharT,
class _Traits,
class _Alloc>
166 typename basic_stringbuf<_CharT, _Traits, _Alloc>::pos_type
168 seekoff(off_type __off, ios_base::seekdir __way, ios_base::openmode __mode)
170 pos_type __ret = pos_type(off_type(-1));
171 bool __testin = (
ios_base::in & this->_M_mode & __mode) != 0;
172 bool __testout = (
ios_base::out & this->_M_mode & __mode) != 0;
173 const bool __testboth = __testin && __testout && __way !=
ios_base::cur;
179 const char_type* __beg = __testin ? this->eback() : this->pbase();
180 if ((__beg || !__off) && (__testin || __testout || __testboth))
184 off_type __newoffi = __off;
185 off_type __newoffo = __newoffi;
188 __newoffi += this->gptr() - __beg;
189 __newoffo += this->pptr() - __beg;
192 __newoffo = __newoffi += this->egptr() - __beg;
194 if ((__testin || __testboth)
196 && this->egptr() - __beg >= __newoffi)
198 this->setg(this->eback(), this->eback() + __newoffi,
200 __ret = pos_type(__newoffi);
202 if ((__testout || __testboth)
204 && this->egptr() - __beg >= __newoffo)
206 _M_pbump(this->pbase(), this->epptr(), __newoffo);
207 __ret = pos_type(__newoffo);
213 template <
class _CharT,
class _Traits,
class _Alloc>
214 typename basic_stringbuf<_CharT, _Traits, _Alloc>::pos_type
216 seekpos(pos_type __sp, ios_base::openmode __mode)
218 pos_type __ret = pos_type(off_type(-1));
219 const bool __testin = (
ios_base::in & this->_M_mode & __mode) != 0;
220 const bool __testout = (
ios_base::out & this->_M_mode & __mode) != 0;
222 const char_type* __beg = __testin ? this->eback() : this->pbase();
223 if ((__beg || !off_type(__sp)) && (__testin || __testout))
227 const off_type __pos(__sp);
228 const bool __testpos = (0 <= __pos
229 && __pos <= this->egptr() - __beg);
233 this->setg(this->eback(), this->eback() + __pos,
236 _M_pbump(this->pbase(), this->epptr(), __pos);
243 template <
class _CharT,
class _Traits,
class _Alloc>
246 _M_sync(char_type* __base, __size_type __i, __size_type __o)
250 char_type* __endg = __base + _M_string.size();
251 char_type* __endp = __base + _M_string.capacity();
253 if (__base != _M_string.data())
262 this->setg(__base, __base + __i, __endg);
265 _M_pbump(__base, __endp, __o);
270 this->setg(__endg, __endg, __endg);
274 template <
class _CharT,
class _Traits,
class _Alloc>
276 basic_stringbuf<_CharT, _Traits, _Alloc>::
277 _M_pbump(char_type* __pbeg, char_type* __pend, off_type __off)
279 this->setp(__pbeg, __pend);
280 while (__off > __gnu_cxx::__numeric_traits<int>::__max)
282 this->pbump(__gnu_cxx::__numeric_traits<int>::__max);
283 __off -= __gnu_cxx::__numeric_traits<int>::__max;
290#if _GLIBCXX_EXTERN_TEMPLATE
291 extern template class basic_stringbuf<char>;
292 extern template class basic_istringstream<char>;
293 extern template class basic_ostringstream<char>;
294 extern template class basic_stringstream<char>;
296#ifdef _GLIBCXX_USE_WCHAR_T
297 extern template class basic_stringbuf<wchar_t>;
298 extern template class basic_istringstream<wchar_t>;
299 extern template class basic_ostringstream<wchar_t>;
300 extern template class basic_stringstream<wchar_t>;
304_GLIBCXX_END_NAMESPACE_VERSION
constexpr const _Tp & max(const _Tp &, const _Tp &)
This does what you think it does.
constexpr const _Tp & min(const _Tp &, const _Tp &)
This does what you think it does.
ISO C++ entities toplevel namespace is std.
The actual work of input and output (for std::string).
virtual int_type underflow()
Fetches more data from the controlled sequence.
virtual pos_type seekpos(pos_type __sp, ios_base::openmode __mode=ios_base::in|ios_base::out)
Alters the stream positions.
virtual pos_type seekoff(off_type __off, ios_base::seekdir __way, ios_base::openmode __mode=ios_base::in|ios_base::out)
Alters the stream positions.
virtual int_type overflow(int_type __c=traits_type::eof())
Consumes data from the buffer; writes to the controlled sequence.
virtual int_type pbackfail(int_type __c=traits_type::eof())
Tries to back up the input sequence.
void push_back(_CharT __c)
Append a single character.
void reserve(size_type __res_arg)
Attempt to preallocate enough memory for specified number of characters.
basic_string & assign(const basic_string &__str)
Set value to contents of another string.
static const seekdir cur
Request a seek relative to the current position within the sequence.
static const seekdir end
Request a seek relative to the current end of the sequence.
static const openmode in
Open for input. Default for ifstream and fstream.
static const openmode out
Open for output. Default for ofstream and fstream.