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
#pragma GCC system_header
00036
00037
#include <locale>
00038
#include <ostream>
00039
00040
namespace std
00041 {
00042
template<
typename _CharT,
typename _Traits>
00043 basic_istream<_CharT, _Traits>::sentry::
00044 sentry(
basic_istream<_CharT, _Traits>& __in,
bool __noskipws)
00045 {
00046
ios_base::iostate __err =
ios_base::iostate(ios_base::goodbit);
00047
if (__in.
good())
00048 {
00049
if (__in.
tie())
00050 __in.
tie()->flush();
00051
if (!__noskipws && (__in.
flags() & ios_base::skipws))
00052 {
00053
const __int_type __eof = traits_type::eof();
00054 __streambuf_type* __sb = __in.
rdbuf();
00055 __int_type __c = __sb->sgetc();
00056
00057 __in._M_check_facet(__in._M_fctype);
00058
const __ctype_type& __ct = *__in._M_fctype;
00059
while (!traits_type::eq_int_type(__c, __eof)
00060 && __ct.is(ctype_base::space,
00061 traits_type::to_char_type(__c)))
00062 __c = __sb->snextc();
00063
00064
00065
00066
00067
if (traits_type::eq_int_type(__c, __eof))
00068 __err |= ios_base::eofbit;
00069 }
00070 }
00071
00072
if (__in.
good() && __err == ios_base::goodbit)
00073 _M_ok =
true;
00074
else
00075 {
00076 _M_ok =
false;
00077 __err |= ios_base::failbit;
00078 __in.
setstate(__err);
00079 }
00080 }
00081
00082
template<
typename _CharT,
typename _Traits>
00083
basic_istream<_CharT, _Traits>&
00084
basic_istream<_CharT, _Traits>::
00085 operator>>(
__istream_type& (*__pf)(
__istream_type&))
00086 {
return __pf(*
this); }
00087
00088
template<
typename _CharT,
typename _Traits>
00089
basic_istream<_CharT, _Traits>&
00090
basic_istream<_CharT, _Traits>::
00091 operator>>(
__ios_type& (*__pf)(
__ios_type&))
00092 {
00093 __pf(*
this);
00094
return *
this;
00095 }
00096
00097
template<
typename _CharT,
typename _Traits>
00098
basic_istream<_CharT, _Traits>&
00099
basic_istream<_CharT, _Traits>::
00100 operator>>(
ios_base& (*__pf)(
ios_base&))
00101 {
00102 __pf(*
this);
00103
return *
this;
00104 }
00105
00106
template<
typename _CharT,
typename _Traits>
00107
basic_istream<_CharT, _Traits>&
00108
basic_istream<_CharT, _Traits>::
00109 operator>>(
bool& __n)
00110 {
00111
sentry __cerb(*
this,
false);
00112
if (__cerb)
00113 {
00114
ios_base::iostate __err =
ios_base::iostate(ios_base::goodbit);
00115
try
00116 {
00117 _M_check_facet(this->_M_fnumget);
00118
const __numget_type& __ng = *this->_M_fnumget;
00119 __ng.get(*
this, 0, *
this, __err, __n);
00120 }
00121
catch(...)
00122 { this->_M_setstate(ios_base::badbit); }
00123
if (__err)
00124 this->
setstate(__err);
00125 }
00126
return *
this;
00127 }
00128
00129
template<
typename _CharT,
typename _Traits>
00130
basic_istream<_CharT, _Traits>&
00131
basic_istream<_CharT, _Traits>::
00132 operator>>(
short& __n)
00133 {
00134
sentry __cerb(*
this,
false);
00135
if (__cerb)
00136 {
00137
ios_base::iostate __err =
ios_base::iostate(ios_base::goodbit);
00138
try
00139 {
00140
long __l;
00141 _M_check_facet(this->_M_fnumget);
00142
const __numget_type& __ng = *this->_M_fnumget;
00143 __ng.get(*
this, 0, *
this, __err, __l);
00144
00145
00146
if (!(__err & ios_base::failbit)
00147 && (
numeric_limits<short>::min() <= __l
00148 && __l <= numeric_limits<short>::max()))
00149 __n = __l;
00150
else
00151 __err |= ios_base::failbit;
00152 }
00153
catch(...)
00154 { this->_M_setstate(ios_base::badbit); }
00155
if (__err)
00156 this->
setstate(__err);
00157 }
00158
return *
this;
00159 }
00160
00161
template<
typename _CharT,
typename _Traits>
00162
basic_istream<_CharT, _Traits>&
00163
basic_istream<_CharT, _Traits>::
00164 operator>>(
unsigned short& __n)
00165 {
00166
sentry __cerb(*
this,
false);
00167
if (__cerb)
00168 {
00169
ios_base::iostate __err =
ios_base::iostate(ios_base::goodbit);
00170
try
00171 {
00172 _M_check_facet(this->_M_fnumget);
00173
const __numget_type& __ng = *this->_M_fnumget;
00174 __ng.get(*
this, 0, *
this, __err, __n);
00175 }
00176
catch(...)
00177 { this->_M_setstate(ios_base::badbit); }
00178
if (__err)
00179 this->
setstate(__err);
00180 }
00181
return *
this;
00182 }
00183
00184
template<
typename _CharT,
typename _Traits>
00185
basic_istream<_CharT, _Traits>&
00186
basic_istream<_CharT, _Traits>::
00187 operator>>(
int& __n)
00188 {
00189
sentry __cerb(*
this,
false);
00190
if (__cerb)
00191 {
00192
ios_base::iostate __err =
ios_base::iostate(ios_base::goodbit);
00193
try
00194 {
00195
long __l;
00196 _M_check_facet(this->_M_fnumget);
00197
const __numget_type& __ng = *this->_M_fnumget;
00198 __ng.get(*
this, 0, *
this, __err, __l);
00199
00200
00201
if (!(__err & ios_base::failbit)
00202 && (
numeric_limits<int>::min() <= __l
00203 && __l <= numeric_limits<int>::max()))
00204 __n = __l;
00205
else
00206 __err |= ios_base::failbit;
00207 }
00208
catch(...)
00209 { this->_M_setstate(ios_base::badbit); }
00210
if (__err)
00211 this->
setstate(__err);
00212 }
00213
return *
this;
00214 }
00215
00216
template<
typename _CharT,
typename _Traits>
00217
basic_istream<_CharT, _Traits>&
00218
basic_istream<_CharT, _Traits>::
00219 operator>>(
unsigned int& __n)
00220 {
00221
sentry __cerb(*
this,
false);
00222
if (__cerb)
00223 {
00224
ios_base::iostate __err =
ios_base::iostate(ios_base::goodbit);
00225
try
00226 {
00227 _M_check_facet(this->_M_fnumget);
00228
const __numget_type& __ng = *this->_M_fnumget;
00229 __ng.get(*
this, 0, *
this, __err, __n);
00230 }
00231
catch(...)
00232 { this->_M_setstate(ios_base::badbit); }
00233
if (__err)
00234 this->
setstate(__err);
00235 }
00236
return *
this;
00237 }
00238
00239
template<
typename _CharT,
typename _Traits>
00240
basic_istream<_CharT, _Traits>&
00241
basic_istream<_CharT, _Traits>::
00242 operator>>(
long& __n)
00243 {
00244
sentry __cerb(*
this,
false);
00245
if (__cerb)
00246 {
00247
ios_base::iostate __err =
ios_base::iostate(ios_base::goodbit);
00248
try
00249 {
00250 _M_check_facet(this->_M_fnumget);
00251
const __numget_type& __ng = *this->_M_fnumget;
00252 __ng.get(*
this, 0, *
this, __err, __n);
00253 }
00254
catch(...)
00255 { this->_M_setstate(ios_base::badbit); }
00256
if (__err)
00257 this->
setstate(__err);
00258 }
00259
return *
this;
00260 }
00261
00262
template<
typename _CharT,
typename _Traits>
00263
basic_istream<_CharT, _Traits>&
00264
basic_istream<_CharT, _Traits>::
00265 operator>>(
unsigned long& __n)
00266 {
00267
sentry __cerb(*
this,
false);
00268
if (__cerb)
00269 {
00270
ios_base::iostate __err =
ios_base::iostate(ios_base::goodbit);
00271
try
00272 {
00273 _M_check_facet(this->_M_fnumget);
00274
const __numget_type& __ng = *this->_M_fnumget;
00275 __ng.get(*
this, 0, *
this, __err, __n);
00276 }
00277
catch(...)
00278 { this->_M_setstate(ios_base::badbit); }
00279
if (__err)
00280 this->
setstate(__err);
00281 }
00282
return *
this;
00283 }
00284
00285
#ifdef _GLIBCPP_USE_LONG_LONG
00286
template<
typename _CharT,
typename _Traits>
00287
basic_istream<_CharT, _Traits>&
00288
basic_istream<_CharT, _Traits>::
00289
operator>>(
long long& __n)
00290 {
00291 sentry __cerb(*
this,
false);
00292
if (__cerb)
00293 {
00294
ios_base::iostate __err =
ios_base::iostate(ios_base::goodbit);
00295
try
00296 {
00297 _M_check_facet(this->_M_fnumget);
00298
const __numget_type& __ng = *this->_M_fnumget;
00299 __ng.get(*
this, 0, *
this, __err, __n);
00300 }
00301
catch(...)
00302 { this->_M_setstate(ios_base::badbit); }
00303
if (__err)
00304 this->
setstate(__err);
00305 }
00306
return *
this;
00307 }
00308
00309
template<
typename _CharT,
typename _Traits>
00310 basic_istream<_CharT, _Traits>&
00311
basic_istream<_CharT, _Traits>::
00312
operator>>(
unsigned long long& __n)
00313 {
00314 sentry __cerb(*
this,
false);
00315
if (__cerb)
00316 {
00317 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
00318
try
00319 {
00320 _M_check_facet(this->_M_fnumget);
00321
const __numget_type& __ng = *this->_M_fnumget;
00322 __ng.get(*
this, 0, *
this, __err, __n);
00323 }
00324
catch(...)
00325 { this->_M_setstate(ios_base::badbit); }
00326
if (__err)
00327 this->
setstate(__err);
00328 }
00329
return *
this;
00330 }
00331
#endif
00332
00333
template<
typename _CharT,
typename _Traits>
00334 basic_istream<_CharT, _Traits>&
00335
basic_istream<_CharT, _Traits>::
00336 operator>>(
float& __n)
00337 {
00338
sentry __cerb(*
this,
false);
00339
if (__cerb)
00340 {
00341
ios_base::iostate __err =
ios_base::iostate(ios_base::goodbit);
00342
try
00343 {
00344 _M_check_facet(this->_M_fnumget);
00345
const __numget_type& __ng = *this->_M_fnumget;
00346 __ng.get(*
this, 0, *
this, __err, __n);
00347 }
00348
catch(...)
00349 { this->_M_setstate(ios_base::badbit); }
00350
if (__err)
00351 this->
setstate(__err);
00352 }
00353
return *
this;
00354 }
00355
00356
template<
typename _CharT,
typename _Traits>
00357
basic_istream<_CharT, _Traits>&
00358
basic_istream<_CharT, _Traits>::
00359 operator>>(
double& __n)
00360 {
00361
sentry __cerb(*
this,
false);
00362
if (__cerb)
00363 {
00364
ios_base::iostate __err =
ios_base::iostate(ios_base::goodbit);
00365
try
00366 {
00367 _M_check_facet(this->_M_fnumget);
00368
const __numget_type& __ng = *this->_M_fnumget;
00369 __ng.get(*
this, 0, *
this, __err, __n);
00370 }
00371
catch(...)
00372 { this->_M_setstate(ios_base::badbit); }
00373
if (__err)
00374 this->
setstate(__err);
00375 }
00376
return *
this;
00377 }
00378
00379
template<
typename _CharT,
typename _Traits>
00380
basic_istream<_CharT, _Traits>&
00381
basic_istream<_CharT, _Traits>::
00382 operator>>(
long double& __n)
00383 {
00384
sentry __cerb(*
this,
false);
00385
if (__cerb)
00386 {
00387
ios_base::iostate __err =
ios_base::iostate(ios_base::goodbit);
00388
try
00389 {
00390 _M_check_facet(this->_M_fnumget);
00391
const __numget_type& __ng = *this->_M_fnumget;
00392 __ng.get(*
this, 0, *
this, __err, __n);
00393 }
00394
catch(...)
00395 { this->_M_setstate(ios_base::badbit); }
00396
if (__err)
00397 this->
setstate(__err);
00398 }
00399
return *
this;
00400 }
00401
00402
template<
typename _CharT,
typename _Traits>
00403
basic_istream<_CharT, _Traits>&
00404
basic_istream<_CharT, _Traits>::
00405 operator>>(
void*& __n)
00406 {
00407
sentry __cerb(*
this,
false);
00408
if (__cerb)
00409 {
00410
ios_base::iostate __err =
ios_base::iostate(ios_base::goodbit);
00411
try
00412 {
00413 _M_check_facet(this->_M_fnumget);
00414
const __numget_type& __ng = *this->_M_fnumget;
00415 __ng.get(*
this, 0, *
this, __err, __n);
00416 }
00417
catch(...)
00418 { this->_M_setstate(ios_base::badbit); }
00419
if (__err)
00420 this->
setstate(__err);
00421 }
00422
return *
this;
00423 }
00424
00425
template<
typename _CharT,
typename _Traits>
00426
basic_istream<_CharT, _Traits>&
00427
basic_istream<_CharT, _Traits>::
00428 operator>>(__streambuf_type* __sbout)
00429 {
00430
ios_base::iostate __err =
ios_base::iostate(ios_base::goodbit);
00431
sentry __cerb(*
this,
false);
00432
if (__cerb && __sbout)
00433 {
00434
try
00435 {
00436
if (!__copy_streambufs(*
this, this->rdbuf(), __sbout))
00437 __err |= ios_base::failbit;
00438 }
00439
catch(...)
00440 { this->_M_setstate(ios_base::failbit); }
00441 }
00442
else if (!__sbout)
00443 __err |= ios_base::failbit;
00444
if (__err)
00445 this->
setstate(__err);
00446
return *
this;
00447 }
00448
00449
template<
typename _CharT,
typename _Traits>
00450
typename basic_istream<_CharT, _Traits>::int_type
00451
basic_istream<_CharT, _Traits>::
00452 get(
void)
00453 {
00454
const int_type __eof = traits_type::eof();
00455
int_type __c = __eof;
00456 _M_gcount = 0;
00457
ios_base::iostate __err =
ios_base::iostate(ios_base::goodbit);
00458
sentry __cerb(*
this,
true);
00459
if (__cerb)
00460 {
00461
try
00462 {
00463 __c = this->
rdbuf()->sbumpc();
00464
00465
if (!traits_type::eq_int_type(__c, __eof))
00466 _M_gcount = 1;
00467
else
00468 __err |= ios_base::eofbit;
00469 }
00470
catch(...)
00471 { this->_M_setstate(ios_base::badbit); }
00472 }
00473
if (!_M_gcount)
00474 __err |= ios_base::failbit;
00475
if (__err)
00476 this->
setstate(__err);
00477
return __c;
00478 }
00479
00480
template<
typename _CharT,
typename _Traits>
00481
basic_istream<_CharT, _Traits>&
00482
basic_istream<_CharT, _Traits>::
00483 get(
char_type& __c)
00484 {
00485 _M_gcount = 0;
00486
ios_base::iostate __err =
ios_base::iostate(ios_base::goodbit);
00487
sentry __cerb(*
this,
true);
00488
if (__cerb)
00489 {
00490
try
00491 {
00492
int_type __cb = this->
rdbuf()->sbumpc();
00493
00494
if (!traits_type::eq_int_type(__cb, traits_type::eof()))
00495 {
00496 _M_gcount = 1;
00497 __c = traits_type::to_char_type(__cb);
00498 }
00499
else
00500 __err |= ios_base::eofbit;
00501 }
00502
catch(...)
00503 { this->_M_setstate(ios_base::badbit); }
00504 }
00505
if (!_M_gcount)
00506 __err |= ios_base::failbit;
00507
if (__err)
00508 this->
setstate(__err);
00509
return *
this;
00510 }
00511
00512
template<
typename _CharT,
typename _Traits>
00513
basic_istream<_CharT, _Traits>&
00514
basic_istream<_CharT, _Traits>::
00515 get(
char_type* __s, streamsize __n,
char_type __delim)
00516 {
00517 _M_gcount = 0;
00518
ios_base::iostate __err =
ios_base::iostate(ios_base::goodbit);
00519
sentry __cerb(*
this,
true);
00520
if (__cerb)
00521 {
00522
try
00523 {
00524
const int_type __idelim = traits_type::to_int_type(__delim);
00525
const int_type __eof = traits_type::eof();
00526 __streambuf_type* __sb = this->
rdbuf();
00527
int_type __c = __sb->sgetc();
00528
00529
while (_M_gcount + 1 < __n
00530 && !traits_type::eq_int_type(__c, __eof)
00531 && !traits_type::eq_int_type(__c, __idelim))
00532 {
00533 *__s++ = traits_type::to_char_type(__c);
00534 __c = __sb->snextc();
00535 ++_M_gcount;
00536 }
00537
if (traits_type::eq_int_type(__c, __eof))
00538 __err |= ios_base::eofbit;
00539 }
00540
catch(...)
00541 { this->_M_setstate(ios_base::badbit); }
00542 }
00543 *__s =
char_type();
00544
if (!_M_gcount)
00545 __err |= ios_base::failbit;
00546
if (__err)
00547 this->
setstate(__err);
00548
return *
this;
00549 }
00550
00551
template<
typename _CharT,
typename _Traits>
00552
basic_istream<_CharT, _Traits>&
00553
basic_istream<_CharT, _Traits>::
00554 get(__streambuf_type& __sb,
char_type __delim)
00555 {
00556 _M_gcount = 0;
00557
ios_base::iostate __err =
ios_base::iostate(ios_base::goodbit);
00558
sentry __cerb(*
this,
true);
00559
if (__cerb)
00560 {
00561
try
00562 {
00563
const int_type __idelim = traits_type::to_int_type(__delim);
00564
const int_type __eof = traits_type::eof();
00565 __streambuf_type* __this_sb = this->
rdbuf();
00566
int_type __c = __this_sb->sgetc();
00567
char_type __c2 = traits_type::to_char_type(__c);
00568
00569
while (!traits_type::eq_int_type(__c, __eof)
00570 && !traits_type::eq_int_type(__c, __idelim)
00571 && !traits_type::eq_int_type(__sb.sputc(__c2), __eof))
00572 {
00573 ++_M_gcount;
00574 __c = __this_sb->snextc();
00575 __c2 = traits_type::to_char_type(__c);
00576 }
00577
if (traits_type::eq_int_type(__c, __eof))
00578 __err |= ios_base::eofbit;
00579 }
00580
catch(...)
00581 { this->_M_setstate(ios_base::badbit); }
00582 }
00583
if (!_M_gcount)
00584 __err |= ios_base::failbit;
00585
if (__err)
00586 this->
setstate(__err);
00587
return *
this;
00588 }
00589
00590
template<
typename _CharT,
typename _Traits>
00591
basic_istream<_CharT, _Traits>&
00592
basic_istream<_CharT, _Traits>::
00593 getline(
char_type* __s, streamsize __n,
char_type __delim)
00594 {
00595 _M_gcount = 0;
00596
ios_base::iostate __err =
ios_base::iostate(ios_base::goodbit);
00597
sentry __cerb(*
this,
true);
00598
if (__cerb)
00599 {
00600
try
00601 {
00602
const int_type __idelim = traits_type::to_int_type(__delim);
00603
const int_type __eof = traits_type::eof();
00604 __streambuf_type* __sb = this->
rdbuf();
00605
int_type __c = __sb->sgetc();
00606
00607
while (_M_gcount + 1 < __n
00608 && !traits_type::eq_int_type(__c, __eof)
00609 && !traits_type::eq_int_type(__c, __idelim))
00610 {
00611 *__s++ = traits_type::to_char_type(__c);
00612 __c = __sb->snextc();
00613 ++_M_gcount;
00614 }
00615
if (traits_type::eq_int_type(__c, __eof))
00616 __err |= ios_base::eofbit;
00617
else
00618 {
00619
if (traits_type::eq_int_type(__c, __idelim))
00620 {
00621 __sb->sbumpc();
00622 ++_M_gcount;
00623 }
00624
else
00625 __err |= ios_base::failbit;
00626 }
00627 }
00628
catch(...)
00629 { this->_M_setstate(ios_base::badbit); }
00630 }
00631 *__s =
char_type();
00632
if (!_M_gcount)
00633 __err |= ios_base::failbit;
00634
if (__err)
00635 this->
setstate(__err);
00636
return *
this;
00637 }
00638
00639
template<
typename _CharT,
typename _Traits>
00640
basic_istream<_CharT, _Traits>&
00641
basic_istream<_CharT, _Traits>::
00642 ignore(streamsize __n,
int_type __delim)
00643 {
00644 _M_gcount = 0;
00645
sentry __cerb(*
this,
true);
00646
if (__cerb && __n > 0)
00647 {
00648
ios_base::iostate __err =
ios_base::iostate(ios_base::goodbit);
00649
try
00650 {
00651
const int_type __eof = traits_type::eof();
00652 __streambuf_type* __sb = this->
rdbuf();
00653
int_type __c;
00654
00655 __n =
min(__n, numeric_limits<streamsize>::
max());
00656
while (_M_gcount < __n
00657 && !traits_type::eq_int_type(__c = __sb->sbumpc(), __eof))
00658 {
00659 ++_M_gcount;
00660
if (traits_type::eq_int_type(__c, __delim))
00661
break;
00662 }
00663
if (traits_type::eq_int_type(__c, __eof))
00664 __err |= ios_base::eofbit;
00665 }
00666
catch(...)
00667 { this->_M_setstate(ios_base::badbit); }
00668
if (__err)
00669 this->
setstate(__err);
00670 }
00671
return *
this;
00672 }
00673
00674
template<
typename _CharT,
typename _Traits>
00675
typename basic_istream<_CharT, _Traits>::int_type
00676
basic_istream<_CharT, _Traits>::
00677 peek(
void)
00678 {
00679
int_type __c = traits_type::eof();
00680 _M_gcount = 0;
00681
sentry __cerb(*
this,
true);
00682
if (__cerb)
00683 {
00684
ios_base::iostate __err =
ios_base::iostate(ios_base::goodbit);
00685
try
00686 {
00687 __c = this->
rdbuf()->sgetc();
00688
if (traits_type::eq_int_type(__c, traits_type::eof()))
00689 __err |= ios_base::eofbit;
00690 }
00691
catch(...)
00692 { this->_M_setstate(ios_base::badbit); }
00693
if (__err)
00694 this->
setstate(__err);
00695 }
00696
return __c;
00697 }
00698
00699
template<
typename _CharT,
typename _Traits>
00700
basic_istream<_CharT, _Traits>&
00701
basic_istream<_CharT, _Traits>::
00702 read(
char_type* __s, streamsize __n)
00703 {
00704 _M_gcount = 0;
00705
sentry __cerb(*
this,
true);
00706
if (__cerb)
00707 {
00708
ios_base::iostate __err =
ios_base::iostate(ios_base::goodbit);
00709
try
00710 {
00711 _M_gcount = this->
rdbuf()->sgetn(__s, __n);
00712
if (_M_gcount != __n)
00713 __err |= (ios_base::eofbit | ios_base::failbit);
00714 }
00715
catch(...)
00716 { this->_M_setstate(ios_base::badbit); }
00717
if (__err)
00718 this->
setstate(__err);
00719 }
00720
return *
this;
00721 }
00722
00723
template<
typename _CharT,
typename _Traits>
00724 streamsize
00725
basic_istream<_CharT, _Traits>::
00726 readsome(
char_type* __s, streamsize __n)
00727 {
00728 _M_gcount = 0;
00729
sentry __cerb(*
this,
true);
00730
if (__cerb)
00731 {
00732
ios_base::iostate __err =
ios_base::iostate(ios_base::goodbit);
00733
try
00734 {
00735
00736 streamsize __num = this->
rdbuf()->in_avail();
00737
if (__num >= 0)
00738 {
00739 __num =
min(__num, __n);
00740
if (__num)
00741 _M_gcount = this->
rdbuf()->sgetn(__s, __num);
00742 }
00743
else
00744 __err |= ios_base::eofbit;
00745 }
00746
catch(...)
00747 { this->_M_setstate(ios_base::badbit); }
00748
if (__err)
00749 this->
setstate(__err);
00750 }
00751
return _M_gcount;
00752 }
00753
00754
template<
typename _CharT,
typename _Traits>
00755
basic_istream<_CharT, _Traits>&
00756
basic_istream<_CharT, _Traits>::
00757 putback(
char_type __c)
00758 {
00759
#ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
00760
00761 _M_gcount = 0;
00762
#endif
00763
sentry __cerb(*
this,
true);
00764
if (__cerb)
00765 {
00766
ios_base::iostate __err =
ios_base::iostate(ios_base::goodbit);
00767
try
00768 {
00769
const int_type __eof = traits_type::eof();
00770 __streambuf_type* __sb = this->
rdbuf();
00771
if (!__sb
00772 || traits_type::eq_int_type(__sb->sputbackc(__c), __eof))
00773 __err |= ios_base::badbit;
00774 }
00775
catch(...)
00776 { this->_M_setstate(ios_base::badbit); }
00777
if (__err)
00778 this->
setstate(__err);
00779 }
00780
return *
this;
00781 }
00782
00783
template<
typename _CharT,
typename _Traits>
00784
basic_istream<_CharT, _Traits>&
00785
basic_istream<_CharT, _Traits>::
00786 unget(
void)
00787 {
00788
#ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
00789
00790 _M_gcount = 0;
00791
#endif
00792
sentry __cerb(*
this,
true);
00793
if (__cerb)
00794 {
00795
ios_base::iostate __err =
ios_base::iostate(ios_base::goodbit);
00796
try
00797 {
00798
const int_type __eof = traits_type::eof();
00799 __streambuf_type* __sb = this->
rdbuf();
00800
if (!__sb
00801 || traits_type::eq_int_type(__sb->sungetc(), __eof))
00802 __err |= ios_base::badbit;
00803 }
00804
catch(...)
00805 { this->_M_setstate(ios_base::badbit); }
00806
if (__err)
00807 this->
setstate(__err);
00808 }
00809
return *
this;
00810 }
00811
00812
template<
typename _CharT,
typename _Traits>
00813
int
00814
basic_istream<_CharT, _Traits>::
00815 sync(
void)
00816 {
00817
00818
00819
int __ret = -1;
00820
sentry __cerb(*
this,
true);
00821
if (__cerb)
00822 {
00823
ios_base::iostate __err =
ios_base::iostate(ios_base::goodbit);
00824
try
00825 {
00826 __streambuf_type* __sb = this->
rdbuf();
00827
if (__sb)
00828 {
00829
if (__sb->pubsync() == -1)
00830 __err |= ios_base::badbit;
00831
else
00832 __ret = 0;
00833 }
00834 }
00835
catch(...)
00836 { this->_M_setstate(ios_base::badbit); }
00837
if (__err)
00838 this->
setstate(__err);
00839 }
00840
return __ret;
00841 }
00842
00843
template<
typename _CharT,
typename _Traits>
00844
typename basic_istream<_CharT, _Traits>::pos_type
00845
basic_istream<_CharT, _Traits>::
00846 tellg(
void)
00847 {
00848
00849
00850
pos_type __ret =
pos_type(-1);
00851
try
00852 {
00853
if (!this->
fail())
00854 __ret = this->
rdbuf()->pubseekoff(0, ios_base::cur, ios_base::in);
00855 }
00856
catch(...)
00857 { this->_M_setstate(ios_base::badbit); }
00858
return __ret;
00859 }
00860
00861
00862
template<
typename _CharT,
typename _Traits>
00863
basic_istream<_CharT, _Traits>&
00864
basic_istream<_CharT, _Traits>::
00865 seekg(
pos_type __pos)
00866 {
00867
00868
00869
ios_base::iostate __err =
ios_base::iostate(ios_base::goodbit);
00870
try
00871 {
00872
if (!this->
fail())
00873 {
00874
00875
pos_type __p = this->
rdbuf()->pubseekpos(__pos, ios_base::in);
00876
00877
00878
if (__p ==
pos_type(
off_type(-1)))
00879 __err |= ios_base::failbit;
00880 }
00881 }
00882
catch(...)
00883 { this->_M_setstate(ios_base::badbit); }
00884
if (__err)
00885 this->
setstate(__err);
00886
return *
this;
00887 }
00888
00889
template<
typename _CharT,
typename _Traits>
00890
basic_istream<_CharT, _Traits>&
00891
basic_istream<_CharT, _Traits>::
00892 seekg(
off_type __off,
ios_base::seekdir __dir)
00893 {
00894
00895
00896
ios_base::iostate __err =
ios_base::iostate(ios_base::goodbit);
00897
try
00898 {
00899
if (!this->
fail())
00900 {
00901
00902
pos_type __p = this->
rdbuf()->pubseekoff(__off, __dir,
00903 ios_base::in);
00904
00905
00906
if (__p ==
pos_type(
off_type(-1)))
00907 __err |= ios_base::failbit;
00908 }
00909 }
00910
catch(...)
00911 { this->_M_setstate(ios_base::badbit); }
00912
if (__err)
00913 this->
setstate(__err);
00914
return *
this;
00915 }
00916
00917
00918
template<
typename _CharT,
typename _Traits>
00919
basic_istream<_CharT, _Traits>&
00920 operator>>(
basic_istream<_CharT, _Traits>& __in, _CharT& __c)
00921 {
00922
typedef basic_istream<_CharT, _Traits> __istream_type;
00923
typename __istream_type::sentry __cerb(__in,
false);
00924
if (__cerb)
00925 {
00926
ios_base::iostate __err =
ios_base::iostate(ios_base::goodbit);
00927
try
00928 {
00929
typename __istream_type::int_type __cb = __in.
rdbuf()->sbumpc();
00930
if (!_Traits::eq_int_type(__cb, _Traits::eof()))
00931 __c = _Traits::to_char_type(__cb);
00932
else
00933 __err |= (ios_base::eofbit | ios_base::failbit);
00934 }
00935
catch(...)
00936 { __in._M_setstate(ios_base::badbit); }
00937
if (__err)
00938 __in.
setstate(__err);
00939 }
00940
return __in;
00941 }
00942
00943
template<
typename _CharT,
typename _Traits>
00944 basic_istream<_CharT, _Traits>&
00945 operator>>(
basic_istream<_CharT, _Traits>& __in, _CharT* __s)
00946 {
00947
typedef basic_istream<_CharT, _Traits> __istream_type;
00948
typedef typename __istream_type::__streambuf_type __streambuf_type;
00949
typedef typename _Traits::int_type int_type;
00950
typedef _CharT char_type;
00951
typedef ctype<_CharT> __ctype_type;
00952
00953 streamsize __extracted = 0;
00954
ios_base::iostate __err =
ios_base::iostate(ios_base::goodbit);
00955
typename __istream_type::sentry __cerb(__in,
false);
00956
if (__cerb)
00957 {
00958
try
00959 {
00960
00961 streamsize __num = __in.
width();
00962
if (__num <= 0)
00963 __num =
numeric_limits<streamsize>::max();
00964
00965
const __ctype_type& __ctype = use_facet<__ctype_type>(__in.
getloc());
00966
const int_type __eof = _Traits::eof();
00967 __streambuf_type* __sb = __in.
rdbuf();
00968 int_type __c = __sb->sgetc();
00969
00970
while (__extracted < __num - 1
00971 && !_Traits::eq_int_type(__c, __eof)
00972 && !__ctype.is(ctype_base::space, _Traits::to_char_type(__c)))
00973 {
00974 *__s++ = _Traits::to_char_type(__c);
00975 ++__extracted;
00976 __c = __sb->snextc();
00977 }
00978
if (_Traits::eq_int_type(__c, __eof))
00979 __err |= ios_base::eofbit;
00980
00981
#ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
00982
00983 *__s = char_type();
00984
#endif
00985
__in.
width(0);
00986 }
00987
catch(...)
00988 { __in._M_setstate(ios_base::badbit); }
00989 }
00990
if (!__extracted)
00991 __err |= ios_base::failbit;
00992
if (__err)
00993 __in.
setstate(__err);
00994
return __in;
00995 }
00996
00997
00998
template<
typename _CharT,
typename _Traits>
00999 basic_istream<_CharT,_Traits>&
01000 ws(
basic_istream<_CharT,_Traits>& __in)
01001 {
01002
typedef basic_istream<_CharT, _Traits> __istream_type;
01003
typedef typename __istream_type::__streambuf_type __streambuf_type;
01004
typedef typename __istream_type::__ctype_type __ctype_type;
01005
typedef typename __istream_type::int_type __int_type;
01006
01007
const __ctype_type& __ctype = use_facet<__ctype_type>(__in.
getloc());
01008
const __int_type __eof = _Traits::eof();
01009 __streambuf_type* __sb = __in.
rdbuf();
01010 __int_type __c = __sb->sgetc();
01011
01012
while (!_Traits::eq_int_type(__c, __eof)
01013 && __ctype.is(ctype_base::space, _Traits::to_char_type(__c)))
01014 __c = __sb->snextc();
01015
01016
if (_Traits::eq_int_type(__c, __eof))
01017 __in.
setstate(ios_base::eofbit);
01018
return __in;
01019 }
01020
01021
01022
template<
typename _CharT,
typename _Traits,
typename _Alloc>
01023 basic_istream<_CharT, _Traits>&
01024
operator>>(basic_istream<_CharT, _Traits>& __in,
01025 basic_string<_CharT, _Traits, _Alloc>& __str)
01026 {
01027
typedef basic_istream<_CharT, _Traits> __istream_type;
01028
typedef typename __istream_type::int_type __int_type;
01029
typedef typename __istream_type::__streambuf_type __streambuf_type;
01030
typedef typename __istream_type::__ctype_type __ctype_type;
01031
typedef basic_string<_CharT, _Traits, _Alloc> __string_type;
01032
typedef typename __string_type::size_type __size_type;
01033
01034 __size_type __extracted = 0;
01035 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
01036
typename __istream_type::sentry __cerb(__in,
false);
01037
if (__cerb)
01038 {
01039
try
01040 {
01041 __str.erase();
01042 streamsize __w = __in.width();
01043 __size_type __n;
01044 __n = __w > 0 ? static_cast<__size_type>(__w) : __str.max_size();
01045
01046
const __ctype_type& __ct = use_facet<__ctype_type>(__in.getloc());
01047
const __int_type __eof = _Traits::eof();
01048 __streambuf_type* __sb = __in.rdbuf();
01049 __int_type __c = __sb->sgetc();
01050
01051
while (__extracted < __n
01052 && !_Traits::eq_int_type(__c, __eof)
01053 && !__ct.is(ctype_base::space, _Traits::to_char_type(__c)))
01054 {
01055 __str += _Traits::to_char_type(__c);
01056 ++__extracted;
01057 __c = __sb->snextc();
01058 }
01059
if (_Traits::eq_int_type(__c, __eof))
01060 __err |= ios_base::eofbit;
01061 __in.width(0);
01062 }
01063
catch(...)
01064 {
01065
01066
01067
01068 __in._M_setstate(ios_base::badbit);
01069 }
01070 }
01071
01072
if (!__extracted)
01073 __err |= ios_base::failbit;
01074
if (__err)
01075 __in.setstate(__err);
01076
return __in;
01077 }
01078
01079
template<
typename _CharT,
typename _Traits,
typename _Alloc>
01080 basic_istream<_CharT, _Traits>&
01081 getline(basic_istream<_CharT, _Traits>& __in,
01082 basic_string<_CharT, _Traits, _Alloc>& __str, _CharT __delim)
01083 {
01084
typedef basic_istream<_CharT, _Traits> __istream_type;
01085
typedef typename __istream_type::int_type __int_type;
01086
typedef typename __istream_type::__streambuf_type __streambuf_type;
01087
typedef typename __istream_type::__ctype_type __ctype_type;
01088
typedef basic_string<_CharT, _Traits, _Alloc> __string_type;
01089
typedef typename __string_type::size_type __size_type;
01090
01091 __size_type __extracted = 0;
01092
const __size_type __n = __str.max_size();
01093
bool __testdelim =
false;
01094 ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
01095
typename __istream_type::sentry __cerb(__in,
true);
01096
if (__cerb)
01097 {
01098
try
01099 {
01100 __str.erase();
01101 __int_type __idelim = _Traits::to_int_type(__delim);
01102 __streambuf_type* __sb = __in.rdbuf();
01103 __int_type __c = __sb->sbumpc();
01104
const __int_type __eof = _Traits::eof();
01105 __testdelim = _Traits::eq_int_type(__c, __idelim);
01106
01107
while (!_Traits::eq_int_type(__c, __eof) && !__testdelim
01108 && __extracted < __n)
01109 {
01110 __str += _Traits::to_char_type(__c);
01111 ++__extracted;
01112 __c = __sb->sbumpc();
01113 __testdelim = _Traits::eq_int_type(__c, __idelim);
01114 }
01115
if (_Traits::eq_int_type(__c, __eof))
01116 __err |= ios_base::eofbit;
01117 }
01118
catch(...)
01119 {
01120
01121
01122
01123 __in._M_setstate(ios_base::badbit);
01124 }
01125 }
01126
if ((!__extracted && !__testdelim) || __extracted == __n)
01127 __err |= ios_base::failbit;
01128
if (__err)
01129 __in.setstate(__err);
01130
return __in;
01131 }
01132
01133
template<
class _CharT,
class _Traits,
class _Alloc>
01134
inline basic_istream<_CharT,_Traits>&
01135 getline(basic_istream<_CharT, _Traits>& __in,
01136 basic_string<_CharT,_Traits,_Alloc>& __str)
01137 {
return getline(__in, __str, __in.widen(
'\n')); }
01138
01139
01140
01141
01142
#if _GLIBCPP_EXTERN_TEMPLATE
01143
extern template class basic_istream<char>;
01144
extern template istream&
ws(istream&);
01145
extern template istream&
operator>>(istream&,
char&);
01146
extern template istream&
operator>>(istream&,
char*);
01147
extern template istream&
operator>>(istream&,
unsigned char&);
01148
extern template istream&
operator>>(istream&,
signed char&);
01149
extern template istream&
operator>>(istream&,
unsigned char*);
01150
extern template istream&
operator>>(istream&,
signed char*);
01151
01152
#ifdef _GLIBCPP_USE_WCHAR_T
01153
extern template class basic_istream<wchar_t>;
01154
extern template wistream&
ws(wistream&);
01155
extern template wistream&
operator>>(wistream&,
wchar_t&);
01156
extern template wistream&
operator>>(wistream&,
wchar_t*);
01157
#endif
01158
#endif
01159
}