diff src/oct-stdstrm.h @ 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 34014c0fb2ce
line wrap: on
line diff
--- a/src/oct-stdstrm.h
+++ b/src/oct-stdstrm.h
@@ -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