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