epoc32/include/stdapis/stlportv5/stl/_streambuf.h
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:33:34 +0100
branchSymbian3
changeset 4 837f303aceeb
parent 3 e1b950c65cb4
permissions -rw-r--r--
Current Symbian^3 public API header files (from PDK 3.0.h)
This is the epoc32/include tree with the "platform" subtrees removed, and
all but a selected few mbg and rsg files removed.
williamr@2
     1
/*
williamr@2
     2
 * Copyright (c) 1999
williamr@2
     3
 * Silicon Graphics Computer Systems, Inc.
williamr@2
     4
 *
williamr@4
     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@4
    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@4
    17
 */
williamr@2
    18
#ifndef _STLP_INTERNAL_STREAMBUF
williamr@2
    19
#define _STLP_INTERNAL_STREAMBUF
williamr@2
    20
williamr@2
    21
#ifndef _STLP_IOS_BASE_H
williamr@4
    22
#  include <stl/_ios_base.h>      // Needed for ios_base bitfield members.
williamr@4
    23
#endif                            // <ios_base> includes <iosfwd>.
williamr@2
    24
williamr@2
    25
_STLP_BEGIN_NAMESPACE
williamr@2
    26
williamr@2
    27
//----------------------------------------------------------------------
williamr@2
    28
// Class basic_streambuf<>, the base class of the streambuf hierarchy.
williamr@2
    29
williamr@2
    30
// A basic_streambuf<> manages an input (get) area and an output (put)
williamr@2
    31
// area.  Each is described by three pointers: a beginning, an end, and a
williamr@2
    32
// current position.  basic_streambuf<> contains some very simple member
williamr@2
    33
// functions that manipulate those six pointers, but almost all of the real
williamr@2
    34
// functionality gets delegated to protected virtual member functions.
williamr@2
    35
// All of the public member functions are inline, and most of the protected
williamr@2
    36
// member functions are virtual.
williamr@2
    37
williamr@2
    38
// Although basic_streambuf<> is not abstract, it is useful only as a base
williamr@2
    39
// class.  Its virtual member functions have default definitions such that
williamr@2
    40
// reading from a basic_streambuf<> will always yield EOF, and writing to a
williamr@2
    41
// basic_streambuf<> will always fail.
williamr@2
    42
williamr@2
    43
// The second template parameter, _Traits, defaults to char_traits<_CharT>.
williamr@2
    44
// The default is declared in header <iosfwd>, and it isn't declared here
williamr@4
    45
// because C++ language rules do not allow it to be declared twice.
williamr@2
    46
williamr@2
    47
template <class _CharT, class _Traits>
williamr@4
    48
class basic_streambuf {
williamr@2
    49
  friend class basic_istream<_CharT, _Traits>;
williamr@2
    50
  friend class basic_ostream<_CharT, _Traits>;
williamr@2
    51
williamr@2
    52
public:                         // Typedefs.
williamr@2
    53
  typedef _CharT                     char_type;
williamr@2
    54
  typedef typename _Traits::int_type int_type;
williamr@2
    55
  typedef typename _Traits::pos_type pos_type;
williamr@2
    56
  typedef typename _Traits::off_type off_type;
williamr@2
    57
  typedef _Traits                    traits_type;
williamr@2
    58
williamr@2
    59
private:                        // Data members.
williamr@2
    60
williamr@2
    61
  char_type* _M_gbegin;         // Beginning of get area
williamr@2
    62
  char_type* _M_gnext;          // Current position within the get area
williamr@2
    63
  char_type* _M_gend;           // End of get area
williamr@2
    64
williamr@2
    65
  char_type* _M_pbegin;         // Beginning of put area
williamr@2
    66
  char_type* _M_pnext;          // Current position within the put area
williamr@2
    67
  char_type* _M_pend;           // End of put area
williamr@2
    68
williamr@2
    69
  locale _M_locale;             // The streambuf's locale object
williamr@2
    70
williamr@4
    71
//public:                         // Extension: locking, for thread safety.
williamr@4
    72
//  _STLP_mutex _M_lock;
williamr@2
    73
williamr@2
    74
public:                         // Destructor.
williamr@4
    75
  virtual ~basic_streambuf();
williamr@2
    76
williamr@2
    77
protected:                      // The default constructor.
williamr@4
    78
  basic_streambuf()
williamr@4
    79
#if defined (_STLP_MSVC) && (_STLP_MSVC < 1300) && defined (_STLP_USE_STATIC_LIB)
williamr@4
    80
    //We make it inline to avoid unresolved symbol.
williamr@4
    81
    : _M_gbegin(0), _M_gnext(0), _M_gend(0),
williamr@4
    82
      _M_pbegin(0), _M_pnext(0), _M_pend(0),
williamr@4
    83
      _M_locale()
williamr@4
    84
  {}
williamr@4
    85
#else
williamr@4
    86
  ;
williamr@4
    87
#endif
williamr@2
    88
williamr@2
    89
protected:                      // Protected interface to the get area.
williamr@2
    90
  char_type* eback() const { return _M_gbegin; } // Beginning
williamr@2
    91
  char_type* gptr()  const { return _M_gnext; }  // Current position
williamr@2
    92
  char_type* egptr() const { return _M_gend; }   // End
williamr@4
    93
williamr@2
    94
  void gbump(int __n) { _M_gnext += __n; }
williamr@2
    95
  void setg(char_type* __gbegin, char_type* __gnext, char_type* __gend) {
williamr@2
    96
    _M_gbegin = __gbegin;
williamr@2
    97
    _M_gnext  = __gnext;
williamr@2
    98
    _M_gend   = __gend;
williamr@2
    99
  }
williamr@2
   100
williamr@2
   101
public:
williamr@2
   102
  // An alternate public interface to the above functions
williamr@2
   103
  // which allows us to avoid using templated friends which
williamr@2
   104
  // are not supported on some compilers.
williamr@2
   105
  char_type* _M_eback() const { return eback(); }
williamr@2
   106
  char_type* _M_gptr()  const { return gptr(); }
williamr@2
   107
  char_type* _M_egptr() const { return egptr(); }
williamr@2
   108
  void _M_gbump(int __n)      { gbump(__n); }
williamr@2
   109
  void _M_setg(char_type* __gbegin, char_type* __gnext, char_type* __gend)
williamr@4
   110
  { this->setg(__gbegin, __gnext, __gend); }
williamr@2
   111
williamr@2
   112
protected:                      // Protected interface to the put area
williamr@2
   113
williamr@2
   114
  char_type* pbase() const { return _M_pbegin; } // Beginning
williamr@2
   115
  char_type* pptr()  const { return _M_pnext; }  // Current position
williamr@2
   116
  char_type* epptr() const { return _M_pend; }   // End
williamr@2
   117
williamr@2
   118
  void pbump(int __n) { _M_pnext += __n; }
williamr@2
   119
  void setp(char_type* __pbegin, char_type* __pend) {
williamr@2
   120
    _M_pbegin = __pbegin;
williamr@2
   121
    _M_pnext  = __pbegin;
williamr@2
   122
    _M_pend   = __pend;
williamr@2
   123
  }
williamr@2
   124
williamr@2
   125
protected:                      // Virtual buffer management functions.
williamr@2
   126
williamr@4
   127
  virtual basic_streambuf<_CharT, _Traits>* setbuf(char_type*, streamsize);
williamr@2
   128
williamr@2
   129
  // Alters the stream position, using an integer offset.  In this
williamr@2
   130
  // class seekoff does nothing; subclasses are expected to override it.
williamr@4
   131
  virtual pos_type seekoff(off_type, ios_base::seekdir,
williamr@2
   132
                           ios_base::openmode = ios_base::in | ios_base::out);
williamr@2
   133
williamr@2
   134
  // Alters the stream position, using a previously obtained streampos.  In
williamr@2
   135
  // this class seekpos does nothing; subclasses are expected to override it.
williamr@4
   136
  virtual pos_type
williamr@2
   137
  seekpos(pos_type, ios_base::openmode = ios_base::in | ios_base::out);
williamr@2
   138
williamr@4
   139
  // Synchronizes (i.e. flushes) the buffer.  All subclasses are expected to
williamr@2
   140
  // override this virtual member function.
williamr@4
   141
  virtual int sync();
williamr@2
   142
williamr@2
   143
williamr@2
   144
public:                         // Buffer management.
williamr@4
   145
  basic_streambuf<_CharT, _Traits>* pubsetbuf(char_type* __s, streamsize __n)
williamr@4
   146
  { return this->setbuf(__s, __n); }
williamr@2
   147
williamr@2
   148
  pos_type pubseekoff(off_type __offset, ios_base::seekdir __way,
williamr@2
   149
                      ios_base::openmode __mod = ios_base::in | ios_base::out)
williamr@4
   150
  { return this->seekoff(__offset, __way, __mod); }
williamr@2
   151
williamr@2
   152
  pos_type pubseekpos(pos_type __sp,
williamr@2
   153
                      ios_base::openmode __mod = ios_base::in | ios_base::out)
williamr@4
   154
  { return this->seekpos(__sp, __mod); }
williamr@2
   155
williamr@2
   156
  int pubsync() { return this->sync(); }
williamr@2
   157
williamr@2
   158
protected:                      // Virtual get area functions, as defined in
williamr@2
   159
                                // 17.5.2.4.3 and 17.5.2.4.4 of the standard.
williamr@2
   160
  // Returns a lower bound on the number of characters that we can read,
williamr@2
   161
  // with underflow, before reaching end of file.  (-1 is a special value:
williamr@2
   162
  // it means that underflow will fail.)  Most subclasses should probably
williamr@2
   163
  // override this virtual member function.
williamr@4
   164
  virtual streamsize showmanyc();
williamr@2
   165
williamr@4
   166
  // Reads up to __n characters.  Return value is the number of
williamr@2
   167
  // characters read.
williamr@4
   168
  virtual streamsize xsgetn(char_type* __s, streamsize __n);
williamr@2
   169
williamr@2
   170
  // Called when there is no read position, i.e. when gptr() is null
williamr@2
   171
  // or when gptr() >= egptr().  Subclasses are expected to override
williamr@2
   172
  // this virtual member function.
williamr@4
   173
  virtual int_type underflow();
williamr@2
   174
williamr@4
   175
  // Similar to underflow(), but used for unbuffered input.  Most
williamr@2
   176
  // subclasses should probably override this virtual member function.
williamr@4
   177
  virtual int_type uflow();
williamr@2
   178
williamr@2
   179
  // Called when there is no putback position, i.e. when gptr() is null
williamr@2
   180
  // or when gptr() == eback().  All subclasses are expected to override
williamr@2
   181
  // this virtual member function.
williamr@4
   182
  virtual int_type pbackfail(int_type = traits_type::eof());
williamr@2
   183
williamr@2
   184
protected:                      // Virtual put area functions, as defined in
williamr@2
   185
                                // 27.5.2.4.5 of the standard.
williamr@2
   186
williamr@2
   187
  // Writes up to __n characters.  Return value is the number of characters
williamr@2
   188
  // written.
williamr@4
   189
  virtual streamsize xsputn(const char_type* __s, streamsize __n);
williamr@2
   190
williamr@2
   191
  // Extension: writes up to __n copies of __c.  Return value is the number
williamr@2
   192
  // of characters written.
williamr@4
   193
  virtual streamsize _M_xsputnc(char_type __c, streamsize __n);
williamr@2
   194
williamr@2
   195
  // Called when there is no write position.  All subclasses are expected to
williamr@2
   196
  // override this virtual member function.
williamr@4
   197
  virtual int_type overflow(int_type = traits_type::eof());
williamr@2
   198
williamr@2
   199
public:                         // Public members for writing characters.
williamr@2
   200
  // Write a single character.
williamr@2
   201
  int_type sputc(char_type __c) {
williamr@2
   202
    return ((_M_pnext < _M_pend) ? _Traits::to_int_type(*_M_pnext++ = __c)
williamr@2
   203
      : this->overflow(_Traits::to_int_type(__c)));
williamr@2
   204
  }
williamr@2
   205
williamr@2
   206
  // Write __n characters.
williamr@2
   207
  streamsize sputn(const char_type* __s, streamsize __n)
williamr@4
   208
  { return this->xsputn(__s, __n); }
williamr@2
   209
williamr@2
   210
  // Extension: write __n copies of __c.
williamr@2
   211
  streamsize _M_sputnc(char_type __c, streamsize __n)
williamr@4
   212
  { return this->_M_xsputnc(__c, __n); }
williamr@2
   213
williamr@2
   214
private:                        // Helper functions.
williamr@4
   215
  int_type _M_snextc_aux();
williamr@2
   216
williamr@2
   217
public:                         // Public members for reading characters.
williamr@2
   218
  streamsize in_avail() {
williamr@2
   219
    return (_M_gnext < _M_gend) ? (_M_gend - _M_gnext) : this->showmanyc();
williamr@2
   220
  }
williamr@4
   221
williamr@2
   222
  // Advance to the next character and return it.
williamr@2
   223
  int_type snextc() {
williamr@4
   224
  return ( _M_gend - _M_gnext > 1 ?
williamr@2
   225
             _Traits::to_int_type(*++_M_gnext) :
williamr@2
   226
             this->_M_snextc_aux());
williamr@2
   227
  }
williamr@2
   228
williamr@2
   229
  // Return the current character and advance to the next.
williamr@2
   230
  int_type sbumpc() {
williamr@4
   231
    return _M_gnext < _M_gend ? _Traits::to_int_type(*_M_gnext++)
williamr@2
   232
      : this->uflow();
williamr@2
   233
  }
williamr@4
   234
williamr@2
   235
  // Return the current character without advancing to the next.
williamr@2
   236
  int_type sgetc() {
williamr@4
   237
    return _M_gnext < _M_gend ? _Traits::to_int_type(*_M_gnext)
williamr@2
   238
      : this->underflow();
williamr@2
   239
  }
williamr@4
   240
williamr@2
   241
  streamsize sgetn(char_type* __s, streamsize __n)
williamr@2
   242
  { return this->xsgetn(__s, __n); }
williamr@4
   243
williamr@2
   244
  int_type sputbackc(char_type __c) {
williamr@2
   245
    return ((_M_gbegin < _M_gnext) && _Traits::eq(__c, *(_M_gnext - 1)))
williamr@2
   246
      ? _Traits::to_int_type(*--_M_gnext)
williamr@2
   247
      : this->pbackfail(_Traits::to_int_type(__c));
williamr@2
   248
  }
williamr@4
   249
williamr@2
   250
  int_type sungetc() {
williamr@2
   251
    return (_M_gbegin < _M_gnext)
williamr@2
   252
      ? _Traits::to_int_type(*--_M_gnext)
williamr@2
   253
      : this->pbackfail();
williamr@2
   254
  }
williamr@2
   255
williamr@2
   256
protected:                      // Virtual locale functions.
williamr@2
   257
williamr@2
   258
  // This is a hook, called by pubimbue() just before pubimbue()
williamr@2
   259
  // sets the streambuf's locale to __loc.  Note that imbue should
williamr@2
   260
  // not (and cannot, since it has no access to streambuf's private
williamr@2
   261
  // members) set the streambuf's locale itself.
williamr@4
   262
  virtual void imbue(const locale&);
williamr@2
   263
williamr@2
   264
public:                         // Locale-related functions.
williamr@4
   265
  locale pubimbue(const locale&);
williamr@2
   266
  locale getloc() const { return _M_locale; }
williamr@2
   267
williamr@4
   268
#if !defined (_STLP_NO_ANACHRONISMS)
williamr@2
   269
  void stossc() { this->sbumpc(); }
williamr@4
   270
#endif
williamr@4
   271
#if defined (__MVS__) || defined (__OS400__)
williamr@2
   272
private: // Data members.
williamr@2
   273
williamr@2
   274
  char_type* _M_gbegin; // Beginning of get area
williamr@2
   275
  char_type* _M_gnext; // Current position within the get area
williamr@2
   276
  char_type* _M_gend; // End of get area
williamr@2
   277
williamr@2
   278
  char_type* _M_pbegin; // Beginning of put area
williamr@2
   279
  char_type* _M_pnext; // Current position within the put area
williamr@2
   280
  char_type* _M_pend; // End of put area
williamr@2
   281
#endif
williamr@2
   282
};
williamr@2
   283
williamr@4
   284
#if defined (_STLP_USE_TEMPLATE_EXPORT)
williamr@4
   285
_STLP_EXPORT_TEMPLATE_CLASS basic_streambuf<char, char_traits<char> >;
williamr@4
   286
#  if !defined (_STLP_NO_WCHAR_T)
williamr@4
   287
_STLP_EXPORT_TEMPLATE_CLASS basic_streambuf<wchar_t, char_traits<wchar_t> >;
williamr@4
   288
#  endif // _STLP_NO_WCHAR_T
williamr@4
   289
#endif // _STLP_USE_TEMPLATE_EXPORT
williamr@2
   290
williamr@4
   291
_STLP_END_NAMESPACE
williamr@2
   292
williamr@4
   293
#if defined (_STLP_EXPOSE_STREAM_IMPLEMENTATION) && !defined (_STLP_LINK_TIME_INSTANTIATION)
williamr@4
   294
#  include <stl/_streambuf.c>
williamr@2
   295
#endif
williamr@2
   296
williamr@2
   297
#endif
williamr@2
   298
williamr@2
   299
// Local Variables:
williamr@2
   300
// mode:C++
williamr@2
   301
// End: