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
00040
#ifndef _IOS_BASE_H
00041
#define _IOS_BASE_H 1
00042
00043
#pragma GCC system_header
00044
00045
#include <bits/atomicity.h>
00046
#include <bits/localefwd.h>
00047
#include <bits/locale_classes.h>
00048
00049
namespace std
00050 {
00051
00052
00053
00054
00055
enum _Ios_Fmtflags { _S_ios_fmtflags_end = 1L << 16 };
00056
00057
inline _Ios_Fmtflags
00058 operator&(_Ios_Fmtflags __a, _Ios_Fmtflags __b)
00059 {
return _Ios_Fmtflags(static_cast<int>(__a) & static_cast<int>(__b)); }
00060
00061
inline _Ios_Fmtflags
00062 operator|(_Ios_Fmtflags __a, _Ios_Fmtflags __b)
00063 {
return _Ios_Fmtflags(static_cast<int>(__a) | static_cast<int>(__b)); }
00064
00065
inline _Ios_Fmtflags
00066 operator^(_Ios_Fmtflags __a, _Ios_Fmtflags __b)
00067 {
return _Ios_Fmtflags(static_cast<int>(__a) ^ static_cast<int>(__b)); }
00068
00069
inline _Ios_Fmtflags
00070 operator|=(_Ios_Fmtflags& __a, _Ios_Fmtflags __b)
00071 {
return __a = __a | __b; }
00072
00073
inline _Ios_Fmtflags
00074 operator&=(_Ios_Fmtflags& __a, _Ios_Fmtflags __b)
00075 {
return __a = __a & __b; }
00076
00077
inline _Ios_Fmtflags
00078 operator^=(_Ios_Fmtflags& __a, _Ios_Fmtflags __b)
00079 {
return __a = __a ^ __b; }
00080
00081
inline _Ios_Fmtflags
00082 operator~(_Ios_Fmtflags __a)
00083 {
return _Ios_Fmtflags(~static_cast<int>(__a)); }
00084
00085
00086
enum _Ios_Openmode { _S_ios_openmode_end = 1L << 16 };
00087
00088
inline _Ios_Openmode
00089 operator&(_Ios_Openmode __a, _Ios_Openmode __b)
00090 {
return _Ios_Openmode(static_cast<int>(__a) & static_cast<int>(__b)); }
00091
00092
inline _Ios_Openmode
00093 operator|(_Ios_Openmode __a, _Ios_Openmode __b)
00094 {
return _Ios_Openmode(static_cast<int>(__a) | static_cast<int>(__b)); }
00095
00096
inline _Ios_Openmode
00097 operator^(_Ios_Openmode __a, _Ios_Openmode __b)
00098 {
return _Ios_Openmode(static_cast<int>(__a) ^ static_cast<int>(__b)); }
00099
00100
inline _Ios_Openmode
00101 operator|=(_Ios_Openmode& __a, _Ios_Openmode __b)
00102 {
return __a = __a | __b; }
00103
00104
inline _Ios_Openmode
00105 operator&=(_Ios_Openmode& __a, _Ios_Openmode __b)
00106 {
return __a = __a & __b; }
00107
00108
inline _Ios_Openmode
00109 operator^=(_Ios_Openmode& __a, _Ios_Openmode __b)
00110 {
return __a = __a ^ __b; }
00111
00112
inline _Ios_Openmode
00113 operator~(_Ios_Openmode __a)
00114 {
return _Ios_Openmode(~static_cast<int>(__a)); }
00115
00116
00117
enum _Ios_Iostate { _S_ios_iostate_end = 1L << 16 };
00118
00119
inline _Ios_Iostate
00120 operator&(_Ios_Iostate __a, _Ios_Iostate __b)
00121 {
return _Ios_Iostate(static_cast<int>(__a) & static_cast<int>(__b)); }
00122
00123
inline _Ios_Iostate
00124 operator|(_Ios_Iostate __a, _Ios_Iostate __b)
00125 {
return _Ios_Iostate(static_cast<int>(__a) | static_cast<int>(__b)); }
00126
00127
inline _Ios_Iostate
00128 operator^(_Ios_Iostate __a, _Ios_Iostate __b)
00129 {
return _Ios_Iostate(static_cast<int>(__a) ^ static_cast<int>(__b)); }
00130
00131
inline _Ios_Iostate
00132 operator|=(_Ios_Iostate& __a, _Ios_Iostate __b)
00133 {
return __a = __a | __b; }
00134
00135
inline _Ios_Iostate
00136 operator&=(_Ios_Iostate& __a, _Ios_Iostate __b)
00137 {
return __a = __a & __b; }
00138
00139
inline _Ios_Iostate
00140 operator^=(_Ios_Iostate& __a, _Ios_Iostate __b)
00141 {
return __a = __a ^ __b; }
00142
00143
inline _Ios_Iostate
00144 operator~(_Ios_Iostate __a)
00145 {
return _Ios_Iostate(~static_cast<int>(__a)); }
00146
00147
enum _Ios_Seekdir { _S_ios_seekdir_end = 1L << 16 };
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158 class ios_base
00159 {
00160
public:
00161
00162
00163
00164 class failure :
public exception
00165 {
00166
public:
00167
00168
00169
explicit
00170
failure(
const string& __str)
throw();
00171
00172
00173
00174
virtual
00175 ~
failure()
throw();
00176
00177
virtual const char*
00178
what()
const throw();
00179
00180
private:
00181
string _M_msg;
00182 };
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210 typedef _Ios_Fmtflags
fmtflags;
00211
00212
00213 static const fmtflags boolalpha =
fmtflags(__ios_flags::_S_boolalpha);
00214
00215
00216 static const fmtflags dec =
fmtflags(__ios_flags::_S_dec);
00217
00218
00219 static const fmtflags fixed =
fmtflags(__ios_flags::_S_fixed);
00220
00221
00222 static const fmtflags hex =
fmtflags(__ios_flags::_S_hex);
00223
00224
00225
00226
00227 static const fmtflags internal =
fmtflags(__ios_flags::_S_internal);
00228
00229
00230
00231 static const fmtflags left =
fmtflags(__ios_flags::_S_left);
00232
00233
00234 static const fmtflags oct =
fmtflags(__ios_flags::_S_oct);
00235
00236
00237
00238 static const fmtflags right =
fmtflags(__ios_flags::_S_right);
00239
00240
00241 static const fmtflags scientific =
fmtflags(__ios_flags::_S_scientific);
00242
00243
00244
00245 static const fmtflags showbase =
fmtflags(__ios_flags::_S_showbase);
00246
00247
00248
00249 static const fmtflags showpoint =
fmtflags(__ios_flags::_S_showpoint);
00250
00251
00252 static const fmtflags showpos =
fmtflags(__ios_flags::_S_showpos);
00253
00254
00255 static const fmtflags skipws =
fmtflags(__ios_flags::_S_skipws);
00256
00257
00258 static const fmtflags unitbuf =
fmtflags(__ios_flags::_S_unitbuf);
00259
00260
00261
00262 static const fmtflags uppercase =
fmtflags(__ios_flags::_S_uppercase);
00263
00264
00265 static const fmtflags adjustfield =
fmtflags(__ios_flags::_S_adjustfield);
00266
00267
00268 static const fmtflags basefield =
fmtflags(__ios_flags::_S_basefield);
00269
00270
00271 static const fmtflags floatfield =
fmtflags(__ios_flags::_S_floatfield);
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285 typedef _Ios_Iostate
iostate;
00286
00287
00288
00289 static const iostate badbit =
iostate(__ios_flags::_S_badbit);
00290
00291
00292 static const iostate eofbit =
iostate(__ios_flags::_S_eofbit);
00293
00294
00295
00296
00297 static const iostate failbit =
iostate(__ios_flags::_S_failbit);
00298
00299
00300 static const iostate goodbit =
iostate(0);
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316 typedef _Ios_Openmode
openmode;
00317
00318
00319 static const openmode app =
openmode(__ios_flags::_S_app);
00320
00321
00322 static const openmode ate =
openmode(__ios_flags::_S_ate);
00323
00324
00325
00326
00327
00328 static const openmode binary =
openmode(__ios_flags::_S_bin);
00329
00330
00331 static const openmode in =
openmode(__ios_flags::_S_in);
00332
00333
00334 static const openmode out =
openmode(__ios_flags::_S_out);
00335
00336
00337 static const openmode trunc =
openmode(__ios_flags::_S_trunc);
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349 typedef _Ios_Seekdir
seekdir;
00350
00351
00352 static const seekdir beg =
seekdir(0);
00353
00354
00355 static const seekdir cur =
seekdir(SEEK_CUR);
00356
00357
00358 static const seekdir end =
seekdir(SEEK_END);
00359
00360
00361
typedef int io_state;
00362
typedef int open_mode;
00363
typedef int seek_dir;
00364
00365
typedef std::streampos streampos;
00366
typedef std::streamoff streamoff;
00367
00368
00369
00370
00371
00372
00373
00374
00375 enum event
00376 {
00377 erase_event,
00378 imbue_event,
00379 copyfmt_event
00380 };
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392 typedef void (*
event_callback) (
event,
ios_base&,
int);
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
void
00405
register_callback(
event_callback __fn,
int __index);
00406
00407
protected:
00408
00409
00410
00411
00412
00413
00414
streamsize _M_precision;
00415
streamsize _M_width;
00416
fmtflags _M_flags;
00417
iostate _M_exception;
00418
iostate _M_streambuf_state;
00419
00420
00421
00422
00423
struct _Callback_list
00424 {
00425
00426 _Callback_list* _M_next;
00427
ios_base::event_callback _M_fn;
00428
int _M_index;
00429 _Atomic_word _M_refcount;
00430
00431 _Callback_list(
ios_base::event_callback __fn,
int __index,
00432 _Callback_list* __cb)
00433 : _M_next(__cb), _M_fn(__fn), _M_index(__index), _M_refcount(0) { }
00434
00435
void
00436 _M_add_reference() { __gnu_cxx::__atomic_add(&_M_refcount, 1); }
00437
00438
00439
int
00440 _M_remove_reference()
00441 {
return __gnu_cxx::__exchange_and_add(&_M_refcount, -1); }
00442 };
00443
00444 _Callback_list* _M_callbacks;
00445
00446
void
00447 _M_call_callbacks(event __ev)
throw();
00448
00449
void
00450 _M_dispose_callbacks(
void);
00451
00452
00453
struct _Words
00454 {
00455
void* _M_pword;
00456
long _M_iword;
00457 _Words() : _M_pword(0), _M_iword(0) { }
00458 };
00459
00460
00461 _Words _M_word_zero;
00462
00463
00464
00465
static const int _S_local_word_size = 8;
00466 _Words _M_local_word[_S_local_word_size];
00467
00468
00469
int _M_word_size;
00470 _Words* _M_word;
00471
00472 _Words&
00473 _M_grow_words(
int __index,
bool __iword);
00474
00475
00476 locale _M_ios_locale;
00477
00478
void
00479 _M_init();
00480
00481
public:
00482
00483
00484
00485
00486
00487
class Init
00488 {
00489
friend class ios_base;
00490
public:
00491 Init();
00492 ~Init();
00493
00494
private:
00495
static _Atomic_word _S_refcount;
00496
static bool _S_synced_with_stdio;
00497 };
00498
00499
00500
00501
00502
00503
00504
inline fmtflags
00505 flags()
const {
return _M_flags; }
00506
00507
00508
00509
00510
00511
00512
00513
00514
inline fmtflags
00515 flags(
fmtflags __fmtfl)
00516 {
00517
fmtflags __old = _M_flags;
00518 _M_flags = __fmtfl;
00519
return __old;
00520 }
00521
00522
00523
00524
00525
00526
00527
00528
00529
00530
inline fmtflags
00531 setf(
fmtflags __fmtfl)
00532 {
00533
fmtflags __old = _M_flags;
00534 _M_flags |= __fmtfl;
00535
return __old;
00536 }
00537
00538
00539
00540
00541
00542
00543
00544
00545
00546
00547
inline fmtflags
00548 setf(
fmtflags __fmtfl,
fmtflags __mask)
00549 {
00550
fmtflags __old = _M_flags;
00551 _M_flags &= ~__mask;
00552 _M_flags |= (__fmtfl & __mask);
00553
return __old;
00554 }
00555
00556
00557
00558
00559
00560
00561
00562
inline void
00563 unsetf(
fmtflags __mask) { _M_flags &= ~__mask; }
00564
00565
00566
00567
00568
00569
00570
00571
00572
00573
00574
inline streamsize
00575 precision()
const {
return _M_precision; }
00576
00577
00578
00579
00580
00581
00582
inline streamsize
00583 precision(
streamsize __prec)
00584 {
00585
streamsize __old = _M_precision;
00586 _M_precision = __prec;
00587
return __old;
00588 }
00589
00590
00591
00592
00593
00594
00595
00596
inline streamsize
00597 width()
const {
return _M_width; }
00598
00599
00600
00601
00602
00603
00604
inline streamsize
00605 width(
streamsize __wide)
00606 {
00607
streamsize __old = _M_width;
00608 _M_width = __wide;
00609
return __old;
00610 }
00611
00612
00613
00614
00615
00616
00617
00618
00619
00620
00621
00622
00623
static bool
00624
sync_with_stdio(
bool __sync =
true);
00625
00626
00627
00628
00629
00630
00631
00632
00633
00634
00635
locale
00636
imbue(
const locale& __loc);
00637
00638
00639
00640
00641
00642
00643
00644
00645
00646
inline locale
00647 getloc()
const {
return _M_ios_locale; }
00648
00649
00650
00651
00652
00653
00654
00655
00656
inline const locale&
00657 _M_getloc()
const {
return _M_ios_locale; }
00658
00659
00660
00661
00662
00663
00664
00665
00666
00667
00668
00669
00670
00671
00672
00673
00674
static int
00675
xalloc() throw();
00676
00677
00678
00679
00680
00681
00682
00683
00684
00685
00686
00687
00688
00689
00690 inline
long&
00691 iword(
int __ix)
00692 {
00693 _Words& __word = (__ix < _M_word_size)
00694 ? _M_word[__ix] : _M_grow_words(__ix,
true);
00695
return __word._M_iword;
00696 }
00697
00698
00699
00700
00701
00702
00703
00704
00705
00706
00707
00708
00709
00710
00711
inline void*&
00712 pword(
int __ix)
00713 {
00714 _Words& __word = (__ix < _M_word_size)
00715 ? _M_word[__ix] : _M_grow_words(__ix,
false);
00716
return __word._M_pword;
00717 }
00718
00719
00720
00721
00722
00723
00724
00725
00726
00727
00728
virtual ~ios_base();
00729
00730
protected:
00731
ios_base();
00732
00733
00734
00735
private:
00736
ios_base(
const ios_base&);
00737
00738
ios_base&
00739 operator=(
const ios_base&);
00740 };
00741
00742
00743
00744
inline ios_base&
00745 boolalpha(
ios_base& __base)
00746 {
00747 __base.
setf(ios_base::boolalpha);
00748
return __base;
00749 }
00750
00751
00752
inline ios_base&
00753 noboolalpha(
ios_base& __base)
00754 {
00755 __base.
unsetf(ios_base::boolalpha);
00756
return __base;
00757 }
00758
00759
00760
inline ios_base&
00761 showbase(
ios_base& __base)
00762 {
00763 __base.
setf(ios_base::showbase);
00764
return __base;
00765 }
00766
00767
00768
inline ios_base&
00769 noshowbase(
ios_base& __base)
00770 {
00771 __base.
unsetf(ios_base::showbase);
00772
return __base;
00773 }
00774
00775
00776
inline ios_base&
00777 showpoint(
ios_base& __base)
00778 {
00779 __base.
setf(ios_base::showpoint);
00780
return __base;
00781 }
00782
00783
00784
inline ios_base&
00785 noshowpoint(
ios_base& __base)
00786 {
00787 __base.
unsetf(ios_base::showpoint);
00788
return __base;
00789 }
00790
00791
00792
inline ios_base&
00793 showpos(
ios_base& __base)
00794 {
00795 __base.
setf(ios_base::showpos);
00796
return __base;
00797 }
00798
00799
00800
inline ios_base&
00801 noshowpos(
ios_base& __base)
00802 {
00803 __base.
unsetf(ios_base::showpos);
00804
return __base;
00805 }
00806
00807
00808
inline ios_base&
00809 skipws(
ios_base& __base)
00810 {
00811 __base.
setf(ios_base::skipws);
00812
return __base;
00813 }
00814
00815
00816
inline ios_base&
00817 noskipws(
ios_base& __base)
00818 {
00819 __base.
unsetf(ios_base::skipws);
00820
return __base;
00821 }
00822
00823
00824
inline ios_base&
00825 uppercase(
ios_base& __base)
00826 {
00827 __base.
setf(ios_base::uppercase);
00828
return __base;
00829 }
00830
00831
00832
inline ios_base&
00833 nouppercase(
ios_base& __base)
00834 {
00835 __base.
unsetf(ios_base::uppercase);
00836
return __base;
00837 }
00838
00839
00840
inline ios_base&
00841 unitbuf(
ios_base& __base)
00842 {
00843 __base.
setf(ios_base::unitbuf);
00844
return __base;
00845 }
00846
00847
00848
inline ios_base&
00849 nounitbuf(
ios_base& __base)
00850 {
00851 __base.
unsetf(ios_base::unitbuf);
00852
return __base;
00853 }
00854
00855
00856
00857
inline ios_base&
00858 internal(
ios_base& __base)
00859 {
00860 __base.
setf(ios_base::internal, ios_base::adjustfield);
00861
return __base;
00862 }
00863
00864
00865
inline ios_base&
00866 left(
ios_base& __base)
00867 {
00868 __base.
setf(ios_base::left, ios_base::adjustfield);
00869
return __base;
00870 }
00871
00872
00873
inline ios_base&
00874 right(
ios_base& __base)
00875 {
00876 __base.
setf(ios_base::right, ios_base::adjustfield);
00877
return __base;
00878 }
00879
00880
00881
00882
inline ios_base&
00883 dec(
ios_base& __base)
00884 {
00885 __base.
setf(ios_base::dec, ios_base::basefield);
00886
return __base;
00887 }
00888
00889
00890
inline ios_base&
00891 hex(
ios_base& __base)
00892 {
00893 __base.
setf(ios_base::hex, ios_base::basefield);
00894
return __base;
00895 }
00896
00897
00898
inline ios_base&
00899 oct(
ios_base& __base)
00900 {
00901 __base.
setf(ios_base::oct, ios_base::basefield);
00902
return __base;
00903 }
00904
00905
00906
00907
inline ios_base&
00908 fixed(
ios_base& __base)
00909 {
00910 __base.
setf(ios_base::fixed, ios_base::floatfield);
00911
return __base;
00912 }
00913
00914
00915
inline ios_base&
00916 scientific(
ios_base& __base)
00917 {
00918 __base.
setf(ios_base::scientific, ios_base::floatfield);
00919
return __base;
00920 }
00921 }
00922
00923
#endif
00924