📄 ios_base.h
字号:
// Iostreams base classes -*- C++ -*-// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004// Free Software Foundation, Inc.//// This file is part of the GNU ISO C++ Library. This library is free// software; you can redistribute it and/or modify it under the// terms of the GNU General Public License as published by the// Free Software Foundation; either version 2, or (at your option)// any later version.// This library is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the// GNU General Public License for more details.// You should have received a copy of the GNU General Public License along// with this library; see the file COPYING. If not, write to the Free// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,// USA.// As a special exception, you may use this file as part of a free software// library without restriction. Specifically, if other files instantiate// templates or use macros or inline functions from this file, or you compile// this file and link it with other files to produce an executable, this// file does not by itself cause the resulting executable to be covered by// the GNU General Public License. This exception does not however// invalidate any other reasons why the executable file might be covered by// the GNU General Public License.//// ISO C++ 14882: 27.4 Iostreams base classes///** @file ios_base.h * This is an internal header file, included by other library headers. * You should not attempt to use it directly. */#ifndef _IOS_BASE_H#define _IOS_BASE_H 1#pragma GCC system_header#include <bits/atomicity.h>#include <bits/localefwd.h>#include <bits/locale_classes.h>namespace std{ // The following definitions of bitmask types are enums, not ints, // as permitted (but not required) in the standard, in order to provide // better type safety in iostream calls. A side effect is that // expressions involving them are no longer compile-time constants. enum _Ios_Fmtflags { _S_boolalpha = 1L << 0, _S_dec = 1L << 1, _S_fixed = 1L << 2, _S_hex = 1L << 3, _S_internal = 1L << 4, _S_left = 1L << 5, _S_oct = 1L << 6, _S_right = 1L << 7, _S_scientific = 1L << 8, _S_showbase = 1L << 9, _S_showpoint = 1L << 10, _S_showpos = 1L << 11, _S_skipws = 1L << 12, _S_unitbuf = 1L << 13, _S_uppercase = 1L << 14, _S_adjustfield = _S_left | _S_right | _S_internal, _S_basefield = _S_dec | _S_oct | _S_hex, _S_floatfield = _S_scientific | _S_fixed, _S_ios_fmtflags_end = 1L << 16 }; inline _Ios_Fmtflags operator&(_Ios_Fmtflags __a, _Ios_Fmtflags __b) { return _Ios_Fmtflags(static_cast<int>(__a) & static_cast<int>(__b)); } inline _Ios_Fmtflags operator|(_Ios_Fmtflags __a, _Ios_Fmtflags __b) { return _Ios_Fmtflags(static_cast<int>(__a) | static_cast<int>(__b)); } inline _Ios_Fmtflags operator^(_Ios_Fmtflags __a, _Ios_Fmtflags __b) { return _Ios_Fmtflags(static_cast<int>(__a) ^ static_cast<int>(__b)); } inline _Ios_Fmtflags& operator|=(_Ios_Fmtflags& __a, _Ios_Fmtflags __b) { return __a = __a | __b; } inline _Ios_Fmtflags& operator&=(_Ios_Fmtflags& __a, _Ios_Fmtflags __b) { return __a = __a & __b; } inline _Ios_Fmtflags& operator^=(_Ios_Fmtflags& __a, _Ios_Fmtflags __b) { return __a = __a ^ __b; } inline _Ios_Fmtflags operator~(_Ios_Fmtflags __a) { return _Ios_Fmtflags(~static_cast<int>(__a)); } enum _Ios_Openmode { _S_app = 1L << 0, _S_ate = 1L << 1, _S_bin = 1L << 2, _S_in = 1L << 3, _S_out = 1L << 4, _S_trunc = 1L << 5, _S_ios_openmode_end = 1L << 16 }; inline _Ios_Openmode operator&(_Ios_Openmode __a, _Ios_Openmode __b) { return _Ios_Openmode(static_cast<int>(__a) & static_cast<int>(__b)); } inline _Ios_Openmode operator|(_Ios_Openmode __a, _Ios_Openmode __b) { return _Ios_Openmode(static_cast<int>(__a) | static_cast<int>(__b)); } inline _Ios_Openmode operator^(_Ios_Openmode __a, _Ios_Openmode __b) { return _Ios_Openmode(static_cast<int>(__a) ^ static_cast<int>(__b)); } inline _Ios_Openmode& operator|=(_Ios_Openmode& __a, _Ios_Openmode __b) { return __a = __a | __b; } inline _Ios_Openmode& operator&=(_Ios_Openmode& __a, _Ios_Openmode __b) { return __a = __a & __b; } inline _Ios_Openmode& operator^=(_Ios_Openmode& __a, _Ios_Openmode __b) { return __a = __a ^ __b; } inline _Ios_Openmode operator~(_Ios_Openmode __a) { return _Ios_Openmode(~static_cast<int>(__a)); } enum _Ios_Iostate { _S_goodbit = 0, _S_badbit = 1L << 0, _S_eofbit = 1L << 1, _S_failbit = 1L << 2, _S_ios_iostate_end = 1L << 16 }; inline _Ios_Iostate operator&(_Ios_Iostate __a, _Ios_Iostate __b) { return _Ios_Iostate(static_cast<int>(__a) & static_cast<int>(__b)); } inline _Ios_Iostate operator|(_Ios_Iostate __a, _Ios_Iostate __b) { return _Ios_Iostate(static_cast<int>(__a) | static_cast<int>(__b)); } inline _Ios_Iostate operator^(_Ios_Iostate __a, _Ios_Iostate __b) { return _Ios_Iostate(static_cast<int>(__a) ^ static_cast<int>(__b)); } inline _Ios_Iostate& operator|=(_Ios_Iostate& __a, _Ios_Iostate __b) { return __a = __a | __b; } inline _Ios_Iostate& operator&=(_Ios_Iostate& __a, _Ios_Iostate __b) { return __a = __a & __b; } inline _Ios_Iostate& operator^=(_Ios_Iostate& __a, _Ios_Iostate __b) { return __a = __a ^ __b; } inline _Ios_Iostate operator~(_Ios_Iostate __a) { return _Ios_Iostate(~static_cast<int>(__a)); } enum _Ios_Seekdir { _S_beg = 0, _S_cur = SEEK_CUR, _S_end = SEEK_END, _S_ios_seekdir_end = 1L << 16 }; // 27.4.2 Class ios_base /** * @brief The very top of the I/O class hierarchy. * * This class defines everything that can be defined about I/O that does * not depend on the type of characters being input or output. Most * people will only see @c ios_base when they need to specify the full * name of the various I/O flags (e.g., the openmodes). */ class ios_base { public: // 27.4.2.1.1 Class ios_base::failure /// These are thrown to indicate problems. Doc me. class failure : public exception { public: // _GLIBCXX_RESOLVE_LIB_DEFECTS // 48. Use of non-existent exception constructor explicit failure(const string& __str) throw(); // This declaration is not useless: // http://gcc.gnu.org/onlinedocs/gcc-3.0.2/gcc_6.html#SEC118 virtual ~failure() throw(); virtual const char* what() const throw(); private: string _M_msg; }; // 27.4.2.1.2 Type ios_base::fmtflags /** * @brief This is a bitmask type. * * @c "_Ios_Fmtflags" is implementation-defined, but it is valid to * perform bitwise operations on these values and expect the Right * Thing to happen. Defined objects of type fmtflags are: * - boolalpha * - dec * - fixed * - hex * - internal * - left * - oct * - right * - scientific * - showbase * - showpoint * - showpos * - skipws * - unitbuf * - uppercase * - adjustfield * - basefield * - floatfield */ typedef _Ios_Fmtflags fmtflags; /// Insert/extract @c bool in alphabetic rather than numeric format. static const fmtflags boolalpha = fmtflags(__ios_flags::_S_boolalpha); /// Converts integer input or generates integer output in decimal base. static const fmtflags dec = fmtflags(__ios_flags::_S_dec); /// Generate floating-point output in fixed-point notation. static const fmtflags fixed = fmtflags(__ios_flags::_S_fixed); /// Converts integer input or generates integer output in hexadecimal base. static const fmtflags hex = fmtflags(__ios_flags::_S_hex); /// Adds fill characters at a designated internal point in certain /// generated output, or identical to @c right if no such point is /// designated. static const fmtflags internal = fmtflags(__ios_flags::_S_internal); /// Adds fill characters on the right (final positions) of certain /// generated output. (I.e., the thing you print is flush left.) static const fmtflags left = fmtflags(__ios_flags::_S_left); /// Converts integer input or generates integer output in octal base. static const fmtflags oct = fmtflags(__ios_flags::_S_oct); /// Adds fill characters on the left (initial positions) of certain /// generated output. (I.e., the thing you print is flush right.) static const fmtflags right = fmtflags(__ios_flags::_S_right); /// Generates floating-point output in scientific notation. static const fmtflags scientific = fmtflags(__ios_flags::_S_scientific); /// Generates a prefix indicating the numeric base of generated integer /// output. static const fmtflags showbase = fmtflags(__ios_flags::_S_showbase); /// Generates a decimal-point character unconditionally in generated /// floating-point output. static const fmtflags showpoint = fmtflags(__ios_flags::_S_showpoint); /// Generates a + sign in non-negative generated numeric output. static const fmtflags showpos = fmtflags(__ios_flags::_S_showpos); /// Skips leading white space before certain input operations. static const fmtflags skipws = fmtflags(__ios_flags::_S_skipws); /// Flushes output after each output operation. static const fmtflags unitbuf = fmtflags(__ios_flags::_S_unitbuf); /// Replaces certain lowercase letters with their uppercase equivalents /// in generated output. static const fmtflags uppercase = fmtflags(__ios_flags::_S_uppercase); /// A mask of left|right|internal. Useful for the 2-arg form of @c setf. static const fmtflags adjustfield = fmtflags(__ios_flags::_S_adjustfield); /// A mask of dec|oct|hex. Useful for the 2-arg form of @c setf. static const fmtflags basefield = fmtflags(__ios_flags::_S_basefield); /// A mask of scientific|fixed. Useful for the 2-arg form of @c setf. static const fmtflags floatfield = fmtflags(__ios_flags::_S_floatfield); // 27.4.2.1.3 Type ios_base::iostate /** * @brief This is a bitmask type. * * @c "_Ios_Iostate" is implementation-defined, but it is valid to * perform bitwise operations on these values and expect the Right * Thing to happen. Defined objects of type iostate are: * - badbit * - eofbit * - failbit * - goodbit */ typedef _Ios_Iostate iostate; /// Indicates a loss of integrity in an input or output sequence (such /// as an irrecoverable read error from a file). static const iostate badbit = iostate(__ios_flags::_S_badbit); /// Indicates that an input operation reached the end of an input sequence. static const iostate eofbit = iostate(__ios_flags::_S_eofbit); /// Indicates that an input operation failed to read the expected /// characters, or that an output operation failed to generate the /// desired characters. static const iostate failbit = iostate(__ios_flags::_S_failbit); /// Indicates all is well. static const iostate goodbit = iostate(0); // 27.4.2.1.4 Type ios_base::openmode /** * @brief This is a bitmask type. * * @c "_Ios_Openmode" is implementation-defined, but it is valid to * perform bitwise operations on these values and expect the Right * Thing to happen. Defined objects of type openmode are: * - app * - ate * - binary * - in * - out * - trunc */ typedef _Ios_Openmode openmode; /// Seek to end before each write. static const openmode app = openmode(__ios_flags::_S_app); /// Open and seek to end immediately after opening. static const openmode ate = openmode(__ios_flags::_S_ate); /// Perform input and output in binary mode (as opposed to text mode). /// This is probably not what you think it is; see /// http://gcc.gnu.org/onlinedocs/libstdc++/27_io/howto.html#3 and /// http://gcc.gnu.org/onlinedocs/libstdc++/27_io/howto.html#7 for more. static const openmode binary = openmode(__ios_flags::_S_bin); /// Open for input. Default for @c ifstream and fstream. static const openmode in = openmode(__ios_flags::_S_in); /// Open for output. Default for @c ofstream and fstream. static const openmode out = openmode(__ios_flags::_S_out); /// Open for input. Default for @c ofstream. static const openmode trunc = openmode(__ios_flags::_S_trunc); // 27.4.2.1.5 Type ios_base::seekdir /** * @brief This is an enumerated type. * * @c "_Ios_Seekdir" is implementation-defined. Defined values * of type seekdir are: * - beg * - cur, equivalent to @c SEEK_CUR in the C standard library. * - end, equivalent to @c SEEK_END in the C standard library. */ typedef _Ios_Seekdir seekdir; /// Request a seek relative to the beginning of the stream. static const seekdir beg = seekdir(0); /// Request a seek relative to the current position within the sequence. static const seekdir cur = seekdir(SEEK_CUR); /// Request a seek relative to the current end of the sequence. static const seekdir end = seekdir(SEEK_END);#ifdef _GLIBCXX_DEPRECATED // Annex D.6 typedef int io_state; typedef int open_mode; typedef int seek_dir; typedef std::streampos streampos; typedef std::streamoff streamoff;#endif // Callbacks; /** * @brief The set of events that may be passed to an event callback. * * erase_event is used during ~ios() and copyfmt(). imbue_event is used * during imbue(). copyfmt_event is used during copyfmt(). */ enum event { erase_event, imbue_event, copyfmt_event }; /** * @brief The type of an event callback function. * @param event One of the members of the event enum. * @param ios_base Reference to the ios_base object. * @param int The integer provided when the callback was registered. * * Event callbacks are user defined functions that get called during * several ios_base and basic_ios functions, specifically imbue(), * copyfmt(), and ~ios(). */ typedef void (*event_callback) (event, ios_base&, int); /** * @brief Add the callback __fn with parameter __index. * @param __fn The function to add. * @param __index The integer to pass to the function when invoked. * * Registers a function as an event callback with an integer parameter to * be passed to the function when invoked. Multiple copies of the * function are allowed. If there are multiple callbacks, they are * invoked in the order they were registered. */ void register_callback(event_callback __fn, int __index); protected: //@{ /** * @if maint * ios_base data members (doc me) * @endif */ streamsize _M_precision; streamsize _M_width; fmtflags _M_flags; iostate _M_exception; iostate _M_streambuf_state; //@} // 27.4.2.6 Members for callbacks // 27.4.2.6 ios_base callbacks struct _Callback_list { // Data Members _Callback_list* _M_next; ios_base::event_callback _M_fn; int _M_index; _Atomic_word _M_refcount; // 0 means one reference. _Callback_list(ios_base::event_callback __fn, int __index, _Callback_list* __cb) : _M_next(__cb), _M_fn(__fn), _M_index(__index), _M_refcount(0) { } void _M_add_reference() { __gnu_cxx::__atomic_add(&_M_refcount, 1); } // 0 => OK to delete. int _M_remove_reference()
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -