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