epoc32/include/stdapis/stlport/stdio_streambuf
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:27:01 +0100
branchSymbian2
changeset 3 e1b950c65cb4
parent 0 061f57f2323e
permissions -rw-r--r--
Attempt to represent the S^2->S^3 header reorganisation as a series of "hg rename" operations
     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 // This header is an extension.  It defines two streambufs:
    19 // stdio_istreambuf, a read-only streambuf synchronized with a C stdio
    20 // FILE object, and stdio_ostreambuf, a write-only streambuf
    21 // synchronized with a C stdio FILE object.  Note that neither 
    22 // stdio_istreambuf nor stdio_ostreambuf is a template; both classes
    23 // are derived from basic_streambuf<char, char_traits<char> >.
    24 
    25 // Note: the imbue() member function is a no-op.  In particular, these
    26 // classes assume that codecvt<char, char, mbstate_t> is always an identity
    27 // transformation.  This is true of the default locale, and of all locales
    28 // defined for the C I/O library.  If you need to use a locale where 
    29 // the codecvt<char, char, mbstate_t> facet performs a nontrivial 
    30 // conversion, then you should use basic_filebuf<> instead of stdio_istreambuf
    31 // or stdio_ostreambuf.  (If you don't understand what any of this means, 
    32 // then it's not a feature you need to worry about.  Locales where 
    33 // codecvt<char, char, mbstate_t> does something nontrivial are a rare
    34 // corner case.)
    35 
    36 
    37 #ifndef _STLP_STDIO_STREAMBUF
    38 #define _STLP_STDIO_STREAMBUF
    39 
    40 #if !defined(STLP_WINCE)
    41 
    42 #include <streambuf>            // For basic_streambuf<>
    43 #include <cstdio>              // For FILE.
    44 
    45 # ifndef _STLP_HAS_NO_NAMESPACES
    46 // This is an extension.  It is in namespace SGI, not namespace std
    47 namespace _SgI {
    48 
    49 # ifdef _STLP_USE_NAMESPACES
    50 using namespace _STLP_STD;
    51   // MSVC needs this
    52 using _STLP_STD::streamsize;
    53 using _STLP_STD::streambuf;
    54 using _STLP_STD::basic_streambuf;
    55 using _STLP_STD::ios_base;
    56   // using _STLP_STD::ios_base::openmode;
    57 # endif
    58 # endif
    59 
    60 // Base class for features common to stdio_istreambuf and stdio_ostreambuf
    61 class stdio_streambuf_base : public basic_streambuf<char, _STLP_STD::char_traits<char> >
    62 {
    63 public:                         // Constructor, destructor.
    64   // The argument may not be null.  It must be an open file pointer.
    65   stdio_streambuf_base(FILE*);
    66 
    67   // The destructor flushes the stream, but does not close it.
    68   ~stdio_streambuf_base();
    69 
    70 protected:                      // Virtual functions from basic_streambuf.
    71   streambuf* setbuf(char*, streamsize);
    72 
    73   pos_type seekoff(off_type, ios_base::seekdir,
    74                    ios_base::openmode
    75                           = ios_base::in | ios_base::out);
    76   pos_type seekpos(pos_type,
    77                    ios_base::openmode
    78                           = ios_base::in | ios_base::out);
    79   int sync();
    80 
    81 protected:
    82   FILE* _M_file;
    83 };
    84 
    85 class stdio_istreambuf : public stdio_streambuf_base
    86 {
    87 public:                         // Constructor, destructor.
    88   stdio_istreambuf(FILE* __f) : stdio_streambuf_base(__f) {}
    89 
    90   ~stdio_istreambuf();
    91 
    92 protected:                      // Virtual functions from basic_streambuf.
    93   streamsize showmanyc();
    94   int_type underflow();
    95   int_type uflow();
    96   virtual int_type pbackfail(int_type c = traits_type::eof());
    97 };
    98 
    99 class stdio_ostreambuf : public stdio_streambuf_base
   100 {
   101 public:                         // Constructor, destructor.
   102   stdio_ostreambuf(FILE* __f) : stdio_streambuf_base(__f) {}
   103   ~stdio_ostreambuf();
   104 
   105 protected:                      // Virtual functions from basic_streambuf.
   106   streamsize showmanyc();
   107   int_type overflow(int_type c = traits_type::eof());
   108 };
   109 
   110 # ifndef _STLP_HAS_NO_NAMESPACES
   111 } // Close namespace _SgI.
   112 # endif
   113 
   114 #endif /* _STLP_STDIO_STREAMBUF */
   115 
   116 #endif /* _STLP_WINCE */
   117 
   118 // Local Variables:
   119 // mode:C++
   120 // End:
   121