2081
|
1 /* |
|
2 |
|
3 Copyright (C) 1996 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 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 |
|
26 #include "oct-stream.h" |
|
27 |
|
28 class istream; |
|
29 class ostream; |
|
30 |
|
31 class |
|
32 octave_base_iostream : public octave_base_stream |
|
33 { |
|
34 public: |
|
35 |
|
36 octave_base_iostream (const string& n = string (), |
|
37 ios::openmode md = ios::in|ios::out, |
|
38 octave_base_stream::arch_type at = native) |
|
39 : octave_base_stream (md, at), nm (n) { } |
|
40 |
|
41 ~octave_base_iostream (void) { } |
|
42 |
|
43 // Position a stream at OFFSET relative to ORIGIN. |
|
44 |
|
45 int seek (streampos offset, ios::seek_dir origin); |
|
46 |
|
47 // Return current stream position. |
|
48 |
|
49 long tell (void) const; |
|
50 |
|
51 // Return non-zero if EOF has been reached on this stream. |
|
52 |
|
53 bool eof (void) const; |
|
54 |
|
55 // The name of the file. |
|
56 |
|
57 string name (void); |
|
58 |
|
59 protected: |
|
60 |
|
61 void invalid_operation (void) const; |
|
62 |
|
63 private: |
|
64 |
|
65 string nm; |
|
66 |
|
67 virtual const char *stream_type (void) const = 0; |
|
68 |
|
69 // No copying! |
|
70 |
|
71 octave_base_iostream (const octave_base_iostream&); |
|
72 |
|
73 octave_base_iostream& operator = (const octave_base_iostream&); |
|
74 }; |
|
75 |
|
76 class |
|
77 octave_istream : public octave_base_iostream |
|
78 { |
|
79 public: |
|
80 |
|
81 octave_istream (istream *arg = 0, const string& nm = string ()) |
|
82 : octave_base_iostream (nm, ios::in, octave_base_stream::native), |
|
83 is (arg) { } |
|
84 |
|
85 ~octave_istream (void) { } |
|
86 |
|
87 istream *input_stream (void) { return is; } |
|
88 |
|
89 ostream *output_stream (void) { return 0; } |
|
90 |
|
91 private: |
|
92 |
|
93 istream *is; |
|
94 |
|
95 const char *stream_type (void) const { return "octave_istream"; } |
|
96 |
|
97 // No copying! |
|
98 |
|
99 octave_istream (const octave_istream&); |
|
100 |
|
101 octave_istream& operator = (const octave_istream&); |
|
102 }; |
|
103 |
|
104 class |
|
105 octave_ostream : public octave_base_iostream |
|
106 { |
|
107 public: |
|
108 |
|
109 octave_ostream (ostream *arg, const string& nm = string ()) |
|
110 : octave_base_iostream (nm, ios::out, octave_base_stream::native), |
|
111 os (arg) { } |
|
112 |
|
113 ~octave_ostream (void) { } |
|
114 |
|
115 istream *input_stream (void) { return 0; } |
|
116 |
|
117 ostream *output_stream (void) { return os; } |
|
118 |
|
119 private: |
|
120 |
|
121 ostream *os; |
|
122 |
|
123 const char *stream_type (void) const { return "octave_ostream"; } |
|
124 |
|
125 // No copying! |
|
126 |
|
127 octave_ostream (const octave_ostream&); |
|
128 |
|
129 octave_ostream& operator = (const octave_ostream&); |
|
130 }; |
|
131 |
|
132 #endif |
|
133 |
|
134 /* |
|
135 ;;; Local Variables: *** |
|
136 ;;; mode: C++ *** |
|
137 ;;; End: *** |
|
138 */ |