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 _CPP_BITS_IOSBASE_H
00041 #define _CPP_BITS_IOSBASE_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 { _M_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 { _M_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 { _M_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 { _M_ios_seekdir_end = 1L << 16 };
00148
00149 class __locale_cache_base;
00150
00151
00160 class ios_base
00161 {
00162 public:
00163
00164
00166 class failure : public exception
00167 {
00168 public:
00169 #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
00170
00171 explicit
00172 failure(const string& __str) throw();
00173
00174
00175
00176 virtual
00177 ~failure() throw();
00178
00179 virtual const char*
00180 what() const throw();
00181
00182 private:
00183 enum { _M_bufsize = 256 };
00184 char _M_name[_M_bufsize];
00185 #endif
00186 };
00187
00188
00214 typedef _Ios_Fmtflags fmtflags;
00216 static const fmtflags boolalpha = fmtflags(__ios_flags::_S_boolalpha);
00218 static const fmtflags dec = fmtflags(__ios_flags::_S_dec);
00220 static const fmtflags fixed = fmtflags(__ios_flags::_S_fixed);
00222 static const fmtflags hex = fmtflags(__ios_flags::_S_hex);
00226 static const fmtflags internal = fmtflags(__ios_flags::_S_internal);
00229 static const fmtflags left = fmtflags(__ios_flags::_S_left);
00231 static const fmtflags oct = fmtflags(__ios_flags::_S_oct);
00234 static const fmtflags right = fmtflags(__ios_flags::_S_right);
00236 static const fmtflags scientific = fmtflags(__ios_flags::_S_scientific);
00239 static const fmtflags showbase = fmtflags(__ios_flags::_S_showbase);
00242 static const fmtflags showpoint = fmtflags(__ios_flags::_S_showpoint);
00244 static const fmtflags showpos = fmtflags(__ios_flags::_S_showpos);
00246 static const fmtflags skipws = fmtflags(__ios_flags::_S_skipws);
00248 static const fmtflags unitbuf = fmtflags(__ios_flags::_S_unitbuf);
00251 static const fmtflags uppercase = fmtflags(__ios_flags::_S_uppercase);
00253 static const fmtflags adjustfield = fmtflags(__ios_flags::_S_adjustfield);
00255 static const fmtflags basefield = fmtflags(__ios_flags::_S_basefield);
00257 static const fmtflags floatfield = fmtflags(__ios_flags::_S_floatfield);
00258
00259
00271 typedef _Ios_Iostate iostate;
00274 static const iostate badbit = iostate(__ios_flags::_S_badbit);
00276 static const iostate eofbit = iostate(__ios_flags::_S_eofbit);
00280 static const iostate failbit = iostate(__ios_flags::_S_failbit);
00282 static const iostate goodbit = iostate(0);
00283
00284
00298 typedef _Ios_Openmode openmode;
00300 static const openmode app = openmode(__ios_flags::_S_app);
00302 static const openmode ate = openmode(__ios_flags::_S_ate);
00307 static const openmode binary = openmode(__ios_flags::_S_bin);
00309 static const openmode in = openmode(__ios_flags::_S_in);
00311 static const openmode out = openmode(__ios_flags::_S_out);
00313 static const openmode trunc = openmode(__ios_flags::_S_trunc);
00314
00315
00325 typedef _Ios_Seekdir seekdir;
00327 static const seekdir beg = seekdir(0);
00329 static const seekdir cur = seekdir(SEEK_CUR);
00331 static const seekdir end = seekdir(SEEK_END);
00332
00333 #ifdef _GLIBCPP_DEPRECATED
00334
00335 typedef int io_state;
00336 typedef int open_mode;
00337 typedef int seek_dir;
00338
00339 typedef std::streampos streampos;
00340 typedef std::streamoff streamoff;
00341 #endif
00342
00343
00347 enum event
00348 {
00349 erase_event,
00350 imbue_event,
00351 copyfmt_event
00352 };
00353
00357 typedef void (*event_callback) (event, ios_base&, int);
00358
00362 void
00363 register_callback(event_callback __fn, int __index);
00364
00365 protected:
00367
00372 streamsize _M_precision;
00373 streamsize _M_width;
00374 fmtflags _M_flags;
00375 iostate _M_exception;
00376 iostate _M_streambuf_state;
00378
00379
00380
00381 struct _Callback_list
00382 {
00383
00384 _Callback_list* _M_next;
00385 ios_base::event_callback _M_fn;
00386 int _M_index;
00387 _Atomic_word _M_refcount;
00388
00389 _Callback_list(ios_base::event_callback __fn, int __index,
00390 _Callback_list* __cb)
00391 : _M_next(__cb), _M_fn(__fn), _M_index(__index), _M_refcount(0) { }
00392
00393 void
00394 _M_add_reference() { __atomic_add(&_M_refcount, 1); }
00395
00396
00397 int
00398 _M_remove_reference() { return __exchange_and_add(&_M_refcount, -1); }
00399 };
00400
00401 _Callback_list* _M_callbacks;
00402
00403 void
00404 _M_call_callbacks(event __ev) throw();
00405
00406 void
00407 _M_dispose_callbacks(void);
00408
00409
00410 struct _Words
00411 {
00412 void* _M_pword;
00413 long _M_iword;
00414 _Words() : _M_pword(0), _M_iword(0) { }
00415 };
00416
00417
00418 _Words _M_word_zero;
00419
00420
00421
00422 static const int _S_local_word_size = 8;
00423 _Words _M_local_word[_S_local_word_size];
00424
00425
00426 int _M_word_size;
00427 _Words* _M_word;
00428
00429 _Words&
00430 _M_grow_words(int __index);
00431
00432
00433 locale _M_ios_locale;
00434
00435 void
00436 _M_init();
00437
00438 public:
00439
00440
00441
00442
00443
00444 class Init
00445 {
00446 friend class ios_base;
00447 public:
00448 Init();
00449 ~Init();
00450
00451 static void
00452 _S_ios_create(bool __sync);
00453
00454 static void
00455 _S_ios_destroy();
00456
00457
00458
00459
00460 static bool
00461 _S_initialized() { return _S_ios_base_init; }
00462
00463 private:
00464 static int _S_ios_base_init;
00465 static bool _S_synced_with_stdio;
00466 };
00467
00468
00473 inline fmtflags
00474 flags() const { return _M_flags; }
00475
00483 inline fmtflags
00484 flags(fmtflags __fmtfl)
00485 {
00486 fmtflags __old = _M_flags;
00487 _M_flags = __fmtfl;
00488 return __old;
00489 }
00490
00499 inline fmtflags
00500 setf(fmtflags __fmtfl)
00501 {
00502 fmtflags __old = _M_flags;
00503 _M_flags |= __fmtfl;
00504 return __old;
00505 }
00506
00516 inline fmtflags
00517 setf(fmtflags __fmtfl, fmtflags __mask)
00518 {
00519 fmtflags __old = _M_flags;
00520 _M_flags &= ~__mask;
00521 _M_flags |= (__fmtfl & __mask);
00522 return __old;
00523 }
00524
00531 inline void
00532 unsetf(fmtflags __mask) { _M_flags &= ~__mask; }
00533
00543 inline streamsize
00544 precision() const { return _M_precision; }
00545
00551 inline streamsize
00552 precision(streamsize __prec)
00553 {
00554 streamsize __old = _M_precision;
00555 _M_precision = __prec;
00556 return __old;
00557 }
00558
00565 inline streamsize
00566 width() const { return _M_width; }
00567
00573 inline streamsize
00574 width(streamsize __wide)
00575 {
00576 streamsize __old = _M_width;
00577 _M_width = __wide;
00578 return __old;
00579 }
00580
00581
00592 static bool
00593 sync_with_stdio(bool __sync = true);
00594
00595
00604 locale
00605 imbue(const locale& __loc);
00606
00615 inline locale
00616 getloc() const { return _M_ios_locale; }
00617
00618
00622 static int
00623 xalloc() throw();
00624
00628 inline long&
00629 iword(int __ix)
00630 {
00631 _Words& __word = (__ix < _M_word_size)
00632 ? _M_word[__ix] : _M_grow_words(__ix);
00633 return __word._M_iword;
00634 }
00635
00639 inline void*&
00640 pword(int __ix)
00641 {
00642 _Words& __word = (__ix < _M_word_size)
00643 ? _M_word[__ix] : _M_grow_words(__ix);
00644 return __word._M_pword;
00645 }
00646
00647
00648
00649 __locale_cache_base&
00650 _M_cache() { return *static_cast<__locale_cache_base*>(pword(0)); }
00651
00652
00657 ~ios_base();
00658
00659 protected:
00660 ios_base();
00661
00662 #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
00663
00664 private:
00665 ios_base(const ios_base&);
00666
00667 ios_base&
00668 operator=(const ios_base&);
00669 #endif
00670 };
00671
00672
00674 inline ios_base&
00675 boolalpha(ios_base& __base)
00676 {
00677 __base.setf(ios_base::boolalpha);
00678 return __base;
00679 }
00680
00682 inline ios_base&
00683 noboolalpha(ios_base& __base)
00684 {
00685 __base.unsetf(ios_base::boolalpha);
00686 return __base;
00687 }
00688
00690 inline ios_base&
00691 showbase(ios_base& __base)
00692 {
00693 __base.setf(ios_base::showbase);
00694 return __base;
00695 }
00696
00698 inline ios_base&
00699 noshowbase(ios_base& __base)
00700 {
00701 __base.unsetf(ios_base::showbase);
00702 return __base;
00703 }
00704
00706 inline ios_base&
00707 showpoint(ios_base& __base)
00708 {
00709 __base.setf(ios_base::showpoint);
00710 return __base;
00711 }
00712
00714 inline ios_base&
00715 noshowpoint(ios_base& __base)
00716 {
00717 __base.unsetf(ios_base::showpoint);
00718 return __base;
00719 }
00720
00722 inline ios_base&
00723 showpos(ios_base& __base)
00724 {
00725 __base.setf(ios_base::showpos);
00726 return __base;
00727 }
00728
00730 inline ios_base&
00731 noshowpos(ios_base& __base)
00732 {
00733 __base.unsetf(ios_base::showpos);
00734 return __base;
00735 }
00736
00738 inline ios_base&
00739 skipws(ios_base& __base)
00740 {
00741 __base.setf(ios_base::skipws);
00742 return __base;
00743 }
00744
00746 inline ios_base&
00747 noskipws(ios_base& __base)
00748 {
00749 __base.unsetf(ios_base::skipws);
00750 return __base;
00751 }
00752
00754 inline ios_base&
00755 uppercase(ios_base& __base)
00756 {
00757 __base.setf(ios_base::uppercase);
00758 return __base;
00759 }
00760
00762 inline ios_base&
00763 nouppercase(ios_base& __base)
00764 {
00765 __base.unsetf(ios_base::uppercase);
00766 return __base;
00767 }
00768
00770 inline ios_base&
00771 unitbuf(ios_base& __base)
00772 {
00773 __base.setf(ios_base::unitbuf);
00774 return __base;
00775 }
00776
00778 inline ios_base&
00779 nounitbuf(ios_base& __base)
00780 {
00781 __base.unsetf(ios_base::unitbuf);
00782 return __base;
00783 }
00784
00785
00787 inline ios_base&
00788 internal(ios_base& __base)
00789 {
00790 __base.setf(ios_base::internal, ios_base::adjustfield);
00791 return __base;
00792 }
00793
00795 inline ios_base&
00796 left(ios_base& __base)
00797 {
00798 __base.setf(ios_base::left, ios_base::adjustfield);
00799 return __base;
00800 }
00801
00803 inline ios_base&
00804 right(ios_base& __base)
00805 {
00806 __base.setf(ios_base::right, ios_base::adjustfield);
00807 return __base;
00808 }
00809
00810
00812 inline ios_base&
00813 dec(ios_base& __base)
00814 {
00815 __base.setf(ios_base::dec, ios_base::basefield);
00816 return __base;
00817 }
00818
00820 inline ios_base&
00821 hex(ios_base& __base)
00822 {
00823 __base.setf(ios_base::hex, ios_base::basefield);
00824 return __base;
00825 }
00826
00828 inline ios_base&
00829 oct(ios_base& __base)
00830 {
00831 __base.setf(ios_base::oct, ios_base::basefield);
00832 return __base;
00833 }
00834
00835
00837 inline ios_base&
00838 fixed(ios_base& __base)
00839 {
00840 __base.setf(ios_base::fixed, ios_base::floatfield);
00841 return __base;
00842 }
00843
00845 inline ios_base&
00846 scientific(ios_base& __base)
00847 {
00848 __base.setf(ios_base::scientific, ios_base::floatfield);
00849 return __base;
00850 }
00851
00852 }
00853
00854 #endif
00855