changeset 4327:c29c382a5b4b

[project @ 2003-02-16 03:24:26 by jwe]
author jwe
date Sun, 16 Feb 2003 03:24:26 +0000
parents 1cae4472c624
children f7b63f362168
files src/ChangeLog src/file-io.cc src/oct-prcstrm.cc src/oct-prcstrm.h src/oct-stdstrm.cc src/oct-stdstrm.h src/syscalls.cc
diffstat 7 files changed, 59 insertions(+), 270 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Sat Feb 15 23:14:47 2003 +0000
+++ b/src/ChangeLog	Sun Feb 16 03:24:26 2003 +0000
@@ -1,5 +1,10 @@
 2003-02-15  John W. Eaton  <jwe@bevo.che.wisc.edu>
 
+	* oct-stdstrm.h, oct-stdstrm.cc (octave_base_stdiostream,
+	octave_iostdiostream, octave_istdiostram, octave_ostdiostream):
+	Combine all functionality into one class, octave_stdiostream.
+	Change all uses.	
+
 	* file-io.cc (Ftmpfile, Fmkstemp): New functions.
 	* oct-stdstrm.h (octave_iostdiostream): New class.
 	(octave_istdiostream::octave_istdiostream,
@@ -9,7 +14,7 @@
 	octave_iostdiostream::create): Make close function the last arg.
 	Change all uses.
 
-	* c-file-ptr-stream.h (iostream): New class.
+	* c-file-ptr-stream.h (io_c_file_ptr_stream): New class.
 
 2003-02-14  John W. Eaton  <jwe@bevo.che.wisc.edu>
 
--- a/src/file-io.cc	Sat Feb 15 23:14:47 2003 +0000
+++ b/src/file-io.cc	Sun Feb 16 03:24:26 2003 +0000
@@ -1550,12 +1550,12 @@
 
 	  std::ios::openmode md = fopen_mode_to_ios_mode ("w+b");
 
-	  octave_stream s = octave_iostdiostream::create (nm, fid, md);
+	  octave_stream s = octave_stdiostream::create (nm, fid, md);
 
 	  if (s)
 	    retval(0) = octave_stream_list::insert (s);
 	  else
-	    error ("tmpfile: failed to create octave_iostdiostream object");
+	    error ("tmpfile: failed to create octave_stdiostream object");
 
 	}
       else
@@ -1635,7 +1635,7 @@
 
 		  std::ios::openmode md = fopen_mode_to_ios_mode (fopen_mode);
 
-		  octave_stream s = octave_iostdiostream::create (nm, fid, md);
+		  octave_stream s = octave_stdiostream::create (nm, fid, md);
 
 		  if (s)
 		    {
@@ -1646,7 +1646,7 @@
 			mark_for_deletion (nm);
 		    }
 		  else
-		    error ("mkstemp: failed to create octave_iostdiostream object");
+		    error ("mkstemp: failed to create octave_stdiostream object");
 		}
 	      else
 		{
--- a/src/oct-prcstrm.cc	Sat Feb 15 23:14:47 2003 +0000
+++ b/src/oct-prcstrm.cc	Sun Feb 16 03:24:26 2003 +0000
@@ -44,8 +44,8 @@
 octave_iprocstream::octave_iprocstream (const std::string& n,
 					std::ios::openmode arg_md,
 					oct_mach_info::float_format flt_fmt)
-  : octave_istdiostream (n, ::popen (n.c_str (), "r"),
-			 arg_md, flt_fmt, cxx_pclose)
+  : octave_stdiostream (n, ::popen (n.c_str (), "r"),
+			arg_md, flt_fmt, cxx_pclose)
 {
 }
 
@@ -64,8 +64,8 @@
 octave_oprocstream::octave_oprocstream (const std::string& n,
 					std::ios::openmode arg_md,
 					oct_mach_info::float_format flt_fmt)
-  : octave_ostdiostream (n, ::popen (n.c_str (), "w"),
-			 arg_md, flt_fmt, cxx_pclose)
+  : octave_stdiostream (n, ::popen (n.c_str (), "w"),
+			arg_md, flt_fmt, cxx_pclose)
 {
 }
 
--- a/src/oct-prcstrm.h	Sat Feb 15 23:14:47 2003 +0000
+++ b/src/oct-prcstrm.h	Sun Feb 16 03:24:26 2003 +0000
@@ -29,7 +29,7 @@
 // oprocstream, which in turn use the octave_procbuf class?
 
 class
-octave_iprocstream : public octave_istdiostream
+octave_iprocstream : public octave_stdiostream
 {
 public:
 
@@ -56,7 +56,7 @@
 };
 
 class
-octave_oprocstream : public octave_ostdiostream
+octave_oprocstream : public octave_stdiostream
 {
 public:
 
--- a/src/oct-stdstrm.cc	Sat Feb 15 23:14:47 2003 +0000
+++ b/src/oct-stdstrm.cc	Sun Feb 16 03:24:26 2003 +0000
@@ -31,7 +31,7 @@
 // Position a stream at OFFSET relative to ORIGIN.
 
 int
-octave_base_stdiostream::seek (std::streamoff offset, std::ios::seekdir origin)
+octave_stdiostream::seek (std::streamoff offset, std::ios::seekdir origin)
 {
   int retval = -1;
 
@@ -54,7 +54,7 @@
 // Return current stream position.
 
 long
-octave_base_stdiostream::tell (void) const
+octave_stdiostream::tell (void) const
 {
   long retval = -1;
 
@@ -74,99 +74,6 @@
   return retval;
 }
 
-octave_stream
-octave_istdiostream::create (const std::string& n, FILE *f,
-			     std::ios::openmode arg_md,
-			     oct_mach_info::float_format flt_fmt,
-			     c_file_ptr_buf::close_fcn cf)
-{
-  return octave_stream (new octave_istdiostream (n, f, arg_md, flt_fmt, cf));
-}
-
-octave_istdiostream::octave_istdiostream (const std::string& n, FILE *f,
-					  std::ios::openmode arg_md,
-					  oct_mach_info::float_format flt_fmt,
-					  c_file_ptr_buf::close_fcn cf)
-  : octave_base_stdiostream (n, arg_md, flt_fmt), is (0)
-{
-  if (f)
-    is = new i_c_file_ptr_stream (f, cf);
-}
-
-octave_istdiostream::~octave_istdiostream (void)
-{
-  delete is;
-}
-
-void
-octave_istdiostream::do_close (void)
-{
-  if (is)
-    is->close ();
-}
-
-octave_stream
-octave_ostdiostream::create (const std::string& n, FILE *f,
-			     std::ios::openmode arg_md,
-			     oct_mach_info::float_format flt_fmt,
-			     c_file_ptr_buf::close_fcn cf)
-{
-  return octave_stream (new octave_ostdiostream (n, f, arg_md, flt_fmt, cf));
-}
-
-octave_ostdiostream::octave_ostdiostream (const std::string& n, FILE *f,
-					  std::ios::openmode arg_md,
-					  oct_mach_info::float_format flt_fmt,
-					  c_file_ptr_buf::close_fcn cf)
-  : octave_base_stdiostream (n, arg_md, flt_fmt), os (0)
-{
-  if (f)
-    os = new o_c_file_ptr_stream (f, cf);
-}
-
-octave_ostdiostream::~octave_ostdiostream (void)
-{
-  delete os;
-}
-
-void
-octave_ostdiostream::do_close (void)
-{
-  if (os)
-    os->close ();
-}
-
-octave_stream
-octave_iostdiostream::create (const std::string& n, FILE *f,
-			      std::ios::openmode arg_md,
-			      oct_mach_info::float_format flt_fmt,
-			      c_file_ptr_buf::close_fcn cf)
-{
-  return octave_stream (new octave_iostdiostream (n, f, arg_md, flt_fmt, cf));
-}
-
-octave_iostdiostream::octave_iostdiostream (const std::string& n, FILE *f,
-					    std::ios::openmode arg_md,
-					    oct_mach_info::float_format flt_fmt,
-					    c_file_ptr_buf::close_fcn cf)
-  : octave_base_stdiostream (n, arg_md, flt_fmt), s (0)
-{
-  if (f)
-    s = new io_c_file_ptr_stream (f, cf);
-}
-
-octave_iostdiostream::~octave_iostdiostream (void)
-{
-  delete s;
-}
-
-void
-octave_iostdiostream::do_close (void)
-{
-  if (s)
-    s->close ();
-}
-
 /*
 ;;; Local Variables: ***
 ;;; mode: C++ ***
--- a/src/oct-stdstrm.h	Sat Feb 15 23:14:47 2003 +0000
+++ b/src/oct-stdstrm.h	Sun Feb 16 03:24:26 2003 +0000
@@ -27,15 +27,28 @@
 #include "c-file-ptr-stream.h"
 
 class
-octave_base_stdiostream : public octave_base_stream
+octave_stdiostream : public octave_base_stream
 {
 public:
 
-  octave_base_stdiostream
-    (const std::string& n,
-     std::ios::openmode arg_md = std::ios::in|std::ios::out,
-     oct_mach_info::float_format flt_fmt = oct_mach_info::native)
-    : octave_base_stream (arg_md, flt_fmt), nm (n) { }
+  octave_stdiostream (const std::string& n, FILE *f = 0,
+		      std::ios::openmode arg_md = std::ios::in|std::ios::out,
+		      oct_mach_info::float_format flt_fmt = oct_mach_info::native,
+		      c_file_ptr_buf::close_fcn cf = c_file_ptr_buf::fclose)
+    : octave_base_stream (arg_md, flt_fmt), nm (n), md (arg_md), s(0)
+  {
+    if (f)
+      s = new io_c_file_ptr_stream (f, cf);
+  }
+
+  static octave_stream
+  create (const std::string& n, FILE *f = 0,
+	  std::ios::openmode arg_md = std::ios::in|std::ios::out,
+	  oct_mach_info::float_format flt_fmt = oct_mach_info::native,
+	  c_file_ptr_buf::close_fcn cf = c_file_ptr_buf::fclose)
+  {
+    return octave_stream (new octave_stdiostream (n, f, arg_md, flt_fmt, cf));
+  }
 
   // Position a stream at OFFSET relative to ORIGIN.
 
@@ -45,158 +58,17 @@
 
   long tell (void) const;
 
+  // Return non-zero if EOF has been reached on this stream.
+
+  bool eof (void) const { return s ? s->eof () : true; }
+
   // The name of the file.
 
   std::string name (void) const { return nm; }
 
-  virtual c_file_ptr_buf *rdbuf (void) const = 0;
-
-  virtual bool bad (void) const = 0;
-
-  virtual void clear (void) = 0;
-
-protected:
-
-  std::string nm;
-
-  ~octave_base_stdiostream (void) { }
-
-  // No copying!
-
-  octave_base_stdiostream (const octave_base_stdiostream&);
-
-  octave_base_stdiostream& operator = (const octave_base_stdiostream&);
-};
-
-class
-octave_istdiostream : public octave_base_stdiostream
-{
-public:
-
-  octave_istdiostream (const std::string& n, FILE *f = 0,
-		       std::ios::openmode arg_md = std::ios::in,
-		       oct_mach_info::float_format flt_fmt = oct_mach_info::native,
-		       c_file_ptr_buf::close_fcn cf = c_file_ptr_buf::fclose);
-
-  static octave_stream
-  create (const std::string& n, FILE *f = 0,
-	  std::ios::openmode arg_md = std::ios::in,
-	  oct_mach_info::float_format flt_fmt = oct_mach_info::native,
-	  c_file_ptr_buf::close_fcn cf = c_file_ptr_buf::fclose);
-
-  // Return non-zero if EOF has been reached on this stream.
-
-  bool eof (void) const { return is ? is->eof () : true; }
-
-  std::istream *input_stream (void) { return is; }
-
-  std::ostream *output_stream (void) { return 0; }
-
-  // XXX FIXME XXX -- should not have to cast away const here.
-  c_file_ptr_buf *rdbuf (void) const
-    { return is ? (const_cast<i_c_file_ptr_stream *> (is))->rdbuf () : 0; }
-
-  bool bad (void) const { return is ? is->bad () : true; }
-
-  void clear (void)
-    {
-      if (is)
-	is->clear ();
-    }
-
-  void do_close (void);
-
-protected:
-
-  i_c_file_ptr_stream *is;
-
-  ~octave_istdiostream (void);
-
-private:
-
-  // No copying!
-
-  octave_istdiostream (const octave_istdiostream&);
-
-  octave_istdiostream& operator = (const octave_istdiostream&);
-};
+  std::istream *input_stream (void) { return (md & std::ios::in) ? s : 0; }
 
-class
-octave_ostdiostream : public octave_base_stdiostream
-{
-public:
-
-  octave_ostdiostream (const std::string& n, FILE *f = 0,
-		       std::ios::openmode arg_md = std::ios::out,
-		       oct_mach_info::float_format flt_fmt = oct_mach_info::native,
-		       c_file_ptr_buf::close_fcn cf = c_file_ptr_buf::fclose);
-
-  static octave_stream
-  create (const std::string& n, FILE *f = 0,
-	  std::ios::openmode arg_md = std::ios::out,
-	  oct_mach_info::float_format flt_fmt = oct_mach_info::native,
-	  c_file_ptr_buf::close_fcn cf = c_file_ptr_buf::fclose);
-
-  // Return non-zero if EOF has been reached on this stream.
-
-  bool eof (void) const { return os ? os->eof () : true; }
-
-  std::istream *input_stream (void) { return 0; }
-
-  std::ostream *output_stream (void) { return os; }
-
-  // XXX FIXME XXX -- should not have to cast away const here.
-  c_file_ptr_buf *rdbuf (void) const
-    { return os ? (const_cast<o_c_file_ptr_stream *> (os))->rdbuf () : 0; }
-
-  bool bad (void) const { return os ? os->bad () : true; }
-
-  void clear (void)
-    {
-      if (os)
-	os->clear ();
-    }
-
-  void do_close (void);
-
-protected:
-
-  o_c_file_ptr_stream *os;
-
-  ~octave_ostdiostream (void);
-
-private:
-
-  // No copying!
-
-  octave_ostdiostream (const octave_ostdiostream&);
-
-  octave_ostdiostream& operator = (const octave_ostdiostream&);
-};
-
-class
-octave_iostdiostream : public octave_base_stdiostream
-{
-public:
-
-  octave_iostdiostream (const std::string& n, FILE *f = 0,
-			std::ios::openmode arg_md = std::ios::in,
-			oct_mach_info::float_format flt_fmt = oct_mach_info::native,
-			c_file_ptr_buf::close_fcn cf = c_file_ptr_buf::fclose);
-
-  static octave_stream
-  create (const std::string& n, FILE *f = 0,
-	  std::ios::openmode arg_md = std::ios::in|std::ios::out,
-	  oct_mach_info::float_format flt_fmt = oct_mach_info::native,
-	  c_file_ptr_buf::close_fcn cf = c_file_ptr_buf::fclose);
-
-  // Return non-zero if EOF has been reached on this stream.
-
-  bool eof (void) const { return s ? s->eof () : true; }
-
-  std::istream *input_stream (void) { return s; }
-
-  std::ostream *output_stream (void) { return s; }
+  std::ostream *output_stream (void) { return (md & std::ios::in) ? s : 0; }
 
   // XXX FIXME XXX -- should not have to cast away const here.
   c_file_ptr_buf *rdbuf (void) const
@@ -204,27 +76,27 @@
 
   bool bad (void) const { return s ? s->bad () : true; }
 
-  void clear (void)
-    {
-      if (s)
-	s->clear ();
-    }
+  void clear (void) { if (s) s->clear (); }
 
-  void do_close (void);
+  void do_close (void) { if (s) s->close (); }
 
 protected:
 
+  std::string nm;
+
+  std::ios::openmode md;
+
   io_c_file_ptr_stream *s;
 
-  ~octave_iostdiostream (void);
+  ~octave_stdiostream (void) { delete s; }
 
 private:
 
   // No copying!
 
-  octave_iostdiostream (const octave_iostdiostream&);
+  octave_stdiostream (const octave_stdiostream&);
 
-  octave_iostdiostream& operator = (const octave_iostdiostream&);
+  octave_stdiostream& operator = (const octave_stdiostream&);
 };
 
 #endif
--- a/src/syscalls.cc	Sat Feb 15 23:14:47 2003 +0000
+++ b/src/syscalls.cc	Sun Feb 16 03:24:26 2003 +0000
@@ -671,8 +671,13 @@
 	  FILE *ifile = fdopen (fid[0], "r");
 	  FILE *ofile = fdopen (fid[1], "w");
 
-	  octave_stream is = octave_istdiostream::create (std::string (), ifile);
-	  octave_stream os = octave_ostdiostream::create (std::string (), ofile);
+	  std::string nm;
+
+	  octave_stream is = octave_stdiostream::create (nm, ifile,
+							 std::ios::in);
+
+	  octave_stream os = octave_stdiostream::create (nm, ofile,
+							 std::ios::out);
 
 	  octave_value_list file_ids;