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