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