GNU Octave  3.8.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
oct-iostrm.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1996-2013 John W. Eaton
4 
5 This file is part of Octave.
6 
7 Octave is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with Octave; see the file COPYING. If not, see
19 <http://www.gnu.org/licenses/>.
20 
21 */
22 
23 #if !defined (octave_oct_iostrm_h)
24 #define octave_oct_iostrm_h 1
25 
26 #include <iosfwd>
27 
28 #include "oct-stream.h"
29 
30 class
32 {
33 public:
34 
35  octave_base_iostream (const std::string& n = std::string (),
36  std::ios::openmode m = std::ios::in|std::ios::out,
39  : octave_base_stream (m, ff), nm (n) { }
40 
41  // Position a stream at OFFSET relative to ORIGIN.
42 
43  int seek (off_t offset, int origin);
44 
45  // Return current stream position.
46 
47  off_t tell (void);
48 
49  // Return non-zero if EOF has been reached on this stream.
50 
51  bool eof (void) const;
52 
53  // The name of the file.
54 
55  std::string name (void) const { return nm; }
56 
57 protected:
58 
60 
61  void invalid_operation (void) const;
62 
63 private:
64 
65  std::string nm;
66 
67  virtual const char *stream_type (void) const = 0;
68 
69  // No copying!
70 
72 
73  octave_base_iostream& operator = (const octave_base_iostream&);
74 };
75 
76 class
78 {
79 public:
80 
81  octave_istream (std::istream *arg = 0, const std::string& n = std::string ())
82  : octave_base_iostream (n, std::ios::in,
83  oct_mach_info::native_float_format ()),
84  is (arg)
85  { }
86 
87  static octave_stream
88  create (std::istream *arg = 0, const std::string& n = std::string ());
89 
90  // Return non-zero if EOF has been reached on this stream.
91 
92  bool eof (void) const;
93 
94  std::istream *input_stream (void) { return is; }
95 
96  std::ostream *output_stream (void) { return 0; }
97 
98 protected:
99 
100  ~octave_istream (void) { }
101 
102 private:
103 
104  std::istream *is;
105 
106  const char *stream_type (void) const { return "octave_istream"; }
107 
108  // No copying!
109 
111 
112  octave_istream& operator = (const octave_istream&);
113 };
114 
115 class
117 {
118 public:
119 
120  octave_ostream (std::ostream *arg, const std::string& n = std::string ())
121  : octave_base_iostream (n, std::ios::out,
122  oct_mach_info::native_float_format ()),
123  os (arg)
124  { }
125 
126  static octave_stream
127  create (std::ostream *arg, const std::string& n = std::string ());
128 
129  // Return non-zero if EOF has been reached on this stream.
130 
131  bool eof (void) const;
132 
133  std::istream *input_stream (void) { return 0; }
134 
135  std::ostream *output_stream (void) { return os; }
136 
137 protected:
138 
139  ~octave_ostream (void) { }
140 
141 private:
142 
143  std::ostream *os;
144 
145  const char *stream_type (void) const { return "octave_ostream"; }
146 
147  // No copying!
148 
150 
151  octave_ostream& operator = (const octave_ostream&);
152 };
153 
154 #endif