changeset 4310:da7226ca8b91

[project @ 2003-01-30 03:26:26 by jwe]
author jwe
date Thu, 30 Jan 2003 03:26:26 +0000
parents a9560cebae6e
children a9e0bff33b02
files src/ChangeLog src/c-file-ptr-stream.cc src/c-file-ptr-stream.h
diffstat 3 files changed, 30 insertions(+), 48 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Tue Jan 28 23:24:58 2003 +0000
+++ b/src/ChangeLog	Thu Jan 30 03:26:26 2003 +0000
@@ -1,3 +1,12 @@
+2003-01-29  John W. Eaton  <jwe@bevo.che.wisc.edu>
+
+	* c-file-ptr-stream.cc (c_file_ptr_buf::underflow_common): New
+	function.
+	* c-file-ptr-stream.h (c_file_ptr_buf::underflow,
+	c_file_ptr_buf::uflow): Use it.
+	(c_file_ptr_buf): Derive from std::streambuf, not OCTAVE_STD_FILEBUF.
+	Don't cache file descriptor.
+
 2003-01-28  John W. Eaton  <jwe@bevo.che.wisc.edu>
 
 	* DLD-FUNCTIONS/minmax.cc: Move min and max functions from here to
--- a/src/c-file-ptr-stream.cc	Tue Jan 28 23:24:58 2003 +0000
+++ b/src/c-file-ptr-stream.cc	Thu Jan 30 03:26:26 2003 +0000
@@ -66,10 +66,22 @@
 }
 
 c_file_ptr_buf::int_type
-c_file_ptr_buf::underflow (void)
+c_file_ptr_buf::underflow_common (bool bump)
 {
   if (f)
-    return fgetc (f);
+    {
+      int_type c = fgetc (f);
+
+      if (! bump
+#if defined (CXX_ISO_COMPLIANT_LIBRARY)
+	  && c != traits_type::eof ())
+#else
+	  && c != EOF)
+#endif
+	ungetc (c, f);
+
+      return c;
+    }
   else
 #if defined (CXX_ISO_COMPLIANT_LIBRARY)
     return traits_type::eof ();
@@ -79,12 +91,6 @@
 }
 
 c_file_ptr_buf::int_type
-c_file_ptr_buf::uflow (void)
-{
-  return underflow ();
-}
-
-c_file_ptr_buf::int_type
 c_file_ptr_buf::pbackfail (int_type c)
 {
 #if defined (CXX_ISO_COMPLIANT_LIBRARY)
--- a/src/c-file-ptr-stream.h	Tue Jan 28 23:24:58 2003 +0000
+++ b/src/c-file-ptr-stream.h	Thu Jan 30 03:26:26 2003 +0000
@@ -28,39 +28,17 @@
 #endif
 
 #include <iostream>
-#include <fstream>
 #include <cstdio>
 
-// The c_file_ptr_buf requires a std::filebuf that accepts an open
-// file descriptor. This feature, while not part of the ISO C++
-// standard, is supported by a variety of C++ compiler runtimes,
-// albeit in slightly different ways.
-//
-// The C++ runtime libraries shipped with GCC versions < 3.0, Sun Pro,
-// Sun Workshop/Forte 5/6, Compaq C++ all support a non-standard filebuf
-// constructor that takes an open file descriptor. The almost ISO compliant
-// GNU C++ runtime shipped with GCC 3.0.x supports a different non-standard
-// filebuf constructor that takes a FILE* instead; starting from GCC 3.1,
-// the GNU C++ runtime removes all non-standard std::filebuf constructors
-// and provides an extension template class __gnu_cxx::stdio_filebuf
-// that supports the the 3.0.x behavior.
-
-#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1) && ! (defined (__APPLE__) && defined (__MACH__))
-# include <ext/stdio_filebuf.h>
-# define OCTAVE_STD_FILEBUF __gnu_cxx::stdio_filebuf<char>
-#else
-# define OCTAVE_STD_FILEBUF std::filebuf
-#endif
-
 class
-c_file_ptr_buf : public OCTAVE_STD_FILEBUF
+c_file_ptr_buf : public std::streambuf
 {
 public:
 
 #if !defined (CXX_ISO_COMPLIANT_LIBRARY)
   typedef int int_type;
 #else
-  typedef std::filebuf::int_type int_type;
+  typedef std::streambuf::int_type int_type;
 #endif
 
   typedef int (*close_fcn) (FILE *);
@@ -68,25 +46,16 @@
   FILE* stdiofile (void) const { return f; }
 
   c_file_ptr_buf (FILE *f_arg, close_fcn cf_arg = fclose)
-    : 
-#if defined __GNUC__ && __GNUC__ >= 3
-    OCTAVE_STD_FILEBUF (f_arg, std::ios::in | std::ios::out),
-#elif defined __INTEL_COMPILER
-    OCTAVE_STD_FILEBUF (f_arg),
-#else
-    OCTAVE_STD_FILEBUF (f_arg ? fileno (f_arg) : -1),
-#endif
-    f (f_arg), cf (cf_arg),
-    fd (f_arg ? fileno (f_arg) : -1)
+    : std::streambuf (), f (f_arg), cf (cf_arg)
     { }
 
   ~c_file_ptr_buf (void);
 
   int_type overflow (int_type);
 
-  int_type underflow (void);
+  int_type underflow (void) { return underflow_common (false); }
 
-  int_type uflow (void);
+  int_type uflow (void) { return underflow_common (true); }
 
   int_type pbackfail (int_type);
 
@@ -106,7 +75,7 @@
 
   int close (void);
 
-  int file_number () const { return fd; }
+  int file_number () const { return f ? fileno (f) : -1; }
 
   static int fclose (FILE *f) { return ::fclose (f); }
 
@@ -118,11 +87,9 @@
 
 private:
 
-  int fd;
+  int_type underflow_common (bool);
 };
 
-#undef OCTAVE_STD_FILEBUF
-
 class
 i_c_file_ptr_stream : public std::istream
 {