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
00039
#ifndef _CPP_SSTREAM
00040
#define _CPP_SSTREAM 1
00041
00042
#pragma GCC system_header
00043
00044
#include <istream>
00045
#include <ostream>
00046
00047
namespace std
00048 {
00049
template<
typename _CharT,
typename _Traits,
typename _Alloc>
00050
class basic_stringbuf :
public basic_streambuf<_CharT, _Traits>
00051 {
00052
public:
00053
00054
typedef _CharT char_type;
00055
typedef _Traits traits_type;
00056
#ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
00057
00058
typedef _Alloc allocator_type;
00059
#endif
00060
typedef typename traits_type::int_type int_type;
00061
typedef typename traits_type::pos_type pos_type;
00062
typedef typename traits_type::off_type off_type;
00063
00064
00065
typedef basic_streambuf<char_type, traits_type> __streambuf_type;
00066
typedef basic_string<char_type, _Traits, _Alloc> __string_type;
00067
typedef typename __string_type::size_type __size_type;
00068
00069
protected:
00070
00071 __string_type _M_string;
00072
00073
public:
00074
00075
explicit
00076 basic_stringbuf(ios_base::openmode __mode = ios_base::in | ios_base::out)
00077 : __streambuf_type(), _M_string()
00078 { _M_stringbuf_init(__mode); }
00079
00080
explicit
00081 basic_stringbuf(
const __string_type& __str,
00082 ios_base::openmode __mode = ios_base::in | ios_base::out)
00083 : __streambuf_type(), _M_string(__str.data(), __str.size())
00084 { _M_stringbuf_init(__mode); }
00085
00086
00087 __string_type
00088 str()
const
00089
{
00090
if (_M_mode & ios_base::out)
00091 {
00092
00093
00094
00095
00096 __size_type __len = _M_string.size();
00097
if (_M_out_cur > _M_out_beg)
00098 __len =
max(__size_type(_M_out_end - _M_out_beg), __len);
00099
return __string_type(_M_out_beg, _M_out_beg + __len);
00100 }
00101
else
00102
return _M_string;
00103 }
00104
00105
void
00106 str(
const __string_type& __s)
00107 {
00108
00109 _M_string.assign(__s.data(), __s.size());
00110 _M_stringbuf_init(_M_mode);
00111 }
00112
00113
protected:
00114
00115
void
00116 _M_stringbuf_init(ios_base::openmode __mode)
00117 {
00118
00119
00120
00121
00122
00123 _M_buf_size = _M_string.size();
00124
00125
00126
00127
00128
00129 _M_buf_size_opt = 512;
00130 _M_mode = __mode;
00131
if (_M_mode & (ios_base::ate | ios_base::app))
00132 _M_really_sync(0, _M_buf_size);
00133
else
00134 _M_really_sync(0, 0);
00135 }
00136
00137
00138
virtual int_type
00139 underflow()
00140 {
00141
if (_M_in_cur && _M_in_cur < _M_in_end)
00142
return traits_type::to_int_type(*gptr());
00143
else
00144
return traits_type::eof();
00145 }
00146
00147
virtual int_type
00148 pbackfail(int_type __c = traits_type::eof());
00149
00150
virtual int_type
00151 overflow(int_type __c = traits_type::eof());
00152
00153
virtual __streambuf_type*
00154 setbuf(char_type* __s, streamsize __n)
00155 {
00156
if (__s && __n)
00157 {
00158 _M_string = __string_type(__s, __n);
00159 _M_really_sync(0, 0);
00160 }
00161
return this;
00162 }
00163
00164
virtual pos_type
00165 seekoff(off_type __off, ios_base::seekdir __way,
00166 ios_base::openmode __mode = ios_base::in | ios_base::out);
00167
00168
virtual pos_type
00169 seekpos(pos_type __sp,
00170 ios_base::openmode __mode = ios_base::in | ios_base::out);
00171
00172
00173
00174
00175
00176
00177
00178
virtual int
00179 _M_really_sync(__size_type __i, __size_type __o)
00180 {
00181 char_type* __base = const_cast<char_type*>(_M_string.data());
00182
bool __testin = _M_mode & ios_base::in;
00183
bool __testout = _M_mode & ios_base::out;
00184 __size_type __len = _M_string.size();
00185
00186 _M_buf = __base;
00187
if (__testin)
00188 this->setg(__base, __base + __i, __base + __len);
00189
if (__testout)
00190 {
00191 this->setp(__base, __base + __len);
00192 _M_out_cur += __o;
00193 }
00194
return 0;
00195 }
00196 };
00197
00198
00199
00200
template<
typename _CharT,
typename _Traits,
typename _Alloc>
00201
class basic_istringstream :
public basic_istream<_CharT, _Traits>
00202 {
00203
public:
00204
00205
typedef _CharT char_type;
00206
typedef _Traits traits_type;
00207
#ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
00208
00209
typedef _Alloc allocator_type;
00210
#endif
00211
typedef typename traits_type::int_type int_type;
00212
typedef typename traits_type::pos_type pos_type;
00213
typedef typename traits_type::off_type off_type;
00214
00215
00216
typedef basic_string<_CharT, _Traits, _Alloc> __string_type;
00217
typedef basic_stringbuf<_CharT, _Traits, _Alloc> __stringbuf_type;
00218
typedef basic_istream<char_type, traits_type> __istream_type;
00219
00220
private:
00221 __stringbuf_type _M_stringbuf;
00222
00223
public:
00224
00225
explicit
00226 basic_istringstream(ios_base::openmode __mode = ios_base::in)
00227 : __istream_type(NULL), _M_stringbuf(__mode | ios_base::in)
00228 { this->init(&_M_stringbuf); }
00229
00230
explicit
00231 basic_istringstream(
const __string_type& __str,
00232 ios_base::openmode __mode = ios_base::in)
00233 : __istream_type(NULL), _M_stringbuf(__str, __mode | ios_base::in)
00234 { this->init(&_M_stringbuf); }
00235
00236 ~basic_istringstream()
00237 { }
00238
00239
00240 __stringbuf_type*
00241 rdbuf()
const
00242
{
return const_cast<__stringbuf_type*>(&_M_stringbuf); }
00243
00244 __string_type
00245 str()
const
00246
{
return _M_stringbuf.str(); }
00247
00248
void
00249 str(
const __string_type& __s)
00250 { _M_stringbuf.str(__s); }
00251 };
00252
00253
00254
00255
template <
typename _CharT,
typename _Traits,
typename _Alloc>
00256
class basic_ostringstream :
public basic_ostream<_CharT, _Traits>
00257 {
00258
public:
00259
00260
typedef _CharT char_type;
00261
typedef _Traits traits_type;
00262
#ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
00263
00264
typedef _Alloc allocator_type;
00265
#endif
00266
typedef typename traits_type::int_type int_type;
00267
typedef typename traits_type::pos_type pos_type;
00268
typedef typename traits_type::off_type off_type;
00269
00270
00271
typedef basic_string<_CharT, _Traits, _Alloc> __string_type;
00272
typedef basic_stringbuf<_CharT, _Traits, _Alloc> __stringbuf_type;
00273
typedef basic_ostream<char_type, traits_type> __ostream_type;
00274
00275
private:
00276 __stringbuf_type _M_stringbuf;
00277
00278
public:
00279
00280
explicit
00281 basic_ostringstream(ios_base::openmode __mode = ios_base::out)
00282 : __ostream_type(NULL), _M_stringbuf(__mode | ios_base::out)
00283 { this->init(&_M_stringbuf); }
00284
00285
explicit
00286 basic_ostringstream(
const __string_type& __str,
00287 ios_base::openmode __mode = ios_base::out)
00288 : __ostream_type(NULL), _M_stringbuf(__str, __mode | ios_base::out)
00289 { this->init(&_M_stringbuf); }
00290
00291 ~basic_ostringstream()
00292 { }
00293
00294
00295 __stringbuf_type*
00296 rdbuf()
const
00297
{
return const_cast<__stringbuf_type*>(&_M_stringbuf); }
00298
00299 __string_type
00300 str()
const
00301
{
return _M_stringbuf.str(); }
00302
00303
void
00304 str(
const __string_type& __s)
00305 { _M_stringbuf.str(__s); }
00306 };
00307
00308
00309
00310
template <
typename _CharT,
typename _Traits,
typename _Alloc>
00311
class basic_stringstream :
public basic_iostream<_CharT, _Traits>
00312 {
00313
public:
00314
00315
typedef _CharT char_type;
00316
typedef _Traits traits_type;
00317
#ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
00318
00319
typedef _Alloc allocator_type;
00320
#endif
00321
typedef typename traits_type::int_type int_type;
00322
typedef typename traits_type::pos_type pos_type;
00323
typedef typename traits_type::off_type off_type;
00324
00325
00326
typedef basic_string<_CharT, _Traits, _Alloc> __string_type;
00327
typedef basic_stringbuf<_CharT, _Traits, _Alloc> __stringbuf_type;
00328
typedef basic_iostream<char_type, traits_type> __iostream_type;
00329
00330
private:
00331 __stringbuf_type _M_stringbuf;
00332
00333
public:
00334
00335
explicit
00336 basic_stringstream(ios_base::openmode __m = ios_base::out | ios_base::in)
00337 : __iostream_type(NULL), _M_stringbuf(__m)
00338 { this->init(&_M_stringbuf); }
00339
00340
explicit
00341 basic_stringstream(
const __string_type& __str,
00342 ios_base::openmode __m = ios_base::out | ios_base::in)
00343 : __iostream_type(NULL), _M_stringbuf(__str, __m)
00344 { this->init(&_M_stringbuf); }
00345
00346 ~basic_stringstream()
00347 { }
00348
00349
00350 __stringbuf_type*
00351 rdbuf()
const
00352
{
return const_cast<__stringbuf_type*>(&_M_stringbuf); }
00353
00354 __string_type
00355 str()
const
00356
{
return _M_stringbuf.str(); }
00357
00358
void
00359 str(
const __string_type& __s)
00360 { _M_stringbuf.str(__s); }
00361 };
00362 }
00363
00364
#ifdef _GLIBCPP_NO_TEMPLATE_EXPORT
00365
# define export
00366
#endif
00367
#ifdef _GLIBCPP_FULLY_COMPLIANT_HEADERS
00368
# include <bits/sstream.tcc>
00369
#endif
00370
00371
#endif