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 |
5307
|
19 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
20 02110-1301, USA. |
2081
|
21 |
|
22 */ |
|
23 |
|
24 #if !defined (octave_octave_iostream_h) |
|
25 #define octave_octave_iostream_h 1 |
|
26 |
3503
|
27 #include <iostream> |
2877
|
28 |
2081
|
29 #include "oct-stream.h" |
|
30 |
|
31 class |
|
32 octave_base_iostream : public octave_base_stream |
|
33 { |
|
34 public: |
|
35 |
3523
|
36 octave_base_iostream (const std::string& n = std::string (), |
4587
|
37 std::ios::openmode m = std::ios::in|std::ios::out, |
5015
|
38 oct_mach_info::float_format ff |
|
39 = oct_mach_info::native_float_format ()) |
4587
|
40 : octave_base_stream (m, ff), nm (n) { } |
2081
|
41 |
|
42 // Position a stream at OFFSET relative to ORIGIN. |
|
43 |
4797
|
44 int seek (long offset, int origin); |
2081
|
45 |
|
46 // Return current stream position. |
|
47 |
4797
|
48 long tell (void); |
2081
|
49 |
|
50 // Return non-zero if EOF has been reached on this stream. |
|
51 |
|
52 bool eof (void) const; |
|
53 |
|
54 // The name of the file. |
|
55 |
3523
|
56 std::string name (void) const { return nm; } |
2081
|
57 |
|
58 protected: |
|
59 |
3340
|
60 ~octave_base_iostream (void) { } |
|
61 |
2081
|
62 void invalid_operation (void) const; |
|
63 |
|
64 private: |
|
65 |
3523
|
66 std::string nm; |
2081
|
67 |
|
68 virtual const char *stream_type (void) const = 0; |
|
69 |
|
70 // No copying! |
|
71 |
|
72 octave_base_iostream (const octave_base_iostream&); |
|
73 |
|
74 octave_base_iostream& operator = (const octave_base_iostream&); |
|
75 }; |
|
76 |
|
77 class |
|
78 octave_istream : public octave_base_iostream |
|
79 { |
|
80 public: |
|
81 |
4587
|
82 octave_istream (std::istream *arg = 0, const std::string& n = std::string ()) |
5015
|
83 : octave_base_iostream (n, std::ios::in, |
|
84 oct_mach_info::native_float_format ()), |
|
85 is (arg) |
|
86 { } |
2081
|
87 |
3340
|
88 static octave_stream |
4587
|
89 create (std::istream *arg = 0, const std::string& n = std::string ()); |
2081
|
90 |
3342
|
91 // Return non-zero if EOF has been reached on this stream. |
|
92 |
|
93 bool eof (void) const; |
|
94 |
3523
|
95 std::istream *input_stream (void) { return is; } |
2081
|
96 |
3523
|
97 std::ostream *output_stream (void) { return 0; } |
2081
|
98 |
3340
|
99 protected: |
|
100 |
|
101 ~octave_istream (void) { } |
|
102 |
2081
|
103 private: |
|
104 |
3523
|
105 std::istream *is; |
2081
|
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 |
4587
|
121 octave_ostream (std::ostream *arg, const std::string& n = std::string ()) |
5015
|
122 : octave_base_iostream (n, std::ios::out, |
|
123 oct_mach_info::native_float_format ()), |
|
124 os (arg) |
|
125 { } |
2081
|
126 |
3340
|
127 static octave_stream |
4587
|
128 create (std::ostream *arg, const std::string& n = std::string ()); |
2081
|
129 |
3342
|
130 // Return non-zero if EOF has been reached on this stream. |
|
131 |
|
132 bool eof (void) const; |
|
133 |
3523
|
134 std::istream *input_stream (void) { return 0; } |
2081
|
135 |
3523
|
136 std::ostream *output_stream (void) { return os; } |
2081
|
137 |
3340
|
138 protected: |
|
139 |
|
140 ~octave_ostream (void) { } |
|
141 |
2081
|
142 private: |
|
143 |
3523
|
144 std::ostream *os; |
2081
|
145 |
|
146 const char *stream_type (void) const { return "octave_ostream"; } |
|
147 |
|
148 // No copying! |
|
149 |
|
150 octave_ostream (const octave_ostream&); |
|
151 |
|
152 octave_ostream& operator = (const octave_ostream&); |
|
153 }; |
|
154 |
|
155 #endif |
|
156 |
|
157 /* |
|
158 ;;; Local Variables: *** |
|
159 ;;; mode: C++ *** |
|
160 ;;; End: *** |
|
161 */ |