00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #ifndef _SSTREAM_TCC
00037 #define _SSTREAM_TCC 1
00038
00039 #pragma GCC system_header
00040
00041 namespace std _GLIBCXX_VISIBILITY(default)
00042 {
00043 _GLIBCXX_BEGIN_NAMESPACE_VERSION
00044
00045 template <class _CharT, class _Traits, class _Alloc>
00046 typename basic_stringbuf<_CharT, _Traits, _Alloc>::int_type
00047 basic_stringbuf<_CharT, _Traits, _Alloc>::
00048 pbackfail(int_type __c)
00049 {
00050 int_type __ret = traits_type::eof();
00051 if (this->eback() < this->gptr())
00052 {
00053
00054
00055 const bool __testeof = traits_type::eq_int_type(__c, __ret);
00056 if (!__testeof)
00057 {
00058 const bool __testeq = traits_type::eq(traits_type::
00059 to_char_type(__c),
00060 this->gptr()[-1]);
00061 const bool __testout = this->_M_mode & ios_base::out;
00062 if (__testeq || __testout)
00063 {
00064 this->gbump(-1);
00065 if (!__testeq)
00066 *this->gptr() = traits_type::to_char_type(__c);
00067 __ret = __c;
00068 }
00069 }
00070 else
00071 {
00072 this->gbump(-1);
00073 __ret = traits_type::not_eof(__c);
00074 }
00075 }
00076 return __ret;
00077 }
00078
00079 template <class _CharT, class _Traits, class _Alloc>
00080 typename basic_stringbuf<_CharT, _Traits, _Alloc>::int_type
00081 basic_stringbuf<_CharT, _Traits, _Alloc>::
00082 overflow(int_type __c)
00083 {
00084 const bool __testout = this->_M_mode & ios_base::out;
00085 if (__builtin_expect(!__testout, false))
00086 return traits_type::eof();
00087
00088 const bool __testeof = traits_type::eq_int_type(__c, traits_type::eof());
00089 if (__builtin_expect(__testeof, false))
00090 return traits_type::not_eof(__c);
00091
00092 const __size_type __capacity = _M_string.capacity();
00093 const __size_type __max_size = _M_string.max_size();
00094 const bool __testput = this->pptr() < this->epptr();
00095 if (__builtin_expect(!__testput && __capacity == __max_size, false))
00096 return traits_type::eof();
00097
00098
00099
00100 const char_type __conv = traits_type::to_char_type(__c);
00101 if (!__testput)
00102 {
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112 const __size_type __opt_len = std::max(__size_type(2 * __capacity),
00113 __size_type(512));
00114 const __size_type __len = std::min(__opt_len, __max_size);
00115 __string_type __tmp;
00116 __tmp.reserve(__len);
00117 if (this->pbase())
00118 __tmp.assign(this->pbase(), this->epptr() - this->pbase());
00119 __tmp.push_back(__conv);
00120 _M_string.swap(__tmp);
00121 _M_sync(const_cast<char_type*>(_M_string.data()),
00122 this->gptr() - this->eback(), this->pptr() - this->pbase());
00123 }
00124 else
00125 *this->pptr() = __conv;
00126 this->pbump(1);
00127 return __c;
00128 }
00129
00130 template <class _CharT, class _Traits, class _Alloc>
00131 typename basic_stringbuf<_CharT, _Traits, _Alloc>::int_type
00132 basic_stringbuf<_CharT, _Traits, _Alloc>::
00133 underflow()
00134 {
00135 int_type __ret = traits_type::eof();
00136 const bool __testin = this->_M_mode & ios_base::in;
00137 if (__testin)
00138 {
00139
00140 _M_update_egptr();
00141
00142 if (this->gptr() < this->egptr())
00143 __ret = traits_type::to_int_type(*this->gptr());
00144 }
00145 return __ret;
00146 }
00147
00148 template <class _CharT, class _Traits, class _Alloc>
00149 typename basic_stringbuf<_CharT, _Traits, _Alloc>::pos_type
00150 basic_stringbuf<_CharT, _Traits, _Alloc>::
00151 seekoff(off_type __off, ios_base::seekdir __way, ios_base::openmode __mode)
00152 {
00153 pos_type __ret = pos_type(off_type(-1));
00154 bool __testin = (ios_base::in & this->_M_mode & __mode) != 0;
00155 bool __testout = (ios_base::out & this->_M_mode & __mode) != 0;
00156 const bool __testboth = __testin && __testout && __way != ios_base::cur;
00157 __testin &= !(__mode & ios_base::out);
00158 __testout &= !(__mode & ios_base::in);
00159
00160
00161
00162 const char_type* __beg = __testin ? this->eback() : this->pbase();
00163 if ((__beg || !__off) && (__testin || __testout || __testboth))
00164 {
00165 _M_update_egptr();
00166
00167 off_type __newoffi = __off;
00168 off_type __newoffo = __newoffi;
00169 if (__way == ios_base::cur)
00170 {
00171 __newoffi += this->gptr() - __beg;
00172 __newoffo += this->pptr() - __beg;
00173 }
00174 else if (__way == ios_base::end)
00175 __newoffo = __newoffi += this->egptr() - __beg;
00176
00177 if ((__testin || __testboth)
00178 && __newoffi >= 0
00179 && this->egptr() - __beg >= __newoffi)
00180 {
00181 this->setg(this->eback(), this->eback() + __newoffi,
00182 this->egptr());
00183 __ret = pos_type(__newoffi);
00184 }
00185 if ((__testout || __testboth)
00186 && __newoffo >= 0
00187 && this->egptr() - __beg >= __newoffo)
00188 {
00189 _M_pbump(this->pbase(), this->epptr(), __newoffo);
00190 __ret = pos_type(__newoffo);
00191 }
00192 }
00193 return __ret;
00194 }
00195
00196 template <class _CharT, class _Traits, class _Alloc>
00197 typename basic_stringbuf<_CharT, _Traits, _Alloc>::pos_type
00198 basic_stringbuf<_CharT, _Traits, _Alloc>::
00199 seekpos(pos_type __sp, ios_base::openmode __mode)
00200 {
00201 pos_type __ret = pos_type(off_type(-1));
00202 const bool __testin = (ios_base::in & this->_M_mode & __mode) != 0;
00203 const bool __testout = (ios_base::out & this->_M_mode & __mode) != 0;
00204
00205 const char_type* __beg = __testin ? this->eback() : this->pbase();
00206 if ((__beg || !off_type(__sp)) && (__testin || __testout))
00207 {
00208 _M_update_egptr();
00209
00210 const off_type __pos(__sp);
00211 const bool __testpos = (0 <= __pos
00212 && __pos <= this->egptr() - __beg);
00213 if (__testpos)
00214 {
00215 if (__testin)
00216 this->setg(this->eback(), this->eback() + __pos,
00217 this->egptr());
00218 if (__testout)
00219 _M_pbump(this->pbase(), this->epptr(), __pos);
00220 __ret = __sp;
00221 }
00222 }
00223 return __ret;
00224 }
00225
00226 template <class _CharT, class _Traits, class _Alloc>
00227 void
00228 basic_stringbuf<_CharT, _Traits, _Alloc>::
00229 _M_sync(char_type* __base, __size_type __i, __size_type __o)
00230 {
00231 const bool __testin = _M_mode & ios_base::in;
00232 const bool __testout = _M_mode & ios_base::out;
00233 char_type* __endg = __base + _M_string.size();
00234 char_type* __endp = __base + _M_string.capacity();
00235
00236 if (__base != _M_string.data())
00237 {
00238
00239 __endg += __i;
00240 __i = 0;
00241 __endp = __endg;
00242 }
00243
00244 if (__testin)
00245 this->setg(__base, __base + __i, __endg);
00246 if (__testout)
00247 {
00248 _M_pbump(__base, __endp, __o);
00249
00250
00251
00252 if (!__testin)
00253 this->setg(__endg, __endg, __endg);
00254 }
00255 }
00256
00257 template <class _CharT, class _Traits, class _Alloc>
00258 void
00259 basic_stringbuf<_CharT, _Traits, _Alloc>::
00260 _M_pbump(char_type* __pbeg, char_type* __pend, off_type __off)
00261 {
00262 this->setp(__pbeg, __pend);
00263 while (__off > __gnu_cxx::__numeric_traits<int>::__max)
00264 {
00265 this->pbump(__gnu_cxx::__numeric_traits<int>::__max);
00266 __off -= __gnu_cxx::__numeric_traits<int>::__max;
00267 }
00268 this->pbump(__off);
00269 }
00270
00271
00272
00273
00274 #if _GLIBCXX_EXTERN_TEMPLATE
00275 extern template class basic_stringbuf<char>;
00276 extern template class basic_istringstream<char>;
00277 extern template class basic_ostringstream<char>;
00278 extern template class basic_stringstream<char>;
00279
00280 #ifdef _GLIBCXX_USE_WCHAR_T
00281 extern template class basic_stringbuf<wchar_t>;
00282 extern template class basic_istringstream<wchar_t>;
00283 extern template class basic_ostringstream<wchar_t>;
00284 extern template class basic_stringstream<wchar_t>;
00285 #endif
00286 #endif
00287
00288 _GLIBCXX_END_NAMESPACE_VERSION
00289 }
00290
00291 #endif