aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3/include/bits/sbuf_iter.h
diff options
context:
space:
mode:
Diffstat (limited to 'libstdc++-v3/include/bits/sbuf_iter.h')
-rw-r--r--libstdc++-v3/include/bits/sbuf_iter.h159
1 files changed, 49 insertions, 110 deletions
diff --git a/libstdc++-v3/include/bits/sbuf_iter.h b/libstdc++-v3/include/bits/sbuf_iter.h
index 7a0e1d5db22..0f2c36db30a 100644
--- a/libstdc++-v3/include/bits/sbuf_iter.h
+++ b/libstdc++-v3/include/bits/sbuf_iter.h
@@ -1,6 +1,6 @@
// Streambuf iterators
-// Copyright (C) 1997-1999 Free Software Foundation, Inc.
+// Copyright (C) 1997-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
@@ -32,31 +32,32 @@
#ifndef _CPP_BITS_SBUF_ITER_H
#define _CPP_BITS_SBUF_ITER_H 1
+#pragma GCC system_header
+
namespace std
{
-
template<typename _CharT, typename _Traits>
class ostreambuf_iterator
-#if 0 // XXX this is standard:
- : public iterator<output_iterator_tag, _CharT, void, void, void>
-#else
- : public output_iterator
-#endif
+ : public iterator<output_iterator_tag, void, void, void, void>
{
public:
-
// Types:
- typedef _CharT char_type;
+ typedef _CharT char_type;
typedef _Traits traits_type;
typedef basic_streambuf<_CharT, _Traits> streambuf_type;
typedef basic_ostream<_CharT, _Traits> ostream_type;
-
+
+ private:
+ streambuf_type* _M_sbuf;
+ bool _M_failed;
+
+ public:
inline
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 ()
- : _M_sbuf(__s), _M_failed(false) { }
+ : _M_sbuf(__s), _M_failed(!_M_sbuf) { }
ostreambuf_iterator&
operator=(_CharT __c);
@@ -76,69 +77,26 @@ namespace std
bool
failed() const throw()
{ return _M_failed; }
-
- private:
- streambuf_type* _M_sbuf;
- 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>
inline ostreambuf_iterator<_CharT, _Traits>&
ostreambuf_iterator<_CharT, _Traits>::operator=(_CharT __c)
{
- if (!_M_failed &&
+ if (!_M_failed &&
_Traits::eq_int_type(_M_sbuf->sputc(__c),_Traits::eof()))
_M_failed = true;
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
- template<class _CharT, class _Traits>
+ template<typename _CharT, typename _Traits>
class istreambuf_iterator
: public iterator<input_iterator_tag, _CharT, typename _Traits::off_type,
_CharT*, _CharT&>
{
public:
-
// Types:
typedef _CharT char_type;
typedef _Traits traits_type;
@@ -148,14 +106,26 @@ namespace std
// Non-standard Types:
typedef istreambuf_iterator<_CharT, _Traits> __istreambufiter_type;
+ private:
+ // 24.5.3 istreambuf_iterator
+ // p 1
+ // If the end of stream is reached (streambuf_type::sgetc()
+ // returns traits_type::eof()), the iterator becomes equal to
+ // the "end of stream" iterator value.
+ // NB: This implementation assumes the "end of stream" value
+ // is EOF, or -1.
+ streambuf_type* _M_sbuf;
+ int_type _M_c;
+
+ public:
istreambuf_iterator() throw()
- : _M_istreambuf(NULL), _M_c(-2) { }
+ : _M_sbuf(NULL), _M_c(-2) { }
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()
- : _M_istreambuf(__s), _M_c(-2) { }
+ : _M_sbuf(__s), _M_c(-2) { }
// NB: This should really have an int_type return
// value, so "end of stream" postion can be checked without
@@ -165,10 +135,10 @@ namespace std
{
// The result of operator*() on an end of stream is undefined.
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;
- else if (_M_istreambuf)
- __ret = traits_type::to_char_type(_M_istreambuf->sgetc());
+ else if (_M_sbuf)
+ __ret = traits_type::to_char_type(_M_sbuf->sgetc());
else
__ret = static_cast<char_type>(traits_type::eof());
return __ret;
@@ -177,32 +147,29 @@ namespace std
__istreambufiter_type&
operator++()
{
- if (_M_istreambuf)
- _M_istreambuf->sbumpc();
+ if (_M_sbuf)
+ _M_sbuf->sbumpc();
_M_c = -2;
return *this;
}
-#ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
- // 14882 says return a proxy object. It should be a const
- // proxy object, but since this class is not mandated, it
- // should allow this signature:
- const __istreambufiter_type
+ __istreambufiter_type
operator++(int)
{
- if (_M_istreambuf)
- _M_c = _M_istreambuf->sbumpc();
- return *this;
+ __istreambufiter_type __old = *this;
+ if (_M_sbuf)
+ __old._M_c = _M_sbuf->sbumpc();
+ _M_c = -2;
+ return __old;
}
-#endif
bool
equal(const __istreambufiter_type& __b)
{
int_type __eof = traits_type::eof();
- bool __thiseof = !_M_istreambuf || _M_istreambuf->sgetc() == __eof;
- bool __beof = !__b._M_istreambuf
- || __b._M_istreambuf->sgetc() == __eof;
+ bool __thiseof = !_M_sbuf || _M_sbuf->sgetc() == __eof;
+ bool __beof = !__b._M_sbuf
+ || __b._M_sbuf->sgetc() == __eof;
return (__thiseof && __beof || (!__thiseof && !__beof));
}
@@ -213,23 +180,12 @@ namespace std
equal(const __istreambufiter_type& __b) const
{
int_type __eof = traits_type::eof();
- bool __thiseof = !_M_istreambuf || _M_istreambuf->sgetc() == __eof;
- bool __beof = !__b._M_istreambuf
- || __b._M_istreambuf->sgetc() == __eof;
+ bool __thiseof = !_M_sbuf || _M_sbuf->sgetc() == __eof;
+ bool __beof = !__b._M_sbuf
+ || __b._M_sbuf->sgetc() == __eof;
return (__thiseof && __beof || (!__thiseof && !__beof));
}
#endif
-
- private:
- // 24.5.3 istreambuf_iterator
- // p 1
- // If the end of stream is reached (streambuf_type::sgetc()
- // returns traits_type::eof()), the iterator becomes equal to
- // the "end of stream" iterator value.
- // NB: This implementation assumes the "end of stream" value
- // is EOF, or -1.
- streambuf_type* _M_istreambuf;
- int_type _M_c;
};
template<typename _CharT, typename _Traits>
@@ -243,22 +199,5 @@ namespace std
operator!=(const istreambuf_iterator<_CharT, _Traits>& __a,
const istreambuf_iterator<_CharT, _Traits>& __b)
{ return !__a.equal(__b); }
-
-} // std::
-
-#endif /* _CPP_BITS_SBUF_ITER_H */
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+} // namespace std
+#endif