2000-04-22 04:33:34 +08:00
|
|
|
// Iostreams base classes -*- C++ -*-
|
|
|
|
|
2003-02-18 13:45:07 +08:00
|
|
|
// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003
|
2002-01-25 05:14:41 +08:00
|
|
|
// Free Software Foundation, Inc.
|
2000-04-22 04:33:34 +08:00
|
|
|
//
|
|
|
|
// 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
|
|
|
|
//
|
|
|
|
|
Makefile.am (std_headers): Remove cXXX from list.
2002-01-04 Benjamin Kosnik <bkoz@redhat.com>
* include/Makefile.am (std_headers): Remove cXXX from list.
(c_base_srcdir): No bits subdirectory.
(c_base_builddir): Same.
(c_base_headers): Adjust names, add ciso646.
(bits_headers): Remove std_xxx.h headers.
* include/Makefile.in: Regenerate.
* include/ext/iterator: Adjust includes.
* include/ext/ropeimpl.h: Same.
* include/ext/stl_hash_fun.h: Same.
* include/ext/algorithm: Same.
* include/backward/bvector.h: Adjust includes.
* include/backward/vector.h: Same.
* include/backward/strstream: Same.
* include/backward/streambuf.h: Same.
* include/backward/stack.h: Same.
* include/backward/set.h: Same.
* include/backward/queue.h: Same.
* include/backward/multiset.h: Same.
* include/backward/multimap.h: Same.
* include/backward/map.h: Same.
* include/backward/list.h: Same.
* include/backward/iterator.h: Same.
* include/backward/iostream.h: Same.
* include/backward/iomanip.h: Same.
* include/backward/fstream.h: Same.
* include/backward/deque.h: Same.
* include/backward/complex.h: Same.
* include/bits/std_algorithm.h: Move to...
* include/std/algorithm: ...here.
* include/bits/std_iosfwd.h, std_locale.h, std_stack.h,
std_bitset.h, std_ios.h, std_map.h, std_stdexcept.h,
std_complex.h, std_iostream.h, std_memory.h, std_streambuf.h,
std_deque.h, std_istream.h, std_numeric.h, std_string.h,
std_fstream.h, std_ostream.h, std_utility.h, std_iterator.h,
std_queue.h, std_valarray.h, std_functional.h, std_limits.h,
std_set.h, std_vector.h, std_iomanip.h, std_list.h, std_sstream.h:
Same.
* include/c_std/bits/std_cassert.h: Move to...
* include/c_std/cassert: Here.
* include/c_std/std_cctype.h, std_cerrno.h, std_cfloat.h,
std_climits.h, std_clocale.h, std_cmath.h, std_csetjmp.h,
std_csignal.h, std_cstdarg.h, std_cstddef.h, std_cstdio.h,
std_cstdlib.h, std_cstring.h, std_ctime.h, std_cwchar.h,
std_cwctype.h: Same.
* include/c_std/cmath: Adjust cmath.tcc include.
* include/c_std/cstdlib: Adjust includes.
* include/c_std/cwchar: Same.
* include/c_std/ctime: Same.
* include/c_std/cstring: Same.
* include/c_std/cstdio: Same.
* include/c_std/bits: Remove directory.
* include/c/bits/std_cassert.h: Move to...
* include/c/cassert: Here.
* include/c/std_cctype.h, std_cerrno.h, std_cfloat.h,
std_climits.h, std_clocale.h, std_cmath.h, std_csetjmp.h,
std_csignal.h, std_cstdarg.h, std_cstddef.h, std_cstdio.h,
std_cstdlib.h, std_cstring.h, std_ctime.h, std_cwchar.h,
std_cwctype.h: Same.
* include/c/bits: Remove directory.
* include/std/cwctype: Remove.
* include/std/cwchar: Remove.
* include/std/ctime: Remove.
* include/std/cstring: Remove.
* include/std/cstdlib: Remove.
* include/std/cstdio: Remove.
* include/std/cstddef: Remove.
* include/std/cstdarg: Remove.
* include/std/csignal: Remove.
* include/std/csetjmp: Remove.
* include/std/cmath: Remove.
* include/std/clocale: Remove.
* include/std/climits: Remove.
* include/std/ciso646: Remove.
* include/std/cfloat: Remove.
* include/std/cerrno: Remove.
* include/std/cctype: Remove.
* include/std/cassert: Remove.
* include/bits/fpos.h: Adjust includes, removing <bits/std_xxx.h>
files and subsituting <.xxx>
* include/bits/valarray_array.h: Same.
* include/bits/stl_uninitialized.h: Same.
* include/bits/stl_alloc.h: Same.
* include/bits/stl_algobase.h: Same.
* include/bits/sstream.tcc: Same.
* include/bits/pthread_allocimpl.h: Same.
* include/bits/ostream.tcc: Same.
* include/bits/localefwd.h: Same.
* include/bits/locale_facets.tcc: Same.
* include/bits/locale_facets.h: Same.
* include/bits/istream.tcc: Same.
* include/bits/char_traits.h: Same.
* include/bits/boost_concept_check.h: Same.
* include/bits/basic_file.h: Same.
* include/std/bitset: Same.
* include/std/complex: Same.
* include/std/fstream: Same.
* include/std/functional: Same.
* include/std/ios: Same.
* include/std/iostream: Same.
* include/std/ostream: Same.
* include/std/sstream: Same.
* include/std/streambuf: Same.
* include/std/string: Same.
* include/std/iterator: Same.
* include/std/valarray: Same.
* src/ios.cc: Adjust includes.
* src/valarray-inst.cc: Same.
* src/string-inst.cc: Same.
* src/stl-inst.cc: Same.
* src/stdexcept.cc: Same.
* src/misc-inst.cc: Same.
* src/localename.cc: Same.
* src/locale-inst.cc: Same.
* src/locale.cc: Same.
* src/limits.cc: Same.
* src/concept-inst.cc: Same.
* src/complex_io.cc: Same.
* src/codecvt.cc: Same.
* src/bitset.cc: Same.
* src/cmath.cc: Same.
From-SVN: r48544
2002-01-05 05:27:36 +08:00
|
|
|
#include <ios>
|
|
|
|
#include <ostream>
|
|
|
|
#include <istream>
|
|
|
|
#include <fstream>
|
2002-01-25 05:14:41 +08:00
|
|
|
#include <bits/atomicity.h>
|
2002-05-01 03:04:43 +08:00
|
|
|
#include <ext/stdio_filebuf.h>
|
2002-01-25 05:14:41 +08:00
|
|
|
|
2002-10-11 15:09:36 +08:00
|
|
|
namespace __gnu_cxx
|
2001-01-06 10:44:11 +08:00
|
|
|
{
|
2001-06-06 09:31:58 +08:00
|
|
|
// Extern declarations for global objects in src/globals.cc.
|
2002-10-11 15:09:36 +08:00
|
|
|
extern stdio_filebuf<char> buf_cout;
|
|
|
|
extern stdio_filebuf<char> buf_cin;
|
|
|
|
extern stdio_filebuf<char> buf_cerr;
|
|
|
|
|
|
|
|
#ifdef _GLIBCPP_USE_WCHAR_T
|
|
|
|
extern stdio_filebuf<wchar_t> buf_wcout;
|
|
|
|
extern stdio_filebuf<wchar_t> buf_wcin;
|
|
|
|
extern stdio_filebuf<wchar_t> buf_wcerr;
|
|
|
|
#endif
|
|
|
|
} // namespace __gnu_cxx
|
|
|
|
|
|
|
|
namespace std
|
|
|
|
{
|
|
|
|
using namespace __gnu_cxx;
|
|
|
|
|
2001-06-06 09:31:58 +08:00
|
|
|
extern istream cin;
|
|
|
|
extern ostream cout;
|
|
|
|
extern ostream cerr;
|
|
|
|
extern ostream clog;
|
2002-05-01 03:04:43 +08:00
|
|
|
|
2001-06-06 09:31:58 +08:00
|
|
|
#ifdef _GLIBCPP_USE_WCHAR_T
|
|
|
|
extern wistream wcin;
|
|
|
|
extern wostream wcout;
|
|
|
|
extern wostream wcerr;
|
|
|
|
extern wostream wclog;
|
|
|
|
#endif
|
|
|
|
|
2000-09-01 16:58:07 +08:00
|
|
|
// Definitions for static const data members of __ios_flags.
|
|
|
|
const __ios_flags::__int_type __ios_flags::_S_boolalpha;
|
|
|
|
const __ios_flags::__int_type __ios_flags::_S_dec;
|
|
|
|
const __ios_flags::__int_type __ios_flags::_S_fixed;
|
|
|
|
const __ios_flags::__int_type __ios_flags::_S_hex;
|
|
|
|
const __ios_flags::__int_type __ios_flags::_S_internal;
|
|
|
|
const __ios_flags::__int_type __ios_flags::_S_left;
|
|
|
|
const __ios_flags::__int_type __ios_flags::_S_oct;
|
|
|
|
const __ios_flags::__int_type __ios_flags::_S_right;
|
|
|
|
const __ios_flags::__int_type __ios_flags::_S_scientific;
|
|
|
|
const __ios_flags::__int_type __ios_flags::_S_showbase;
|
|
|
|
const __ios_flags::__int_type __ios_flags::_S_showpoint;
|
|
|
|
const __ios_flags::__int_type __ios_flags::_S_showpos;
|
|
|
|
const __ios_flags::__int_type __ios_flags::_S_skipws;
|
|
|
|
const __ios_flags::__int_type __ios_flags::_S_unitbuf;
|
|
|
|
const __ios_flags::__int_type __ios_flags::_S_uppercase;
|
|
|
|
const __ios_flags::__int_type __ios_flags::_S_adjustfield;
|
|
|
|
const __ios_flags::__int_type __ios_flags::_S_basefield;
|
|
|
|
const __ios_flags::__int_type __ios_flags::_S_floatfield;
|
|
|
|
|
|
|
|
const __ios_flags::__int_type __ios_flags::_S_badbit;
|
|
|
|
const __ios_flags::__int_type __ios_flags::_S_eofbit;
|
|
|
|
const __ios_flags::__int_type __ios_flags::_S_failbit;
|
|
|
|
|
|
|
|
const __ios_flags::__int_type __ios_flags::_S_app;
|
|
|
|
const __ios_flags::__int_type __ios_flags::_S_ate;
|
|
|
|
const __ios_flags::__int_type __ios_flags::_S_bin;
|
|
|
|
const __ios_flags::__int_type __ios_flags::_S_in;
|
|
|
|
const __ios_flags::__int_type __ios_flags::_S_out;
|
|
|
|
const __ios_flags::__int_type __ios_flags::_S_trunc;
|
|
|
|
|
|
|
|
// Definitions for static const members of ios_base.
|
2000-04-22 04:33:34 +08:00
|
|
|
const ios_base::fmtflags ios_base::boolalpha;
|
|
|
|
const ios_base::fmtflags ios_base::dec;
|
|
|
|
const ios_base::fmtflags ios_base::fixed;
|
|
|
|
const ios_base::fmtflags ios_base::hex;
|
|
|
|
const ios_base::fmtflags ios_base::internal;
|
|
|
|
const ios_base::fmtflags ios_base::left;
|
|
|
|
const ios_base::fmtflags ios_base::oct;
|
|
|
|
const ios_base::fmtflags ios_base::right;
|
|
|
|
const ios_base::fmtflags ios_base::scientific;
|
|
|
|
const ios_base::fmtflags ios_base::showbase;
|
|
|
|
const ios_base::fmtflags ios_base::showpoint;
|
|
|
|
const ios_base::fmtflags ios_base::showpos;
|
|
|
|
const ios_base::fmtflags ios_base::skipws;
|
|
|
|
const ios_base::fmtflags ios_base::unitbuf;
|
|
|
|
const ios_base::fmtflags ios_base::uppercase;
|
|
|
|
const ios_base::fmtflags ios_base::adjustfield;
|
|
|
|
const ios_base::fmtflags ios_base::basefield;
|
|
|
|
const ios_base::fmtflags ios_base::floatfield;
|
|
|
|
|
|
|
|
const ios_base::iostate ios_base::badbit;
|
|
|
|
const ios_base::iostate ios_base::eofbit;
|
|
|
|
const ios_base::iostate ios_base::failbit;
|
|
|
|
const ios_base::iostate ios_base::goodbit;
|
|
|
|
|
|
|
|
const ios_base::openmode ios_base::app;
|
|
|
|
const ios_base::openmode ios_base::ate;
|
|
|
|
const ios_base::openmode ios_base::binary;
|
|
|
|
const ios_base::openmode ios_base::in;
|
|
|
|
const ios_base::openmode ios_base::out;
|
|
|
|
const ios_base::openmode ios_base::trunc;
|
|
|
|
|
|
|
|
const ios_base::seekdir ios_base::beg;
|
|
|
|
const ios_base::seekdir ios_base::cur;
|
|
|
|
const ios_base::seekdir ios_base::end;
|
|
|
|
|
2002-04-02 02:39:37 +08:00
|
|
|
const int ios_base::_S_local_word_size;
|
2000-09-01 16:58:07 +08:00
|
|
|
int ios_base::Init::_S_ios_base_init = 0;
|
2001-01-11 01:24:11 +08:00
|
|
|
bool ios_base::Init::_S_synced_with_stdio = true;
|
2000-09-01 16:58:07 +08:00
|
|
|
|
2001-01-17 15:44:57 +08:00
|
|
|
ios_base::failure::failure(const string& __str) throw()
|
2000-04-22 04:33:34 +08:00
|
|
|
{
|
|
|
|
strncpy(_M_name, __str.c_str(), _M_bufsize);
|
|
|
|
_M_name[_M_bufsize - 1] = '\0';
|
|
|
|
}
|
|
|
|
|
2001-01-17 15:44:57 +08:00
|
|
|
ios_base::failure::~failure() throw()
|
2000-11-23 12:53:40 +08:00
|
|
|
{ }
|
|
|
|
|
|
|
|
const char*
|
|
|
|
ios_base::failure::what() const throw()
|
|
|
|
{ return _M_name; }
|
|
|
|
|
2001-04-04 09:02:26 +08:00
|
|
|
void
|
2003-04-29 01:15:03 +08:00
|
|
|
ios_base::Init::_S_create_buffers(bool __sync)
|
2001-04-04 09:02:26 +08:00
|
|
|
{
|
2003-02-11 18:43:49 +08:00
|
|
|
size_t __out_size = __sync ? 0 : static_cast<size_t>(BUFSIZ);
|
re PR libstdc++/7744 (streambuf::in_avail() always returns 0 (zero) for cin input stream)
2003-03-09 Paolo Carlini <pcarlini@unitus.it>
Nathan Myers <ncm@cantrip.org>
PR libstdc++/7744
* config/io/basic_file_stdio.h (__basic_file<>::xsgetn, xsputn,
seekoff, seekpos): Add a boolean parameter __stdio.
* config/io/basic_file_stdio.cc (__basic_file<>::xsgetn, xsputn,
seekoff, seekpos): If __stdio == true, use fread (fwrite, fseek/ftell,
fseek/ftell, respectively), otherwise read (write, lseek, lseek,
respectively).
* include/bits/fstream.tcc (basic_filebuf<>::_M_convert_to_external,
_M_really_overflow, seekoff): Use the boolean parameter in the calls.
* include/std/std_fstream.h (sync): Likewise.
* src/fstream.cc (basic_filebuf<>::_M_underflow_common): Likewise.
* src/ios.cc (ios_base::Init::_S_ios_create(bool)): Revert libstdc++/8399
commit involving isatty(0).
* acinclude.m4 (GLIBCPP_CHECK_UNISTD_DECL_AND_LINKAGE_1): Remove.
(GLIBCPP_CHECK_UNISTD_SUPPORT): Remove
* configure.in: Remove call.
* aclocal.m4: Regenerate.
* config.h.in: Regenerate.
* configure: Regenerate.
* testsuite/27_io/narrow_stream_objects.cc (test11): Add.
Co-Authored-By: Nathan Myers <ncm@cantrip.org>
From-SVN: r64051
2003-03-10 06:31:45 +08:00
|
|
|
size_t __in_size = __sync ? 1 : static_cast<size_t>(BUFSIZ);
|
2001-07-03 04:50:40 +08:00
|
|
|
|
2003-04-29 01:15:03 +08:00
|
|
|
// Create stream buffers for the standard streams and use those
|
|
|
|
// buffers without destroying and recreating the streams.
|
2002-05-01 03:04:43 +08:00
|
|
|
new (&buf_cout) stdio_filebuf<char>(stdout, ios_base::out, __out_size);
|
|
|
|
new (&buf_cin) stdio_filebuf<char>(stdin, ios_base::in, __in_size);
|
|
|
|
new (&buf_cerr) stdio_filebuf<char>(stderr, ios_base::out, __out_size);
|
2003-04-29 01:15:03 +08:00
|
|
|
cout.rdbuf(&buf_cout);
|
|
|
|
cin.rdbuf(&buf_cin);
|
|
|
|
cerr.rdbuf(&buf_cerr);
|
|
|
|
clog.rdbuf(&buf_cerr);
|
2001-04-04 09:02:26 +08:00
|
|
|
|
|
|
|
#ifdef _GLIBCPP_USE_WCHAR_T
|
2002-05-01 03:04:43 +08:00
|
|
|
new (&buf_wcout) stdio_filebuf<wchar_t>(stdout, ios_base::out, __out_size);
|
|
|
|
new (&buf_wcin) stdio_filebuf<wchar_t>(stdin, ios_base::in, __in_size);
|
|
|
|
new (&buf_wcerr) stdio_filebuf<wchar_t>(stderr, ios_base::out, __out_size);
|
2003-04-29 01:15:03 +08:00
|
|
|
wcout.rdbuf(&buf_wcout);
|
|
|
|
wcin.rdbuf(&buf_wcin);
|
|
|
|
wcerr.rdbuf(&buf_wcerr);
|
|
|
|
wclog.rdbuf(&buf_wcerr);
|
2001-04-04 09:02:26 +08:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2003-04-29 01:15:03 +08:00
|
|
|
ios_base::Init::_S_destroy_buffers()
|
2001-04-04 09:02:26 +08:00
|
|
|
{
|
2001-06-06 09:31:58 +08:00
|
|
|
// Explicitly call dtors to free any memory that is dynamically
|
|
|
|
// allocated by filebuf ctor or member functions, but don't
|
|
|
|
// deallocate all memory by calling operator delete.
|
2002-05-01 03:04:43 +08:00
|
|
|
buf_cout.~stdio_filebuf();
|
|
|
|
buf_cin.~stdio_filebuf();
|
|
|
|
buf_cerr.~stdio_filebuf();
|
|
|
|
|
2000-04-22 04:33:34 +08:00
|
|
|
#ifdef _GLIBCPP_USE_WCHAR_T
|
2002-05-01 03:04:43 +08:00
|
|
|
buf_wcout.~stdio_filebuf();
|
|
|
|
buf_wcin.~stdio_filebuf();
|
|
|
|
buf_wcerr.~stdio_filebuf();
|
2000-04-22 04:33:34 +08:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2001-06-06 09:31:58 +08:00
|
|
|
ios_base::Init::Init()
|
|
|
|
{
|
2001-07-04 10:39:02 +08:00
|
|
|
if (_S_ios_base_init == 0)
|
2001-06-06 09:31:58 +08:00
|
|
|
{
|
|
|
|
// Standard streams default to synced with "C" operations.
|
|
|
|
ios_base::Init::_S_synced_with_stdio = true;
|
2003-04-29 01:15:03 +08:00
|
|
|
|
|
|
|
// The standard streams are constructed once only and never destroyed.
|
|
|
|
// The stream buffers are set in _S_create_buffers below.
|
|
|
|
new (&cout) ostream(NULL);
|
|
|
|
new (&cin) istream(NULL);
|
|
|
|
new (&cerr) ostream(NULL);
|
|
|
|
new (&clog) ostream(NULL);
|
|
|
|
cin.tie(&cout);
|
|
|
|
cerr.flags(ios_base::unitbuf);
|
|
|
|
|
|
|
|
#ifdef _GLIBCPP_USE_WCHAR_T
|
|
|
|
new (&wcout) wostream(NULL);
|
|
|
|
new (&wcin) wistream(NULL);
|
|
|
|
new (&wcerr) wostream(NULL);
|
|
|
|
new (&wclog) wostream(NULL);
|
|
|
|
wcin.tie(&wcout);
|
|
|
|
wcerr.flags(ios_base::unitbuf);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
_S_create_buffers(ios_base::Init::_S_synced_with_stdio);
|
|
|
|
_S_ios_base_init = 1;
|
2001-06-06 09:31:58 +08:00
|
|
|
}
|
2001-07-04 10:39:02 +08:00
|
|
|
++_S_ios_base_init;
|
2001-06-06 09:31:58 +08:00
|
|
|
}
|
|
|
|
|
2000-04-22 04:33:34 +08:00
|
|
|
ios_base::Init::~Init()
|
|
|
|
{
|
2003-04-29 01:15:03 +08:00
|
|
|
if (--_S_ios_base_init == 1)
|
|
|
|
{
|
|
|
|
// Catch any exceptions thrown by basic_ostream::flush()
|
|
|
|
try
|
|
|
|
{
|
|
|
|
// Flush standard output streams as required by 27.4.2.1.6
|
|
|
|
cout.flush();
|
|
|
|
cerr.flush();
|
|
|
|
clog.flush();
|
|
|
|
|
|
|
|
#ifdef _GLIBCPP_USE_WCHAR_T
|
|
|
|
wcout.flush();
|
|
|
|
wcerr.flush();
|
|
|
|
wclog.flush();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{ }
|
|
|
|
}
|
2000-04-22 04:33:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// 27.4.2.5 ios_base storage functions
|
|
|
|
int
|
|
|
|
ios_base::xalloc() throw()
|
|
|
|
{
|
2002-01-25 05:14:41 +08:00
|
|
|
// Implementation note: Initialize top to zero to ensure that
|
|
|
|
// initialization occurs before main() is started.
|
2002-04-02 02:39:37 +08:00
|
|
|
static _Atomic_word _S_top = 0;
|
|
|
|
return __exchange_and_add(&_S_top, 1) + 4;
|
2000-04-22 04:33:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// 27.4.2.5 iword/pword storage
|
|
|
|
ios_base::_Words&
|
|
|
|
ios_base::_M_grow_words(int ix)
|
|
|
|
{
|
2002-04-02 02:39:37 +08:00
|
|
|
// Precondition: _M_word_size <= ix
|
|
|
|
int newsize = _S_local_word_size;
|
|
|
|
_Words* words = _M_local_word;
|
|
|
|
if (ix > _S_local_word_size - 1)
|
2000-04-22 04:33:34 +08:00
|
|
|
{
|
2002-04-29 15:00:50 +08:00
|
|
|
if (ix < numeric_limits<int>::max())
|
|
|
|
{
|
|
|
|
newsize = ix + 1;
|
|
|
|
try
|
|
|
|
{ words = new _Words[newsize]; }
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
_M_streambuf_state |= badbit;
|
|
|
|
if (_M_streambuf_state & _M_exception)
|
2003-04-29 07:05:57 +08:00
|
|
|
__throw_ios_failure("ios_base::_M_grow_words "
|
|
|
|
"allocation failed");
|
2002-04-29 15:00:50 +08:00
|
|
|
return _M_word_zero;
|
|
|
|
}
|
|
|
|
for (int i = 0; i < _M_word_size; i++)
|
|
|
|
words[i] = _M_word[i];
|
|
|
|
if (_M_word && _M_word != _M_local_word)
|
|
|
|
{
|
|
|
|
delete [] _M_word;
|
|
|
|
_M_word = 0;
|
|
|
|
}
|
|
|
|
}
|
2002-04-02 02:39:37 +08:00
|
|
|
else
|
2000-04-22 04:33:34 +08:00
|
|
|
{
|
2002-04-02 02:39:37 +08:00
|
|
|
_M_streambuf_state |= badbit;
|
2003-03-05 11:01:42 +08:00
|
|
|
if (_M_streambuf_state & _M_exception)
|
2003-04-29 07:05:57 +08:00
|
|
|
__throw_ios_failure("ios_base::_M_grow_words ix not valid");
|
2002-04-02 02:39:37 +08:00
|
|
|
return _M_word_zero;
|
|
|
|
}
|
2000-04-22 04:33:34 +08:00
|
|
|
}
|
2002-04-02 02:39:37 +08:00
|
|
|
_M_word = words;
|
|
|
|
_M_word_size = newsize;
|
|
|
|
return _M_word[ix];
|
2000-04-22 04:33:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Called only by basic_ios<>::init.
|
|
|
|
void
|
|
|
|
ios_base::_M_init()
|
|
|
|
{
|
|
|
|
// NB: May be called more than once
|
|
|
|
_M_precision = 6;
|
2001-01-06 10:44:11 +08:00
|
|
|
_M_width = 0;
|
|
|
|
_M_flags = skipws | dec;
|
2000-07-19 16:04:38 +08:00
|
|
|
_M_ios_locale = locale();
|
2000-04-22 04:33:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// 27.4.2.3 ios_base locale functions
|
|
|
|
locale
|
|
|
|
ios_base::imbue(const locale& __loc)
|
|
|
|
{
|
2000-07-19 16:04:38 +08:00
|
|
|
locale __old = _M_ios_locale;
|
|
|
|
_M_ios_locale = __loc;
|
2000-04-22 04:33:34 +08:00
|
|
|
_M_call_callbacks(imbue_event);
|
|
|
|
return __old;
|
|
|
|
}
|
|
|
|
|
2003-03-08 14:17:11 +08:00
|
|
|
ios_base::ios_base() : _M_callbacks(0), _M_word_size(_S_local_word_size),
|
|
|
|
_M_word(_M_local_word), _M_locale_cache(0)
|
2000-04-22 04:33:34 +08:00
|
|
|
{
|
2002-02-26 12:55:48 +08:00
|
|
|
// Do nothing: basic_ios::init() does it.
|
2002-04-02 02:39:37 +08:00
|
|
|
// NB: _M_callbacks and _M_word must be zero for non-initialized
|
2002-02-26 12:55:48 +08:00
|
|
|
// ios_base to go through ~ios_base gracefully.
|
2000-04-22 04:33:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// 27.4.2.7 ios_base constructors/destructors
|
|
|
|
ios_base::~ios_base()
|
|
|
|
{
|
|
|
|
_M_call_callbacks(erase_event);
|
|
|
|
_M_dispose_callbacks();
|
2003-03-07 02:10:26 +08:00
|
|
|
if (_M_word != _M_local_word)
|
2002-04-02 02:39:37 +08:00
|
|
|
{
|
|
|
|
delete [] _M_word;
|
|
|
|
_M_word = 0;
|
|
|
|
}
|
2000-04-22 04:33:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ios_base::register_callback(event_callback __fn, int __index)
|
|
|
|
{ _M_callbacks = new _Callback_list(__fn, __index, _M_callbacks); }
|
|
|
|
|
|
|
|
void
|
|
|
|
ios_base::_M_call_callbacks(event __e) throw()
|
|
|
|
{
|
2002-02-26 12:55:48 +08:00
|
|
|
_Callback_list* __p = _M_callbacks;
|
|
|
|
while (__p)
|
2000-04-22 04:33:34 +08:00
|
|
|
{
|
2002-02-26 12:55:48 +08:00
|
|
|
try
|
|
|
|
{ (*__p->_M_fn) (__e, *this, __p->_M_index); }
|
|
|
|
catch (...)
|
|
|
|
{ }
|
|
|
|
__p = __p->_M_next;
|
2000-04-22 04:33:34 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ios_base::_M_dispose_callbacks(void)
|
|
|
|
{
|
|
|
|
_Callback_list* __p = _M_callbacks;
|
|
|
|
while (__p && __p->_M_remove_reference() == 0)
|
|
|
|
{
|
|
|
|
_Callback_list* __next = __p->_M_next;
|
|
|
|
delete __p;
|
|
|
|
__p = __next;
|
|
|
|
}
|
|
|
|
_M_callbacks = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ios_base::sync_with_stdio(bool __sync)
|
|
|
|
{
|
|
|
|
#ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
|
|
|
|
// 49. Underspecification of ios_base::sync_with_stdio
|
2001-01-11 01:24:11 +08:00
|
|
|
bool __ret = ios_base::Init::_S_synced_with_stdio;
|
2001-01-06 10:44:11 +08:00
|
|
|
#endif
|
2000-07-19 08:57:38 +08:00
|
|
|
|
2001-01-06 10:44:11 +08:00
|
|
|
// Turn off sync with C FILE* for cin, cout, cerr, clog iff
|
|
|
|
// currently synchronized.
|
2000-07-26 14:51:38 +08:00
|
|
|
if (!__sync && __ret)
|
2000-04-22 04:33:34 +08:00
|
|
|
{
|
2003-04-29 01:15:03 +08:00
|
|
|
ios_base::Init::_S_synced_with_stdio = __sync;
|
|
|
|
ios_base::Init::_S_destroy_buffers();
|
|
|
|
ios_base::Init::_S_create_buffers(__sync);
|
2000-04-22 04:33:34 +08:00
|
|
|
}
|
2000-07-26 14:51:38 +08:00
|
|
|
return __ret;
|
2000-04-22 04:33:34 +08:00
|
|
|
}
|
|
|
|
} // namespace std
|