35 #define _SSTREAM_TCC 1
37 #pragma GCC system_header
39 namespace 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
45 basic_stringbuf<_CharT, _Traits, _Alloc>::
46 pbackfail(int_type __c)
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
79 basic_stringbuf<_CharT, _Traits, _Alloc>::
80 overflow(int_type __c)
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();
91 const __size_type __max_size = _M_string.max_size();
92 const bool __testput = this->pptr() < this->epptr();
93 if (__builtin_expect(!__testput && __capacity == __max_size,
false))
94 return traits_type::eof();
98 const char_type __conv = traits_type::to_char_type(__c);
110 const __size_type __opt_len =
std::max(__size_type(2 * __capacity),
112 const __size_type __len =
std::min(__opt_len, __max_size);
114 __tmp.reserve(__len);
116 __tmp.assign(this->pbase(), this->epptr() - this->pbase());
117 __tmp.push_back(__conv);
118 _M_string.swap(__tmp);
119 _M_sync(const_cast<char_type*>(_M_string.data()),
120 this->gptr() - this->eback(), this->pptr() - this->pbase());
123 *this->pptr() = __conv;
128 template <
class _CharT,
class _Traits,
class _Alloc>
129 typename basic_stringbuf<_CharT, _Traits, _Alloc>::int_type
133 int_type __ret = traits_type::eof();
140 if (this->gptr() < this->egptr())
141 __ret = traits_type::to_int_type(*this->gptr());
146 template <
class _CharT,
class _Traits,
class _Alloc>
147 typename basic_stringbuf<_CharT, _Traits, _Alloc>::pos_type
149 seekoff(off_type __off, ios_base::seekdir __way, ios_base::openmode __mode)
151 pos_type __ret = pos_type(off_type(-1));
152 bool __testin = (
ios_base::in & this->_M_mode & __mode) != 0;
153 bool __testout = (ios_base::out & this->_M_mode & __mode) != 0;
154 const bool __testboth = __testin && __testout && __way !=
ios_base::cur;
160 const char_type* __beg = __testin ? this->eback() : this->pbase();
161 if ((__beg || !__off) && (__testin || __testout || __testboth))
165 off_type __newoffi = __off;
166 off_type __newoffo = __newoffi;
169 __newoffi += this->gptr() - __beg;
170 __newoffo += this->pptr() - __beg;
173 __newoffo = __newoffi += this->egptr() - __beg;
175 if ((__testin || __testboth)
177 && this->egptr() - __beg >= __newoffi)
179 this->setg(this->eback(), this->eback() + __newoffi,
181 __ret = pos_type(__newoffi);
183 if ((__testout || __testboth)
185 && this->egptr() - __beg >= __newoffo)
187 _M_pbump(this->pbase(), this->epptr(), __newoffo);
188 __ret = pos_type(__newoffo);
194 template <
class _CharT,
class _Traits,
class _Alloc>
195 typename basic_stringbuf<_CharT, _Traits, _Alloc>::pos_type
197 seekpos(pos_type __sp, ios_base::openmode __mode)
199 pos_type __ret = pos_type(off_type(-1));
200 const bool __testin = (
ios_base::in & this->_M_mode & __mode) != 0;
201 const bool __testout = (ios_base::out & this->_M_mode & __mode) != 0;
203 const char_type* __beg = __testin ? this->eback() : this->pbase();
204 if ((__beg || !off_type(__sp)) && (__testin || __testout))
208 const off_type __pos(__sp);
209 const bool __testpos = (0 <= __pos
210 && __pos <= this->egptr() - __beg);
214 this->setg(this->eback(), this->eback() + __pos,
217 _M_pbump(this->pbase(), this->epptr(), __pos);
224 template <
class _CharT,
class _Traits,
class _Alloc>
231 char_type* __endg = __base + _M_string.size();
232 char_type* __endp = __base + _M_string.capacity();
234 if (__base != _M_string.data())
243 this->setg(__base, __base + __i, __endg);
246 _M_pbump(__base, __endp, __o);
251 this->setg(__endg, __endg, __endg);
255 template <
class _CharT,
class _Traits,
class _Alloc>
257 basic_stringbuf<_CharT, _Traits, _Alloc>::
258 _M_pbump(char_type* __pbeg, char_type* __pend, off_type __off)
260 this->setp(__pbeg, __pend);
261 while (__off > __gnu_cxx::__numeric_traits<int>::__max)
263 this->pbump(__gnu_cxx::__numeric_traits<int>::__max);
264 __off -= __gnu_cxx::__numeric_traits<int>::__max;
271 #if _GLIBCXX_EXTERN_TEMPLATE
272 extern template class basic_stringbuf<char>;
273 extern template class basic_istringstream<char>;
274 extern template class basic_ostringstream<char>;
275 extern template class basic_stringstream<char>;
277 #ifdef _GLIBCXX_USE_WCHAR_T
278 extern template class basic_stringbuf<wchar_t>;
279 extern template class basic_istringstream<wchar_t>;
280 extern template class basic_ostringstream<wchar_t>;
281 extern template class basic_stringstream<wchar_t>;
285 _GLIBCXX_END_NAMESPACE_VERSION
The actual work of input and output (for std::string).
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.
static const seekdir end
Request a seek relative to the current end of the sequence.
_GLIBCXX14_CONSTEXPR const _Tp & min(const _Tp &, const _Tp &)
This does what you think it does.
virtual pos_type seekpos(pos_type __sp, ios_base::openmode __mode=ios_base::in|ios_base::out)
Alters the stream positions.
virtual int_type underflow()
Fetches more data from the controlled 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.
static const seekdir cur
Request a seek relative to the current position within the sequence.
_Siter_base< _Iterator >::iterator_type __base(_Iterator __it)
_GLIBCXX14_CONSTEXPR const _Tp & max(const _Tp &, const _Tp &)
This does what you think it does.