libstdc++
|
00001 // Iostreams base classes -*- C++ -*- 00002 00003 // Copyright (C) 1997-2019 Free Software Foundation, Inc. 00004 // 00005 // This file is part of the GNU ISO C++ Library. This library is free 00006 // software; you can redistribute it and/or modify it under the 00007 // terms of the GNU General Public License as published by the 00008 // Free Software Foundation; either version 3, or (at your option) 00009 // any later version. 00010 00011 // This library is distributed in the hope that it will be useful, 00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 // GNU General Public License for more details. 00015 00016 // Under Section 7 of GPL version 3, you are granted additional 00017 // permissions described in the GCC Runtime Library Exception, version 00018 // 3.1, as published by the Free Software Foundation. 00019 00020 // You should have received a copy of the GNU General Public License and 00021 // a copy of the GCC Runtime Library Exception along with this program; 00022 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 00023 // <http://www.gnu.org/licenses/>. 00024 00025 /** @file bits/ios_base.h 00026 * This is an internal header file, included by other library headers. 00027 * Do not attempt to use it directly. @headername{ios} 00028 */ 00029 00030 // 00031 // ISO C++ 14882: 27.4 Iostreams base classes 00032 // 00033 00034 #ifndef _IOS_BASE_H 00035 #define _IOS_BASE_H 1 00036 00037 #pragma GCC system_header 00038 00039 #include <ext/atomicity.h> 00040 #include <bits/localefwd.h> 00041 #include <bits/locale_classes.h> 00042 00043 #if __cplusplus < 201103L 00044 # include <stdexcept> 00045 #else 00046 # include <system_error> 00047 #endif 00048 00049 namespace std _GLIBCXX_VISIBILITY(default) 00050 { 00051 _GLIBCXX_BEGIN_NAMESPACE_VERSION 00052 00053 // The following definitions of bitmask types are enums, not ints, 00054 // as permitted (but not required) in the standard, in order to provide 00055 // better type safety in iostream calls. A side effect is that in C++98 00056 // expressions involving them are not compile-time constants. 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 _S_ios_fmtflags_max = __INT_MAX__, 00079 _S_ios_fmtflags_min = ~__INT_MAX__ 00080 }; 00081 00082 inline _GLIBCXX_CONSTEXPR _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 _GLIBCXX_CONSTEXPR _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 _GLIBCXX_CONSTEXPR _Ios_Fmtflags 00091 operator^(_Ios_Fmtflags __a, _Ios_Fmtflags __b) 00092 { return _Ios_Fmtflags(static_cast<int>(__a) ^ static_cast<int>(__b)); } 00093 00094 inline _GLIBCXX_CONSTEXPR _Ios_Fmtflags 00095 operator~(_Ios_Fmtflags __a) 00096 { return _Ios_Fmtflags(~static_cast<int>(__a)); } 00097 00098 inline const _Ios_Fmtflags& 00099 operator|=(_Ios_Fmtflags& __a, _Ios_Fmtflags __b) 00100 { return __a = __a | __b; } 00101 00102 inline const _Ios_Fmtflags& 00103 operator&=(_Ios_Fmtflags& __a, _Ios_Fmtflags __b) 00104 { return __a = __a & __b; } 00105 00106 inline const _Ios_Fmtflags& 00107 operator^=(_Ios_Fmtflags& __a, _Ios_Fmtflags __b) 00108 { return __a = __a ^ __b; } 00109 00110 00111 enum _Ios_Openmode 00112 { 00113 _S_app = 1L << 0, 00114 _S_ate = 1L << 1, 00115 _S_bin = 1L << 2, 00116 _S_in = 1L << 3, 00117 _S_out = 1L << 4, 00118 _S_trunc = 1L << 5, 00119 _S_ios_openmode_end = 1L << 16, 00120 _S_ios_openmode_max = __INT_MAX__, 00121 _S_ios_openmode_min = ~__INT_MAX__ 00122 }; 00123 00124 inline _GLIBCXX_CONSTEXPR _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 _GLIBCXX_CONSTEXPR _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 _GLIBCXX_CONSTEXPR _Ios_Openmode 00133 operator^(_Ios_Openmode __a, _Ios_Openmode __b) 00134 { return _Ios_Openmode(static_cast<int>(__a) ^ static_cast<int>(__b)); } 00135 00136 inline _GLIBCXX_CONSTEXPR _Ios_Openmode 00137 operator~(_Ios_Openmode __a) 00138 { return _Ios_Openmode(~static_cast<int>(__a)); } 00139 00140 inline const _Ios_Openmode& 00141 operator|=(_Ios_Openmode& __a, _Ios_Openmode __b) 00142 { return __a = __a | __b; } 00143 00144 inline const _Ios_Openmode& 00145 operator&=(_Ios_Openmode& __a, _Ios_Openmode __b) 00146 { return __a = __a & __b; } 00147 00148 inline const _Ios_Openmode& 00149 operator^=(_Ios_Openmode& __a, _Ios_Openmode __b) 00150 { return __a = __a ^ __b; } 00151 00152 00153 enum _Ios_Iostate 00154 { 00155 _S_goodbit = 0, 00156 _S_badbit = 1L << 0, 00157 _S_eofbit = 1L << 1, 00158 _S_failbit = 1L << 2, 00159 _S_ios_iostate_end = 1L << 16, 00160 _S_ios_iostate_max = __INT_MAX__, 00161 _S_ios_iostate_min = ~__INT_MAX__ 00162 }; 00163 00164 inline _GLIBCXX_CONSTEXPR _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 _GLIBCXX_CONSTEXPR _Ios_Iostate 00169 operator|(_Ios_Iostate __a, _Ios_Iostate __b) 00170 { return _Ios_Iostate(static_cast<int>(__a) | static_cast<int>(__b)); } 00171 00172 inline _GLIBCXX_CONSTEXPR _Ios_Iostate 00173 operator^(_Ios_Iostate __a, _Ios_Iostate __b) 00174 { return _Ios_Iostate(static_cast<int>(__a) ^ static_cast<int>(__b)); } 00175 00176 inline _GLIBCXX_CONSTEXPR _Ios_Iostate 00177 operator~(_Ios_Iostate __a) 00178 { return _Ios_Iostate(~static_cast<int>(__a)); } 00179 00180 inline const _Ios_Iostate& 00181 operator|=(_Ios_Iostate& __a, _Ios_Iostate __b) 00182 { return __a = __a | __b; } 00183 00184 inline const _Ios_Iostate& 00185 operator&=(_Ios_Iostate& __a, _Ios_Iostate __b) 00186 { return __a = __a & __b; } 00187 00188 inline const _Ios_Iostate& 00189 operator^=(_Ios_Iostate& __a, _Ios_Iostate __b) 00190 { return __a = __a ^ __b; } 00191 00192 00193 enum _Ios_Seekdir 00194 { 00195 _S_beg = 0, 00196 _S_cur = _GLIBCXX_STDIO_SEEK_CUR, 00197 _S_end = _GLIBCXX_STDIO_SEEK_END, 00198 _S_ios_seekdir_end = 1L << 16 00199 }; 00200 00201 #if __cplusplus >= 201103L 00202 /// I/O error code 00203 enum class io_errc { stream = 1 }; 00204 00205 template <> struct is_error_code_enum<io_errc> : public true_type { }; 00206 00207 const error_category& iostream_category() noexcept; 00208 00209 inline error_code 00210 make_error_code(io_errc __e) noexcept 00211 { return error_code(static_cast<int>(__e), iostream_category()); } 00212 00213 inline error_condition 00214 make_error_condition(io_errc __e) noexcept 00215 { return error_condition(static_cast<int>(__e), iostream_category()); } 00216 #endif 00217 00218 // 27.4.2 Class ios_base 00219 /** 00220 * @brief The base of the I/O class hierarchy. 00221 * @ingroup io 00222 * 00223 * This class defines everything that can be defined about I/O that does 00224 * not depend on the type of characters being input or output. Most 00225 * people will only see @c ios_base when they need to specify the full 00226 * name of the various I/O flags (e.g., the openmodes). 00227 */ 00228 class ios_base 00229 { 00230 #if _GLIBCXX_USE_CXX11_ABI 00231 #if __cplusplus < 201103L 00232 // Type that is layout-compatible with std::system_error 00233 struct system_error : std::runtime_error 00234 { 00235 // Type that is layout-compatible with std::error_code 00236 struct error_code 00237 { 00238 error_code() { } 00239 private: 00240 int _M_value; 00241 const void* _M_cat; 00242 } _M_code; 00243 }; 00244 #endif 00245 #endif 00246 public: 00247 00248 /** 00249 * @brief These are thrown to indicate problems with io. 00250 * @ingroup exceptions 00251 * 00252 * 27.4.2.1.1 Class ios_base::failure 00253 */ 00254 #if _GLIBCXX_USE_CXX11_ABI 00255 class _GLIBCXX_ABI_TAG_CXX11 failure : public system_error 00256 { 00257 public: 00258 explicit 00259 failure(const string& __str); 00260 00261 #if __cplusplus >= 201103L 00262 explicit 00263 failure(const string&, const error_code&); 00264 00265 explicit 00266 failure(const char*, const error_code& = io_errc::stream); 00267 #endif 00268 00269 virtual 00270 ~failure() throw(); 00271 00272 virtual const char* 00273 what() const throw(); 00274 }; 00275 #else 00276 class failure : public exception 00277 { 00278 public: 00279 // _GLIBCXX_RESOLVE_LIB_DEFECTS 00280 // 48. Use of non-existent exception constructor 00281 explicit 00282 failure(const string& __str) throw(); 00283 00284 // This declaration is not useless: 00285 // http://gcc.gnu.org/onlinedocs/gcc-4.3.2/gcc/Vague-Linkage.html 00286 virtual 00287 ~failure() throw(); 00288 00289 virtual const char* 00290 what() const throw(); 00291 00292 private: 00293 string _M_msg; 00294 }; 00295 #endif 00296 00297 // 27.4.2.1.2 Type ios_base::fmtflags 00298 /** 00299 * @brief This is a bitmask type. 00300 * 00301 * @c @a _Ios_Fmtflags is implementation-defined, but it is valid to 00302 * perform bitwise operations on these values and expect the Right 00303 * Thing to happen. Defined objects of type fmtflags are: 00304 * - boolalpha 00305 * - dec 00306 * - fixed 00307 * - hex 00308 * - internal 00309 * - left 00310 * - oct 00311 * - right 00312 * - scientific 00313 * - showbase 00314 * - showpoint 00315 * - showpos 00316 * - skipws 00317 * - unitbuf 00318 * - uppercase 00319 * - adjustfield 00320 * - basefield 00321 * - floatfield 00322 */ 00323 typedef _Ios_Fmtflags fmtflags; 00324 00325 /// Insert/extract @c bool in alphabetic rather than numeric format. 00326 static const fmtflags boolalpha = _S_boolalpha; 00327 00328 /// Converts integer input or generates integer output in decimal base. 00329 static const fmtflags dec = _S_dec; 00330 00331 /// Generate floating-point output in fixed-point notation. 00332 static const fmtflags fixed = _S_fixed; 00333 00334 /// Converts integer input or generates integer output in hexadecimal base. 00335 static const fmtflags hex = _S_hex; 00336 00337 /// Adds fill characters at a designated internal point in certain 00338 /// generated output, or identical to @c right if no such point is 00339 /// designated. 00340 static const fmtflags internal = _S_internal; 00341 00342 /// Adds fill characters on the right (final positions) of certain 00343 /// generated output. (I.e., the thing you print is flush left.) 00344 static const fmtflags left = _S_left; 00345 00346 /// Converts integer input or generates integer output in octal base. 00347 static const fmtflags oct = _S_oct; 00348 00349 /// Adds fill characters on the left (initial positions) of certain 00350 /// generated output. (I.e., the thing you print is flush right.) 00351 static const fmtflags right = _S_right; 00352 00353 /// Generates floating-point output in scientific notation. 00354 static const fmtflags scientific = _S_scientific; 00355 00356 /// Generates a prefix indicating the numeric base of generated integer 00357 /// output. 00358 static const fmtflags showbase = _S_showbase; 00359 00360 /// Generates a decimal-point character unconditionally in generated 00361 /// floating-point output. 00362 static const fmtflags showpoint = _S_showpoint; 00363 00364 /// Generates a + sign in non-negative generated numeric output. 00365 static const fmtflags showpos = _S_showpos; 00366 00367 /// Skips leading white space before certain input operations. 00368 static const fmtflags skipws = _S_skipws; 00369 00370 /// Flushes output after each output operation. 00371 static const fmtflags unitbuf = _S_unitbuf; 00372 00373 /// Replaces certain lowercase letters with their uppercase equivalents 00374 /// in generated output. 00375 static const fmtflags uppercase = _S_uppercase; 00376 00377 /// A mask of left|right|internal. Useful for the 2-arg form of @c setf. 00378 static const fmtflags adjustfield = _S_adjustfield; 00379 00380 /// A mask of dec|oct|hex. Useful for the 2-arg form of @c setf. 00381 static const fmtflags basefield = _S_basefield; 00382 00383 /// A mask of scientific|fixed. Useful for the 2-arg form of @c setf. 00384 static const fmtflags floatfield = _S_floatfield; 00385 00386 // 27.4.2.1.3 Type ios_base::iostate 00387 /** 00388 * @brief This is a bitmask type. 00389 * 00390 * @c @a _Ios_Iostate is implementation-defined, but it is valid to 00391 * perform bitwise operations on these values and expect the Right 00392 * Thing to happen. Defined objects of type iostate are: 00393 * - badbit 00394 * - eofbit 00395 * - failbit 00396 * - goodbit 00397 */ 00398 typedef _Ios_Iostate iostate; 00399 00400 /// Indicates a loss of integrity in an input or output sequence (such 00401 /// as an irrecoverable read error from a file). 00402 static const iostate badbit = _S_badbit; 00403 00404 /// Indicates that an input operation reached the end of an input sequence. 00405 static const iostate eofbit = _S_eofbit; 00406 00407 /// Indicates that an input operation failed to read the expected 00408 /// characters, or that an output operation failed to generate the 00409 /// desired characters. 00410 static const iostate failbit = _S_failbit; 00411 00412 /// Indicates all is well. 00413 static const iostate goodbit = _S_goodbit; 00414 00415 // 27.4.2.1.4 Type ios_base::openmode 00416 /** 00417 * @brief This is a bitmask type. 00418 * 00419 * @c @a _Ios_Openmode is implementation-defined, but it is valid to 00420 * perform bitwise operations on these values and expect the Right 00421 * Thing to happen. Defined objects of type openmode are: 00422 * - app 00423 * - ate 00424 * - binary 00425 * - in 00426 * - out 00427 * - trunc 00428 */ 00429 typedef _Ios_Openmode openmode; 00430 00431 /// Seek to end before each write. 00432 static const openmode app = _S_app; 00433 00434 /// Open and seek to end immediately after opening. 00435 static const openmode ate = _S_ate; 00436 00437 /// Perform input and output in binary mode (as opposed to text mode). 00438 /// This is probably not what you think it is; see 00439 /// https://gcc.gnu.org/onlinedocs/libstdc++/manual/fstreams.html#std.io.filestreams.binary 00440 static const openmode binary = _S_bin; 00441 00442 /// Open for input. Default for @c ifstream and fstream. 00443 static const openmode in = _S_in; 00444 00445 /// Open for output. Default for @c ofstream and fstream. 00446 static const openmode out = _S_out; 00447 00448 /// Open for input. Default for @c ofstream. 00449 static const openmode trunc = _S_trunc; 00450 00451 // 27.4.2.1.5 Type ios_base::seekdir 00452 /** 00453 * @brief This is an enumerated type. 00454 * 00455 * @c @a _Ios_Seekdir is implementation-defined. Defined values 00456 * of type seekdir are: 00457 * - beg 00458 * - cur, equivalent to @c SEEK_CUR in the C standard library. 00459 * - end, equivalent to @c SEEK_END in the C standard library. 00460 */ 00461 typedef _Ios_Seekdir seekdir; 00462 00463 /// Request a seek relative to the beginning of the stream. 00464 static const seekdir beg = _S_beg; 00465 00466 /// Request a seek relative to the current position within the sequence. 00467 static const seekdir cur = _S_cur; 00468 00469 /// Request a seek relative to the current end of the sequence. 00470 static const seekdir end = _S_end; 00471 00472 #if __cplusplus <= 201402L 00473 // Annex D.6 (removed in C++17) 00474 typedef int io_state; 00475 typedef int open_mode; 00476 typedef int seek_dir; 00477 00478 typedef std::streampos streampos; 00479 typedef std::streamoff streamoff; 00480 #endif 00481 00482 // Callbacks; 00483 /** 00484 * @brief The set of events that may be passed to an event callback. 00485 * 00486 * erase_event is used during ~ios() and copyfmt(). imbue_event is used 00487 * during imbue(). copyfmt_event is used during copyfmt(). 00488 */ 00489 enum event 00490 { 00491 erase_event, 00492 imbue_event, 00493 copyfmt_event 00494 }; 00495 00496 /** 00497 * @brief The type of an event callback function. 00498 * @param __e One of the members of the event enum. 00499 * @param __b Reference to the ios_base object. 00500 * @param __i The integer provided when the callback was registered. 00501 * 00502 * Event callbacks are user defined functions that get called during 00503 * several ios_base and basic_ios functions, specifically imbue(), 00504 * copyfmt(), and ~ios(). 00505 */ 00506 typedef void (*event_callback) (event __e, ios_base& __b, int __i); 00507 00508 /** 00509 * @brief Add the callback __fn with parameter __index. 00510 * @param __fn The function to add. 00511 * @param __index The integer to pass to the function when invoked. 00512 * 00513 * Registers a function as an event callback with an integer parameter to 00514 * be passed to the function when invoked. Multiple copies of the 00515 * function are allowed. If there are multiple callbacks, they are 00516 * invoked in the order they were registered. 00517 */ 00518 void 00519 register_callback(event_callback __fn, int __index); 00520 00521 protected: 00522 streamsize _M_precision; 00523 streamsize _M_width; 00524 fmtflags _M_flags; 00525 iostate _M_exception; 00526 iostate _M_streambuf_state; 00527 00528 // 27.4.2.6 Members for callbacks 00529 // 27.4.2.6 ios_base callbacks 00530 struct _Callback_list 00531 { 00532 // Data Members 00533 _Callback_list* _M_next; 00534 ios_base::event_callback _M_fn; 00535 int _M_index; 00536 _Atomic_word _M_refcount; // 0 means one reference. 00537 00538 _Callback_list(ios_base::event_callback __fn, int __index, 00539 _Callback_list* __cb) 00540 : _M_next(__cb), _M_fn(__fn), _M_index(__index), _M_refcount(0) { } 00541 00542 void 00543 _M_add_reference() { __gnu_cxx::__atomic_add_dispatch(&_M_refcount, 1); } 00544 00545 // 0 => OK to delete. 00546 int 00547 _M_remove_reference() 00548 { 00549 // Be race-detector-friendly. For more info see bits/c++config. 00550 _GLIBCXX_SYNCHRONIZATION_HAPPENS_BEFORE(&_M_refcount); 00551 int __res = __gnu_cxx::__exchange_and_add_dispatch(&_M_refcount, -1); 00552 if (__res == 0) 00553 { 00554 _GLIBCXX_SYNCHRONIZATION_HAPPENS_AFTER(&_M_refcount); 00555 } 00556 return __res; 00557 } 00558 }; 00559 00560 _Callback_list* _M_callbacks; 00561 00562 void 00563 _M_call_callbacks(event __ev) throw(); 00564 00565 void 00566 _M_dispose_callbacks(void) throw(); 00567 00568 // 27.4.2.5 Members for iword/pword storage 00569 struct _Words 00570 { 00571 void* _M_pword; 00572 long _M_iword; 00573 _Words() : _M_pword(0), _M_iword(0) { } 00574 }; 00575 00576 // Only for failed iword/pword calls. 00577 _Words _M_word_zero; 00578 00579 // Guaranteed storage. 00580 // The first 5 iword and pword slots are reserved for internal use. 00581 enum { _S_local_word_size = 8 }; 00582 _Words _M_local_word[_S_local_word_size]; 00583 00584 // Allocated storage. 00585 int _M_word_size; 00586 _Words* _M_word; 00587 00588 _Words& 00589 _M_grow_words(int __index, bool __iword); 00590 00591 // Members for locale and locale caching. 00592 locale _M_ios_locale; 00593 00594 void 00595 _M_init() throw(); 00596 00597 public: 00598 00599 // 27.4.2.1.6 Class ios_base::Init 00600 // Used to initialize standard streams. In theory, g++ could use 00601 // -finit-priority to order this stuff correctly without going 00602 // through these machinations. 00603 class Init 00604 { 00605 friend class ios_base; 00606 public: 00607 Init(); 00608 ~Init(); 00609 00610 #if __cplusplus >= 201103L 00611 Init(const Init&) = default; 00612 Init& operator=(const Init&) = default; 00613 #endif 00614 00615 private: 00616 static _Atomic_word _S_refcount; 00617 static bool _S_synced_with_stdio; 00618 }; 00619 00620 // [27.4.2.2] fmtflags state functions 00621 /** 00622 * @brief Access to format flags. 00623 * @return The format control flags for both input and output. 00624 */ 00625 fmtflags 00626 flags() const 00627 { return _M_flags; } 00628 00629 /** 00630 * @brief Setting new format flags all at once. 00631 * @param __fmtfl The new flags to set. 00632 * @return The previous format control flags. 00633 * 00634 * This function overwrites all the format flags with @a __fmtfl. 00635 */ 00636 fmtflags 00637 flags(fmtflags __fmtfl) 00638 { 00639 fmtflags __old = _M_flags; 00640 _M_flags = __fmtfl; 00641 return __old; 00642 } 00643 00644 /** 00645 * @brief Setting new format flags. 00646 * @param __fmtfl Additional flags to set. 00647 * @return The previous format control flags. 00648 * 00649 * This function sets additional flags in format control. Flags that 00650 * were previously set remain set. 00651 */ 00652 fmtflags 00653 setf(fmtflags __fmtfl) 00654 { 00655 fmtflags __old = _M_flags; 00656 _M_flags |= __fmtfl; 00657 return __old; 00658 } 00659 00660 /** 00661 * @brief Setting new format flags. 00662 * @param __fmtfl Additional flags to set. 00663 * @param __mask The flags mask for @a fmtfl. 00664 * @return The previous format control flags. 00665 * 00666 * This function clears @a mask in the format flags, then sets 00667 * @a fmtfl @c & @a mask. An example mask is @c ios_base::adjustfield. 00668 */ 00669 fmtflags 00670 setf(fmtflags __fmtfl, fmtflags __mask) 00671 { 00672 fmtflags __old = _M_flags; 00673 _M_flags &= ~__mask; 00674 _M_flags |= (__fmtfl & __mask); 00675 return __old; 00676 } 00677 00678 /** 00679 * @brief Clearing format flags. 00680 * @param __mask The flags to unset. 00681 * 00682 * This function clears @a __mask in the format flags. 00683 */ 00684 void 00685 unsetf(fmtflags __mask) 00686 { _M_flags &= ~__mask; } 00687 00688 /** 00689 * @brief Flags access. 00690 * @return The precision to generate on certain output operations. 00691 * 00692 * Be careful if you try to give a definition of @a precision here; see 00693 * DR 189. 00694 */ 00695 streamsize 00696 precision() const 00697 { return _M_precision; } 00698 00699 /** 00700 * @brief Changing flags. 00701 * @param __prec The new precision value. 00702 * @return The previous value of precision(). 00703 */ 00704 streamsize 00705 precision(streamsize __prec) 00706 { 00707 streamsize __old = _M_precision; 00708 _M_precision = __prec; 00709 return __old; 00710 } 00711 00712 /** 00713 * @brief Flags access. 00714 * @return The minimum field width to generate on output operations. 00715 * 00716 * <em>Minimum field width</em> refers to the number of characters. 00717 */ 00718 streamsize 00719 width() const 00720 { return _M_width; } 00721 00722 /** 00723 * @brief Changing flags. 00724 * @param __wide The new width value. 00725 * @return The previous value of width(). 00726 */ 00727 streamsize 00728 width(streamsize __wide) 00729 { 00730 streamsize __old = _M_width; 00731 _M_width = __wide; 00732 return __old; 00733 } 00734 00735 // [27.4.2.4] ios_base static members 00736 /** 00737 * @brief Interaction with the standard C I/O objects. 00738 * @param __sync Whether to synchronize or not. 00739 * @return True if the standard streams were previously synchronized. 00740 * 00741 * The synchronization referred to is @e only that between the standard 00742 * C facilities (e.g., stdout) and the standard C++ objects (e.g., 00743 * cout). User-declared streams are unaffected. See 00744 * https://gcc.gnu.org/onlinedocs/libstdc++/manual/fstreams.html#std.io.filestreams.binary 00745 */ 00746 static bool 00747 sync_with_stdio(bool __sync = true); 00748 00749 // [27.4.2.3] ios_base locale functions 00750 /** 00751 * @brief Setting a new locale. 00752 * @param __loc The new locale. 00753 * @return The previous locale. 00754 * 00755 * Sets the new locale for this stream, and then invokes each callback 00756 * with imbue_event. 00757 */ 00758 locale 00759 imbue(const locale& __loc) throw(); 00760 00761 /** 00762 * @brief Locale access 00763 * @return A copy of the current locale. 00764 * 00765 * If @c imbue(loc) has previously been called, then this function 00766 * returns @c loc. Otherwise, it returns a copy of @c std::locale(), 00767 * the global C++ locale. 00768 */ 00769 locale 00770 getloc() const 00771 { return _M_ios_locale; } 00772 00773 /** 00774 * @brief Locale access 00775 * @return A reference to the current locale. 00776 * 00777 * Like getloc above, but returns a reference instead of 00778 * generating a copy. 00779 */ 00780 const locale& 00781 _M_getloc() const 00782 { return _M_ios_locale; } 00783 00784 // [27.4.2.5] ios_base storage functions 00785 /** 00786 * @brief Access to unique indices. 00787 * @return An integer different from all previous calls. 00788 * 00789 * This function returns a unique integer every time it is called. It 00790 * can be used for any purpose, but is primarily intended to be a unique 00791 * index for the iword and pword functions. The expectation is that an 00792 * application calls xalloc in order to obtain an index in the iword and 00793 * pword arrays that can be used without fear of conflict. 00794 * 00795 * The implementation maintains a static variable that is incremented and 00796 * returned on each invocation. xalloc is guaranteed to return an index 00797 * that is safe to use in the iword and pword arrays. 00798 */ 00799 static int 00800 xalloc() throw(); 00801 00802 /** 00803 * @brief Access to integer array. 00804 * @param __ix Index into the array. 00805 * @return A reference to an integer associated with the index. 00806 * 00807 * The iword function provides access to an array of integers that can be 00808 * used for any purpose. The array grows as required to hold the 00809 * supplied index. All integers in the array are initialized to 0. 00810 * 00811 * The implementation reserves several indices. You should use xalloc to 00812 * obtain an index that is safe to use. Also note that since the array 00813 * can grow dynamically, it is not safe to hold onto the reference. 00814 */ 00815 long& 00816 iword(int __ix) 00817 { 00818 _Words& __word = ((unsigned)__ix < (unsigned)_M_word_size) 00819 ? _M_word[__ix] : _M_grow_words(__ix, true); 00820 return __word._M_iword; 00821 } 00822 00823 /** 00824 * @brief Access to void pointer array. 00825 * @param __ix Index into the array. 00826 * @return A reference to a void* associated with the index. 00827 * 00828 * The pword function provides access to an array of pointers that can be 00829 * used for any purpose. The array grows as required to hold the 00830 * supplied index. All pointers in the array are initialized to 0. 00831 * 00832 * The implementation reserves several indices. You should use xalloc to 00833 * obtain an index that is safe to use. Also note that since the array 00834 * can grow dynamically, it is not safe to hold onto the reference. 00835 */ 00836 void*& 00837 pword(int __ix) 00838 { 00839 _Words& __word = ((unsigned)__ix < (unsigned)_M_word_size) 00840 ? _M_word[__ix] : _M_grow_words(__ix, false); 00841 return __word._M_pword; 00842 } 00843 00844 // Destructor 00845 /** 00846 * Invokes each callback with erase_event. Destroys local storage. 00847 * 00848 * Note that the ios_base object for the standard streams never gets 00849 * destroyed. As a result, any callbacks registered with the standard 00850 * streams will not get invoked with erase_event (unless copyfmt is 00851 * used). 00852 */ 00853 virtual ~ios_base(); 00854 00855 protected: 00856 ios_base() throw (); 00857 00858 #if __cplusplus < 201103L 00859 // _GLIBCXX_RESOLVE_LIB_DEFECTS 00860 // 50. Copy constructor and assignment operator of ios_base 00861 private: 00862 ios_base(const ios_base&); 00863 00864 ios_base& 00865 operator=(const ios_base&); 00866 #else 00867 public: 00868 ios_base(const ios_base&) = delete; 00869 00870 ios_base& 00871 operator=(const ios_base&) = delete; 00872 00873 protected: 00874 void 00875 _M_move(ios_base&) noexcept; 00876 00877 void 00878 _M_swap(ios_base& __rhs) noexcept; 00879 #endif 00880 }; 00881 00882 // [27.4.5.1] fmtflags manipulators 00883 /// Calls base.setf(ios_base::boolalpha). 00884 inline ios_base& 00885 boolalpha(ios_base& __base) 00886 { 00887 __base.setf(ios_base::boolalpha); 00888 return __base; 00889 } 00890 00891 /// Calls base.unsetf(ios_base::boolalpha). 00892 inline ios_base& 00893 noboolalpha(ios_base& __base) 00894 { 00895 __base.unsetf(ios_base::boolalpha); 00896 return __base; 00897 } 00898 00899 /// Calls base.setf(ios_base::showbase). 00900 inline ios_base& 00901 showbase(ios_base& __base) 00902 { 00903 __base.setf(ios_base::showbase); 00904 return __base; 00905 } 00906 00907 /// Calls base.unsetf(ios_base::showbase). 00908 inline ios_base& 00909 noshowbase(ios_base& __base) 00910 { 00911 __base.unsetf(ios_base::showbase); 00912 return __base; 00913 } 00914 00915 /// Calls base.setf(ios_base::showpoint). 00916 inline ios_base& 00917 showpoint(ios_base& __base) 00918 { 00919 __base.setf(ios_base::showpoint); 00920 return __base; 00921 } 00922 00923 /// Calls base.unsetf(ios_base::showpoint). 00924 inline ios_base& 00925 noshowpoint(ios_base& __base) 00926 { 00927 __base.unsetf(ios_base::showpoint); 00928 return __base; 00929 } 00930 00931 /// Calls base.setf(ios_base::showpos). 00932 inline ios_base& 00933 showpos(ios_base& __base) 00934 { 00935 __base.setf(ios_base::showpos); 00936 return __base; 00937 } 00938 00939 /// Calls base.unsetf(ios_base::showpos). 00940 inline ios_base& 00941 noshowpos(ios_base& __base) 00942 { 00943 __base.unsetf(ios_base::showpos); 00944 return __base; 00945 } 00946 00947 /// Calls base.setf(ios_base::skipws). 00948 inline ios_base& 00949 skipws(ios_base& __base) 00950 { 00951 __base.setf(ios_base::skipws); 00952 return __base; 00953 } 00954 00955 /// Calls base.unsetf(ios_base::skipws). 00956 inline ios_base& 00957 noskipws(ios_base& __base) 00958 { 00959 __base.unsetf(ios_base::skipws); 00960 return __base; 00961 } 00962 00963 /// Calls base.setf(ios_base::uppercase). 00964 inline ios_base& 00965 uppercase(ios_base& __base) 00966 { 00967 __base.setf(ios_base::uppercase); 00968 return __base; 00969 } 00970 00971 /// Calls base.unsetf(ios_base::uppercase). 00972 inline ios_base& 00973 nouppercase(ios_base& __base) 00974 { 00975 __base.unsetf(ios_base::uppercase); 00976 return __base; 00977 } 00978 00979 /// Calls base.setf(ios_base::unitbuf). 00980 inline ios_base& 00981 unitbuf(ios_base& __base) 00982 { 00983 __base.setf(ios_base::unitbuf); 00984 return __base; 00985 } 00986 00987 /// Calls base.unsetf(ios_base::unitbuf). 00988 inline ios_base& 00989 nounitbuf(ios_base& __base) 00990 { 00991 __base.unsetf(ios_base::unitbuf); 00992 return __base; 00993 } 00994 00995 // [27.4.5.2] adjustfield manipulators 00996 /// Calls base.setf(ios_base::internal, ios_base::adjustfield). 00997 inline ios_base& 00998 internal(ios_base& __base) 00999 { 01000 __base.setf(ios_base::internal, ios_base::adjustfield); 01001 return __base; 01002 } 01003 01004 /// Calls base.setf(ios_base::left, ios_base::adjustfield). 01005 inline ios_base& 01006 left(ios_base& __base) 01007 { 01008 __base.setf(ios_base::left, ios_base::adjustfield); 01009 return __base; 01010 } 01011 01012 /// Calls base.setf(ios_base::right, ios_base::adjustfield). 01013 inline ios_base& 01014 right(ios_base& __base) 01015 { 01016 __base.setf(ios_base::right, ios_base::adjustfield); 01017 return __base; 01018 } 01019 01020 // [27.4.5.3] basefield manipulators 01021 /// Calls base.setf(ios_base::dec, ios_base::basefield). 01022 inline ios_base& 01023 dec(ios_base& __base) 01024 { 01025 __base.setf(ios_base::dec, ios_base::basefield); 01026 return __base; 01027 } 01028 01029 /// Calls base.setf(ios_base::hex, ios_base::basefield). 01030 inline ios_base& 01031 hex(ios_base& __base) 01032 { 01033 __base.setf(ios_base::hex, ios_base::basefield); 01034 return __base; 01035 } 01036 01037 /// Calls base.setf(ios_base::oct, ios_base::basefield). 01038 inline ios_base& 01039 oct(ios_base& __base) 01040 { 01041 __base.setf(ios_base::oct, ios_base::basefield); 01042 return __base; 01043 } 01044 01045 // [27.4.5.4] floatfield manipulators 01046 /// Calls base.setf(ios_base::fixed, ios_base::floatfield). 01047 inline ios_base& 01048 fixed(ios_base& __base) 01049 { 01050 __base.setf(ios_base::fixed, ios_base::floatfield); 01051 return __base; 01052 } 01053 01054 /// Calls base.setf(ios_base::scientific, ios_base::floatfield). 01055 inline ios_base& 01056 scientific(ios_base& __base) 01057 { 01058 __base.setf(ios_base::scientific, ios_base::floatfield); 01059 return __base; 01060 } 01061 01062 #if __cplusplus >= 201103L 01063 // New C++11 floatfield manipulators 01064 01065 /// Calls 01066 /// base.setf(ios_base::fixed|ios_base::scientific, ios_base::floatfield) 01067 inline ios_base& 01068 hexfloat(ios_base& __base) 01069 { 01070 __base.setf(ios_base::fixed | ios_base::scientific, ios_base::floatfield); 01071 return __base; 01072 } 01073 01074 /// Calls @c base.unsetf(ios_base::floatfield) 01075 inline ios_base& 01076 defaultfloat(ios_base& __base) 01077 { 01078 __base.unsetf(ios_base::floatfield); 01079 return __base; 01080 } 01081 #endif 01082 01083 _GLIBCXX_END_NAMESPACE_VERSION 01084 } // namespace 01085 01086 #endif /* _IOS_BASE_H */