epoc32/include/tools/stlport/stl/_sstream.h
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:33:34 +0100
branchSymbian3
changeset 4 837f303aceeb
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@4
     1
/*
williamr@4
     2
 * Copyright (c) 1999
williamr@4
     3
 * Silicon Graphics Computer Systems, Inc.
williamr@4
     4
 *
williamr@4
     5
 * Copyright (c) 1999
williamr@4
     6
 * Boris Fomitchev
williamr@4
     7
 *
williamr@4
     8
 * This material is provided "as is", with absolutely no warranty expressed
williamr@4
     9
 * or implied. Any use is at your own risk.
williamr@4
    10
 *
williamr@4
    11
 * Permission to use or copy this software for any purpose is hereby granted
williamr@4
    12
 * without fee, provided the above notices are retained on all copies.
williamr@4
    13
 * Permission to modify the code and to distribute modified code is granted,
williamr@4
    14
 * provided the above notices are retained, and a notice that the code was
williamr@4
    15
 * modified is included with the above copyright notice.
williamr@4
    16
 *
williamr@4
    17
 */
williamr@4
    18
williamr@4
    19
williamr@4
    20
// This header defines classes basic_stringbuf, basic_istringstream,
williamr@4
    21
// basic_ostringstream, and basic_stringstream.  These classes
williamr@4
    22
// represent streamsbufs and streams whose sources or destinations are
williamr@4
    23
// C++ strings.
williamr@4
    24
williamr@4
    25
#ifndef _STLP_INTERNAL_SSTREAM
williamr@4
    26
#define _STLP_INTERNAL_SSTREAM
williamr@4
    27
williamr@4
    28
#ifndef _STLP_INTERNAL_STREAMBUF
williamr@4
    29
#  include <stl/_streambuf.h>
williamr@4
    30
#endif
williamr@4
    31
williamr@4
    32
#ifndef _STLP_INTERNAL_ISTREAM
williamr@4
    33
#  include <stl/_istream.h> // Includes <ostream>, <ios>, <iosfwd>
williamr@4
    34
#endif
williamr@4
    35
williamr@4
    36
#ifndef _STLP_INTERNAL_STRING_H
williamr@4
    37
#  include <stl/_string.h>
williamr@4
    38
#endif
williamr@4
    39
williamr@4
    40
_STLP_BEGIN_NAMESPACE
williamr@4
    41
williamr@4
    42
//----------------------------------------------------------------------
williamr@4
    43
// This version of basic_stringbuf relies on the internal details of
williamr@4
    44
// basic_string.  It relies on the fact that, in this implementation,
williamr@4
    45
// basic_string's iterators are pointers.  It also assumes (as allowed
williamr@4
    46
// by the standard) that _CharT is a POD type.
williamr@4
    47
williamr@4
    48
// We have a very small buffer for the put area, just so that we don't
williamr@4
    49
// have to use append() for every sputc.  Conceptually, the buffer
williamr@4
    50
// immediately follows the end of the underlying string.  We use this
williamr@4
    51
// buffer when appending to write-only streambufs, but we don't use it
williamr@4
    52
// for read-write streambufs.
williamr@4
    53
williamr@4
    54
template <class _CharT, class _Traits, class _Alloc>
williamr@4
    55
class basic_stringbuf : public basic_streambuf<_CharT, _Traits> {
williamr@4
    56
public:                         // Typedefs.
williamr@4
    57
  typedef _CharT                     char_type;
williamr@4
    58
  typedef typename _Traits::int_type int_type;
williamr@4
    59
  typedef typename _Traits::pos_type pos_type;
williamr@4
    60
  typedef typename _Traits::off_type off_type;
williamr@4
    61
  typedef _Traits                    traits_type;
williamr@4
    62
williamr@4
    63
  typedef basic_streambuf<_CharT, _Traits>          _Base;
williamr@4
    64
  typedef basic_stringbuf<_CharT, _Traits, _Alloc>  _Self;
williamr@4
    65
  typedef basic_string<_CharT, _Traits, _Alloc>     _String;
williamr@4
    66
williamr@4
    67
public:                         // Constructors, destructor.
williamr@4
    68
  explicit basic_stringbuf(ios_base::openmode __mode
williamr@4
    69
                                      = ios_base::in | ios_base::out);
williamr@4
    70
  explicit basic_stringbuf(const _String& __s, ios_base::openmode __mode
williamr@4
    71
                                      = ios_base::in | ios_base::out);
williamr@4
    72
  virtual ~basic_stringbuf();
williamr@4
    73
williamr@4
    74
public:                         // Get or set the string.
williamr@4
    75
  _String str() const { _M_append_buffer(); return _M_str; }
williamr@4
    76
  void str(const _String& __s);
williamr@4
    77
williamr@4
    78
protected:                      // Overridden virtual member functions.
williamr@4
    79
  virtual int_type underflow();
williamr@4
    80
  virtual int_type uflow();
williamr@4
    81
  virtual int_type pbackfail(int_type __c);
williamr@4
    82
  virtual int_type overflow(int_type __c);
williamr@4
    83
  int_type pbackfail() {return pbackfail(_Traits::eof());}
williamr@4
    84
  int_type overflow() {return overflow(_Traits::eof());}
williamr@4
    85
williamr@4
    86
  virtual streamsize xsputn(const char_type* __s, streamsize __n);
williamr@4
    87
  virtual streamsize _M_xsputnc(char_type __c, streamsize __n);
williamr@4
    88
williamr@4
    89
  virtual _Base* setbuf(_CharT* __buf, streamsize __n);
williamr@4
    90
  virtual pos_type seekoff(off_type __off, ios_base::seekdir __dir,
williamr@4
    91
                           ios_base::openmode __mode
williamr@4
    92
                                      = ios_base::in | ios_base::out);
williamr@4
    93
  virtual pos_type seekpos(pos_type __pos, ios_base::openmode __mode
williamr@4
    94
                                      = ios_base::in | ios_base::out);
williamr@4
    95
williamr@4
    96
private:                        // Helper functions.
williamr@4
    97
  // Append the internal buffer to the string if necessary.
williamr@4
    98
  void _M_append_buffer() const;
williamr@4
    99
  void _M_set_ptrs();
williamr@4
   100
williamr@4
   101
private:
williamr@4
   102
  ios_base::openmode _M_mode;
williamr@4
   103
  mutable basic_string<_CharT, _Traits, _Alloc> _M_str;
williamr@4
   104
williamr@4
   105
  enum _JustName { _S_BufSiz = 8 };
williamr@4
   106
  _CharT _M_Buf[ 8 /* _S_BufSiz */];
williamr@4
   107
};
williamr@4
   108
williamr@4
   109
#if defined (_STLP_USE_TEMPLATE_EXPORT)
williamr@4
   110
_STLP_EXPORT_TEMPLATE_CLASS basic_stringbuf<char, char_traits<char>, allocator<char> >;
williamr@4
   111
#  if !defined (_STLP_NO_WCHAR_T)
williamr@4
   112
_STLP_EXPORT_TEMPLATE_CLASS basic_stringbuf<wchar_t, char_traits<wchar_t>, allocator<wchar_t>  >;
williamr@4
   113
#  endif
williamr@4
   114
#endif /* _STLP_USE_TEMPLATE_EXPORT */
williamr@4
   115
williamr@4
   116
//----------------------------------------------------------------------
williamr@4
   117
// Class basic_istringstream, an input stream that uses a stringbuf.
williamr@4
   118
williamr@4
   119
template <class _CharT, class _Traits, class _Alloc>
williamr@4
   120
class basic_istringstream : public basic_istream<_CharT, _Traits> {
williamr@4
   121
public:                         // Typedefs
williamr@4
   122
  typedef typename _Traits::char_type   char_type;
williamr@4
   123
  typedef typename _Traits::int_type    int_type;
williamr@4
   124
  typedef typename _Traits::pos_type    pos_type;
williamr@4
   125
  typedef typename _Traits::off_type    off_type;
williamr@4
   126
  typedef _Traits traits_type;
williamr@4
   127
williamr@4
   128
  typedef basic_ios<_CharT, _Traits>                _Basic_ios;
williamr@4
   129
  typedef basic_istream<_CharT, _Traits>            _Base;
williamr@4
   130
  typedef basic_string<_CharT, _Traits, _Alloc>     _String;
williamr@4
   131
  typedef basic_stringbuf<_CharT, _Traits, _Alloc>  _Buf;
williamr@4
   132
williamr@4
   133
public:                         // Constructors, destructor.
williamr@4
   134
  basic_istringstream(ios_base::openmode __mode = ios_base::in);
williamr@4
   135
  basic_istringstream(const _String& __str,
williamr@4
   136
                      ios_base::openmode __mode = ios_base::in);
williamr@4
   137
  ~basic_istringstream();
williamr@4
   138
williamr@4
   139
public:                         // Member functions
williamr@4
   140
williamr@4
   141
  basic_stringbuf<_CharT, _Traits, _Alloc>* rdbuf() const
williamr@4
   142
    { return __CONST_CAST(_Buf*,&_M_buf); }
williamr@4
   143
williamr@4
   144
  _String str() const { return _M_buf.str(); }
williamr@4
   145
  void str(const _String& __s) { _M_buf.str(__s); }
williamr@4
   146
williamr@4
   147
private:
williamr@4
   148
  basic_stringbuf<_CharT, _Traits, _Alloc> _M_buf;
williamr@4
   149
williamr@4
   150
#if defined (_STLP_MSVC) && (_STLP_MSVC >= 1300 && _STLP_MSVC <= 1310)
williamr@4
   151
  typedef basic_istringstream<_CharT, _Traits> _Self;
williamr@4
   152
  //explicitely defined as private to avoid warnings:
williamr@4
   153
  basic_istringstream(_Self const&);
williamr@4
   154
  _Self& operator = (_Self const&);
williamr@4
   155
#endif
williamr@4
   156
};
williamr@4
   157
williamr@4
   158
williamr@4
   159
//----------------------------------------------------------------------
williamr@4
   160
// Class basic_ostringstream, an output stream that uses a stringbuf.
williamr@4
   161
williamr@4
   162
template <class _CharT, class _Traits, class _Alloc>
williamr@4
   163
class basic_ostringstream : public basic_ostream<_CharT, _Traits> {
williamr@4
   164
public:                         // Typedefs
williamr@4
   165
  typedef typename _Traits::char_type   char_type;
williamr@4
   166
  typedef typename _Traits::int_type    int_type;
williamr@4
   167
  typedef typename _Traits::pos_type    pos_type;
williamr@4
   168
  typedef typename _Traits::off_type    off_type;
williamr@4
   169
  typedef _Traits traits_type;
williamr@4
   170
williamr@4
   171
  typedef basic_ios<_CharT, _Traits>                _Basic_ios;
williamr@4
   172
  typedef basic_ostream<_CharT, _Traits>            _Base;
williamr@4
   173
  typedef basic_string<_CharT, _Traits, _Alloc>     _String;
williamr@4
   174
  typedef basic_stringbuf<_CharT, _Traits, _Alloc>  _Buf;
williamr@4
   175
williamr@4
   176
public:                         // Constructors, destructor.
williamr@4
   177
  basic_ostringstream(ios_base::openmode __mode = ios_base::out);
williamr@4
   178
  basic_ostringstream(const _String& __str,
williamr@4
   179
                      ios_base::openmode __mode = ios_base::out);
williamr@4
   180
  ~basic_ostringstream();
williamr@4
   181
williamr@4
   182
public:                         // Member functions.
williamr@4
   183
williamr@4
   184
  basic_stringbuf<_CharT, _Traits, _Alloc>* rdbuf() const
williamr@4
   185
    { return __CONST_CAST(_Buf*,&_M_buf); }
williamr@4
   186
williamr@4
   187
  _String str() const { return _M_buf.str(); }
williamr@4
   188
    void str(const _String& __s) { _M_buf.str(__s); } // dwa 02/07/00 - BUG STOMPER DAVE
williamr@4
   189
williamr@4
   190
williamr@4
   191
private:
williamr@4
   192
  basic_stringbuf<_CharT, _Traits, _Alloc> _M_buf;
williamr@4
   193
williamr@4
   194
#if defined (_STLP_MSVC) && (_STLP_MSVC >= 1300 && _STLP_MSVC <= 1310)
williamr@4
   195
  typedef basic_ostringstream<_CharT, _Traits> _Self;
williamr@4
   196
  //explicitely defined as private to avoid warnings:
williamr@4
   197
  basic_ostringstream(_Self const&);
williamr@4
   198
  _Self& operator = (_Self const&);
williamr@4
   199
#endif
williamr@4
   200
};
williamr@4
   201
williamr@4
   202
williamr@4
   203
//----------------------------------------------------------------------
williamr@4
   204
// Class basic_stringstream, a bidirectional stream that uses a stringbuf.
williamr@4
   205
williamr@4
   206
template <class _CharT, class _Traits, class _Alloc>
williamr@4
   207
class basic_stringstream : public basic_iostream<_CharT, _Traits> {
williamr@4
   208
public:                         // Typedefs
williamr@4
   209
  typedef typename _Traits::char_type char_type;
williamr@4
   210
  typedef typename _Traits::int_type  int_type;
williamr@4
   211
  typedef typename _Traits::pos_type  pos_type;
williamr@4
   212
  typedef typename _Traits::off_type  off_type;
williamr@4
   213
  typedef _Traits  traits_type;
williamr@4
   214
williamr@4
   215
  typedef basic_ios<_CharT, _Traits>                 _Basic_ios;
williamr@4
   216
  typedef basic_iostream<_CharT, _Traits>            _Base;
williamr@4
   217
  typedef basic_string<_CharT, _Traits, _Alloc>      _String;
williamr@4
   218
  typedef basic_stringbuf<_CharT, _Traits, _Alloc>  _Buf;
williamr@4
   219
williamr@4
   220
  typedef ios_base::openmode openmode;
williamr@4
   221
williamr@4
   222
public:                         // Constructors, destructor.
williamr@4
   223
  basic_stringstream(openmode __mod = ios_base::in | ios_base::out);
williamr@4
   224
  basic_stringstream(const _String& __str,
williamr@4
   225
                     openmode __mod = ios_base::in | ios_base::out);
williamr@4
   226
  ~basic_stringstream();
williamr@4
   227
williamr@4
   228
public:                         // Member functions.
williamr@4
   229
williamr@4
   230
  basic_stringbuf<_CharT, _Traits, _Alloc>* rdbuf() const
williamr@4
   231
    { return __CONST_CAST(_Buf*,&_M_buf); }
williamr@4
   232
williamr@4
   233
  _String str() const { return _M_buf.str(); }
williamr@4
   234
    void str(const _String& __s) { _M_buf.str(__s); }
williamr@4
   235
williamr@4
   236
private:
williamr@4
   237
  basic_stringbuf<_CharT, _Traits, _Alloc> _M_buf;
williamr@4
   238
williamr@4
   239
#if defined (_STLP_MSVC) && (_STLP_MSVC >= 1300 && _STLP_MSVC <= 1310)
williamr@4
   240
  typedef basic_stringstream<_CharT, _Traits> _Self;
williamr@4
   241
  //explicitely defined as private to avoid warnings:
williamr@4
   242
  basic_stringstream(_Self const&);
williamr@4
   243
  _Self& operator = (_Self const&);
williamr@4
   244
#endif
williamr@4
   245
};
williamr@4
   246
williamr@4
   247
williamr@4
   248
#if defined (_STLP_USE_TEMPLATE_EXPORT)
williamr@4
   249
_STLP_EXPORT_TEMPLATE_CLASS basic_istringstream<char, char_traits<char>, allocator<char> >;
williamr@4
   250
_STLP_EXPORT_TEMPLATE_CLASS basic_ostringstream<char, char_traits<char>, allocator<char> >;
williamr@4
   251
_STLP_EXPORT_TEMPLATE_CLASS basic_stringstream<char, char_traits<char>, allocator<char> >;
williamr@4
   252
#  if !defined (_STLP_NO_WCHAR_T)
williamr@4
   253
_STLP_EXPORT_TEMPLATE_CLASS basic_istringstream<wchar_t, char_traits<wchar_t>, allocator<wchar_t>  >;
williamr@4
   254
_STLP_EXPORT_TEMPLATE_CLASS basic_ostringstream<wchar_t, char_traits<wchar_t>, allocator<wchar_t>  >;
williamr@4
   255
_STLP_EXPORT_TEMPLATE_CLASS basic_stringstream<wchar_t, char_traits<wchar_t>, allocator<wchar_t>  >;
williamr@4
   256
#  endif
williamr@4
   257
#endif /* _STLP_USE_TEMPLATE_EXPORT */
williamr@4
   258
williamr@4
   259
_STLP_END_NAMESPACE
williamr@4
   260
williamr@4
   261
#if defined (_STLP_EXPOSE_STREAM_IMPLEMENTATION) && !defined (_STLP_LINK_TIME_INSTANTIATION)
williamr@4
   262
#  include <stl/_sstream.c>
williamr@4
   263
#endif
williamr@4
   264
williamr@4
   265
#endif /* _STLP_INTERNAL_SSTREAM */
williamr@4
   266
williamr@4
   267
// Local Variables:
williamr@4
   268
// mode:C++
williamr@4
   269
// End: