2081
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 John W. Eaton |
2081
|
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 2, or (at your option) any |
|
10 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, write to the Free |
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
20 |
|
21 */ |
|
22 |
|
23 #if !defined (octave_octave_iostream_h) |
|
24 #define octave_octave_iostream_h 1 |
|
25 |
2877
|
26 #include <iostream.h> |
|
27 |
2081
|
28 #include "oct-stream.h" |
|
29 |
|
30 class istream; |
|
31 class ostream; |
|
32 |
|
33 class |
|
34 octave_base_iostream : public octave_base_stream |
|
35 { |
|
36 public: |
|
37 |
|
38 octave_base_iostream (const string& n = string (), |
|
39 ios::openmode md = ios::in|ios::out, |
2317
|
40 oct_mach_info::float_format flt_fmt = |
|
41 oct_mach_info::native) |
|
42 : octave_base_stream (md, flt_fmt), nm (n) { } |
2081
|
43 |
|
44 // Position a stream at OFFSET relative to ORIGIN. |
|
45 |
2610
|
46 int seek (streamoff offset, ios::seek_dir origin); |
2081
|
47 |
|
48 // Return current stream position. |
|
49 |
|
50 long tell (void) const; |
|
51 |
|
52 // Return non-zero if EOF has been reached on this stream. |
|
53 |
|
54 bool eof (void) const; |
|
55 |
|
56 // The name of the file. |
|
57 |
3340
|
58 string name (void) const { return nm; } |
2081
|
59 |
|
60 protected: |
|
61 |
3340
|
62 ~octave_base_iostream (void) { } |
|
63 |
2081
|
64 void invalid_operation (void) const; |
|
65 |
|
66 private: |
|
67 |
|
68 string nm; |
|
69 |
|
70 virtual const char *stream_type (void) const = 0; |
|
71 |
|
72 // No copying! |
|
73 |
|
74 octave_base_iostream (const octave_base_iostream&); |
|
75 |
|
76 octave_base_iostream& operator = (const octave_base_iostream&); |
|
77 }; |
|
78 |
|
79 class |
|
80 octave_istream : public octave_base_iostream |
|
81 { |
|
82 public: |
|
83 |
|
84 octave_istream (istream *arg = 0, const string& nm = string ()) |
2317
|
85 : octave_base_iostream (nm, ios::in, oct_mach_info::native), |
2081
|
86 is (arg) { } |
|
87 |
3340
|
88 static octave_stream |
|
89 create (istream *arg = 0, const string& nm = string ()); |
2081
|
90 |
3342
|
91 // Return non-zero if EOF has been reached on this stream. |
|
92 |
|
93 bool eof (void) const; |
|
94 |
2081
|
95 istream *input_stream (void) { return is; } |
|
96 |
|
97 ostream *output_stream (void) { return 0; } |
|
98 |
3340
|
99 protected: |
|
100 |
|
101 ~octave_istream (void) { } |
|
102 |
2081
|
103 private: |
|
104 |
|
105 istream *is; |
|
106 |
|
107 const char *stream_type (void) const { return "octave_istream"; } |
|
108 |
|
109 // No copying! |
|
110 |
|
111 octave_istream (const octave_istream&); |
|
112 |
|
113 octave_istream& operator = (const octave_istream&); |
|
114 }; |
|
115 |
|
116 class |
|
117 octave_ostream : public octave_base_iostream |
|
118 { |
|
119 public: |
|
120 |
|
121 octave_ostream (ostream *arg, const string& nm = string ()) |
2317
|
122 : octave_base_iostream (nm, ios::out, oct_mach_info::native), |
2081
|
123 os (arg) { } |
|
124 |
3340
|
125 static octave_stream |
|
126 create (ostream *arg, const string& nm = string ()); |
2081
|
127 |
3342
|
128 // Return non-zero if EOF has been reached on this stream. |
|
129 |
|
130 bool eof (void) const; |
|
131 |
2081
|
132 istream *input_stream (void) { return 0; } |
|
133 |
|
134 ostream *output_stream (void) { return os; } |
|
135 |
3340
|
136 protected: |
|
137 |
|
138 ~octave_ostream (void) { } |
|
139 |
2081
|
140 private: |
|
141 |
|
142 ostream *os; |
|
143 |
|
144 const char *stream_type (void) const { return "octave_ostream"; } |
|
145 |
|
146 // No copying! |
|
147 |
|
148 octave_ostream (const octave_ostream&); |
|
149 |
|
150 octave_ostream& operator = (const octave_ostream&); |
|
151 }; |
|
152 |
|
153 #endif |
|
154 |
|
155 /* |
|
156 ;;; Local Variables: *** |
|
157 ;;; mode: C++ *** |
|
158 ;;; End: *** |
|
159 */ |