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 |
7016
|
9 Free Software Foundation; either version 3 of the License, or (at your |
|
10 option) any later version. |
2081
|
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 |
7016
|
18 along with Octave; see the file COPYING. If not, see |
|
19 <http://www.gnu.org/licenses/>. |
2081
|
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 (), |
4587
|
36 std::ios::openmode m = std::ios::in|std::ios::out, |
5015
|
37 oct_mach_info::float_format ff |
|
38 = oct_mach_info::native_float_format ()) |
4587
|
39 : octave_base_stream (m, ff), nm (n) { } |
2081
|
40 |
|
41 // Position a stream at OFFSET relative to ORIGIN. |
|
42 |
4797
|
43 int seek (long offset, int origin); |
2081
|
44 |
|
45 // Return current stream position. |
|
46 |
4797
|
47 long tell (void); |
2081
|
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 |
4587
|
81 octave_istream (std::istream *arg = 0, const std::string& n = std::string ()) |
5015
|
82 : octave_base_iostream (n, std::ios::in, |
|
83 oct_mach_info::native_float_format ()), |
|
84 is (arg) |
|
85 { } |
2081
|
86 |
3340
|
87 static octave_stream |
4587
|
88 create (std::istream *arg = 0, const std::string& n = std::string ()); |
2081
|
89 |
3342
|
90 // Return non-zero if EOF has been reached on this stream. |
|
91 |
|
92 bool eof (void) const; |
|
93 |
3523
|
94 std::istream *input_stream (void) { return is; } |
2081
|
95 |
3523
|
96 std::ostream *output_stream (void) { return 0; } |
2081
|
97 |
3340
|
98 protected: |
|
99 |
|
100 ~octave_istream (void) { } |
|
101 |
2081
|
102 private: |
|
103 |
3523
|
104 std::istream *is; |
2081
|
105 |
|
106 const char *stream_type (void) const { return "octave_istream"; } |
|
107 |
|
108 // No copying! |
|
109 |
|
110 octave_istream (const octave_istream&); |
|
111 |
|
112 octave_istream& operator = (const octave_istream&); |
|
113 }; |
|
114 |
|
115 class |
|
116 octave_ostream : public octave_base_iostream |
|
117 { |
|
118 public: |
|
119 |
4587
|
120 octave_ostream (std::ostream *arg, const std::string& n = std::string ()) |
5015
|
121 : octave_base_iostream (n, std::ios::out, |
|
122 oct_mach_info::native_float_format ()), |
|
123 os (arg) |
|
124 { } |
2081
|
125 |
3340
|
126 static octave_stream |
4587
|
127 create (std::ostream *arg, const std::string& n = std::string ()); |
2081
|
128 |
3342
|
129 // Return non-zero if EOF has been reached on this stream. |
|
130 |
|
131 bool eof (void) const; |
|
132 |
3523
|
133 std::istream *input_stream (void) { return 0; } |
2081
|
134 |
3523
|
135 std::ostream *output_stream (void) { return os; } |
2081
|
136 |
3340
|
137 protected: |
|
138 |
|
139 ~octave_ostream (void) { } |
|
140 |
2081
|
141 private: |
|
142 |
3523
|
143 std::ostream *os; |
2081
|
144 |
|
145 const char *stream_type (void) const { return "octave_ostream"; } |
|
146 |
|
147 // No copying! |
|
148 |
|
149 octave_ostream (const octave_ostream&); |
|
150 |
|
151 octave_ostream& operator = (const octave_ostream&); |
|
152 }; |
|
153 |
|
154 #endif |
|
155 |
|
156 /* |
|
157 ;;; Local Variables: *** |
|
158 ;;; mode: C++ *** |
|
159 ;;; End: *** |
|
160 */ |