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