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 void
00248 _M_pbump(char_type* __pbeg, char_type* __pend, off_type __off);
00249 };
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262 template<typename _CharT, typename _Traits, typename _Alloc>
00263 class basic_istringstream : public basic_istream<_CharT, _Traits>
00264 {
00265 public:
00266
00267 typedef _CharT char_type;
00268 typedef _Traits traits_type;
00269
00270
00271 typedef _Alloc allocator_type;
00272 typedef typename traits_type::int_type int_type;
00273 typedef typename traits_type::pos_type pos_type;
00274 typedef typename traits_type::off_type off_type;
00275
00276
00277 typedef basic_string<_CharT, _Traits, _Alloc> __string_type;
00278 typedef basic_stringbuf<_CharT, _Traits, _Alloc> __stringbuf_type;
00279 typedef basic_istream<char_type, traits_type> __istream_type;
00280
00281 private:
00282 __stringbuf_type _M_stringbuf;
00283
00284 public:
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298 explicit
00299 basic_istringstream(ios_base::openmode __mode = ios_base::in)
00300 : __istream_type(), _M_stringbuf(__mode | ios_base::in)
00301 { this->init(&_M_stringbuf); }
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316 explicit
00317 basic_istringstream(const __string_type& __str,
00318 ios_base::openmode __mode = ios_base::in)
00319 : __istream_type(), _M_stringbuf(__str, __mode | ios_base::in)
00320 { this->init(&_M_stringbuf); }
00321
00322
00323
00324
00325
00326
00327
00328 ~basic_istringstream()
00329 { }
00330
00331
00332
00333
00334
00335
00336
00337
00338 __stringbuf_type*
00339 rdbuf() const
00340 { return const_cast<__stringbuf_type*>(&_M_stringbuf); }
00341
00342
00343
00344
00345
00346 __string_type
00347 str() const
00348 { return _M_stringbuf.str(); }
00349
00350
00351
00352
00353
00354
00355
00356 void
00357 str(const __string_type& __s)
00358 { _M_stringbuf.str(__s); }
00359 };
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372 template <typename _CharT, typename _Traits, typename _Alloc>
00373 class basic_ostringstream : public basic_ostream<_CharT, _Traits>
00374 {
00375 public:
00376
00377 typedef _CharT char_type;
00378 typedef _Traits traits_type;
00379
00380
00381 typedef _Alloc allocator_type;
00382 typedef typename traits_type::int_type int_type;
00383 typedef typename traits_type::pos_type pos_type;
00384 typedef typename traits_type::off_type off_type;
00385
00386
00387 typedef basic_string<_CharT, _Traits, _Alloc> __string_type;
00388 typedef basic_stringbuf<_CharT, _Traits, _Alloc> __stringbuf_type;
00389 typedef basic_ostream<char_type, traits_type> __ostream_type;
00390
00391 private:
00392 __stringbuf_type _M_stringbuf;
00393
00394 public:
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408 explicit
00409 basic_ostringstream(ios_base::openmode __mode = ios_base::out)
00410 : __ostream_type(), _M_stringbuf(__mode | ios_base::out)
00411 { this->init(&_M_stringbuf); }
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426 explicit
00427 basic_ostringstream(const __string_type& __str,
00428 ios_base::openmode __mode = ios_base::out)
00429 : __ostream_type(), _M_stringbuf(__str, __mode | ios_base::out)
00430 { this->init(&_M_stringbuf); }
00431
00432
00433
00434
00435
00436
00437
00438 ~basic_ostringstream()
00439 { }
00440
00441
00442
00443
00444
00445
00446
00447
00448 __stringbuf_type*
00449 rdbuf() const
00450 { return const_cast<__stringbuf_type*>(&_M_stringbuf); }
00451
00452
00453
00454
00455
00456 __string_type
00457 str() const
00458 { return _M_stringbuf.str(); }
00459
00460
00461
00462
00463
00464
00465
00466 void
00467 str(const __string_type& __s)
00468 { _M_stringbuf.str(__s); }
00469 };
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482 template <typename _CharT, typename _Traits, typename _Alloc>
00483 class basic_stringstream : public basic_iostream<_CharT, _Traits>
00484 {
00485 public:
00486
00487 typedef _CharT char_type;
00488 typedef _Traits traits_type;
00489
00490
00491 typedef _Alloc allocator_type;
00492 typedef typename traits_type::int_type int_type;
00493 typedef typename traits_type::pos_type pos_type;
00494 typedef typename traits_type::off_type off_type;
00495
00496
00497 typedef basic_string<_CharT, _Traits, _Alloc> __string_type;
00498 typedef basic_stringbuf<_CharT, _Traits, _Alloc> __stringbuf_type;
00499 typedef basic_iostream<char_type, traits_type> __iostream_type;
00500
00501 private:
00502 __stringbuf_type _M_stringbuf;
00503
00504 public:
00505
00506
00507
00508
00509
00510
00511
00512
00513
00514
00515
00516 explicit
00517 basic_stringstream(ios_base::openmode __m = ios_base::out | ios_base::in)
00518 : __iostream_type(), _M_stringbuf(__m)
00519 { this->init(&_M_stringbuf); }
00520
00521
00522
00523
00524
00525
00526
00527
00528
00529
00530
00531
00532 explicit
00533 basic_stringstream(const __string_type& __str,
00534 ios_base::openmode __m = ios_base::out | ios_base::in)
00535 : __iostream_type(), _M_stringbuf(__str, __m)
00536 { this->init(&_M_stringbuf); }
00537
00538
00539
00540
00541
00542
00543
00544 ~basic_stringstream()
00545 { }
00546
00547
00548
00549
00550
00551
00552
00553
00554 __stringbuf_type*
00555 rdbuf() const
00556 { return const_cast<__stringbuf_type*>(&_M_stringbuf); }
00557
00558
00559
00560
00561
00562 __string_type
00563 str() const
00564 { return _M_stringbuf.str(); }
00565
00566
00567
00568
00569
00570
00571
00572 void
00573 str(const __string_type& __s)
00574 { _M_stringbuf.str(__s); }
00575 };
00576
00577 _GLIBCXX_END_NAMESPACE_VERSION
00578 }
00579
00580 #include <bits/sstream.tcc>
00581
00582 #endif