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
00037
00038
00039 #ifndef _GLIBCXX_SSTREAM
00040 #define _GLIBCXX_SSTREAM 1
00041
00042 #pragma GCC system_header
00043
00044 #include <istream>
00045 #include <ostream>
00046
00047 namespace std
00048 {
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061 template<typename _CharT, typename _Traits, typename _Alloc>
00062 class basic_stringbuf : public basic_streambuf<_CharT, _Traits>
00063 {
00064 public:
00065
00066 typedef _CharT char_type;
00067 typedef _Traits traits_type;
00068
00069
00070 typedef _Alloc allocator_type;
00071 typedef typename traits_type::int_type int_type;
00072 typedef typename traits_type::pos_type pos_type;
00073 typedef typename traits_type::off_type off_type;
00074
00075 typedef basic_streambuf<char_type, traits_type> __streambuf_type;
00076 typedef basic_string<char_type, _Traits, _Alloc> __string_type;
00077 typedef typename __string_type::size_type __size_type;
00078
00079 protected:
00080
00081
00082
00083
00084
00085 ios_base::openmode _M_mode;
00086
00087
00088 __string_type _M_string;
00089
00090 public:
00091
00092
00093
00094
00095
00096
00097
00098
00099 explicit
00100 basic_stringbuf(ios_base::openmode __mode = ios_base::in | ios_base::out)
00101 : __streambuf_type(), _M_mode(__mode), _M_string()
00102 { }
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112 explicit
00113 basic_stringbuf(const __string_type& __str,
00114 ios_base::openmode __mode = ios_base::in | ios_base::out)
00115 : __streambuf_type(), _M_mode(), _M_string(__str.data(), __str.size())
00116 { _M_stringbuf_init(__mode); }
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127 __string_type
00128 str() const
00129 {
00130 if (this->pptr())
00131 {
00132
00133 if (this->pptr() > this->egptr())
00134 return __string_type(this->pbase(), this->pptr());
00135 else
00136 return __string_type(this->pbase(), this->egptr());
00137 }
00138 else
00139 return _M_string;
00140 }
00141
00142
00143
00144
00145
00146
00147
00148
00149 void
00150 str(const __string_type& __s)
00151 {
00152
00153 _M_string.assign(__s.data(), __s.size());
00154 _M_stringbuf_init(this->_M_mode);
00155 }
00156
00157 protected:
00158
00159 void
00160 _M_stringbuf_init(ios_base::openmode __mode)
00161 {
00162 this->_M_mode = __mode;
00163
00164 __size_type __len = 0;
00165 if (this->_M_mode & (ios_base::ate | ios_base::app))
00166 __len = _M_string.size();
00167 _M_sync(const_cast<char_type*>(_M_string.data()), 0, __len);
00168 }
00169
00170 virtual int_type
00171 underflow();
00172
00173 virtual int_type
00174 pbackfail(int_type __c = traits_type::eof());
00175
00176 virtual int_type
00177 overflow(int_type __c = traits_type::eof());
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190 virtual __streambuf_type*
00191 setbuf(char_type* __s, streamsize __n)
00192 {
00193 if (__s && __n >= 0)
00194 {
00195
00196
00197
00198
00199
00200
00201 _M_string.assign(__s, __n);
00202
00203
00204 _M_sync(__s, 0, 0);
00205 }
00206 return this;
00207 }
00208
00209 virtual pos_type
00210 seekoff(off_type __off, ios_base::seekdir __way,
00211 ios_base::openmode __mode = ios_base::in | ios_base::out);
00212
00213 virtual pos_type
00214 seekpos(pos_type __sp,
00215 ios_base::openmode __mode = ios_base::in | ios_base::out);
00216
00217
00218
00219
00220
00221
00222
00223 void
00224 _M_sync(char_type* __base, __size_type __i, __size_type __o)
00225 {
00226 const bool __testin = this->_M_mode & ios_base::in;
00227 const bool __testout = this->_M_mode & ios_base::out;
00228 char_type* __end = __base + _M_string.size();
00229
00230 if (__testin)
00231 this->setg(__base, __base + __i, __end);
00232 if (__testout)
00233 {
00234
00235
00236
00237 if (__base == _M_string.data())
00238 this->setp(__base, __base + _M_string.capacity());
00239 else
00240 this->setp(__base, __end);
00241 this->pbump(__o);
00242
00243
00244
00245 if (!__testin)
00246 this->setg(__end, __end, __end);
00247 }
00248 }
00249
00250
00251
00252 void
00253 _M_update_egptr()
00254 {
00255 const bool __testin = this->_M_mode & ios_base::in;
00256
00257 if (this->pptr() && this->pptr() > this->egptr())
00258 if (__testin)
00259 this->setg(this->eback(), this->gptr(), this->pptr());
00260 else
00261 this->setg(this->pptr(), this->pptr(), this->pptr());
00262 }
00263 };
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275 template<typename _CharT, typename _Traits, typename _Alloc>
00276 class basic_istringstream : public basic_istream<_CharT, _Traits>
00277 {
00278 public:
00279
00280 typedef _CharT char_type;
00281 typedef _Traits traits_type;
00282
00283
00284 typedef _Alloc allocator_type;
00285 typedef typename traits_type::int_type int_type;
00286 typedef typename traits_type::pos_type pos_type;
00287 typedef typename traits_type::off_type off_type;
00288
00289
00290 typedef basic_string<_CharT, _Traits, _Alloc> __string_type;
00291 typedef basic_stringbuf<_CharT, _Traits, _Alloc> __stringbuf_type;
00292 typedef basic_istream<char_type, traits_type> __istream_type;
00293
00294 private:
00295 __stringbuf_type _M_stringbuf;
00296
00297 public:
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313 explicit
00314 basic_istringstream(ios_base::openmode __mode = ios_base::in)
00315 : __istream_type(), _M_stringbuf(__mode | ios_base::in)
00316 { this->init(&_M_stringbuf); }
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333 explicit
00334 basic_istringstream(const __string_type& __str,
00335 ios_base::openmode __mode = ios_base::in)
00336 : __istream_type(), _M_stringbuf(__str, __mode | ios_base::in)
00337 { this->init(&_M_stringbuf); }
00338
00339
00340
00341
00342
00343
00344
00345 ~basic_istringstream()
00346 { }
00347
00348
00349
00350
00351
00352
00353
00354
00355 __stringbuf_type*
00356 rdbuf() const
00357 { return const_cast<__stringbuf_type*>(&_M_stringbuf); }
00358
00359
00360
00361
00362
00363 __string_type
00364 str() const
00365 { return _M_stringbuf.str(); }
00366
00367
00368
00369
00370
00371
00372
00373 void
00374 str(const __string_type& __s)
00375 { _M_stringbuf.str(__s); }
00376 };
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388 template <typename _CharT, typename _Traits, typename _Alloc>
00389 class basic_ostringstream : public basic_ostream<_CharT, _Traits>
00390 {
00391 public:
00392
00393 typedef _CharT char_type;
00394 typedef _Traits traits_type;
00395
00396
00397 typedef _Alloc allocator_type;
00398 typedef typename traits_type::int_type int_type;
00399 typedef typename traits_type::pos_type pos_type;
00400 typedef typename traits_type::off_type off_type;
00401
00402
00403 typedef basic_string<_CharT, _Traits, _Alloc> __string_type;
00404 typedef basic_stringbuf<_CharT, _Traits, _Alloc> __stringbuf_type;
00405 typedef basic_ostream<char_type, traits_type> __ostream_type;
00406
00407 private:
00408 __stringbuf_type _M_stringbuf;
00409
00410 public:
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426 explicit
00427 basic_ostringstream(ios_base::openmode __mode = ios_base::out)
00428 : __ostream_type(), _M_stringbuf(__mode | ios_base::out)
00429 { this->init(&_M_stringbuf); }
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446 explicit
00447 basic_ostringstream(const __string_type& __str,
00448 ios_base::openmode __mode = ios_base::out)
00449 : __ostream_type(), _M_stringbuf(__str, __mode | ios_base::out)
00450 { this->init(&_M_stringbuf); }
00451
00452
00453
00454
00455
00456
00457
00458 ~basic_ostringstream()
00459 { }
00460
00461
00462
00463
00464
00465
00466
00467
00468 __stringbuf_type*
00469 rdbuf() const
00470 { return const_cast<__stringbuf_type*>(&_M_stringbuf); }
00471
00472
00473
00474
00475
00476 __string_type
00477 str() const
00478 { return _M_stringbuf.str(); }
00479
00480
00481
00482
00483
00484
00485
00486 void
00487 str(const __string_type& __s)
00488 { _M_stringbuf.str(__s); }
00489 };
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501 template <typename _CharT, typename _Traits, typename _Alloc>
00502 class basic_stringstream : public basic_iostream<_CharT, _Traits>
00503 {
00504 public:
00505
00506 typedef _CharT char_type;
00507 typedef _Traits traits_type;
00508
00509
00510 typedef _Alloc allocator_type;
00511 typedef typename traits_type::int_type int_type;
00512 typedef typename traits_type::pos_type pos_type;
00513 typedef typename traits_type::off_type off_type;
00514
00515
00516 typedef basic_string<_CharT, _Traits, _Alloc> __string_type;
00517 typedef basic_stringbuf<_CharT, _Traits, _Alloc> __stringbuf_type;
00518 typedef basic_iostream<char_type, traits_type> __iostream_type;
00519
00520 private:
00521 __stringbuf_type _M_stringbuf;
00522
00523 public:
00524
00525
00526
00527
00528
00529
00530
00531
00532
00533
00534
00535
00536
00537 explicit
00538 basic_stringstream(ios_base::openmode __m = ios_base::out | ios_base::in)
00539 : __iostream_type(), _M_stringbuf(__m)
00540 { this->init(&_M_stringbuf); }
00541
00542
00543
00544
00545
00546
00547
00548
00549
00550
00551
00552
00553
00554
00555 explicit
00556 basic_stringstream(const __string_type& __str,
00557 ios_base::openmode __m = ios_base::out | ios_base::in)
00558 : __iostream_type(), _M_stringbuf(__str, __m)
00559 { this->init(&_M_stringbuf); }
00560
00561
00562
00563
00564
00565
00566
00567 ~basic_stringstream()
00568 { }
00569
00570
00571
00572
00573
00574
00575
00576
00577 __stringbuf_type*
00578 rdbuf() const
00579 { return const_cast<__stringbuf_type*>(&_M_stringbuf); }
00580
00581
00582
00583
00584
00585 __string_type
00586 str() const
00587 { return _M_stringbuf.str(); }
00588
00589
00590
00591
00592
00593
00594
00595 void
00596 str(const __string_type& __s)
00597 { _M_stringbuf.str(__s); }
00598 };
00599 }
00600
00601 #ifndef _GLIBCXX_EXPORT_TEMPLATE
00602 # include <bits/sstream.tcc>
00603 #endif
00604
00605 #endif