3628
|
1 /* |
|
2 |
|
3 Copyright (C) 2000 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_c_file_ptr_stream_h) |
|
24 #define octave_c_file_ptr_stream_h 1 |
|
25 |
4192
|
26 #if defined (__GNUG__) && defined (USE_PRAGMA_INTERFACE_IMPLEMENTATION) |
3628
|
27 #pragma interface |
|
28 #endif |
|
29 |
|
30 #include <iostream> |
3775
|
31 #include <cstdio> |
3628
|
32 |
|
33 class |
4310
|
34 c_file_ptr_buf : public std::streambuf |
3628
|
35 { |
|
36 public: |
|
37 |
3775
|
38 #if !defined (CXX_ISO_COMPLIANT_LIBRARY) |
|
39 typedef int int_type; |
3944
|
40 #else |
4310
|
41 typedef std::streambuf::int_type int_type; |
3775
|
42 #endif |
|
43 |
3716
|
44 typedef int (*close_fcn) (FILE *); |
|
45 |
3628
|
46 FILE* stdiofile (void) const { return f; } |
|
47 |
3951
|
48 c_file_ptr_buf (FILE *f_arg, close_fcn cf_arg = fclose) |
4310
|
49 : std::streambuf (), f (f_arg), cf (cf_arg) |
3775
|
50 { } |
3628
|
51 |
|
52 ~c_file_ptr_buf (void); |
|
53 |
3775
|
54 int_type overflow (int_type); |
3628
|
55 |
4310
|
56 int_type underflow (void) { return underflow_common (false); } |
3628
|
57 |
4310
|
58 int_type uflow (void) { return underflow_common (true); } |
3628
|
59 |
3775
|
60 int_type pbackfail (int_type); |
3628
|
61 |
|
62 std::streamsize xsputn (const char*, std::streamsize); |
|
63 |
|
64 std::streamsize xsgetn (char *, std::streamsize); |
|
65 |
|
66 std::streampos seekoff (std::streamoff, std::ios::seekdir, |
|
67 std::ios::openmode = std::ios::in | std::ios::out); |
|
68 |
|
69 std::streampos seekpos (std::streampos, |
|
70 std::ios::openmode = std::ios::in | std::ios::out); |
|
71 |
|
72 int sync (void); |
3644
|
73 |
3652
|
74 int flush (void); |
|
75 |
|
76 int close (void); |
|
77 |
4310
|
78 int file_number () const { return f ? fileno (f) : -1; } |
3775
|
79 |
3951
|
80 static int fclose (FILE *f) { return ::fclose (f); } |
|
81 |
3644
|
82 protected: |
|
83 |
|
84 FILE *f; |
3716
|
85 |
|
86 close_fcn cf; |
3775
|
87 |
|
88 private: |
|
89 |
4310
|
90 int_type underflow_common (bool); |
3628
|
91 }; |
|
92 |
|
93 class |
|
94 i_c_file_ptr_stream : public std::istream |
|
95 { |
3644
|
96 public: |
|
97 |
3951
|
98 i_c_file_ptr_stream (FILE* f, |
|
99 c_file_ptr_buf::close_fcn cf = c_file_ptr_buf::fclose) |
3775
|
100 : std::istream (0), buf (new c_file_ptr_buf (f, cf)) { init (buf); } |
3644
|
101 |
|
102 ~i_c_file_ptr_stream (void) { delete buf; buf = 0; } |
|
103 |
|
104 c_file_ptr_buf *rdbuf (void) { return buf; } |
|
105 |
4326
|
106 void close (void) { if (buf) buf->close (); } |
3652
|
107 |
3628
|
108 private: |
|
109 |
3644
|
110 c_file_ptr_buf *buf; |
3628
|
111 }; |
|
112 |
|
113 class |
|
114 o_c_file_ptr_stream : public std::ostream |
|
115 { |
3644
|
116 public: |
|
117 |
3951
|
118 o_c_file_ptr_stream (FILE* f, |
|
119 c_file_ptr_buf::close_fcn cf = c_file_ptr_buf::fclose) |
3775
|
120 : std::ostream (0), buf (new c_file_ptr_buf (f, cf)) { init (buf); } |
3644
|
121 |
|
122 ~o_c_file_ptr_stream (void) { delete buf; buf = 0; } |
|
123 |
|
124 c_file_ptr_buf *rdbuf (void) { return buf; } |
|
125 |
4326
|
126 void close (void) { if (buf) buf->close (); } |
|
127 |
|
128 private: |
|
129 |
|
130 c_file_ptr_buf *buf; |
|
131 }; |
|
132 |
|
133 class |
|
134 io_c_file_ptr_stream : public std::iostream |
|
135 { |
|
136 public: |
|
137 |
|
138 io_c_file_ptr_stream (FILE* f, |
|
139 c_file_ptr_buf::close_fcn cf = c_file_ptr_buf::fclose) |
|
140 : std::iostream (0), buf (new c_file_ptr_buf (f, cf)) { init (buf); } |
|
141 |
|
142 ~io_c_file_ptr_stream (void) { delete buf; buf = 0; } |
|
143 |
|
144 c_file_ptr_buf *rdbuf (void) { return buf; } |
|
145 |
|
146 void close (void) { if (buf) buf->close (); } |
3652
|
147 |
3628
|
148 private: |
|
149 |
3644
|
150 c_file_ptr_buf *buf; |
3628
|
151 }; |
|
152 |
|
153 #endif |
|
154 |
|
155 /* |
|
156 ;;; Local Variables: *** |
|
157 ;;; mode: C++ *** |
|
158 ;;; End: *** |
|
159 */ |
|
160 |