ostreambuf_iterator.cc: New file.
2001-04-30 Benjamin Kosnik <bkoz@redhat.com> libstdc++/2627 * testsuite/24_iterators/ostreambuf_iterator.cc: New file. * include/bits/sbuf_iter.h (ostreambuf_iterator): Remove bogus specializations. From-SVN: r41694
This commit is contained in:
parent
60de6385e1
commit
b85381b911
|
@ -1,3 +1,10 @@
|
||||||
|
2001-04-30 Benjamin Kosnik <bkoz@redhat.com>
|
||||||
|
|
||||||
|
libstdc++/2627
|
||||||
|
* testsuite/24_iterators/ostreambuf_iterator.cc: New file.
|
||||||
|
* include/bits/sbuf_iter.h (ostreambuf_iterator): Remove bogus
|
||||||
|
specializations.
|
||||||
|
|
||||||
2001-04-30 Benjamin Kosnik <bkoz@redhat.com>
|
2001-04-30 Benjamin Kosnik <bkoz@redhat.com>
|
||||||
|
|
||||||
libstdc++/2964
|
libstdc++/2964
|
||||||
|
|
|
@ -36,29 +36,23 @@
|
||||||
|
|
||||||
namespace std
|
namespace std
|
||||||
{
|
{
|
||||||
|
|
||||||
template<typename _CharT, typename _Traits>
|
template<typename _CharT, typename _Traits>
|
||||||
class ostreambuf_iterator
|
class ostreambuf_iterator
|
||||||
#if 1 // XXX this is standard:
|
|
||||||
: public iterator<output_iterator_tag, _CharT, void, void, void>
|
: public iterator<output_iterator_tag, _CharT, void, void, void>
|
||||||
#else
|
|
||||||
: public output_iterator
|
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
// Types:
|
// Types:
|
||||||
typedef _CharT char_type;
|
typedef _CharT char_type;
|
||||||
typedef _Traits traits_type;
|
typedef _Traits traits_type;
|
||||||
typedef basic_streambuf<_CharT, _Traits> streambuf_type;
|
typedef basic_streambuf<_CharT, _Traits> streambuf_type;
|
||||||
typedef basic_ostream<_CharT, _Traits> ostream_type;
|
typedef basic_ostream<_CharT, _Traits> ostream_type;
|
||||||
|
|
||||||
inline
|
inline
|
||||||
ostreambuf_iterator(ostream_type& __s) throw ()
|
ostreambuf_iterator(ostream_type& __s) throw ()
|
||||||
: _M_sbuf(__s.rdbuf()), _M_failed(false) { }
|
: _M_sbuf(__s.rdbuf()), _M_failed(!_M_sbuf) { }
|
||||||
|
|
||||||
ostreambuf_iterator(streambuf_type* __s) throw ()
|
ostreambuf_iterator(streambuf_type* __s) throw ()
|
||||||
: _M_sbuf(__s), _M_failed(false) { }
|
: _M_sbuf(__s), _M_failed(!_M_sbuf) { }
|
||||||
|
|
||||||
ostreambuf_iterator&
|
ostreambuf_iterator&
|
||||||
operator=(_CharT __c);
|
operator=(_CharT __c);
|
||||||
|
@ -82,57 +76,19 @@ namespace std
|
||||||
private:
|
private:
|
||||||
streambuf_type* _M_sbuf;
|
streambuf_type* _M_sbuf;
|
||||||
bool _M_failed;
|
bool _M_failed;
|
||||||
|
|
||||||
#if 0
|
|
||||||
template<>
|
|
||||||
friend char const*
|
|
||||||
copy(char const* __first, char const* __last,
|
|
||||||
ostreambuf_iterator<char,char_traits<char> > __to);
|
|
||||||
template<>
|
|
||||||
friend wchar_t const*
|
|
||||||
copy(wchar_t const* __first, wchar_t const* __last,
|
|
||||||
ostreambuf_iterator<wchar_t,char_traits<wchar_t> > __to);
|
|
||||||
#endif
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename _CharT, typename _Traits>
|
template<typename _CharT, typename _Traits>
|
||||||
inline ostreambuf_iterator<_CharT, _Traits>&
|
inline ostreambuf_iterator<_CharT, _Traits>&
|
||||||
ostreambuf_iterator<_CharT, _Traits>::operator=(_CharT __c)
|
ostreambuf_iterator<_CharT, _Traits>::operator=(_CharT __c)
|
||||||
{
|
{
|
||||||
if (!_M_failed &&
|
if (!_M_failed &&
|
||||||
_Traits::eq_int_type(_M_sbuf->sputc(__c),_Traits::eof()))
|
_Traits::eq_int_type(_M_sbuf->sputc(__c),_Traits::eof()))
|
||||||
_M_failed = true;
|
_M_failed = true;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
// Optimized specializations of standard algorithms
|
|
||||||
// These are specialized only for standard types
|
|
||||||
// (with no unbound arguments) to avoid creating
|
|
||||||
// overload problems with user specializations.
|
|
||||||
|
|
||||||
template<>
|
|
||||||
char const*
|
|
||||||
copy(char const* __first, char const* __last,
|
|
||||||
ostreambuf_iterator<char,char_traits<char> > __to)
|
|
||||||
{
|
|
||||||
if (!__to._M_failed)
|
|
||||||
__to._M_sbuf->sputn(__first, __last-__first);
|
|
||||||
return __last;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<>
|
|
||||||
wchar_t const*
|
|
||||||
copy(wchar_t const* __first, wchar_t const* __last,
|
|
||||||
ostreambuf_iterator<whar_t,char_traits<wchar_t> > __to)
|
|
||||||
{
|
|
||||||
if (!__to._M_failed)
|
|
||||||
__to._M_sbuf->sputn(__first, __last-__first);
|
|
||||||
return __last;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// 24.5.3 Template class istreambuf_iterator
|
// 24.5.3 Template class istreambuf_iterator
|
||||||
template<class _CharT, class _Traits>
|
template<class _CharT, class _Traits>
|
||||||
class istreambuf_iterator
|
class istreambuf_iterator
|
||||||
|
@ -151,13 +107,13 @@ namespace std
|
||||||
typedef istreambuf_iterator<_CharT, _Traits> __istreambufiter_type;
|
typedef istreambuf_iterator<_CharT, _Traits> __istreambufiter_type;
|
||||||
|
|
||||||
istreambuf_iterator() throw()
|
istreambuf_iterator() throw()
|
||||||
: _M_istreambuf(NULL), _M_c(-2) { }
|
: _M_sbuf(NULL), _M_c(-2) { }
|
||||||
|
|
||||||
istreambuf_iterator(istream_type& __s) throw()
|
istreambuf_iterator(istream_type& __s) throw()
|
||||||
: _M_istreambuf(__s.rdbuf()), _M_c(-2) { }
|
: _M_sbuf(__s.rdbuf()), _M_c(-2) { }
|
||||||
|
|
||||||
istreambuf_iterator(streambuf_type* __s) throw()
|
istreambuf_iterator(streambuf_type* __s) throw()
|
||||||
: _M_istreambuf(__s), _M_c(-2) { }
|
: _M_sbuf(__s), _M_c(-2) { }
|
||||||
|
|
||||||
// NB: This should really have an int_type return
|
// NB: This should really have an int_type return
|
||||||
// value, so "end of stream" postion can be checked without
|
// value, so "end of stream" postion can be checked without
|
||||||
|
@ -167,10 +123,10 @@ namespace std
|
||||||
{
|
{
|
||||||
// The result of operator*() on an end of stream is undefined.
|
// The result of operator*() on an end of stream is undefined.
|
||||||
char_type __ret;
|
char_type __ret;
|
||||||
if (_M_istreambuf && _M_c != static_cast<int_type>(-2))
|
if (_M_sbuf && _M_c != static_cast<int_type>(-2))
|
||||||
__ret = _M_c;
|
__ret = _M_c;
|
||||||
else if (_M_istreambuf)
|
else if (_M_sbuf)
|
||||||
__ret = traits_type::to_char_type(_M_istreambuf->sgetc());
|
__ret = traits_type::to_char_type(_M_sbuf->sgetc());
|
||||||
else
|
else
|
||||||
__ret = static_cast<char_type>(traits_type::eof());
|
__ret = static_cast<char_type>(traits_type::eof());
|
||||||
return __ret;
|
return __ret;
|
||||||
|
@ -179,8 +135,8 @@ namespace std
|
||||||
__istreambufiter_type&
|
__istreambufiter_type&
|
||||||
operator++()
|
operator++()
|
||||||
{
|
{
|
||||||
if (_M_istreambuf)
|
if (_M_sbuf)
|
||||||
_M_istreambuf->sbumpc();
|
_M_sbuf->sbumpc();
|
||||||
_M_c = -2;
|
_M_c = -2;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
@ -192,8 +148,8 @@ namespace std
|
||||||
const __istreambufiter_type
|
const __istreambufiter_type
|
||||||
operator++(int)
|
operator++(int)
|
||||||
{
|
{
|
||||||
if (_M_istreambuf)
|
if (_M_sbuf)
|
||||||
_M_c = _M_istreambuf->sbumpc();
|
_M_c = _M_sbuf->sbumpc();
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -202,9 +158,9 @@ namespace std
|
||||||
equal(const __istreambufiter_type& __b)
|
equal(const __istreambufiter_type& __b)
|
||||||
{
|
{
|
||||||
int_type __eof = traits_type::eof();
|
int_type __eof = traits_type::eof();
|
||||||
bool __thiseof = !_M_istreambuf || _M_istreambuf->sgetc() == __eof;
|
bool __thiseof = !_M_sbuf || _M_sbuf->sgetc() == __eof;
|
||||||
bool __beof = !__b._M_istreambuf
|
bool __beof = !__b._M_sbuf
|
||||||
|| __b._M_istreambuf->sgetc() == __eof;
|
|| __b._M_sbuf->sgetc() == __eof;
|
||||||
return (__thiseof && __beof || (!__thiseof && !__beof));
|
return (__thiseof && __beof || (!__thiseof && !__beof));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -215,9 +171,9 @@ namespace std
|
||||||
equal(const __istreambufiter_type& __b) const
|
equal(const __istreambufiter_type& __b) const
|
||||||
{
|
{
|
||||||
int_type __eof = traits_type::eof();
|
int_type __eof = traits_type::eof();
|
||||||
bool __thiseof = !_M_istreambuf || _M_istreambuf->sgetc() == __eof;
|
bool __thiseof = !_M_sbuf || _M_sbuf->sgetc() == __eof;
|
||||||
bool __beof = !__b._M_istreambuf
|
bool __beof = !__b._M_sbuf
|
||||||
|| __b._M_istreambuf->sgetc() == __eof;
|
|| __b._M_sbuf->sgetc() == __eof;
|
||||||
return (__thiseof && __beof || (!__thiseof && !__beof));
|
return (__thiseof && __beof || (!__thiseof && !__beof));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -230,7 +186,7 @@ namespace std
|
||||||
// the "end of stream" iterator value.
|
// the "end of stream" iterator value.
|
||||||
// NB: This implementation assumes the "end of stream" value
|
// NB: This implementation assumes the "end of stream" value
|
||||||
// is EOF, or -1.
|
// is EOF, or -1.
|
||||||
streambuf_type* _M_istreambuf;
|
streambuf_type* _M_sbuf;
|
||||||
int_type _M_c;
|
int_type _M_c;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -246,7 +202,6 @@ namespace std
|
||||||
const istreambuf_iterator<_CharT, _Traits>& __b)
|
const istreambuf_iterator<_CharT, _Traits>& __b)
|
||||||
{ return !__a.equal(__b); }
|
{ return !__a.equal(__b); }
|
||||||
|
|
||||||
} // std::
|
} // namespace std
|
||||||
|
|
||||||
#endif /* _CPP_BITS_SBUF_ITER_H */
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
|
@ -0,0 +1,97 @@
|
||||||
|
// 2001-04-30 Benjamin Kosnik <bkoz@redhat.com>
|
||||||
|
|
||||||
|
// Copyright (C) 2001 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.
|
||||||
|
|
||||||
|
// 24.5.4 template class ostreambuf_iterator
|
||||||
|
|
||||||
|
#include <sstream>
|
||||||
|
#include <iterator>
|
||||||
|
#include <debug_assert.h>
|
||||||
|
|
||||||
|
bool test01(void)
|
||||||
|
{
|
||||||
|
typedef std::ostreambuf_iterator<char> costreambuf_iter;
|
||||||
|
typedef costreambuf_iter::streambuf_type cstreambuf_type;
|
||||||
|
bool test = true;
|
||||||
|
const char slit01[] = "playa hermosa, liberia, guanacaste";
|
||||||
|
std::string str01(slit01);
|
||||||
|
std::string tmp;
|
||||||
|
std::stringbuf strbuf01;
|
||||||
|
std::stringbuf strbuf02(str01);
|
||||||
|
std::ostringstream ostrs00(str01);
|
||||||
|
std::ostringstream ostrs01(str01);
|
||||||
|
|
||||||
|
// ctor sanity checks
|
||||||
|
costreambuf_iter ostrb_it01(ostrs00);
|
||||||
|
VERIFY( !ostrb_it01.failed() );
|
||||||
|
ostrb_it01++;
|
||||||
|
++ostrb_it01;
|
||||||
|
VERIFY( !ostrb_it01.failed() );
|
||||||
|
ostrb_it01 = 'a';
|
||||||
|
VERIFY( !ostrb_it01.failed() );
|
||||||
|
*ostrb_it01;
|
||||||
|
VERIFY( !ostrb_it01.failed() );
|
||||||
|
|
||||||
|
costreambuf_iter ostrb_it02(NULL);
|
||||||
|
VERIFY( ostrb_it02.failed() );
|
||||||
|
ostrb_it02++;
|
||||||
|
++ostrb_it02;
|
||||||
|
VERIFY( ostrb_it02.failed() );
|
||||||
|
*ostrb_it02;
|
||||||
|
VERIFY( ostrb_it02.failed() );
|
||||||
|
ostrb_it02 = 'a';
|
||||||
|
VERIFY( ostrb_it02.failed() );
|
||||||
|
|
||||||
|
// charT operator*() const
|
||||||
|
// ostreambuf_iterator& operator++();
|
||||||
|
// ostreambuf_iterator& operator++(int);
|
||||||
|
costreambuf_iter ostrb_it27(ostrs00);
|
||||||
|
VERIFY( !ostrb_it27.failed() );
|
||||||
|
for (int i = 0; i < strlen(slit01) - 2; ++i)
|
||||||
|
ostrb_it27 = 'a';
|
||||||
|
VERIFY( !ostrb_it27.failed() );
|
||||||
|
tmp = ostrs00.str();
|
||||||
|
VERIFY ( tmp == str01 );
|
||||||
|
|
||||||
|
costreambuf_iter ostrb_it28(ostrs01);
|
||||||
|
VERIFY( !ostrb_it28.failed() );
|
||||||
|
for (int i = 0; i < strlen(slit01) + 1; ++i)
|
||||||
|
ostrb_it28 = 'b';
|
||||||
|
VERIFY( !ostrb_it28.failed() );
|
||||||
|
tmp = ostrs01.str();
|
||||||
|
VERIFY ( tmp != str01 );
|
||||||
|
|
||||||
|
#ifdef DEBUG_ASSERT
|
||||||
|
assert(test);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return test;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
test01();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue