Mercurial > hg > octave-nkf
comparison src/oct-stdstrm.h @ 2081:e9ec222a53e1
[project @ 1996-04-25 03:17:36 by jwe]
Initial revision
author | jwe |
---|---|
date | Thu, 25 Apr 1996 03:17:36 +0000 |
parents | |
children | a64f53e6fc73 |
comparison
equal
deleted
inserted
replaced
2080:452f63bfa60c | 2081:e9ec222a53e1 |
---|---|
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_stdiostream_h) | |
24 #define octave_octave_stdiostream_h 1 | |
25 | |
26 #include <stdiostream.h> | |
27 | |
28 #include "oct-stream.h" | |
29 | |
30 class | |
31 octave_base_stdiostream : public octave_base_stream | |
32 { | |
33 public: | |
34 | |
35 octave_base_stdiostream (const string& n, FILE *f, | |
36 ios::openmode arg_md = ios::in|ios::out, | |
37 arch_type arg_at = native) | |
38 : octave_base_stream (arg_md, arg_at), nm (n), fp (f) { } | |
39 | |
40 ~octave_base_stdiostream (void); | |
41 | |
42 // Position a stream at OFFSET relative to ORIGIN. | |
43 | |
44 int seek (streampos offset, ios::seek_dir origin); | |
45 | |
46 // Return current stream position. | |
47 | |
48 long tell (void) const; | |
49 | |
50 // The name of the file. | |
51 | |
52 string name (void) { return nm; } | |
53 | |
54 virtual stdiobuf *rdbuf (void) const = 0; | |
55 | |
56 virtual bool bad (void) const = 0; | |
57 | |
58 virtual void clear (void) = 0; | |
59 | |
60 protected: | |
61 | |
62 string nm; | |
63 | |
64 FILE *fp; | |
65 | |
66 // No copying! | |
67 | |
68 octave_base_stdiostream (const octave_base_stdiostream&); | |
69 | |
70 octave_base_stdiostream& operator = (const octave_base_stdiostream&); | |
71 }; | |
72 | |
73 class | |
74 octave_istdiostream : public octave_base_stdiostream | |
75 { | |
76 public: | |
77 | |
78 octave_istdiostream (const string& n, FILE *f = 0, | |
79 ios::openmode arg_md = ios::in, | |
80 arch_type arg_at = native); | |
81 | |
82 ~octave_istdiostream (void); | |
83 | |
84 // Return non-zero if EOF has been reached on this stream. | |
85 | |
86 bool eof (void) const { return is ? is->eof () : true; } | |
87 | |
88 istream *input_stream (void) { return is; } | |
89 | |
90 ostream *output_stream (void) { return 0; } | |
91 | |
92 // XXX FIXME XXX -- should not have to cast away const here. | |
93 stdiobuf *rdbuf (void) const | |
94 { return is ? ((istdiostream *) is)->rdbuf () : 0; } | |
95 | |
96 bool bad (void) const { return is ? is->bad () : true; } | |
97 | |
98 void clear (void) | |
99 { | |
100 if (is) | |
101 is->clear (); | |
102 } | |
103 | |
104 protected: | |
105 | |
106 istdiostream *is; | |
107 | |
108 private: | |
109 | |
110 // No copying! | |
111 | |
112 octave_istdiostream (const octave_istdiostream&); | |
113 | |
114 octave_istdiostream& operator = (const octave_istdiostream&); | |
115 }; | |
116 | |
117 class | |
118 octave_ostdiostream : public octave_base_stdiostream | |
119 { | |
120 public: | |
121 | |
122 octave_ostdiostream (const string& n, FILE *f = 0, | |
123 ios::openmode arg_md = ios::out, | |
124 arch_type arg_at = native); | |
125 | |
126 ~octave_ostdiostream (void); | |
127 | |
128 // Return non-zero if EOF has been reached on this stream. | |
129 | |
130 bool eof (void) const { return os ? os->eof () : true; } | |
131 | |
132 istream *input_stream (void) { return 0; } | |
133 | |
134 ostream *output_stream (void) { return os; } | |
135 | |
136 // XXX FIXME XXX -- should not have to cast away const here. | |
137 stdiobuf *rdbuf (void) const | |
138 { return os ? ((ostdiostream *) os)->rdbuf () : 0; } | |
139 | |
140 bool bad (void) const { return os ? os->bad () : true; } | |
141 | |
142 void clear (void) | |
143 { | |
144 if (os) | |
145 os->clear (); | |
146 } | |
147 | |
148 protected: | |
149 | |
150 ostdiostream *os; | |
151 | |
152 private: | |
153 | |
154 // No copying! | |
155 | |
156 octave_ostdiostream (const octave_ostdiostream&); | |
157 | |
158 octave_ostdiostream& operator = (const octave_ostdiostream&); | |
159 }; | |
160 | |
161 #endif | |
162 | |
163 /* | |
164 ;;; Local Variables: *** | |
165 ;;; mode: C++ *** | |
166 ;;; End: *** | |
167 */ |