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> |
|
31 #include <stdio.h> |
|
32 |
|
33 class |
|
34 c_file_ptr_buf : public std::streambuf |
|
35 { |
|
36 public: |
|
37 |
|
38 FILE* stdiofile (void) const { return f; } |
|
39 |
|
40 c_file_ptr_buf (FILE *f_arg) : std::streambuf (), f (f_arg) { } |
|
41 |
|
42 ~c_file_ptr_buf (void); |
|
43 |
|
44 int overflow (int); |
|
45 |
|
46 int underflow (void); |
|
47 |
|
48 int uflow (void); |
|
49 |
|
50 int pbackfail (int); |
|
51 |
|
52 std::streamsize xsputn (const char*, std::streamsize); |
|
53 |
|
54 std::streamsize xsgetn (char *, std::streamsize); |
|
55 |
|
56 std::streampos seekoff (std::streamoff, std::ios::seekdir, |
|
57 std::ios::openmode = std::ios::in | std::ios::out); |
|
58 |
|
59 std::streampos seekpos (std::streampos, |
|
60 std::ios::openmode = std::ios::in | std::ios::out); |
|
61 |
|
62 int sync (void); |
3644
|
63 |
|
64 protected: |
|
65 |
|
66 FILE *f; |
3628
|
67 }; |
|
68 |
|
69 class |
|
70 i_c_file_ptr_stream : public std::istream |
|
71 { |
3644
|
72 public: |
|
73 |
|
74 i_c_file_ptr_stream (FILE* f) |
|
75 : std::istream (), buf (new c_file_ptr_buf (f)) { init (buf); } |
|
76 |
|
77 ~i_c_file_ptr_stream (void) { delete buf; buf = 0; } |
|
78 |
|
79 c_file_ptr_buf *rdbuf (void) { return buf; } |
|
80 |
3628
|
81 private: |
|
82 |
3644
|
83 c_file_ptr_buf *buf; |
3628
|
84 }; |
|
85 |
|
86 class |
|
87 o_c_file_ptr_stream : public std::ostream |
|
88 { |
3644
|
89 public: |
|
90 |
|
91 o_c_file_ptr_stream (FILE* f) |
|
92 : std::ostream (), buf (new c_file_ptr_buf (f)) { init (buf); } |
|
93 |
|
94 ~o_c_file_ptr_stream (void) { delete buf; buf = 0; } |
|
95 |
|
96 c_file_ptr_buf *rdbuf (void) { return buf; } |
|
97 |
3628
|
98 private: |
|
99 |
3644
|
100 c_file_ptr_buf *buf; |
3628
|
101 }; |
|
102 |
|
103 #endif |
|
104 |
|
105 /* |
|
106 ;;; Local Variables: *** |
|
107 ;;; mode: C++ *** |
|
108 ;;; End: *** |
|
109 */ |
|
110 |