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->gbump((__beg + __newoffi) - this->gptr());
00182 __ret = pos_type(__newoffi);
00183 }
00184 if ((__testout || __testboth)
00185 && __newoffo >= 0
00186 && this->egptr() - __beg >= __newoffo)
00187 {
00188 this->pbump((__beg + __newoffo) - this->pptr());
00189 __ret = pos_type(__newoffo);
00190 }
00191 }
00192 return __ret;
00193 }
00194
00195 template <class _CharT, class _Traits, class _Alloc>
00196 typename basic_stringbuf<_CharT, _Traits, _Alloc>::pos_type
00197 basic_stringbuf<_CharT, _Traits, _Alloc>::
00198 seekpos(pos_type __sp, ios_base::openmode __mode)
00199 {
00200 pos_type __ret = pos_type(off_type(-1));
00201 const bool __testin = (ios_base::in & this->_M_mode & __mode) != 0;
00202 const bool __testout = (ios_base::out & this->_M_mode & __mode) != 0;
00203
00204 const char_type* __beg = __testin ? this->eback() : this->pbase();
00205 if ((__beg || !off_type(__sp)) && (__testin || __testout))
00206 {
00207 _M_update_egptr();
00208
00209 const off_type __pos(__sp);
00210 const bool __testpos = (0 <= __pos
00211 && __pos <= this->egptr() - __beg);
00212 if (__testpos)
00213 {
00214 if (__testin)
00215 this->gbump((__beg + __pos) - this->gptr());
00216 if (__testout)
00217 this->pbump((__beg + __pos) - this->pptr());
00218 __ret = __sp;
00219 }
00220 }
00221 return __ret;
00222 }
00223
00224 template <class _CharT, class _Traits, class _Alloc>
00225 void
00226 basic_stringbuf<_CharT, _Traits, _Alloc>::
00227 _M_sync(char_type* __base, __size_type __i, __size_type __o)
00228 {
00229 const bool __testin = _M_mode & ios_base::in;
00230 const bool __testout = _M_mode & ios_base::out;
00231 char_type* __endg = __base + _M_string.size();
00232 char_type* __endp = __base + _M_string.capacity();
00233
00234 if (__base != _M_string.data())
00235 {
00236
00237 __endg += __i;
00238 __i = 0;
00239 __endp = __endg;
00240 }
00241
00242 if (__testin)
00243 this->setg(__base, __base + __i, __endg);
00244 if (__testout)
00245 {
00246 this->setp(__base, __endp);
00247 this->pbump(__o);
00248
00249
00250
00251 if (!__testin)
00252 this->setg(__endg, __endg, __endg);
00253 }
00254 }
00255
00256
00257
00258
00259 #if _GLIBCXX_EXTERN_TEMPLATE
00260 extern template class basic_stringbuf<char>;
00261 extern template class basic_istringstream<char>;
00262 extern template class basic_ostringstream<char>;
00263 extern template class basic_stringstream<char>;
00264
00265 #ifdef _GLIBCXX_USE_WCHAR_T
00266 extern template class basic_stringbuf<wchar_t>;
00267 extern template class basic_istringstream<wchar_t>;
00268 extern template class basic_ostringstream<wchar_t>;
00269 extern template class basic_stringstream<wchar_t>;
00270 #endif
00271 #endif
00272
00273 _GLIBCXX_END_NAMESPACE_VERSION
00274 }
00275
00276 #endif