epoc32/include/stdapis/stlport/stl/_strstream.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
 * © Portions copyright (c) 2006-2007 Nokia Corporation.  All rights reserved.
williamr@4
     3
 *
williamr@4
     4
 * Copyright (c) 1999
williamr@4
     5
 * Silicon Graphics Computer Systems, Inc.
williamr@4
     6
 *
williamr@4
     7
 * Copyright (c) 1999 
williamr@4
     8
 * Boris Fomitchev
williamr@4
     9
 *
williamr@4
    10
 * This material is provided "as is", with absolutely no warranty expressed
williamr@4
    11
 * or implied. Any use is at your own risk.
williamr@4
    12
 *
williamr@4
    13
 * Permission to use or copy this software for any purpose is hereby granted 
williamr@4
    14
 * without fee, provided the above notices are retained on all copies.
williamr@4
    15
 * Permission to modify the code and to distribute modified code is granted,
williamr@4
    16
 * provided the above notices are retained, and a notice that the code was
williamr@4
    17
 * modified is included with the above copyright notice.
williamr@4
    18
 *
williamr@4
    19
 */
williamr@4
    20
williamr@4
    21
williamr@4
    22
williamr@4
    23
#ifndef _STLP_INTERNAL_STREAMBUF
williamr@4
    24
#include <stl/_streambuf.h>
williamr@4
    25
#endif
williamr@4
    26
#ifndef _STLP_ISTREAM
williamr@4
    27
#include <istream>              // Includes <ostream>, <ios>, <iosfwd>
williamr@4
    28
#endif
williamr@4
    29
#ifndef _STLP_STRING_H
williamr@4
    30
#include <stl/_string.h>
williamr@4
    31
#endif
williamr@4
    32
williamr@4
    33
_STLP_BEGIN_NAMESPACE
williamr@4
    34
williamr@4
    35
#ifndef _STLP_USE_NAMESPACES
williamr@4
    36
# define strstream _STLP_strstream 
williamr@4
    37
# define ostrstream _STLP_ostrstream
williamr@4
    38
# define istrstream _STLP_istrstream
williamr@4
    39
# define strstreambuf _STLP_strstreambuf
williamr@4
    40
#endif
williamr@4
    41
williamr@4
    42
//----------------------------------------------------------------------
williamr@4
    43
// Class strstreambuf, a streambuf class that manages an array of char.
williamr@4
    44
// Note that this class is not a template.
williamr@4
    45
#ifdef __SYMBIAN32__
williamr@4
    46
class strstreambuf : public basic_streambuf<char, char_traits<char> > 
williamr@4
    47
#else
williamr@4
    48
class _STLP_CLASS_DECLSPEC strstreambuf : public basic_streambuf<char, char_traits<char> >
williamr@4
    49
#endif
williamr@4
    50
{
williamr@4
    51
public:                         // Types.
williamr@4
    52
  typedef char_traits<char>              _Traits;
williamr@4
    53
  typedef basic_streambuf<char, char_traits<char> > _Base;
williamr@4
    54
  typedef void* (*__alloc_fn)(size_t);
williamr@4
    55
  typedef void (*__free_fn)(void*);
williamr@4
    56
public:                         // Constructor, destructor
williamr@4
    57
williamr@4
    58
  explicit strstreambuf(streamsize _Initial_capacity = 0);
williamr@4
    59
williamr@4
    60
  _STLP_DECLSPEC strstreambuf(__alloc_fn, __free_fn);
williamr@4
    61
williamr@4
    62
  _STLP_DECLSPEC strstreambuf(char* __get, streamsize __n, char* __put = 0);
williamr@4
    63
  _STLP_DECLSPEC strstreambuf(signed char* __get, streamsize __n, signed char* __put = 0);
williamr@4
    64
  _STLP_DECLSPEC strstreambuf(unsigned char* __get, streamsize __n, unsigned char* __put=0);
williamr@4
    65
williamr@4
    66
  _STLP_DECLSPEC strstreambuf(const char* __get, streamsize __n);
williamr@4
    67
  _STLP_DECLSPEC strstreambuf(const signed char* __get, streamsize __n);
williamr@4
    68
  _STLP_DECLSPEC strstreambuf(const unsigned char* __get, streamsize __n);
williamr@4
    69
williamr@4
    70
  virtual ~strstreambuf();
williamr@4
    71
williamr@4
    72
public:                         // strstreambuf operations.
williamr@4
    73
  _STLP_DECLSPEC void freeze(bool = true);
williamr@4
    74
  _STLP_DECLSPEC char* str();
williamr@4
    75
  _STLP_DECLSPEC int pcount() const;
williamr@4
    76
williamr@4
    77
protected:                      // Overridden virtual member functions.
williamr@4
    78
  virtual int_type overflow(int_type __c  = _Traits::eof());
williamr@4
    79
  virtual int_type pbackfail(int_type __c = _Traits::eof());
williamr@4
    80
  virtual int_type underflow();
williamr@4
    81
  virtual _Base* setbuf(char* __buf, streamsize __n);
williamr@4
    82
  virtual pos_type seekoff(off_type __off, ios_base::seekdir __dir,
williamr@4
    83
                           ios_base::openmode __mode 
williamr@4
    84
                                      = ios_base::in | ios_base::out);
williamr@4
    85
  virtual pos_type seekpos(pos_type __pos, ios_base::openmode __mode 
williamr@4
    86
                                      = ios_base::in | ios_base::out);
williamr@4
    87
williamr@4
    88
private:                        // Helper functions.
williamr@4
    89
  // Dynamic allocation, possibly using _M_alloc_fun and _M_free_fun.
williamr@4
    90
  char* _M_alloc(size_t);
williamr@4
    91
  inline void  _M_free(char*);
williamr@4
    92
williamr@4
    93
  // Helper function used in constructors.
williamr@4
    94
  void _M_setup(char* __get, char* __put, streamsize __n);
williamr@4
    95
private:                        // Data members.
williamr@4
    96
  __alloc_fn _M_alloc_fun;
williamr@4
    97
  __free_fn  _M_free_fun;
williamr@4
    98
  bool _M_dynamic  : 1;
williamr@4
    99
  bool _M_frozen   : 1;
williamr@4
   100
  bool _M_constant : 1;
williamr@4
   101
#ifdef __SYMBIAN32__
williamr@4
   102
  char* _pfrozenendsave;
williamr@4
   103
  char* _pgetfrozenendsave;
williamr@4
   104
#endif
williamr@4
   105
};
williamr@4
   106
williamr@4
   107
inline strstreambuf::~strstreambuf()
williamr@4
   108
{
williamr@4
   109
#ifdef __SYMBIAN32__
williamr@4
   110
  if (_M_dynamic && !_M_frozen)
williamr@4
   111
  {
williamr@4
   112
  	if (_M_free_fun)
williamr@4
   113
  		_M_free_fun(eback());
williamr@4
   114
  	else
williamr@4
   115
  		_M_free(eback());
williamr@4
   116
  }
williamr@4
   117
#else  
williamr@4
   118
	if (_M_dynamic && !_M_frozen)
williamr@4
   119
        _M_free(eback());
williamr@4
   120
#endif	
williamr@4
   121
}
williamr@4
   122
williamr@4
   123
inline void strstreambuf::_M_free(char* p)
williamr@4
   124
{
williamr@4
   125
  if (p)
williamr@4
   126
    if (_M_free_fun)
williamr@4
   127
      _M_free_fun(p);
williamr@4
   128
    else
williamr@4
   129
      delete[] p;
williamr@4
   130
}
williamr@4
   131
williamr@4
   132
williamr@4
   133
//----------------------------------------------------------------------
williamr@4
   134
// Class istrstream, an istream that manages a strstreambuf.
williamr@4
   135
williamr@4
   136
#ifdef __SYMBIAN32__
williamr@4
   137
NONSHARABLE_CLASS (istrstream) : public basic_istream<char, char_traits<char> >
williamr@4
   138
#else
williamr@4
   139
class _STLP_CLASS_DECLSPEC istrstream : public basic_istream<char, char_traits<char> >
williamr@4
   140
#endif
williamr@4
   141
{
williamr@4
   142
public:
williamr@4
   143
  _STLP_DECLSPEC explicit istrstream(char*);
williamr@4
   144
  _STLP_DECLSPEC explicit istrstream(const char*);
williamr@4
   145
  _STLP_DECLSPEC istrstream(char* , streamsize);
williamr@4
   146
  _STLP_DECLSPEC istrstream(const char*, streamsize);
williamr@4
   147
  virtual ~istrstream();
williamr@4
   148
  
williamr@4
   149
  _STLP_DECLSPEC strstreambuf* rdbuf() const;
williamr@4
   150
  _STLP_DECLSPEC char* str();
williamr@4
   151
williamr@4
   152
private:
williamr@4
   153
  strstreambuf _M_buf;
williamr@4
   154
};
williamr@4
   155
williamr@4
   156
//----------------------------------------------------------------------
williamr@4
   157
// Class ostrstream
williamr@4
   158
#ifdef __SYMBIAN32__
williamr@4
   159
NONSHARABLE_CLASS (ostrstream) : public basic_ostream<char, char_traits<char> >
williamr@4
   160
#else
williamr@4
   161
class _STLP_CLASS_DECLSPEC ostrstream : public basic_ostream<char, char_traits<char> >
williamr@4
   162
#endif
williamr@4
   163
{
williamr@4
   164
public:
williamr@4
   165
  _STLP_DECLSPEC ostrstream();
williamr@4
   166
  _STLP_DECLSPEC ostrstream(char*, int, ios_base::openmode = ios_base::out);
williamr@4
   167
  virtual ~ostrstream();
williamr@4
   168
williamr@4
   169
  _STLP_DECLSPEC strstreambuf* rdbuf() const;
williamr@4
   170
  _STLP_DECLSPEC void freeze(bool = true);
williamr@4
   171
  _STLP_DECLSPEC char* str();
williamr@4
   172
  _STLP_DECLSPEC int pcount() const;
williamr@4
   173
williamr@4
   174
private:
williamr@4
   175
  strstreambuf _M_buf;
williamr@4
   176
};
williamr@4
   177
williamr@4
   178
//----------------------------------------------------------------------
williamr@4
   179
// Class strstream
williamr@4
   180
#ifdef __SYMBIAN32__
williamr@4
   181
NONSHARABLE_CLASS (strstream) : public basic_iostream<char, char_traits<char> >
williamr@4
   182
#else
williamr@4
   183
class _STLP_CLASS_DECLSPEC strstream : public basic_iostream<char, char_traits<char> >
williamr@4
   184
#endif
williamr@4
   185
{
williamr@4
   186
public:
williamr@4
   187
  typedef char                        char_type;
williamr@4
   188
  typedef char_traits<char>::int_type int_type;
williamr@4
   189
  typedef char_traits<char>::pos_type pos_type;
williamr@4
   190
  typedef char_traits<char>::off_type off_type;
williamr@4
   191
williamr@4
   192
  _STLP_DECLSPEC strstream();
williamr@4
   193
  _STLP_DECLSPEC strstream(char*, int, ios_base::openmode = ios_base::in | ios_base::out);
williamr@4
   194
  virtual ~strstream();
williamr@4
   195
williamr@4
   196
  _STLP_DECLSPEC strstreambuf* rdbuf() const;
williamr@4
   197
  _STLP_DECLSPEC void freeze(bool = true);
williamr@4
   198
  _STLP_DECLSPEC int pcount() const;
williamr@4
   199
  _STLP_DECLSPEC char* str();
williamr@4
   200
williamr@4
   201
private:
williamr@4
   202
  strstreambuf _M_buf;
williamr@4
   203
};
williamr@4
   204
williamr@4
   205
_STLP_END_NAMESPACE