Mercurial > hg > octave-lyh
annotate src/oct-stdstrm.h @ 10313:f3b65e1ae355
untabify src header files
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 11 Feb 2010 12:16:43 -0500 |
parents | 5e972e2deffe |
children | 594adb99a25e |
rev | line source |
---|---|
2081 | 1 /* |
2 | |
7017 | 3 Copyright (C) 1996, 1997, 1999, 2000, 2001, 2002, 2003, 2004, 2005, |
4 2006, 2007 John W. Eaton | |
2081 | 5 |
6 This file is part of Octave. | |
7 | |
8 Octave is free software; you can redistribute it and/or modify it | |
9 under the terms of the GNU General Public License as published by the | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
2081 | 12 |
13 Octave is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
2081 | 21 |
22 */ | |
23 | |
24 #if !defined (octave_octave_stdiostream_h) | |
25 #define octave_octave_stdiostream_h 1 | |
26 | |
27 #include "oct-stream.h" | |
3630 | 28 #include "c-file-ptr-stream.h" |
2081 | 29 |
5325 | 30 template <typename BUF_T, typename STREAM_T, typename FILE_T> |
2081 | 31 class |
5325 | 32 octave_tstdiostream : public octave_base_stream |
2081 | 33 { |
34 public: | |
35 | |
5325 | 36 octave_tstdiostream (const std::string& n, FILE_T f = 0, |
10313 | 37 std::ios::openmode m = std::ios::in|std::ios::out, |
38 oct_mach_info::float_format ff | |
39 = oct_mach_info::native_float_format (), | |
40 typename BUF_T::close_fcn cf = BUF_T::file_close) | |
5325 | 41 : octave_base_stream (m, ff), nm (n), md (m), |
5370 | 42 s (f ? new STREAM_T (f, cf) : 0) |
5325 | 43 { } |
4327 | 44 |
45 static octave_stream | |
5325 | 46 create (const std::string& n, FILE_T f = 0, |
10313 | 47 std::ios::openmode m = std::ios::in|std::ios::out, |
48 oct_mach_info::float_format ff | |
49 = oct_mach_info::native_float_format (), | |
50 typename BUF_T::close_fcn cf = BUF_T::file_close) | |
4327 | 51 { |
5325 | 52 return octave_stream (new octave_tstdiostream (n, f, m, ff, cf)); |
4327 | 53 } |
2081 | 54 |
55 // Position a stream at OFFSET relative to ORIGIN. | |
56 | |
5325 | 57 int seek (long offset, int origin) |
58 { return s ? s->seek (offset, origin) : -1; } | |
2081 | 59 |
60 // Return current stream position. | |
61 | |
5325 | 62 long tell (void) { return s ? s->tell () : -1; } |
2081 | 63 |
4327 | 64 // Return non-zero if EOF has been reached on this stream. |
65 | |
66 bool eof (void) const { return s ? s->eof () : true; } | |
67 | |
2081 | 68 // The name of the file. |
69 | |
3523 | 70 std::string name (void) const { return nm; } |
2081 | 71 |
4327 | 72 std::istream *input_stream (void) { return (md & std::ios::in) ? s : 0; } |
2081 | 73 |
4361 | 74 std::ostream *output_stream (void) { return (md & std::ios::out) ? s : 0; } |
4326 | 75 |
5775 | 76 // FIXME -- should not have to cast away const here. |
5325 | 77 BUF_T *rdbuf (void) const |
78 { return s ? (const_cast<STREAM_T *> (s))->rdbuf () : 0; } | |
4326 | 79 |
80 bool bad (void) const { return s ? s->bad () : true; } | |
81 | |
4327 | 82 void clear (void) { if (s) s->clear (); } |
4326 | 83 |
10288
5e972e2deffe
avoid some possible gnulib #defines
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
84 void do_close (void) { if (s) s->stream_close (); } |
4326 | 85 |
86 protected: | |
87 | |
4327 | 88 std::string nm; |
89 | |
90 std::ios::openmode md; | |
91 | |
5325 | 92 STREAM_T *s; |
4326 | 93 |
5325 | 94 ~octave_tstdiostream (void) { delete s; } |
4326 | 95 |
96 private: | |
97 | |
98 // No copying! | |
99 | |
5325 | 100 octave_tstdiostream (const octave_tstdiostream&); |
101 | |
102 octave_tstdiostream& operator = (const octave_tstdiostream&); | |
103 }; | |
4326 | 104 |
5325 | 105 typedef octave_tstdiostream<c_file_ptr_buf, io_c_file_ptr_stream, FILE *> octave_stdiostream; |
106 | |
107 #ifdef HAVE_ZLIB | |
108 | |
109 typedef octave_tstdiostream<c_zfile_ptr_buf, io_c_zfile_ptr_stream, gzFile> octave_zstdiostream; | |
110 | |
111 #endif | |
4326 | 112 |
2081 | 113 #endif |