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