2000-10-05 19:27:02 +08:00
|
|
|
// String based streams -*- C++ -*-
|
|
|
|
|
2002-02-01 11:20:39 +08:00
|
|
|
// Copyright (C) 1997, 1998, 1999, 2001, 2002
|
|
|
|
// Free Software Foundation, Inc.
|
2000-10-05 19:27:02 +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.7 String-based streams
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef _CPP_BITS_SSTREAM_TCC
|
|
|
|
#define _CPP_BITS_SSTREAM_TCC 1
|
|
|
|
|
2002-02-17 03:33:43 +08:00
|
|
|
#pragma GCC system_header
|
|
|
|
|
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 <sstream>
|
2000-10-05 19:27:02 +08:00
|
|
|
|
2001-03-05 05:34:02 +08:00
|
|
|
namespace std
|
|
|
|
{
|
2000-10-05 19:27:02 +08:00
|
|
|
template <class _CharT, class _Traits, class _Alloc>
|
2001-07-20 08:09:31 +08:00
|
|
|
typename basic_stringbuf<_CharT, _Traits, _Alloc>::int_type
|
2000-10-05 19:27:02 +08:00
|
|
|
basic_stringbuf<_CharT, _Traits, _Alloc>::
|
|
|
|
pbackfail(int_type __c)
|
|
|
|
{
|
|
|
|
int_type __ret = traits_type::eof();
|
|
|
|
bool __testeof = traits_type::eq_int_type(__c, traits_type::eof());
|
|
|
|
bool __testpos = _M_in_cur && _M_in_beg < _M_in_cur;
|
|
|
|
|
|
|
|
// Try to put back __c into input sequence in one of three ways.
|
|
|
|
// Order these tests done in is unspecified by the standard.
|
|
|
|
if (__testpos)
|
|
|
|
{
|
|
|
|
if (traits_type::eq(traits_type::to_char_type(__c), this->gptr()[-1])
|
|
|
|
&& !__testeof)
|
|
|
|
{
|
|
|
|
--_M_in_cur;
|
|
|
|
__ret = __c;
|
|
|
|
}
|
|
|
|
else if (!__testeof)
|
|
|
|
{
|
|
|
|
--_M_in_cur;
|
|
|
|
*_M_in_cur = traits_type::to_char_type(__c);
|
|
|
|
__ret = __c;
|
|
|
|
}
|
|
|
|
else if (__testeof)
|
|
|
|
{
|
|
|
|
--_M_in_cur;
|
|
|
|
__ret = traits_type::not_eof(__c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return __ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _CharT, class _Traits, class _Alloc>
|
2001-07-20 08:09:31 +08:00
|
|
|
typename basic_stringbuf<_CharT, _Traits, _Alloc>::int_type
|
2000-10-05 19:27:02 +08:00
|
|
|
basic_stringbuf<_CharT, _Traits, _Alloc>::
|
|
|
|
overflow(int_type __c)
|
|
|
|
{
|
|
|
|
int_type __ret = traits_type::eof();
|
|
|
|
bool __testeof = traits_type::eq_int_type(__c, __ret);
|
|
|
|
bool __testwrite = _M_out_cur < _M_buf + _M_buf_size;
|
|
|
|
bool __testout = _M_mode & ios_base::out;
|
|
|
|
|
|
|
|
// Try to append __c into output sequence in one of two ways.
|
|
|
|
// Order these tests done in is unspecified by the standard.
|
|
|
|
if (__testout)
|
|
|
|
{
|
|
|
|
if (!__testeof)
|
|
|
|
{
|
|
|
|
__size_type __len = max(_M_buf_size, _M_buf_size_opt);
|
|
|
|
__len *= 2;
|
|
|
|
|
|
|
|
if (__testwrite)
|
2002-07-04 17:20:01 +08:00
|
|
|
__ret = this->sputc(traits_type::to_char_type(__c));
|
2000-10-05 19:27:02 +08:00
|
|
|
else if (__len <= _M_string.max_size())
|
|
|
|
{
|
|
|
|
// Force-allocate, re-sync.
|
|
|
|
_M_string = this->str();
|
|
|
|
_M_string.reserve(__len);
|
2002-07-04 17:20:01 +08:00
|
|
|
_M_buf_size = __len;
|
2000-10-05 19:27:02 +08:00
|
|
|
_M_really_sync(_M_in_cur - _M_in_beg,
|
|
|
|
_M_out_cur - _M_out_beg);
|
|
|
|
*_M_out_cur = traits_type::to_char_type(__c);
|
|
|
|
_M_out_cur_move(1);
|
|
|
|
__ret = __c;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
__ret = traits_type::not_eof(__c);
|
|
|
|
}
|
|
|
|
return __ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _CharT, class _Traits, class _Alloc>
|
2001-07-20 08:09:31 +08:00
|
|
|
typename basic_stringbuf<_CharT, _Traits, _Alloc>::pos_type
|
2000-10-05 19:27:02 +08:00
|
|
|
basic_stringbuf<_CharT, _Traits, _Alloc>::
|
|
|
|
seekoff(off_type __off, ios_base::seekdir __way, ios_base::openmode __mode)
|
|
|
|
{
|
|
|
|
pos_type __ret = pos_type(off_type(-1));
|
2002-04-09 16:48:33 +08:00
|
|
|
bool __testin = (ios_base::in & _M_mode & __mode) != 0;
|
|
|
|
bool __testout = (ios_base::out & _M_mode & __mode) != 0;
|
2000-10-05 19:27:02 +08:00
|
|
|
bool __testboth = __testin && __testout && __way != ios_base::cur;
|
2002-04-09 14:14:32 +08:00
|
|
|
__testin &= !(__mode & ios_base::out);
|
|
|
|
__testout &= !(__mode & ios_base::in);
|
|
|
|
|
|
|
|
if (_M_buf_size && (__testin || __testout || __testboth))
|
2000-10-05 19:27:02 +08:00
|
|
|
{
|
|
|
|
char_type* __beg = _M_buf;
|
|
|
|
char_type* __curi = NULL;
|
|
|
|
char_type* __curo = NULL;
|
|
|
|
char_type* __endi = NULL;
|
|
|
|
char_type* __endo = NULL;
|
|
|
|
|
2002-04-09 14:14:32 +08:00
|
|
|
if (__testin || __testboth)
|
2000-10-05 19:27:02 +08:00
|
|
|
{
|
|
|
|
__curi = this->gptr();
|
|
|
|
__endi = this->egptr();
|
|
|
|
}
|
2002-04-09 14:14:32 +08:00
|
|
|
if (__testout || __testboth)
|
2000-10-05 19:27:02 +08:00
|
|
|
{
|
|
|
|
__curo = this->pptr();
|
|
|
|
__endo = this->epptr();
|
|
|
|
}
|
|
|
|
|
|
|
|
off_type __newoffi = 0;
|
|
|
|
off_type __newoffo = 0;
|
|
|
|
if (__way == ios_base::cur)
|
|
|
|
{
|
|
|
|
__newoffi = __curi - __beg;
|
|
|
|
__newoffo = __curo - __beg;
|
|
|
|
}
|
|
|
|
else if (__way == ios_base::end)
|
|
|
|
{
|
|
|
|
__newoffi = __endi - __beg;
|
|
|
|
__newoffo = __endo - __beg;
|
|
|
|
}
|
|
|
|
|
2002-04-09 14:14:32 +08:00
|
|
|
if ((__testin || __testboth)
|
2000-10-05 19:27:02 +08:00
|
|
|
&& __newoffi + __off >= 0 && __endi - __beg >= __newoffi + __off)
|
|
|
|
{
|
|
|
|
_M_in_cur = __beg + __newoffi + __off;
|
|
|
|
__ret = pos_type(__newoffi);
|
|
|
|
}
|
2002-04-09 14:14:32 +08:00
|
|
|
if ((__testout || __testboth)
|
2000-10-05 19:27:02 +08:00
|
|
|
&& __newoffo + __off >= 0 && __endo - __beg >= __newoffo + __off)
|
|
|
|
{
|
|
|
|
_M_out_cur_move(__newoffo + __off - (_M_out_cur - __beg));
|
|
|
|
__ret = pos_type(__newoffo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return __ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _CharT, class _Traits, class _Alloc>
|
2001-07-20 08:09:31 +08:00
|
|
|
typename basic_stringbuf<_CharT, _Traits, _Alloc>::pos_type
|
2000-10-05 19:27:02 +08:00
|
|
|
basic_stringbuf<_CharT, _Traits, _Alloc>::
|
|
|
|
seekpos(pos_type __sp, ios_base::openmode __mode)
|
|
|
|
{
|
|
|
|
pos_type __ret = pos_type(off_type(-1));
|
|
|
|
|
2002-04-09 14:14:32 +08:00
|
|
|
if (_M_buf_size)
|
2000-10-05 19:27:02 +08:00
|
|
|
{
|
2002-07-31 10:47:36 +08:00
|
|
|
off_type __pos = __sp; // Use streamoff operator to do conversion.
|
2002-04-09 14:14:32 +08:00
|
|
|
char_type* __beg = NULL;
|
|
|
|
char_type* __end = NULL;
|
2002-04-09 16:48:33 +08:00
|
|
|
bool __testin = (ios_base::in & _M_mode & __mode) != 0;
|
|
|
|
bool __testout = (ios_base::out & _M_mode & __mode) != 0;
|
2002-04-09 14:14:32 +08:00
|
|
|
bool __testboth = __testin && __testout;
|
|
|
|
__testin &= !(__mode & ios_base::out);
|
|
|
|
__testout &= !(__mode & ios_base::in);
|
|
|
|
|
|
|
|
// NB: Ordered.
|
|
|
|
bool __testposi = false;
|
|
|
|
bool __testposo = false;
|
|
|
|
if (__testin || __testboth)
|
|
|
|
{
|
|
|
|
__beg = this->eback();
|
|
|
|
__end = this->egptr();
|
|
|
|
if (0 <= __pos && __pos <= __end - __beg)
|
|
|
|
__testposi = true;
|
|
|
|
}
|
|
|
|
if (__testout || __testboth)
|
|
|
|
{
|
|
|
|
__beg = this->pbase();
|
|
|
|
__end = _M_buf + _M_buf_size;
|
|
|
|
if (0 <= __pos && __pos <= __end - __beg)
|
|
|
|
__testposo = true;
|
|
|
|
}
|
|
|
|
if (__testposi || __testposo)
|
|
|
|
{
|
|
|
|
if (__testposi)
|
|
|
|
_M_in_cur = _M_in_beg + __pos;
|
|
|
|
if (__testposo)
|
|
|
|
_M_out_cur_move((__pos) - (_M_out_cur - __beg));
|
|
|
|
__ret = pos_type(off_type(__pos));
|
|
|
|
}
|
2000-10-05 19:27:02 +08:00
|
|
|
}
|
|
|
|
return __ret;
|
|
|
|
}
|
Tune for size.
2002-02-15 Benjamin Kosnik <bkoz@redhat.com>
Tune for size.
* src/string-inst.cc (string::_Rep::_S_terminal): Remove redundant
explicit instantiation.
(string::_Rep::_S_max_size): Same.
* include/bits/basic_string.tcc: Add extern explicit
instantiations for string, wstring.
* include/bits/basic_ios.tcc: Add extern explicit instantiations
for ios, wios.
* include/bits/streambuf.tcc: Same, for streambuf, wstreambuf.
* include/bits/istream.tcc: Same, for istream, wistream.
* include/bits/ostream.tcc: Same for ostream, wostream, iostream,
wiostream.
* include/bits/sstream.tcc: Same, for stringbuf, wstringbuf,
istringstream, wistringstream, ostringstream, wostringstream,
stringstream, wstringstream.
* include/bits/fstream.tcc: Same, for filebuf, wfilebuf, ifstream,
wifstream, ofstream, wofstream, fstream, wfstream.
* src/misc-inst.cc: Correct comments.
Add iomanip instantiations for wide streams.
* include/std/std_iomanip.h: Same.
* include/bits/locale_facets.tcc: Same.
* include/std/std_streambuf.h: Correct
_GLIBCPP_FULLY_COMPLIANT_HEADERS guard.
* include/std/std_sstream.h: Same.
* include/std/std_ostream.h: Same.
* include/std/std_istream.h: Same.
* include/std/std_fstream.h: Same.
* include/std/std_streambuf.h: Add definitions for private copy
ctor and assignment operator.
* include/std/std_istream.h: Remove declared but undefined copy
ctor and assignment operator. This is taken care of in ios_base,
so adding it in the derived class as well is superfluous.
* include/std/std_ostream.h: Same.
* include/bits/basic_ios.h (basic_ios::clear): Don't inline.
* include/bits/basic_ios.tcc (basic_ios::clear): Move definition here.
From-SVN: r49798
2002-02-16 08:19:13 +08:00
|
|
|
|
|
|
|
// Inhibit implicit instantiations for required instantiations,
|
|
|
|
// which are defined via explicit instantiations elsewhere.
|
|
|
|
// NB: This syntax is a GNU extension.
|
|
|
|
extern template class basic_stringbuf<char>;
|
|
|
|
extern template class basic_stringbuf<wchar_t>;
|
|
|
|
extern template class basic_istringstream<char>;
|
|
|
|
extern template class basic_istringstream<wchar_t>;
|
|
|
|
extern template class basic_ostringstream<char>;
|
|
|
|
extern template class basic_ostringstream<wchar_t>;
|
|
|
|
extern template class basic_stringstream<char>;
|
|
|
|
extern template class basic_stringstream<wchar_t>;
|
2000-10-05 19:27:02 +08:00
|
|
|
} // namespace std
|
|
|
|
|
2002-02-01 11:20:39 +08:00
|
|
|
#endif
|