197403Sobrien// Iostreams base classes -*- C++ -*- 297403Sobrien 3169691Skan// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 497403Sobrien// Free Software Foundation, Inc. 597403Sobrien// 697403Sobrien// This file is part of the GNU ISO C++ Library. This library is free 797403Sobrien// software; you can redistribute it and/or modify it under the 897403Sobrien// terms of the GNU General Public License as published by the 997403Sobrien// Free Software Foundation; either version 2, or (at your option) 1097403Sobrien// any later version. 1197403Sobrien 1297403Sobrien// This library is distributed in the hope that it will be useful, 1397403Sobrien// but WITHOUT ANY WARRANTY; without even the implied warranty of 1497403Sobrien// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1597403Sobrien// GNU General Public License for more details. 1697403Sobrien 1797403Sobrien// You should have received a copy of the GNU General Public License along 1897403Sobrien// with this library; see the file COPYING. If not, write to the Free 19169691Skan// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 2097403Sobrien// USA. 2197403Sobrien 2297403Sobrien// As a special exception, you may use this file as part of a free software 2397403Sobrien// library without restriction. Specifically, if other files instantiate 2497403Sobrien// templates or use macros or inline functions from this file, or you compile 2597403Sobrien// this file and link it with other files to produce an executable, this 2697403Sobrien// file does not by itself cause the resulting executable to be covered by 2797403Sobrien// the GNU General Public License. This exception does not however 2897403Sobrien// invalidate any other reasons why the executable file might be covered by 2997403Sobrien// the GNU General Public License. 3097403Sobrien 3197403Sobrien/** @file ios_base.h 3297403Sobrien * This is an internal header file, included by other library headers. 3397403Sobrien * You should not attempt to use it directly. 3497403Sobrien */ 3597403Sobrien 36169691Skan// 37169691Skan// ISO C++ 14882: 27.4 Iostreams base classes 38169691Skan// 39169691Skan 40132720Skan#ifndef _IOS_BASE_H 41132720Skan#define _IOS_BASE_H 1 4297403Sobrien 4397403Sobrien#pragma GCC system_header 4497403Sobrien 45169691Skan#include <ext/atomicity.h> 46117397Skan#include <bits/localefwd.h> 47117397Skan#include <bits/locale_classes.h> 4897403Sobrien 49169691Skan_GLIBCXX_BEGIN_NAMESPACE(std) 50169691Skan 5197403Sobrien // The following definitions of bitmask types are enums, not ints, 5297403Sobrien // as permitted (but not required) in the standard, in order to provide 5397403Sobrien // better type safety in iostream calls. A side effect is that 5497403Sobrien // expressions involving them are no longer compile-time constants. 55146897Skan enum _Ios_Fmtflags 56146897Skan { 57146897Skan _S_boolalpha = 1L << 0, 58146897Skan _S_dec = 1L << 1, 59146897Skan _S_fixed = 1L << 2, 60146897Skan _S_hex = 1L << 3, 61146897Skan _S_internal = 1L << 4, 62146897Skan _S_left = 1L << 5, 63146897Skan _S_oct = 1L << 6, 64146897Skan _S_right = 1L << 7, 65146897Skan _S_scientific = 1L << 8, 66146897Skan _S_showbase = 1L << 9, 67146897Skan _S_showpoint = 1L << 10, 68146897Skan _S_showpos = 1L << 11, 69146897Skan _S_skipws = 1L << 12, 70146897Skan _S_unitbuf = 1L << 13, 71146897Skan _S_uppercase = 1L << 14, 72146897Skan _S_adjustfield = _S_left | _S_right | _S_internal, 73146897Skan _S_basefield = _S_dec | _S_oct | _S_hex, 74146897Skan _S_floatfield = _S_scientific | _S_fixed, 75146897Skan _S_ios_fmtflags_end = 1L << 16 76146897Skan }; 7797403Sobrien 78132720Skan inline _Ios_Fmtflags 7997403Sobrien operator&(_Ios_Fmtflags __a, _Ios_Fmtflags __b) 8097403Sobrien { return _Ios_Fmtflags(static_cast<int>(__a) & static_cast<int>(__b)); } 8197403Sobrien 82132720Skan inline _Ios_Fmtflags 8397403Sobrien operator|(_Ios_Fmtflags __a, _Ios_Fmtflags __b) 8497403Sobrien { return _Ios_Fmtflags(static_cast<int>(__a) | static_cast<int>(__b)); } 8597403Sobrien 86132720Skan inline _Ios_Fmtflags 8797403Sobrien operator^(_Ios_Fmtflags __a, _Ios_Fmtflags __b) 8897403Sobrien { return _Ios_Fmtflags(static_cast<int>(__a) ^ static_cast<int>(__b)); } 8997403Sobrien 90146897Skan inline _Ios_Fmtflags& 9197403Sobrien operator|=(_Ios_Fmtflags& __a, _Ios_Fmtflags __b) 9297403Sobrien { return __a = __a | __b; } 9397403Sobrien 94146897Skan inline _Ios_Fmtflags& 9597403Sobrien operator&=(_Ios_Fmtflags& __a, _Ios_Fmtflags __b) 9697403Sobrien { return __a = __a & __b; } 9797403Sobrien 98146897Skan inline _Ios_Fmtflags& 9997403Sobrien operator^=(_Ios_Fmtflags& __a, _Ios_Fmtflags __b) 10097403Sobrien { return __a = __a ^ __b; } 10197403Sobrien 102132720Skan inline _Ios_Fmtflags 10397403Sobrien operator~(_Ios_Fmtflags __a) 10497403Sobrien { return _Ios_Fmtflags(~static_cast<int>(__a)); } 10597403Sobrien 10697403Sobrien 107146897Skan enum _Ios_Openmode 108146897Skan { 109146897Skan _S_app = 1L << 0, 110146897Skan _S_ate = 1L << 1, 111146897Skan _S_bin = 1L << 2, 112146897Skan _S_in = 1L << 3, 113146897Skan _S_out = 1L << 4, 114146897Skan _S_trunc = 1L << 5, 115146897Skan _S_ios_openmode_end = 1L << 16 116146897Skan }; 11797403Sobrien 118132720Skan inline _Ios_Openmode 11997403Sobrien operator&(_Ios_Openmode __a, _Ios_Openmode __b) 12097403Sobrien { return _Ios_Openmode(static_cast<int>(__a) & static_cast<int>(__b)); } 12197403Sobrien 122132720Skan inline _Ios_Openmode 12397403Sobrien operator|(_Ios_Openmode __a, _Ios_Openmode __b) 12497403Sobrien { return _Ios_Openmode(static_cast<int>(__a) | static_cast<int>(__b)); } 12597403Sobrien 126132720Skan inline _Ios_Openmode 12797403Sobrien operator^(_Ios_Openmode __a, _Ios_Openmode __b) 12897403Sobrien { return _Ios_Openmode(static_cast<int>(__a) ^ static_cast<int>(__b)); } 12997403Sobrien 130146897Skan inline _Ios_Openmode& 13197403Sobrien operator|=(_Ios_Openmode& __a, _Ios_Openmode __b) 13297403Sobrien { return __a = __a | __b; } 13397403Sobrien 134146897Skan inline _Ios_Openmode& 13597403Sobrien operator&=(_Ios_Openmode& __a, _Ios_Openmode __b) 13697403Sobrien { return __a = __a & __b; } 13797403Sobrien 138146897Skan inline _Ios_Openmode& 13997403Sobrien operator^=(_Ios_Openmode& __a, _Ios_Openmode __b) 14097403Sobrien { return __a = __a ^ __b; } 14197403Sobrien 142132720Skan inline _Ios_Openmode 14397403Sobrien operator~(_Ios_Openmode __a) 14497403Sobrien { return _Ios_Openmode(~static_cast<int>(__a)); } 14597403Sobrien 14697403Sobrien 147146897Skan enum _Ios_Iostate 148146897Skan { 149146897Skan _S_goodbit = 0, 150146897Skan _S_badbit = 1L << 0, 151146897Skan _S_eofbit = 1L << 1, 152146897Skan _S_failbit = 1L << 2, 153146897Skan _S_ios_iostate_end = 1L << 16 154146897Skan }; 15597403Sobrien 156132720Skan inline _Ios_Iostate 15797403Sobrien operator&(_Ios_Iostate __a, _Ios_Iostate __b) 15897403Sobrien { return _Ios_Iostate(static_cast<int>(__a) & static_cast<int>(__b)); } 15997403Sobrien 160132720Skan inline _Ios_Iostate 16197403Sobrien operator|(_Ios_Iostate __a, _Ios_Iostate __b) 16297403Sobrien { return _Ios_Iostate(static_cast<int>(__a) | static_cast<int>(__b)); } 16397403Sobrien 164132720Skan inline _Ios_Iostate 16597403Sobrien operator^(_Ios_Iostate __a, _Ios_Iostate __b) 16697403Sobrien { return _Ios_Iostate(static_cast<int>(__a) ^ static_cast<int>(__b)); } 16797403Sobrien 168146897Skan inline _Ios_Iostate& 16997403Sobrien operator|=(_Ios_Iostate& __a, _Ios_Iostate __b) 17097403Sobrien { return __a = __a | __b; } 17197403Sobrien 172146897Skan inline _Ios_Iostate& 17397403Sobrien operator&=(_Ios_Iostate& __a, _Ios_Iostate __b) 17497403Sobrien { return __a = __a & __b; } 17597403Sobrien 176146897Skan inline _Ios_Iostate& 17797403Sobrien operator^=(_Ios_Iostate& __a, _Ios_Iostate __b) 17897403Sobrien { return __a = __a ^ __b; } 17997403Sobrien 180132720Skan inline _Ios_Iostate 18197403Sobrien operator~(_Ios_Iostate __a) 18297403Sobrien { return _Ios_Iostate(~static_cast<int>(__a)); } 18397403Sobrien 184146897Skan enum _Ios_Seekdir 185146897Skan { 186146897Skan _S_beg = 0, 187146897Skan _S_cur = SEEK_CUR, 188146897Skan _S_end = SEEK_END, 189146897Skan _S_ios_seekdir_end = 1L << 16 190146897Skan }; 19197403Sobrien 19297403Sobrien // 27.4.2 Class ios_base 193117397Skan /** 194169691Skan * @brief The base of the I/O class hierarchy. 195117397Skan * 196117397Skan * This class defines everything that can be defined about I/O that does 197117397Skan * not depend on the type of characters being input or output. Most 198117397Skan * people will only see @c ios_base when they need to specify the full 199117397Skan * name of the various I/O flags (e.g., the openmodes). 200117397Skan */ 20197403Sobrien class ios_base 20297403Sobrien { 20397403Sobrien public: 204132720Skan 20597403Sobrien // 27.4.2.1.1 Class ios_base::failure 206117397Skan /// These are thrown to indicate problems. Doc me. 20797403Sobrien class failure : public exception 20897403Sobrien { 20997403Sobrien public: 210132720Skan // _GLIBCXX_RESOLVE_LIB_DEFECTS 211132720Skan // 48. Use of non-existent exception constructor 212132720Skan explicit 21397403Sobrien failure(const string& __str) throw(); 21497403Sobrien 21597403Sobrien // This declaration is not useless: 21697403Sobrien // http://gcc.gnu.org/onlinedocs/gcc-3.0.2/gcc_6.html#SEC118 217132720Skan virtual 21897403Sobrien ~failure() throw(); 21997403Sobrien 22097403Sobrien virtual const char* 22197403Sobrien what() const throw(); 222132720Skan 22397403Sobrien private: 224132720Skan string _M_msg; 22597403Sobrien }; 22697403Sobrien 22797403Sobrien // 27.4.2.1.2 Type ios_base::fmtflags 228117397Skan /** 229117397Skan * @brief This is a bitmask type. 230117397Skan * 231117397Skan * @c "_Ios_Fmtflags" is implementation-defined, but it is valid to 232117397Skan * perform bitwise operations on these values and expect the Right 233117397Skan * Thing to happen. Defined objects of type fmtflags are: 234117397Skan * - boolalpha 235117397Skan * - dec 236117397Skan * - fixed 237117397Skan * - hex 238117397Skan * - internal 239117397Skan * - left 240117397Skan * - oct 241117397Skan * - right 242117397Skan * - scientific 243117397Skan * - showbase 244117397Skan * - showpoint 245117397Skan * - showpos 246117397Skan * - skipws 247117397Skan * - unitbuf 248117397Skan * - uppercase 249117397Skan * - adjustfield 250117397Skan * - basefield 251117397Skan * - floatfield 252117397Skan */ 25397403Sobrien typedef _Ios_Fmtflags fmtflags; 254132720Skan 255117397Skan /// Insert/extract @c bool in alphabetic rather than numeric format. 256169691Skan static const fmtflags boolalpha = _S_boolalpha; 257132720Skan 258117397Skan /// Converts integer input or generates integer output in decimal base. 259169691Skan static const fmtflags dec = _S_dec; 260132720Skan 261117397Skan /// Generate floating-point output in fixed-point notation. 262169691Skan static const fmtflags fixed = _S_fixed; 263132720Skan 264117397Skan /// Converts integer input or generates integer output in hexadecimal base. 265169691Skan static const fmtflags hex = _S_hex; 266132720Skan 267117397Skan /// Adds fill characters at a designated internal point in certain 268117397Skan /// generated output, or identical to @c right if no such point is 269117397Skan /// designated. 270169691Skan static const fmtflags internal = _S_internal; 271132720Skan 272117397Skan /// Adds fill characters on the right (final positions) of certain 273117397Skan /// generated output. (I.e., the thing you print is flush left.) 274169691Skan static const fmtflags left = _S_left; 275132720Skan 276117397Skan /// Converts integer input or generates integer output in octal base. 277169691Skan static const fmtflags oct = _S_oct; 278132720Skan 279117397Skan /// Adds fill characters on the left (initial positions) of certain 280117397Skan /// generated output. (I.e., the thing you print is flush right.) 281169691Skan static const fmtflags right = _S_right; 282132720Skan 283117397Skan /// Generates floating-point output in scientific notation. 284169691Skan static const fmtflags scientific = _S_scientific; 285132720Skan 286117397Skan /// Generates a prefix indicating the numeric base of generated integer 287117397Skan /// output. 288169691Skan static const fmtflags showbase = _S_showbase; 289132720Skan 290117397Skan /// Generates a decimal-point character unconditionally in generated 291117397Skan /// floating-point output. 292169691Skan static const fmtflags showpoint = _S_showpoint; 293132720Skan 294117397Skan /// Generates a + sign in non-negative generated numeric output. 295169691Skan static const fmtflags showpos = _S_showpos; 296132720Skan 297117397Skan /// Skips leading white space before certain input operations. 298169691Skan static const fmtflags skipws = _S_skipws; 299132720Skan 300117397Skan /// Flushes output after each output operation. 301169691Skan static const fmtflags unitbuf = _S_unitbuf; 302132720Skan 303117397Skan /// Replaces certain lowercase letters with their uppercase equivalents 304117397Skan /// in generated output. 305169691Skan static const fmtflags uppercase = _S_uppercase; 306132720Skan 307117397Skan /// A mask of left|right|internal. Useful for the 2-arg form of @c setf. 308169691Skan static const fmtflags adjustfield = _S_adjustfield; 309132720Skan 310117397Skan /// A mask of dec|oct|hex. Useful for the 2-arg form of @c setf. 311169691Skan static const fmtflags basefield = _S_basefield; 312132720Skan 313117397Skan /// A mask of scientific|fixed. Useful for the 2-arg form of @c setf. 314169691Skan static const fmtflags floatfield = _S_floatfield; 31597403Sobrien 31697403Sobrien // 27.4.2.1.3 Type ios_base::iostate 317117397Skan /** 318117397Skan * @brief This is a bitmask type. 319117397Skan * 320117397Skan * @c "_Ios_Iostate" is implementation-defined, but it is valid to 321117397Skan * perform bitwise operations on these values and expect the Right 322117397Skan * Thing to happen. Defined objects of type iostate are: 323117397Skan * - badbit 324117397Skan * - eofbit 325117397Skan * - failbit 326117397Skan * - goodbit 327117397Skan */ 32897403Sobrien typedef _Ios_Iostate iostate; 329132720Skan 330117397Skan /// Indicates a loss of integrity in an input or output sequence (such 331117397Skan /// as an irrecoverable read error from a file). 332169691Skan static const iostate badbit = _S_badbit; 333132720Skan 334117397Skan /// Indicates that an input operation reached the end of an input sequence. 335169691Skan static const iostate eofbit = _S_eofbit; 336132720Skan 337117397Skan /// Indicates that an input operation failed to read the expected 338117397Skan /// characters, or that an output operation failed to generate the 339117397Skan /// desired characters. 340169691Skan static const iostate failbit = _S_failbit; 341132720Skan 342117397Skan /// Indicates all is well. 343169691Skan static const iostate goodbit = _S_goodbit; 34497403Sobrien 345117397Skan // 27.4.2.1.4 Type ios_base::openmode 346117397Skan /** 347117397Skan * @brief This is a bitmask type. 348117397Skan * 349117397Skan * @c "_Ios_Openmode" is implementation-defined, but it is valid to 350117397Skan * perform bitwise operations on these values and expect the Right 351117397Skan * Thing to happen. Defined objects of type openmode are: 352117397Skan * - app 353117397Skan * - ate 354117397Skan * - binary 355117397Skan * - in 356117397Skan * - out 357117397Skan * - trunc 358117397Skan */ 35997403Sobrien typedef _Ios_Openmode openmode; 360132720Skan 361117397Skan /// Seek to end before each write. 362169691Skan static const openmode app = _S_app; 363132720Skan 364117397Skan /// Open and seek to end immediately after opening. 365169691Skan static const openmode ate = _S_ate; 366132720Skan 367117397Skan /// Perform input and output in binary mode (as opposed to text mode). 368117397Skan /// This is probably not what you think it is; see 369117397Skan /// http://gcc.gnu.org/onlinedocs/libstdc++/27_io/howto.html#3 and 370117397Skan /// http://gcc.gnu.org/onlinedocs/libstdc++/27_io/howto.html#7 for more. 371169691Skan static const openmode binary = _S_bin; 372132720Skan 373117397Skan /// Open for input. Default for @c ifstream and fstream. 374169691Skan static const openmode in = _S_in; 375132720Skan 376117397Skan /// Open for output. Default for @c ofstream and fstream. 377169691Skan static const openmode out = _S_out; 378132720Skan 379117397Skan /// Open for input. Default for @c ofstream. 380169691Skan static const openmode trunc = _S_trunc; 38197403Sobrien 382117397Skan // 27.4.2.1.5 Type ios_base::seekdir 383117397Skan /** 384117397Skan * @brief This is an enumerated type. 385117397Skan * 386117397Skan * @c "_Ios_Seekdir" is implementation-defined. Defined values 387117397Skan * of type seekdir are: 388117397Skan * - beg 389117397Skan * - cur, equivalent to @c SEEK_CUR in the C standard library. 390117397Skan * - end, equivalent to @c SEEK_END in the C standard library. 391117397Skan */ 39297403Sobrien typedef _Ios_Seekdir seekdir; 393132720Skan 394117397Skan /// Request a seek relative to the beginning of the stream. 395169691Skan static const seekdir beg = _S_beg; 396132720Skan 397117397Skan /// Request a seek relative to the current position within the sequence. 398169691Skan static const seekdir cur = _S_cur; 399132720Skan 400117397Skan /// Request a seek relative to the current end of the sequence. 401169691Skan static const seekdir end = _S_end; 40297403Sobrien 403117397Skan // Annex D.6 40497403Sobrien typedef int io_state; 40597403Sobrien typedef int open_mode; 40697403Sobrien typedef int seek_dir; 407132720Skan 408107606Sobrien typedef std::streampos streampos; 409107606Sobrien typedef std::streamoff streamoff; 41097403Sobrien 41197403Sobrien // Callbacks; 412117397Skan /** 413132720Skan * @brief The set of events that may be passed to an event callback. 414132720Skan * 415132720Skan * erase_event is used during ~ios() and copyfmt(). imbue_event is used 416132720Skan * during imbue(). copyfmt_event is used during copyfmt(). 417117397Skan */ 41897403Sobrien enum event 41997403Sobrien { 42097403Sobrien erase_event, 42197403Sobrien imbue_event, 42297403Sobrien copyfmt_event 42397403Sobrien }; 42497403Sobrien 425117397Skan /** 426132720Skan * @brief The type of an event callback function. 427132720Skan * @param event One of the members of the event enum. 428132720Skan * @param ios_base Reference to the ios_base object. 429132720Skan * @param int The integer provided when the callback was registered. 430132720Skan * 431132720Skan * Event callbacks are user defined functions that get called during 432132720Skan * several ios_base and basic_ios functions, specifically imbue(), 433132720Skan * copyfmt(), and ~ios(). 434117397Skan */ 43597403Sobrien typedef void (*event_callback) (event, ios_base&, int); 43697403Sobrien 437117397Skan /** 438132720Skan * @brief Add the callback __fn with parameter __index. 439132720Skan * @param __fn The function to add. 440132720Skan * @param __index The integer to pass to the function when invoked. 441132720Skan * 442132720Skan * Registers a function as an event callback with an integer parameter to 443132720Skan * be passed to the function when invoked. Multiple copies of the 444132720Skan * function are allowed. If there are multiple callbacks, they are 445132720Skan * invoked in the order they were registered. 446117397Skan */ 447132720Skan void 44897403Sobrien register_callback(event_callback __fn, int __index); 44997403Sobrien 45097403Sobrien protected: 451117397Skan //@{ 452117397Skan /** 453117397Skan * @if maint 454117397Skan * ios_base data members (doc me) 455117397Skan * @endif 456117397Skan */ 457132720Skan streamsize _M_precision; 458132720Skan streamsize _M_width; 459132720Skan fmtflags _M_flags; 460132720Skan iostate _M_exception; 461132720Skan iostate _M_streambuf_state; 462117397Skan //@} 46397403Sobrien 46497403Sobrien // 27.4.2.6 Members for callbacks 46597403Sobrien // 27.4.2.6 ios_base callbacks 46697403Sobrien struct _Callback_list 46797403Sobrien { 46897403Sobrien // Data Members 469132720Skan _Callback_list* _M_next; 470132720Skan ios_base::event_callback _M_fn; 471132720Skan int _M_index; 47297403Sobrien _Atomic_word _M_refcount; // 0 means one reference. 473132720Skan 474132720Skan _Callback_list(ios_base::event_callback __fn, int __index, 47597403Sobrien _Callback_list* __cb) 47697403Sobrien : _M_next(__cb), _M_fn(__fn), _M_index(__index), _M_refcount(0) { } 47797403Sobrien 478132720Skan void 479169691Skan _M_add_reference() { __gnu_cxx::__atomic_add_dispatch(&_M_refcount, 1); } 480132720Skan 48197403Sobrien // 0 => OK to delete. 482132720Skan int 483132720Skan _M_remove_reference() 484169691Skan { return __gnu_cxx::__exchange_and_add_dispatch(&_M_refcount, -1); } 48597403Sobrien }; 48697403Sobrien 487132720Skan _Callback_list* _M_callbacks; 48897403Sobrien 489132720Skan void 49097403Sobrien _M_call_callbacks(event __ev) throw(); 49197403Sobrien 492132720Skan void 49397403Sobrien _M_dispose_callbacks(void); 49497403Sobrien 49597403Sobrien // 27.4.2.5 Members for iword/pword storage 496132720Skan struct _Words 497132720Skan { 498132720Skan void* _M_pword; 499132720Skan long _M_iword; 50097403Sobrien _Words() : _M_pword(0), _M_iword(0) { } 50197403Sobrien }; 50297403Sobrien 50397403Sobrien // Only for failed iword/pword calls. 504132720Skan _Words _M_word_zero; 50597403Sobrien 50697403Sobrien // Guaranteed storage. 507117397Skan // The first 5 iword and pword slots are reserved for internal use. 508169691Skan enum { _S_local_word_size = 8 }; 509132720Skan _Words _M_local_word[_S_local_word_size]; 51097403Sobrien 51197403Sobrien // Allocated storage. 512132720Skan int _M_word_size; 513132720Skan _Words* _M_word; 51497403Sobrien 515132720Skan _Words& 516132720Skan _M_grow_words(int __index, bool __iword); 517132720Skan 51897403Sobrien // Members for locale and locale caching. 519132720Skan locale _M_ios_locale; 52097403Sobrien 521132720Skan void 52297403Sobrien _M_init(); 52397403Sobrien 52497403Sobrien public: 52597403Sobrien 52697403Sobrien // 27.4.2.1.6 Class ios_base::Init 52797403Sobrien // Used to initialize standard streams. In theory, g++ could use 52897403Sobrien // -finit-priority to order this stuff correctly without going 529132720Skan // through these machinations. 530132720Skan class Init 53197403Sobrien { 53297403Sobrien friend class ios_base; 53397403Sobrien public: 53497403Sobrien Init(); 53597403Sobrien ~Init(); 53697403Sobrien 53797403Sobrien private: 538132720Skan static _Atomic_word _S_refcount; 539132720Skan static bool _S_synced_with_stdio; 54097403Sobrien }; 54197403Sobrien 542117397Skan // [27.4.2.2] fmtflags state functions 543117397Skan /** 544117397Skan * @brief Access to format flags. 545117397Skan * @return The format control flags for both input and output. 546117397Skan */ 547132720Skan inline fmtflags 54897403Sobrien flags() const { return _M_flags; } 54997403Sobrien 550117397Skan /** 551117397Skan * @brief Setting new format flags all at once. 552117397Skan * @param fmtfl The new flags to set. 553117397Skan * @return The previous format control flags. 554117397Skan * 555117397Skan * This function overwrites all the format flags with @a fmtfl. 556117397Skan */ 557132720Skan inline fmtflags 55897403Sobrien flags(fmtflags __fmtfl) 559132720Skan { 560132720Skan fmtflags __old = _M_flags; 561132720Skan _M_flags = __fmtfl; 562132720Skan return __old; 56397403Sobrien } 56497403Sobrien 565117397Skan /** 566117397Skan * @brief Setting new format flags. 567117397Skan * @param fmtfl Additional flags to set. 568117397Skan * @return The previous format control flags. 569117397Skan * 570117397Skan * This function sets additional flags in format control. Flags that 571117397Skan * were previously set remain set. 572117397Skan */ 573132720Skan inline fmtflags 57497403Sobrien setf(fmtflags __fmtfl) 575132720Skan { 576132720Skan fmtflags __old = _M_flags; 577132720Skan _M_flags |= __fmtfl; 578132720Skan return __old; 57997403Sobrien } 58097403Sobrien 581117397Skan /** 582117397Skan * @brief Setting new format flags. 583117397Skan * @param fmtfl Additional flags to set. 584117397Skan * @param mask The flags mask for @a fmtfl. 585117397Skan * @return The previous format control flags. 586117397Skan * 587117397Skan * This function clears @a mask in the format flags, then sets 588117397Skan * @a fmtfl @c & @a mask. An example mask is @c ios_base::adjustfield. 589117397Skan */ 590132720Skan inline fmtflags 59197403Sobrien setf(fmtflags __fmtfl, fmtflags __mask) 59297403Sobrien { 59397403Sobrien fmtflags __old = _M_flags; 59497403Sobrien _M_flags &= ~__mask; 59597403Sobrien _M_flags |= (__fmtfl & __mask); 59697403Sobrien return __old; 59797403Sobrien } 59897403Sobrien 599117397Skan /** 600117397Skan * @brief Clearing format flags. 601117397Skan * @param mask The flags to unset. 602117397Skan * 603117397Skan * This function clears @a mask in the format flags. 604117397Skan */ 605132720Skan inline void 60697403Sobrien unsetf(fmtflags __mask) { _M_flags &= ~__mask; } 60797403Sobrien 608117397Skan /** 609117397Skan * @brief Flags access. 610117397Skan * @return The precision to generate on certain output operations. 611117397Skan * 612117397Skan * @if maint 613117397Skan * Be careful if you try to give a definition of "precision" here; see 614117397Skan * DR 189. 615117397Skan * @endif 616117397Skan */ 617132720Skan inline streamsize 61897403Sobrien precision() const { return _M_precision; } 61997403Sobrien 620117397Skan /** 621117397Skan * @brief Changing flags. 622117397Skan * @param prec The new precision value. 623117397Skan * @return The previous value of precision(). 624117397Skan */ 625132720Skan inline streamsize 62697403Sobrien precision(streamsize __prec) 627132720Skan { 628132720Skan streamsize __old = _M_precision; 629132720Skan _M_precision = __prec; 630132720Skan return __old; 63197403Sobrien } 63297403Sobrien 633117397Skan /** 634117397Skan * @brief Flags access. 635117397Skan * @return The minimum field width to generate on output operations. 636117397Skan * 637117397Skan * "Minimum field width" refers to the number of characters. 638117397Skan */ 639132720Skan inline streamsize 64097403Sobrien width() const { return _M_width; } 64197403Sobrien 642117397Skan /** 643117397Skan * @brief Changing flags. 644117397Skan * @param wide The new width value. 645117397Skan * @return The previous value of width(). 646117397Skan */ 647132720Skan inline streamsize 64897403Sobrien width(streamsize __wide) 649132720Skan { 650132720Skan streamsize __old = _M_width; 651132720Skan _M_width = __wide; 652132720Skan return __old; 65397403Sobrien } 65497403Sobrien 655117397Skan // [27.4.2.4] ios_base static members 656117397Skan /** 657117397Skan * @brief Interaction with the standard C I/O objects. 658117397Skan * @param sync Whether to synchronize or not. 659117397Skan * @return True if the standard streams were previously synchronized. 660117397Skan * 661117397Skan * The synchronization referred to is @e only that between the standard 662117397Skan * C facilities (e.g., stdout) and the standard C++ objects (e.g., 663117397Skan * cout). User-declared streams are unaffected. See 664117397Skan * http://gcc.gnu.org/onlinedocs/libstdc++/27_io/howto.html#8 for more. 665117397Skan */ 666132720Skan static bool 66797403Sobrien sync_with_stdio(bool __sync = true); 66897403Sobrien 669117397Skan // [27.4.2.3] ios_base locale functions 670117397Skan /** 671117397Skan * @brief Setting a new locale. 672117397Skan * @param loc The new locale. 673117397Skan * @return The previous locale. 674117397Skan * 675132720Skan * Sets the new locale for this stream, and then invokes each callback 676132720Skan * with imbue_event. 677117397Skan */ 678132720Skan locale 67997403Sobrien imbue(const locale& __loc); 68097403Sobrien 681117397Skan /** 682117397Skan * @brief Locale access 683117397Skan * @return A copy of the current locale. 684117397Skan * 685117397Skan * If @c imbue(loc) has previously been called, then this function 686117397Skan * returns @c loc. Otherwise, it returns a copy of @c std::locale(), 687117397Skan * the global C++ locale. 688117397Skan */ 689132720Skan inline locale 69097403Sobrien getloc() const { return _M_ios_locale; } 69197403Sobrien 692117397Skan /** 693117397Skan * @brief Locale access 694117397Skan * @return A reference to the current locale. 695117397Skan * 696117397Skan * Like getloc above, but returns a reference instead of 697117397Skan * generating a copy. 698117397Skan */ 699132720Skan inline const locale& 700117397Skan _M_getloc() const { return _M_ios_locale; } 701117397Skan 702117397Skan // [27.4.2.5] ios_base storage functions 703117397Skan /** 704132720Skan * @brief Access to unique indices. 705132720Skan * @return An integer different from all previous calls. 706132720Skan * 707132720Skan * This function returns a unique integer every time it is called. It 708132720Skan * can be used for any purpose, but is primarily intended to be a unique 709132720Skan * index for the iword and pword functions. The expectation is that an 710132720Skan * application calls xalloc in order to obtain an index in the iword and 711132720Skan * pword arrays that can be used without fear of conflict. 712132720Skan * 713132720Skan * The implementation maintains a static variable that is incremented and 714132720Skan * returned on each invocation. xalloc is guaranteed to return an index 715132720Skan * that is safe to use in the iword and pword arrays. 716117397Skan */ 717132720Skan static int 71897403Sobrien xalloc() throw(); 71997403Sobrien 720117397Skan /** 721132720Skan * @brief Access to integer array. 722132720Skan * @param __ix Index into the array. 723132720Skan * @return A reference to an integer associated with the index. 724132720Skan * 725132720Skan * The iword function provides access to an array of integers that can be 726132720Skan * used for any purpose. The array grows as required to hold the 727132720Skan * supplied index. All integers in the array are initialized to 0. 728132720Skan * 729132720Skan * The implementation reserves several indices. You should use xalloc to 730132720Skan * obtain an index that is safe to use. Also note that since the array 731132720Skan * can grow dynamically, it is not safe to hold onto the reference. 732117397Skan */ 733132720Skan inline long& 73497403Sobrien iword(int __ix) 73597403Sobrien { 736132720Skan _Words& __word = (__ix < _M_word_size) 737132720Skan ? _M_word[__ix] : _M_grow_words(__ix, true); 73897403Sobrien return __word._M_iword; 73997403Sobrien } 74097403Sobrien 741117397Skan /** 742132720Skan * @brief Access to void pointer array. 743132720Skan * @param __ix Index into the array. 744132720Skan * @return A reference to a void* associated with the index. 745132720Skan * 746132720Skan * The pword function provides access to an array of pointers that can be 747132720Skan * used for any purpose. The array grows as required to hold the 748132720Skan * supplied index. All pointers in the array are initialized to 0. 749132720Skan * 750132720Skan * The implementation reserves several indices. You should use xalloc to 751132720Skan * obtain an index that is safe to use. Also note that since the array 752132720Skan * can grow dynamically, it is not safe to hold onto the reference. 753117397Skan */ 754132720Skan inline void*& 75597403Sobrien pword(int __ix) 75697403Sobrien { 757132720Skan _Words& __word = (__ix < _M_word_size) 758132720Skan ? _M_word[__ix] : _M_grow_words(__ix, false); 75997403Sobrien return __word._M_pword; 76097403Sobrien } 76197403Sobrien 76297403Sobrien // Destructor 763117397Skan /** 764132720Skan * Invokes each callback with erase_event. Destroys local storage. 765132720Skan * 766132720Skan * Note that the ios_base object for the standard streams never gets 767132720Skan * destroyed. As a result, any callbacks registered with the standard 768132720Skan * streams will not get invoked with erase_event (unless copyfmt is 769132720Skan * used). 770117397Skan */ 771132720Skan virtual ~ios_base(); 77297403Sobrien 77397403Sobrien protected: 77497403Sobrien ios_base(); 77597403Sobrien 776132720Skan // _GLIBCXX_RESOLVE_LIB_DEFECTS 777132720Skan // 50. Copy constructor and assignment operator of ios_base 77897403Sobrien private: 77997403Sobrien ios_base(const ios_base&); 78097403Sobrien 781132720Skan ios_base& 78297403Sobrien operator=(const ios_base&); 78397403Sobrien }; 784132720Skan 785117397Skan // [27.4.5.1] fmtflags manipulators 786117397Skan /// Calls base.setf(ios_base::boolalpha). 787132720Skan inline ios_base& 78897403Sobrien boolalpha(ios_base& __base) 78997403Sobrien { 79097403Sobrien __base.setf(ios_base::boolalpha); 79197403Sobrien return __base; 79297403Sobrien } 79397403Sobrien 794117397Skan /// Calls base.unsetf(ios_base::boolalpha). 795132720Skan inline ios_base& 79697403Sobrien noboolalpha(ios_base& __base) 79797403Sobrien { 79897403Sobrien __base.unsetf(ios_base::boolalpha); 79997403Sobrien return __base; 80097403Sobrien } 80197403Sobrien 802117397Skan /// Calls base.setf(ios_base::showbase). 803132720Skan inline ios_base& 80497403Sobrien showbase(ios_base& __base) 80597403Sobrien { 80697403Sobrien __base.setf(ios_base::showbase); 80797403Sobrien return __base; 80897403Sobrien } 80997403Sobrien 810117397Skan /// Calls base.unsetf(ios_base::showbase). 811132720Skan inline ios_base& 81297403Sobrien noshowbase(ios_base& __base) 81397403Sobrien { 81497403Sobrien __base.unsetf(ios_base::showbase); 81597403Sobrien return __base; 81697403Sobrien } 81797403Sobrien 818117397Skan /// Calls base.setf(ios_base::showpoint). 819132720Skan inline ios_base& 82097403Sobrien showpoint(ios_base& __base) 82197403Sobrien { 82297403Sobrien __base.setf(ios_base::showpoint); 82397403Sobrien return __base; 82497403Sobrien } 82597403Sobrien 826117397Skan /// Calls base.unsetf(ios_base::showpoint). 827132720Skan inline ios_base& 82897403Sobrien noshowpoint(ios_base& __base) 82997403Sobrien { 83097403Sobrien __base.unsetf(ios_base::showpoint); 83197403Sobrien return __base; 83297403Sobrien } 83397403Sobrien 834117397Skan /// Calls base.setf(ios_base::showpos). 835132720Skan inline ios_base& 83697403Sobrien showpos(ios_base& __base) 83797403Sobrien { 83897403Sobrien __base.setf(ios_base::showpos); 83997403Sobrien return __base; 84097403Sobrien } 84197403Sobrien 842117397Skan /// Calls base.unsetf(ios_base::showpos). 843132720Skan inline ios_base& 84497403Sobrien noshowpos(ios_base& __base) 84597403Sobrien { 84697403Sobrien __base.unsetf(ios_base::showpos); 84797403Sobrien return __base; 84897403Sobrien } 84997403Sobrien 850117397Skan /// Calls base.setf(ios_base::skipws). 851132720Skan inline ios_base& 85297403Sobrien skipws(ios_base& __base) 85397403Sobrien { 85497403Sobrien __base.setf(ios_base::skipws); 85597403Sobrien return __base; 85697403Sobrien } 857132720Skan 858117397Skan /// Calls base.unsetf(ios_base::skipws). 859132720Skan inline ios_base& 86097403Sobrien noskipws(ios_base& __base) 86197403Sobrien { 86297403Sobrien __base.unsetf(ios_base::skipws); 86397403Sobrien return __base; 86497403Sobrien } 86597403Sobrien 866117397Skan /// Calls base.setf(ios_base::uppercase). 867132720Skan inline ios_base& 86897403Sobrien uppercase(ios_base& __base) 86997403Sobrien { 87097403Sobrien __base.setf(ios_base::uppercase); 87197403Sobrien return __base; 87297403Sobrien } 87397403Sobrien 874117397Skan /// Calls base.unsetf(ios_base::uppercase). 875132720Skan inline ios_base& 87697403Sobrien nouppercase(ios_base& __base) 87797403Sobrien { 87897403Sobrien __base.unsetf(ios_base::uppercase); 87997403Sobrien return __base; 88097403Sobrien } 88197403Sobrien 882117397Skan /// Calls base.setf(ios_base::unitbuf). 883132720Skan inline ios_base& 88497403Sobrien unitbuf(ios_base& __base) 88597403Sobrien { 886132720Skan __base.setf(ios_base::unitbuf); 88797403Sobrien return __base; 88897403Sobrien } 88997403Sobrien 890117397Skan /// Calls base.unsetf(ios_base::unitbuf). 891132720Skan inline ios_base& 89297403Sobrien nounitbuf(ios_base& __base) 89397403Sobrien { 89497403Sobrien __base.unsetf(ios_base::unitbuf); 895132720Skan return __base; 89697403Sobrien } 89797403Sobrien 898117397Skan // [27.4.5.2] adjustfield anipulators 899117397Skan /// Calls base.setf(ios_base::internal, ios_base::adjustfield). 900132720Skan inline ios_base& 90197403Sobrien internal(ios_base& __base) 90297403Sobrien { 90397403Sobrien __base.setf(ios_base::internal, ios_base::adjustfield); 904132720Skan return __base; 90597403Sobrien } 90697403Sobrien 907117397Skan /// Calls base.setf(ios_base::left, ios_base::adjustfield). 908132720Skan inline ios_base& 90997403Sobrien left(ios_base& __base) 91097403Sobrien { 91197403Sobrien __base.setf(ios_base::left, ios_base::adjustfield); 91297403Sobrien return __base; 91397403Sobrien } 914132720Skan 915117397Skan /// Calls base.setf(ios_base::right, ios_base::adjustfield). 916132720Skan inline ios_base& 91797403Sobrien right(ios_base& __base) 91897403Sobrien { 91997403Sobrien __base.setf(ios_base::right, ios_base::adjustfield); 92097403Sobrien return __base; 92197403Sobrien } 922132720Skan 923117397Skan // [27.4.5.3] basefield anipulators 924117397Skan /// Calls base.setf(ios_base::dec, ios_base::basefield). 925132720Skan inline ios_base& 92697403Sobrien dec(ios_base& __base) 92797403Sobrien { 92897403Sobrien __base.setf(ios_base::dec, ios_base::basefield); 92997403Sobrien return __base; 93097403Sobrien } 931132720Skan 932117397Skan /// Calls base.setf(ios_base::hex, ios_base::basefield). 933132720Skan inline ios_base& 93497403Sobrien hex(ios_base& __base) 93597403Sobrien { 93697403Sobrien __base.setf(ios_base::hex, ios_base::basefield); 93797403Sobrien return __base; 93897403Sobrien } 93997403Sobrien 940117397Skan /// Calls base.setf(ios_base::oct, ios_base::basefield). 941132720Skan inline ios_base& 94297403Sobrien oct(ios_base& __base) 94397403Sobrien { 94497403Sobrien __base.setf(ios_base::oct, ios_base::basefield); 94597403Sobrien return __base; 94697403Sobrien } 947132720Skan 948117397Skan // [27.4.5.4] floatfield anipulators 949117397Skan /// Calls base.setf(ios_base::fixed, ios_base::floatfield). 950132720Skan inline ios_base& 95197403Sobrien fixed(ios_base& __base) 95297403Sobrien { 95397403Sobrien __base.setf(ios_base::fixed, ios_base::floatfield); 95497403Sobrien return __base; 95597403Sobrien } 95697403Sobrien 957117397Skan /// Calls base.setf(ios_base::scientific, ios_base::floatfield). 958132720Skan inline ios_base& 95997403Sobrien scientific(ios_base& __base) 96097403Sobrien { 96197403Sobrien __base.setf(ios_base::scientific, ios_base::floatfield); 96297403Sobrien return __base; 96397403Sobrien } 96497403Sobrien 965169691Skan_GLIBCXX_END_NAMESPACE 966169691Skan 967132720Skan#endif /* _IOS_BASE_H */ 96897403Sobrien 969