oct-iostrm.h

Go to the documentation of this file.
00001 /*
00002 
00003 Copyright (C) 1996-2012 John W. Eaton
00004 
00005 This file is part of Octave.
00006 
00007 Octave is free software; you can redistribute it and/or modify it
00008 under the terms of the GNU General Public License as published by the
00009 Free Software Foundation; either version 3 of the License, or (at your
00010 option) any later version.
00011 
00012 Octave is distributed in the hope that it will be useful, but WITHOUT
00013 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00014 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00015 for more details.
00016 
00017 You should have received a copy of the GNU General Public License
00018 along with Octave; see the file COPYING.  If not, see
00019 <http://www.gnu.org/licenses/>.
00020 
00021 */
00022 
00023 #if !defined (octave_octave_iostream_h)
00024 #define octave_octave_iostream_h 1
00025 
00026 #include <iosfwd>
00027 
00028 #include "oct-stream.h"
00029 
00030 class
00031 octave_base_iostream : public octave_base_stream
00032 {
00033 public:
00034 
00035   octave_base_iostream (const std::string& n = std::string (),
00036                         std::ios::openmode m = std::ios::in|std::ios::out,
00037                         oct_mach_info::float_format ff
00038                           = oct_mach_info::native_float_format ())
00039     : octave_base_stream (m, ff), nm (n) { }
00040 
00041   // Position a stream at OFFSET relative to ORIGIN.
00042 
00043   int seek (long offset, int origin);
00044 
00045   // Return current stream position.
00046 
00047   long tell (void);
00048 
00049   // Return non-zero if EOF has been reached on this stream.
00050 
00051   bool eof (void) const;
00052 
00053   // The name of the file.
00054 
00055   std::string name (void) const { return nm; }
00056 
00057 protected:
00058 
00059   ~octave_base_iostream (void) { }
00060 
00061   void invalid_operation (void) const;
00062 
00063 private:
00064 
00065   std::string nm;
00066 
00067   virtual const char *stream_type (void) const = 0;
00068 
00069   // No copying!
00070 
00071   octave_base_iostream (const octave_base_iostream&);
00072 
00073   octave_base_iostream& operator = (const octave_base_iostream&);
00074 };
00075 
00076 class
00077 octave_istream : public octave_base_iostream
00078 {
00079 public:
00080 
00081   octave_istream (std::istream *arg = 0, const std::string& n = std::string ())
00082     : octave_base_iostream (n, std::ios::in,
00083                             oct_mach_info::native_float_format ()),
00084       is (arg)
00085   { }
00086 
00087   static octave_stream
00088   create (std::istream *arg = 0, const std::string& n = std::string ());
00089 
00090   // Return non-zero if EOF has been reached on this stream.
00091 
00092   bool eof (void) const;
00093 
00094   std::istream *input_stream (void) { return is; }
00095 
00096   std::ostream *output_stream (void) { return 0; }
00097 
00098 protected:
00099 
00100   ~octave_istream (void) { }
00101 
00102 private:
00103 
00104   std::istream *is;
00105 
00106   const char *stream_type (void) const { return "octave_istream"; }
00107 
00108   // No copying!
00109 
00110   octave_istream (const octave_istream&);
00111 
00112   octave_istream& operator = (const octave_istream&);
00113 };
00114 
00115 class
00116 octave_ostream : public octave_base_iostream
00117 {
00118 public:
00119 
00120   octave_ostream (std::ostream *arg, const std::string& n = std::string ())
00121     : octave_base_iostream (n, std::ios::out,
00122                             oct_mach_info::native_float_format ()),
00123       os (arg)
00124   { }
00125 
00126   static octave_stream
00127   create (std::ostream *arg, const std::string& n = std::string ());
00128 
00129   // Return non-zero if EOF has been reached on this stream.
00130 
00131   bool eof (void) const;
00132 
00133   std::istream *input_stream (void) { return 0; }
00134 
00135   std::ostream *output_stream (void) { return os; }
00136 
00137 protected:
00138 
00139   ~octave_ostream (void) { }
00140 
00141 private:
00142 
00143   std::ostream *os;
00144 
00145   const char *stream_type (void) const { return "octave_ostream"; }
00146 
00147   // No copying!
00148 
00149   octave_ostream (const octave_ostream&);
00150 
00151   octave_ostream& operator = (const octave_ostream&);
00152 };
00153 
00154 #endif
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines