sl@0
|
1 |
/*
|
sl@0
|
2 |
* Copyright (c) 1999
|
sl@0
|
3 |
* Silicon Graphics Computer Systems, Inc.
|
sl@0
|
4 |
*
|
sl@0
|
5 |
* Copyright (c) 1999
|
sl@0
|
6 |
* Boris Fomitchev
|
sl@0
|
7 |
*
|
sl@0
|
8 |
* This material is provided "as is", with absolutely no warranty expressed
|
sl@0
|
9 |
* or implied. Any use is at your own risk.
|
sl@0
|
10 |
*
|
sl@0
|
11 |
* Permission to use or copy this software for any purpose is hereby granted
|
sl@0
|
12 |
* without fee, provided the above notices are retained on all copies.
|
sl@0
|
13 |
* Permission to modify the code and to distribute modified code is granted,
|
sl@0
|
14 |
* provided the above notices are retained, and a notice that the code was
|
sl@0
|
15 |
* modified is included with the above copyright notice.
|
sl@0
|
16 |
*
|
sl@0
|
17 |
*/
|
sl@0
|
18 |
|
sl@0
|
19 |
// This header is an extension. It defines two streambufs:
|
sl@0
|
20 |
// stdio_istreambuf, a read-only streambuf synchronized with a C stdio
|
sl@0
|
21 |
// FILE object, and stdio_ostreambuf, a write-only streambuf
|
sl@0
|
22 |
// synchronized with a C stdio FILE object. Note that neither
|
sl@0
|
23 |
// stdio_istreambuf nor stdio_ostreambuf is a template; both classes
|
sl@0
|
24 |
// are derived from basic_streambuf<char, char_traits<char> >.
|
sl@0
|
25 |
|
sl@0
|
26 |
// Note: the imbue() member function is a no-op. In particular, these
|
sl@0
|
27 |
// classes assume that codecvt<char, char, mbstate_t> is always an identity
|
sl@0
|
28 |
// transformation. This is true of the default locale, and of all locales
|
sl@0
|
29 |
// defined for the C I/O library. If you need to use a locale where
|
sl@0
|
30 |
// the codecvt<char, char, mbstate_t> facet performs a nontrivial
|
sl@0
|
31 |
// conversion, then you should use basic_filebuf<> instead of stdio_istreambuf
|
sl@0
|
32 |
// or stdio_ostreambuf. (If you don't understand what any of this means,
|
sl@0
|
33 |
// then it's not a feature you need to worry about. Locales where
|
sl@0
|
34 |
// codecvt<char, char, mbstate_t> does something nontrivial are a rare
|
sl@0
|
35 |
// corner case.)
|
sl@0
|
36 |
|
sl@0
|
37 |
|
sl@0
|
38 |
#ifndef _STLP_STDIO_STREAMBUF
|
sl@0
|
39 |
#define _STLP_STDIO_STREAMBUF
|
sl@0
|
40 |
|
sl@0
|
41 |
#include <streambuf>
|
sl@0
|
42 |
#include <cstdio> // For FILE.
|
sl@0
|
43 |
|
sl@0
|
44 |
_STLP_BEGIN_NAMESPACE
|
sl@0
|
45 |
_STLP_MOVE_TO_PRIV_NAMESPACE
|
sl@0
|
46 |
|
sl@0
|
47 |
// Base class for features common to stdio_istreambuf and stdio_ostreambuf
|
sl@0
|
48 |
class stdio_streambuf_base :
|
sl@0
|
49 |
public basic_streambuf<char, char_traits<char> > /* FILE_basic_streambuf */ {
|
sl@0
|
50 |
public: // Constructor, destructor.
|
sl@0
|
51 |
// The argument may not be null. It must be an open file pointer.
|
sl@0
|
52 |
stdio_streambuf_base(FILE*);
|
sl@0
|
53 |
|
sl@0
|
54 |
// The destructor flushes the stream, but does not close it.
|
sl@0
|
55 |
~stdio_streambuf_base();
|
sl@0
|
56 |
|
sl@0
|
57 |
protected: // Virtual functions from basic_streambuf.
|
sl@0
|
58 |
streambuf* setbuf(char*, streamsize);
|
sl@0
|
59 |
|
sl@0
|
60 |
pos_type seekoff(off_type, ios_base::seekdir,
|
sl@0
|
61 |
ios_base::openmode
|
sl@0
|
62 |
= ios_base::in | ios_base::out);
|
sl@0
|
63 |
pos_type seekpos(pos_type,
|
sl@0
|
64 |
ios_base::openmode
|
sl@0
|
65 |
= ios_base::in | ios_base::out);
|
sl@0
|
66 |
int sync();
|
sl@0
|
67 |
|
sl@0
|
68 |
protected:
|
sl@0
|
69 |
FILE* _M_file;
|
sl@0
|
70 |
};
|
sl@0
|
71 |
|
sl@0
|
72 |
class stdio_istreambuf : public stdio_streambuf_base {
|
sl@0
|
73 |
public: // Constructor, destructor.
|
sl@0
|
74 |
stdio_istreambuf(FILE* __f) : stdio_streambuf_base(__f) {}
|
sl@0
|
75 |
~stdio_istreambuf();
|
sl@0
|
76 |
|
sl@0
|
77 |
protected: // Virtual functions from basic_streambuf.
|
sl@0
|
78 |
streamsize showmanyc();
|
sl@0
|
79 |
int_type underflow();
|
sl@0
|
80 |
int_type uflow();
|
sl@0
|
81 |
virtual int_type pbackfail(int_type c = traits_type::eof());
|
sl@0
|
82 |
};
|
sl@0
|
83 |
|
sl@0
|
84 |
class stdio_ostreambuf : public stdio_streambuf_base {
|
sl@0
|
85 |
public: // Constructor, destructor.
|
sl@0
|
86 |
stdio_ostreambuf(FILE* __f) : stdio_streambuf_base(__f) {}
|
sl@0
|
87 |
~stdio_ostreambuf();
|
sl@0
|
88 |
|
sl@0
|
89 |
protected: // Virtual functions from basic_streambuf.
|
sl@0
|
90 |
streamsize showmanyc();
|
sl@0
|
91 |
int_type overflow(int_type c = traits_type::eof());
|
sl@0
|
92 |
};
|
sl@0
|
93 |
|
sl@0
|
94 |
_STLP_MOVE_TO_STD_NAMESPACE
|
sl@0
|
95 |
_STLP_END_NAMESPACE
|
sl@0
|
96 |
|
sl@0
|
97 |
#endif /* _STLP_STDIO_STREAMBUF */
|
sl@0
|
98 |
|
sl@0
|
99 |
// Local Variables:
|
sl@0
|
100 |
// mode:C++
|
sl@0
|
101 |
// End:
|