ostreambuf_iterator.cc: New file.
authorBenjamin Kosnik <bkoz@redhat.com>
Mon, 30 Apr 2001 20:53:31 +0000 (20:53 +0000)
committerBenjamin Kosnik <bkoz@gcc.gnu.org>
Mon, 30 Apr 2001 20:53:31 +0000 (20:53 +0000)
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

libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/sbuf_iter.h
libstdc++-v3/testsuite/24_iterators/ostreambuf_iterator.cc [new file with mode: 0644]

index 1821a9fa42fc5df46ed93cefaecf80c35adc4d3a..acbaaffb5958db6279d02370e9b2dbb59f8b3736 100644 (file)
@@ -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>
 
        libstdc++/2964
index 052b0dfbe852e20cd579c280b5ff300425fd9492..6bec6d2037a51adcac2cea8d708d622a4f3360fa 100644 (file)
 
 namespace std
 {
-
   template<typename _CharT, typename _Traits>
     class ostreambuf_iterator
-#if 1      // XXX this is standard:
     : public iterator<output_iterator_tag, _CharT, void, void, void>
-#else
-    : public output_iterator
-#endif
     {
     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;
       
       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);
@@ -82,57 +76,19 @@ namespace std
     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>
     class istreambuf_iterator
@@ -151,13 +107,13 @@ namespace std
       typedef istreambuf_iterator<_CharT, _Traits>     __istreambufiter_type;
 
       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
@@ -167,10 +123,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;
@@ -179,8 +135,8 @@ namespace std
       __istreambufiter_type& 
       operator++()
       { 
-       if (_M_istreambuf)
-         _M_istreambuf->sbumpc();
+       if (_M_sbuf)
+         _M_sbuf->sbumpc();
        _M_c = -2;
        return *this; 
       }
@@ -192,8 +148,8 @@ namespace std
       const __istreambufiter_type
       operator++(int)
       {
-       if (_M_istreambuf)
-         _M_c = _M_istreambuf->sbumpc();
+       if (_M_sbuf)
+         _M_c = _M_sbuf->sbumpc();
        return *this; 
       }
 #endif
@@ -202,9 +158,9 @@ namespace std
       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));
       }
 
@@ -215,9 +171,9 @@ 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
@@ -230,7 +186,7 @@ namespace std
       // the "end of stream" iterator value.
       // NB: This implementation assumes the "end of stream" value
       // is EOF, or -1.
-      streambuf_type*          _M_istreambuf;  
+      streambuf_type*          _M_sbuf;  
       int_type                         _M_c;
     };
 
@@ -246,7 +202,6 @@ namespace std
               const istreambuf_iterator<_CharT, _Traits>& __b)
     { return !__a.equal(__b); }
 
-} // std::
-
-#endif /* _CPP_BITS_SBUF_ITER_H */
+} // namespace std
 
+#endif
diff --git a/libstdc++-v3/testsuite/24_iterators/ostreambuf_iterator.cc b/libstdc++-v3/testsuite/24_iterators/ostreambuf_iterator.cc
new file mode 100644 (file)
index 0000000..9f1544f
--- /dev/null
@@ -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;
+}
+
+
+
+
+