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
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
00056 {
00057 _S_boolalpha = 1L << 0,
00058 _S_dec = 1L << 1,
00059 _S_fixed = 1L << 2,
00060 _S_hex = 1L << 3,
00061 _S_internal = 1L << 4,
00062 _S_left = 1L << 5,
00063 _S_oct = 1L << 6,
00064 _S_right = 1L << 7,
00065 _S_scientific = 1L << 8,
00066 _S_showbase = 1L << 9,
00067 _S_showpoint = 1L << 10,
00068 _S_showpos = 1L << 11,
00069 _S_skipws = 1L << 12,
00070 _S_unitbuf = 1L << 13,
00071 _S_uppercase = 1L << 14,
00072 _S_adjustfield = _S_left | _S_right | _S_internal,
00073 _S_basefield = _S_dec | _S_oct | _S_hex,
00074 _S_floatfield = _S_scientific | _S_fixed,
00075 _S_ios_fmtflags_end = 1L << 16
00076 };
00077
00078 inline _Ios_Fmtflags
00079 operator&(_Ios_Fmtflags __a, _Ios_Fmtflags __b)
00080 { return _Ios_Fmtflags(static_cast<int>(__a) & static_cast<int>(__b)); }
00081
00082 inline _Ios_Fmtflags
00083 operator|(_Ios_Fmtflags __a, _Ios_Fmtflags __b)
00084 { return _Ios_Fmtflags(static_cast<int>(__a) | static_cast<int>(__b)); }
00085
00086 inline _Ios_Fmtflags
00087 operator^(_Ios_Fmtflags __a, _Ios_Fmtflags __b)
00088 { return _Ios_Fmtflags(static_cast<int>(__a) ^ static_cast<int>(__b)); }
00089
00090 inline _Ios_Fmtflags&
00091 operator|=(_Ios_Fmtflags& __a, _Ios_Fmtflags __b)
00092 { return __a = __a | __b; }
00093
00094 inline _Ios_Fmtflags&
00095 operator&=(_Ios_Fmtflags& __a, _Ios_Fmtflags __b)
00096 { return __a = __a & __b; }
00097
00098 inline _Ios_Fmtflags&
00099 operator^=(_Ios_Fmtflags& __a, _Ios_Fmtflags __b)
00100 { return __a = __a ^ __b; }
00101
00102 inline _Ios_Fmtflags
00103 operator~(_Ios_Fmtflags __a)
00104 { return _Ios_Fmtflags(~static_cast<int>(__a)); }
00105
00106
00107 enum _Ios_Openmode
00108 {
00109 _S_app = 1L << 0,
00110 _S_ate = 1L << 1,
00111 _S_bin = 1L << 2,
00112 _S_in = 1L << 3,
00113 _S_out = 1L << 4,
00114 _S_trunc = 1L << 5,
00115 _S_ios_openmode_end = 1L << 16
00116 };
00117
00118 inline _Ios_Openmode
00119 operator&(_Ios_Openmode __a, _Ios_Openmode __b)
00120 { return _Ios_Openmode(static_cast<int>(__a) & static_cast<int>(__b)); }
00121
00122 inline _Ios_Openmode
00123 operator|(_Ios_Openmode __a, _Ios_Openmode __b)
00124 { return _Ios_Openmode(static_cast<int>(__a) | static_cast<int>(__b)); }
00125
00126 inline _Ios_Openmode
00127 operator^(_Ios_Openmode __a, _Ios_Openmode __b)
00128 { return _Ios_Openmode(static_cast<int>(__a) ^ static_cast<int>(__b)); }
00129
00130 inline _Ios_Openmode&
00131 operator|=(_Ios_Openmode& __a, _Ios_Openmode __b)
00132 { return __a = __a | __b; }
00133
00134 inline _Ios_Openmode&
00135 operator&=(_Ios_Openmode& __a, _Ios_Openmode __b)
00136 { return __a = __a & __b; }
00137
00138 inline _Ios_Openmode&
00139 operator^=(_Ios_Openmode& __a, _Ios_Openmode __b)
00140 { return __a = __a ^ __b; }
00141
00142 inline _Ios_Openmode
00143 operator~(_Ios_Openmode __a)
00144 { return _Ios_Openmode(~static_cast<int>(__a)); }
00145
00146
00147 enum _Ios_Iostate
00148 {
00149 _S_goodbit = 0,
00150 _S_badbit = 1L << 0,
00151 _S_eofbit = 1L << 1,
00152 _S_failbit = 1L << 2,
00153 _S_ios_iostate_end = 1L << 16
00154 };
00155
00156 inline _Ios_Iostate
00157 operator&(_Ios_Iostate __a, _Ios_Iostate __b)
00158 { return _Ios_Iostate(static_cast<int>(__a) & static_cast<int>(__b)); }
00159
00160 inline _Ios_Iostate
00161 operator|(_Ios_Iostate __a, _Ios_Iostate __b)
00162 { return _Ios_Iostate(static_cast<int>(__a) | static_cast<int>(__b)); }
00163
00164 inline _Ios_Iostate
00165 operator^(_Ios_Iostate __a, _Ios_Iostate __b)
00166 { return _Ios_Iostate(static_cast<int>(__a) ^ static_cast<int>(__b)); }
00167
00168 inline _Ios_Iostate&
00169 operator|=(_Ios_Iostate& __a, _Ios_Iostate __b)
00170 { return __a = __a | __b; }
00171
00172 inline _Ios_Iostate&
00173 operator&=(_Ios_Iostate& __a, _Ios_Iostate __b)
00174 { return __a = __a & __b; }
00175
00176 inline _Ios_Iostate&
00177 operator^=(_Ios_Iostate& __a, _Ios_Iostate __b)
00178 { return __a = __a ^ __b; }
00179
00180 inline _Ios_Iostate
00181 operator~(_Ios_Iostate __a)
00182 { return _Ios_Iostate(~static_cast<int>(__a)); }
00183
00184 enum _Ios_Seekdir
00185 {
00186 _S_beg = 0,
00187 _S_cur = SEEK_CUR,
00188 _S_end = SEEK_END,
00189 _S_ios_seekdir_end = 1L << 16
00190 };
00191
00192
00201 class ios_base
00202 {
00203 public:
00204
00205
00207 class failure : public exception
00208 {
00209 public:
00210
00211
00212 explicit
00213 failure(const string& __str) throw();
00214
00215
00216
00217 virtual
00218 ~failure() throw();
00219
00220 virtual const char*
00221 what() const throw();
00222
00223 private:
00224 string _M_msg;
00225 };
00226
00227
00253 typedef _Ios_Fmtflags fmtflags;
00254
00256 static const fmtflags boolalpha = fmtflags(__ios_flags::_S_boolalpha);
00257
00259 static const fmtflags dec = fmtflags(__ios_flags::_S_dec);
00260
00262 static const fmtflags fixed = fmtflags(__ios_flags::_S_fixed);
00263
00265 static const fmtflags hex = fmtflags(__ios_flags::_S_hex);
00266
00270 static const fmtflags internal = fmtflags(__ios_flags::_S_internal);
00271
00274 static const fmtflags left = fmtflags(__ios_flags::_S_left);
00275
00277 static const fmtflags oct = fmtflags(__ios_flags::_S_oct);
00278
00281 static const fmtflags right = fmtflags(__ios_flags::_S_right);
00282
00284 static const fmtflags scientific = fmtflags(__ios_flags::_S_scientific);
00285
00288 static const fmtflags showbase = fmtflags(__ios_flags::_S_showbase);
00289
00292 static const fmtflags showpoint = fmtflags(__ios_flags::_S_showpoint);
00293
00295 static const fmtflags showpos = fmtflags(__ios_flags::_S_showpos);
00296
00298 static const fmtflags skipws = fmtflags(__ios_flags::_S_skipws);
00299
00301 static const fmtflags unitbuf = fmtflags(__ios_flags::_S_unitbuf);
00302
00305 static const fmtflags uppercase = fmtflags(__ios_flags::_S_uppercase);
00306
00308 static const fmtflags adjustfield = fmtflags(__ios_flags::_S_adjustfield);
00309
00311 static const fmtflags basefield = fmtflags(__ios_flags::_S_basefield);
00312
00314 static const fmtflags floatfield = fmtflags(__ios_flags::_S_floatfield);
00315
00316
00328 typedef _Ios_Iostate iostate;
00329
00332 static const iostate badbit = iostate(__ios_flags::_S_badbit);
00333
00335 static const iostate eofbit = iostate(__ios_flags::_S_eofbit);
00336
00340 static const iostate failbit = iostate(__ios_flags::_S_failbit);
00341
00343 static const iostate goodbit = iostate(0);
00344
00345
00359 typedef _Ios_Openmode openmode;
00360
00362 static const openmode app = openmode(__ios_flags::_S_app);
00363
00365 static const openmode ate = openmode(__ios_flags::_S_ate);
00366
00371 static const openmode binary = openmode(__ios_flags::_S_bin);
00372
00374 static const openmode in = openmode(__ios_flags::_S_in);
00375
00377 static const openmode out = openmode(__ios_flags::_S_out);
00378
00380 static const openmode trunc = openmode(__ios_flags::_S_trunc);
00381
00382
00392 typedef _Ios_Seekdir seekdir;
00393
00395 static const seekdir beg = seekdir(0);
00396
00398 static const seekdir cur = seekdir(SEEK_CUR);
00399
00401 static const seekdir end = seekdir(SEEK_END);
00402
00403 #ifdef _GLIBCXX_DEPRECATED
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 #endif
00412
00413
00420 enum event
00421 {
00422 erase_event,
00423 imbue_event,
00424 copyfmt_event
00425 };
00426
00437 typedef void (*event_callback) (event, ios_base&, int);
00438
00449 void
00450 register_callback(event_callback __fn, int __index);
00451
00452 protected:
00454
00459 streamsize _M_precision;
00460 streamsize _M_width;
00461 fmtflags _M_flags;
00462 iostate _M_exception;
00463 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(&_M_refcount, 1); }
00482
00483
00484 int
00485 _M_remove_reference()
00486 { return __gnu_cxx::__exchange_and_add(&_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);
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 static const int _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();
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
00549 inline fmtflags
00550 flags() const { return _M_flags; }
00551
00559 inline fmtflags
00560 flags(fmtflags __fmtfl)
00561 {
00562 fmtflags __old = _M_flags;
00563 _M_flags = __fmtfl;
00564 return __old;
00565 }
00566
00575 inline fmtflags
00576 setf(fmtflags __fmtfl)
00577 {
00578 fmtflags __old = _M_flags;
00579 _M_flags |= __fmtfl;
00580 return __old;
00581 }
00582
00592 inline fmtflags
00593 setf(fmtflags __fmtfl, fmtflags __mask)
00594 {
00595 fmtflags __old = _M_flags;
00596 _M_flags &= ~__mask;
00597 _M_flags |= (__fmtfl & __mask);
00598 return __old;
00599 }
00600
00607 inline void
00608 unsetf(fmtflags __mask) { _M_flags &= ~__mask; }
00609
00619 inline streamsize
00620 precision() const { return _M_precision; }
00621
00627 inline streamsize
00628 precision(streamsize __prec)
00629 {
00630 streamsize __old = _M_precision;
00631 _M_precision = __prec;
00632 return __old;
00633 }
00634
00641 inline streamsize
00642 width() const { return _M_width; }
00643
00649 inline streamsize
00650 width(streamsize __wide)
00651 {
00652 streamsize __old = _M_width;
00653 _M_width = __wide;
00654 return __old;
00655 }
00656
00657
00668 static bool
00669 sync_with_stdio(bool __sync = true);
00670
00671
00680 locale
00681 imbue(const locale& __loc);
00682
00691 inline locale
00692 getloc() const { return _M_ios_locale; }
00693
00701 inline const locale&
00702 _M_getloc() const { return _M_ios_locale; }
00703
00704
00719 static int
00720 xalloc() throw();
00721
00735 inline long&
00736 iword(int __ix)
00737 {
00738 _Words& __word = (__ix < _M_word_size)
00739 ? _M_word[__ix] : _M_grow_words(__ix, true);
00740 return __word._M_iword;
00741 }
00742
00756 inline void*&
00757 pword(int __ix)
00758 {
00759 _Words& __word = (__ix < _M_word_size)
00760 ? _M_word[__ix] : _M_grow_words(__ix, false);
00761 return __word._M_pword;
00762 }
00763
00764
00773 virtual ~ios_base();
00774
00775 protected:
00776 ios_base();
00777
00778
00779
00780 private:
00781 ios_base(const ios_base&);
00782
00783 ios_base&
00784 operator=(const ios_base&);
00785 };
00786
00787
00789 inline ios_base&
00790 boolalpha(ios_base& __base)
00791 {
00792 __base.setf(ios_base::boolalpha);
00793 return __base;
00794 }
00795
00797 inline ios_base&
00798 noboolalpha(ios_base& __base)
00799 {
00800 __base.unsetf(ios_base::boolalpha);
00801 return __base;
00802 }
00803
00805 inline ios_base&
00806 showbase(ios_base& __base)
00807 {
00808 __base.setf(ios_base::showbase);
00809 return __base;
00810 }
00811
00813 inline ios_base&
00814 noshowbase(ios_base& __base)
00815 {
00816 __base.unsetf(ios_base::showbase);
00817 return __base;
00818 }
00819
00821 inline ios_base&
00822 showpoint(ios_base& __base)
00823 {
00824 __base.setf(ios_base::showpoint);
00825 return __base;
00826 }
00827
00829 inline ios_base&
00830 noshowpoint(ios_base& __base)
00831 {
00832 __base.unsetf(ios_base::showpoint);
00833 return __base;
00834 }
00835
00837 inline ios_base&
00838 showpos(ios_base& __base)
00839 {
00840 __base.setf(ios_base::showpos);
00841 return __base;
00842 }
00843
00845 inline ios_base&
00846 noshowpos(ios_base& __base)
00847 {
00848 __base.unsetf(ios_base::showpos);
00849 return __base;
00850 }
00851
00853 inline ios_base&
00854 skipws(ios_base& __base)
00855 {
00856 __base.setf(ios_base::skipws);
00857 return __base;
00858 }
00859
00861 inline ios_base&
00862 noskipws(ios_base& __base)
00863 {
00864 __base.unsetf(ios_base::skipws);
00865 return __base;
00866 }
00867
00869 inline ios_base&
00870 uppercase(ios_base& __base)
00871 {
00872 __base.setf(ios_base::uppercase);
00873 return __base;
00874 }
00875
00877 inline ios_base&
00878 nouppercase(ios_base& __base)
00879 {
00880 __base.unsetf(ios_base::uppercase);
00881 return __base;
00882 }
00883
00885 inline ios_base&
00886 unitbuf(ios_base& __base)
00887 {
00888 __base.setf(ios_base::unitbuf);
00889 return __base;
00890 }
00891
00893 inline ios_base&
00894 nounitbuf(ios_base& __base)
00895 {
00896 __base.unsetf(ios_base::unitbuf);
00897 return __base;
00898 }
00899
00900
00902 inline ios_base&
00903 internal(ios_base& __base)
00904 {
00905 __base.setf(ios_base::internal, ios_base::adjustfield);
00906 return __base;
00907 }
00908
00910 inline ios_base&
00911 left(ios_base& __base)
00912 {
00913 __base.setf(ios_base::left, ios_base::adjustfield);
00914 return __base;
00915 }
00916
00918 inline ios_base&
00919 right(ios_base& __base)
00920 {
00921 __base.setf(ios_base::right, ios_base::adjustfield);
00922 return __base;
00923 }
00924
00925
00927 inline ios_base&
00928 dec(ios_base& __base)
00929 {
00930 __base.setf(ios_base::dec, ios_base::basefield);
00931 return __base;
00932 }
00933
00935 inline ios_base&
00936 hex(ios_base& __base)
00937 {
00938 __base.setf(ios_base::hex, ios_base::basefield);
00939 return __base;
00940 }
00941
00943 inline ios_base&
00944 oct(ios_base& __base)
00945 {
00946 __base.setf(ios_base::oct, ios_base::basefield);
00947 return __base;
00948 }
00949
00950
00952 inline ios_base&
00953 fixed(ios_base& __base)
00954 {
00955 __base.setf(ios_base::fixed, ios_base::floatfield);
00956 return __base;
00957 }
00958
00960 inline ios_base&
00961 scientific(ios_base& __base)
00962 {
00963 __base.setf(ios_base::scientific, ios_base::floatfield);
00964 return __base;
00965 }
00966 }
00967
00968 #endif
00969