/home/ntakagi/work/STLport-5.1.5/src/stdio_streambuf.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 1999
00003  * Silicon Graphics Computer Systems, Inc.
00004  *
00005  * Copyright (c) 1999
00006  * Boris Fomitchev
00007  *
00008  * This material is provided "as is", with absolutely no warranty expressed
00009  * or implied. Any use is at your own risk.
00010  *
00011  * Permission to use or copy this software for any purpose is hereby granted
00012  * without fee, provided the above notices are retained on all copies.
00013  * Permission to modify the code and to distribute modified code is granted,
00014  * provided the above notices are retained, and a notice that the code was
00015  * modified is included with the above copyright notice.
00016  *
00017  */
00018 
00019 // This header is an extension.  It defines two streambufs:
00020 // stdio_istreambuf, a read-only streambuf synchronized with a C stdio
00021 // FILE object, and stdio_ostreambuf, a write-only streambuf
00022 // synchronized with a C stdio FILE object.  Note that neither
00023 // stdio_istreambuf nor stdio_ostreambuf is a template; both classes
00024 // are derived from basic_streambuf<char, char_traits<char> >.
00025 
00026 // Note: the imbue() member function is a no-op.  In particular, these
00027 // classes assume that codecvt<char, char, mbstate_t> is always an identity
00028 // transformation.  This is true of the default locale, and of all locales
00029 // defined for the C I/O library.  If you need to use a locale where
00030 // the codecvt<char, char, mbstate_t> facet performs a nontrivial
00031 // conversion, then you should use basic_filebuf<> instead of stdio_istreambuf
00032 // or stdio_ostreambuf.  (If you don't understand what any of this means,
00033 // then it's not a feature you need to worry about.  Locales where
00034 // codecvt<char, char, mbstate_t> does something nontrivial are a rare
00035 // corner case.)
00036 
00037 
00038 #ifndef _STLP_STDIO_STREAMBUF
00039 #define _STLP_STDIO_STREAMBUF
00040 
00041 #include <streambuf>
00042 #include <cstdio>              // For FILE.
00043 
00044 _STLP_BEGIN_NAMESPACE
00045 _STLP_MOVE_TO_PRIV_NAMESPACE
00046 
00047 // Base class for features common to stdio_istreambuf and stdio_ostreambuf
00048 class stdio_streambuf_base :
00049   public basic_streambuf<char, char_traits<char> > /* FILE_basic_streambuf */ {
00050 public:                         // Constructor, destructor.
00051   // The argument may not be null.  It must be an open file pointer.
00052   stdio_streambuf_base(FILE*);
00053 
00054   // The destructor flushes the stream, but does not close it.
00055   ~stdio_streambuf_base();
00056 
00057 protected:                      // Virtual functions from basic_streambuf.
00058   streambuf* setbuf(char*, streamsize);
00059 
00060   pos_type seekoff(off_type, ios_base::seekdir,
00061                    ios_base::openmode
00062                           = ios_base::in | ios_base::out);
00063   pos_type seekpos(pos_type,
00064                    ios_base::openmode
00065                           = ios_base::in | ios_base::out);
00066   int sync();
00067 
00068 protected:
00069   FILE* _M_file;
00070 };
00071 
00072 class stdio_istreambuf : public stdio_streambuf_base {
00073 public:                         // Constructor, destructor.
00074   stdio_istreambuf(FILE* __f) : stdio_streambuf_base(__f) {}
00075   ~stdio_istreambuf();
00076 
00077 protected:                      // Virtual functions from basic_streambuf.
00078   streamsize showmanyc();
00079   int_type underflow();
00080   int_type uflow();
00081   virtual int_type pbackfail(int_type c = traits_type::eof());
00082 };
00083 
00084 class stdio_ostreambuf : public stdio_streambuf_base {
00085 public:                         // Constructor, destructor.
00086   stdio_ostreambuf(FILE* __f) : stdio_streambuf_base(__f) {}
00087   ~stdio_ostreambuf();
00088 
00089 protected:                      // Virtual functions from basic_streambuf.
00090   streamsize showmanyc();
00091   int_type overflow(int_type c = traits_type::eof());
00092 };
00093 
00094 _STLP_MOVE_TO_STD_NAMESPACE
00095 _STLP_END_NAMESPACE
00096 
00097 #endif /* _STLP_STDIO_STREAMBUF */
00098 
00099 // Local Variables:
00100 // mode:C++
00101 // End:



Generated on Mon Mar 10 15:32:17 2008 by  doxygen 1.5.1