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 |
3503
|
26 #include <iostream> |
2877
|
27 |
2081
|
28 #include "oct-stream.h" |
|
29 |
|
30 class |
|
31 octave_base_iostream : public octave_base_stream |
|
32 { |
|
33 public: |
|
34 |
3523
|
35 octave_base_iostream (const std::string& n = std::string (), |
2081
|
36 ios::openmode md = ios::in|ios::out, |
2317
|
37 oct_mach_info::float_format flt_fmt = |
|
38 oct_mach_info::native) |
|
39 : octave_base_stream (md, flt_fmt), nm (n) { } |
2081
|
40 |
|
41 // Position a stream at OFFSET relative to ORIGIN. |
|
42 |
2610
|
43 int seek (streamoff offset, ios::seek_dir origin); |
2081
|
44 |
|
45 // Return current stream position. |
|
46 |
|
47 long tell (void) const; |
|
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 |
3523
|
55 std::string name (void) const { return nm; } |
2081
|
56 |
|
57 protected: |
|
58 |
3340
|
59 ~octave_base_iostream (void) { } |
|
60 |
2081
|
61 void invalid_operation (void) const; |
|
62 |
|
63 private: |
|
64 |
3523
|
65 std::string nm; |
2081
|
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 |
3523
|
81 octave_istream (std::istream *arg = 0, const std::string& nm = std::string ()) |
2317
|
82 : octave_base_iostream (nm, ios::in, oct_mach_info::native), |
2081
|
83 is (arg) { } |
|
84 |
3340
|
85 static octave_stream |
3523
|
86 create (std::istream *arg = 0, const std::string& nm = std::string ()); |
2081
|
87 |
3342
|
88 // Return non-zero if EOF has been reached on this stream. |
|
89 |
|
90 bool eof (void) const; |
|
91 |
3523
|
92 std::istream *input_stream (void) { return is; } |
2081
|
93 |
3523
|
94 std::ostream *output_stream (void) { return 0; } |
2081
|
95 |
3340
|
96 protected: |
|
97 |
|
98 ~octave_istream (void) { } |
|
99 |
2081
|
100 private: |
|
101 |
3523
|
102 std::istream *is; |
2081
|
103 |
|
104 const char *stream_type (void) const { return "octave_istream"; } |
|
105 |
|
106 // No copying! |
|
107 |
|
108 octave_istream (const octave_istream&); |
|
109 |
|
110 octave_istream& operator = (const octave_istream&); |
|
111 }; |
|
112 |
|
113 class |
|
114 octave_ostream : public octave_base_iostream |
|
115 { |
|
116 public: |
|
117 |
3523
|
118 octave_ostream (std::ostream *arg, const std::string& nm = std::string ()) |
2317
|
119 : octave_base_iostream (nm, ios::out, oct_mach_info::native), |
2081
|
120 os (arg) { } |
|
121 |
3340
|
122 static octave_stream |
3523
|
123 create (std::ostream *arg, const std::string& nm = std::string ()); |
2081
|
124 |
3342
|
125 // Return non-zero if EOF has been reached on this stream. |
|
126 |
|
127 bool eof (void) const; |
|
128 |
3523
|
129 std::istream *input_stream (void) { return 0; } |
2081
|
130 |
3523
|
131 std::ostream *output_stream (void) { return os; } |
2081
|
132 |
3340
|
133 protected: |
|
134 |
|
135 ~octave_ostream (void) { } |
|
136 |
2081
|
137 private: |
|
138 |
3523
|
139 std::ostream *os; |
2081
|
140 |
|
141 const char *stream_type (void) const { return "octave_ostream"; } |
|
142 |
|
143 // No copying! |
|
144 |
|
145 octave_ostream (const octave_ostream&); |
|
146 |
|
147 octave_ostream& operator = (const octave_ostream&); |
|
148 }; |
|
149 |
|
150 #endif |
|
151 |
|
152 /* |
|
153 ;;; Local Variables: *** |
|
154 ;;; mode: C++ *** |
|
155 ;;; End: *** |
|
156 */ |