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