epoc32/include/stdapis/stlportv5/stl/_strstream.h
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:27:01 +0100
branchSymbian2
changeset 3 e1b950c65cb4
parent 2 epoc32/include/stdapis/stlport/stl/_strstream.h@2fe1408b6811
child 4 837f303aceeb
permissions -rw-r--r--
Attempt to represent the S^2->S^3 header reorganisation as a series of "hg rename" operations
williamr@2
     1
/*
williamr@2
     2
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
williamr@2
     3
williamr@2
     4
* Redistribution and use in source and binary forms, with or without 
williamr@2
     5
* modification, are permitted provided that the following conditions are met:
williamr@2
     6
williamr@2
     7
* Redistributions of source code must retain the above copyright notice, this 
williamr@2
     8
* list of conditions and the following disclaimer.
williamr@2
     9
* Redistributions in binary form must reproduce the above copyright notice, 
williamr@2
    10
* this list of conditions and the following disclaimer in the documentation 
williamr@2
    11
* and/or other materials provided with the distribution.
williamr@2
    12
* Neither the name of Nokia Corporation nor the names of its contributors 
williamr@2
    13
* may be used to endorse or promote products derived from this software 
williamr@2
    14
* without specific prior written permission.
williamr@2
    15
williamr@2
    16
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
williamr@2
    17
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
williamr@2
    18
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
williamr@2
    19
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 
williamr@2
    20
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
williamr@2
    21
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
williamr@2
    22
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
williamr@2
    23
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 
williamr@2
    24
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
williamr@2
    25
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
williamr@2
    26
*
williamr@2
    27
* Description:
williamr@2
    28
*
williamr@2
    29
*/
williamr@2
    30
williamr@2
    31
#ifndef _STLP_INTERNAL_STREAMBUF
williamr@2
    32
#include <stl/_streambuf.h>
williamr@2
    33
#endif
williamr@2
    34
#ifndef _STLP_ISTREAM
williamr@2
    35
#include <istream>              // Includes <ostream>, <ios>, <iosfwd>
williamr@2
    36
#endif
williamr@2
    37
#ifndef _STLP_STRING_H
williamr@2
    38
#include <stl/_string.h>
williamr@2
    39
#endif
williamr@2
    40
williamr@2
    41
_STLP_BEGIN_NAMESPACE
williamr@2
    42
williamr@2
    43
#ifndef _STLP_USE_NAMESPACES
williamr@2
    44
# define strstream _STLP_strstream 
williamr@2
    45
# define ostrstream _STLP_ostrstream
williamr@2
    46
# define istrstream _STLP_istrstream
williamr@2
    47
# define strstreambuf _STLP_strstreambuf
williamr@2
    48
#endif
williamr@2
    49
williamr@2
    50
//----------------------------------------------------------------------
williamr@2
    51
// Class strstreambuf, a streambuf class that manages an array of char.
williamr@2
    52
// Note that this class is not a template.
williamr@2
    53
#ifdef __SYMBIAN32__
williamr@2
    54
class strstreambuf : public basic_streambuf<char, char_traits<char> > 
williamr@2
    55
#else
williamr@2
    56
class _STLP_CLASS_DECLSPEC strstreambuf : public basic_streambuf<char, char_traits<char> >
williamr@2
    57
#endif
williamr@2
    58
{
williamr@2
    59
public:                         // Types.
williamr@2
    60
  typedef char_traits<char>              _Traits;
williamr@2
    61
  typedef basic_streambuf<char, char_traits<char> > _Base;
williamr@2
    62
  typedef void* (*__alloc_fn)(size_t);
williamr@2
    63
  typedef void (*__free_fn)(void*);
williamr@2
    64
public:                         // Constructor, destructor
williamr@2
    65
williamr@2
    66
  explicit strstreambuf(streamsize _Initial_capacity = 0);
williamr@2
    67
williamr@2
    68
  _STLP_DECLSPEC strstreambuf(__alloc_fn, __free_fn);
williamr@2
    69
williamr@2
    70
  _STLP_DECLSPEC strstreambuf(char* __get, streamsize __n, char* __put = 0);
williamr@2
    71
  _STLP_DECLSPEC strstreambuf(signed char* __get, streamsize __n, signed char* __put = 0);
williamr@2
    72
  _STLP_DECLSPEC strstreambuf(unsigned char* __get, streamsize __n, unsigned char* __put=0);
williamr@2
    73
williamr@2
    74
  _STLP_DECLSPEC strstreambuf(const char* __get, streamsize __n);
williamr@2
    75
  _STLP_DECLSPEC strstreambuf(const signed char* __get, streamsize __n);
williamr@2
    76
  _STLP_DECLSPEC strstreambuf(const unsigned char* __get, streamsize __n);
williamr@2
    77
williamr@2
    78
  virtual ~strstreambuf();
williamr@2
    79
williamr@2
    80
public:                         // strstreambuf operations.
williamr@2
    81
  _STLP_DECLSPEC void freeze(bool = true);
williamr@2
    82
  _STLP_DECLSPEC char* str();
williamr@2
    83
  _STLP_DECLSPEC int pcount() const;
williamr@2
    84
williamr@2
    85
protected:                      // Overridden virtual member functions.
williamr@2
    86
  virtual int_type overflow(int_type __c  = _Traits::eof());
williamr@2
    87
  virtual int_type pbackfail(int_type __c = _Traits::eof());
williamr@2
    88
  virtual int_type underflow();
williamr@2
    89
  virtual _Base* setbuf(char* __buf, streamsize __n);
williamr@2
    90
  virtual pos_type seekoff(off_type __off, ios_base::seekdir __dir,
williamr@2
    91
                           ios_base::openmode __mode 
williamr@2
    92
                                      = ios_base::in | ios_base::out);
williamr@2
    93
  virtual pos_type seekpos(pos_type __pos, ios_base::openmode __mode 
williamr@2
    94
                                      = ios_base::in | ios_base::out);
williamr@2
    95
williamr@2
    96
private:                        // Helper functions.
williamr@2
    97
  // Dynamic allocation, possibly using _M_alloc_fun and _M_free_fun.
williamr@2
    98
  char* _M_alloc(size_t);
williamr@2
    99
  inline void  _M_free(char*);
williamr@2
   100
williamr@2
   101
  // Helper function used in constructors.
williamr@2
   102
  void _M_setup(char* __get, char* __put, streamsize __n);
williamr@2
   103
private:                        // Data members.
williamr@2
   104
  __alloc_fn _M_alloc_fun;
williamr@2
   105
  __free_fn  _M_free_fun;
williamr@2
   106
  bool _M_dynamic  : 1;
williamr@2
   107
  bool _M_frozen   : 1;
williamr@2
   108
  bool _M_constant : 1;
williamr@2
   109
#ifdef __SYMBIAN32__
williamr@2
   110
  char* _pfrozenendsave;
williamr@2
   111
  char* _pgetfrozenendsave;
williamr@2
   112
#endif
williamr@2
   113
};
williamr@2
   114
williamr@2
   115
inline strstreambuf::~strstreambuf()
williamr@2
   116
{
williamr@2
   117
#ifdef __SYMBIAN32__
williamr@2
   118
  if (_M_dynamic && !_M_frozen)
williamr@2
   119
  {
williamr@2
   120
  	if (_M_free_fun)
williamr@2
   121
  		_M_free_fun(eback());
williamr@2
   122
  	else
williamr@2
   123
  		_M_free(eback());
williamr@2
   124
  }
williamr@2
   125
#else  
williamr@2
   126
	if (_M_dynamic && !_M_frozen)
williamr@2
   127
        _M_free(eback());
williamr@2
   128
#endif	
williamr@2
   129
}
williamr@2
   130
williamr@2
   131
inline void strstreambuf::_M_free(char* p)
williamr@2
   132
{
williamr@2
   133
  if (p)
williamr@2
   134
    if (_M_free_fun)
williamr@2
   135
      _M_free_fun(p);
williamr@2
   136
    else
williamr@2
   137
      delete[] p;
williamr@2
   138
}
williamr@2
   139
williamr@2
   140
williamr@2
   141
//----------------------------------------------------------------------
williamr@2
   142
// Class istrstream, an istream that manages a strstreambuf.
williamr@2
   143
williamr@2
   144
#ifdef __SYMBIAN32__
williamr@2
   145
NONSHARABLE_CLASS (istrstream) : public basic_istream<char, char_traits<char> >
williamr@2
   146
#else
williamr@2
   147
class _STLP_CLASS_DECLSPEC istrstream : public basic_istream<char, char_traits<char> >
williamr@2
   148
#endif
williamr@2
   149
{
williamr@2
   150
public:
williamr@2
   151
  _STLP_DECLSPEC explicit istrstream(char*);
williamr@2
   152
  _STLP_DECLSPEC explicit istrstream(const char*);
williamr@2
   153
  _STLP_DECLSPEC istrstream(char* , streamsize);
williamr@2
   154
  _STLP_DECLSPEC istrstream(const char*, streamsize);
williamr@2
   155
  virtual ~istrstream();
williamr@2
   156
  
williamr@2
   157
  _STLP_DECLSPEC strstreambuf* rdbuf() const;
williamr@2
   158
  _STLP_DECLSPEC char* str();
williamr@2
   159
williamr@2
   160
private:
williamr@2
   161
  strstreambuf _M_buf;
williamr@2
   162
};
williamr@2
   163
williamr@2
   164
//----------------------------------------------------------------------
williamr@2
   165
// Class ostrstream
williamr@2
   166
#ifdef __SYMBIAN32__
williamr@2
   167
NONSHARABLE_CLASS (ostrstream) : public basic_ostream<char, char_traits<char> >
williamr@2
   168
#else
williamr@2
   169
class _STLP_CLASS_DECLSPEC ostrstream : public basic_ostream<char, char_traits<char> >
williamr@2
   170
#endif
williamr@2
   171
{
williamr@2
   172
public:
williamr@2
   173
  _STLP_DECLSPEC ostrstream();
williamr@2
   174
  _STLP_DECLSPEC ostrstream(char*, int, ios_base::openmode = ios_base::out);
williamr@2
   175
  virtual ~ostrstream();
williamr@2
   176
williamr@2
   177
  _STLP_DECLSPEC strstreambuf* rdbuf() const;
williamr@2
   178
  _STLP_DECLSPEC void freeze(bool = true);
williamr@2
   179
  _STLP_DECLSPEC char* str();
williamr@2
   180
  _STLP_DECLSPEC int pcount() const;
williamr@2
   181
williamr@2
   182
private:
williamr@2
   183
  strstreambuf _M_buf;
williamr@2
   184
};
williamr@2
   185
williamr@2
   186
//----------------------------------------------------------------------
williamr@2
   187
// Class strstream
williamr@2
   188
#ifdef __SYMBIAN32__
williamr@2
   189
NONSHARABLE_CLASS (strstream) : public basic_iostream<char, char_traits<char> >
williamr@2
   190
#else
williamr@2
   191
class _STLP_CLASS_DECLSPEC strstream : public basic_iostream<char, char_traits<char> >
williamr@2
   192
#endif
williamr@2
   193
{
williamr@2
   194
public:
williamr@2
   195
  typedef char                        char_type;
williamr@2
   196
  typedef char_traits<char>::int_type int_type;
williamr@2
   197
  typedef char_traits<char>::pos_type pos_type;
williamr@2
   198
  typedef char_traits<char>::off_type off_type;
williamr@2
   199
williamr@2
   200
  _STLP_DECLSPEC strstream();
williamr@2
   201
  _STLP_DECLSPEC strstream(char*, int, ios_base::openmode = ios_base::in | ios_base::out);
williamr@2
   202
  virtual ~strstream();
williamr@2
   203
williamr@2
   204
  _STLP_DECLSPEC strstreambuf* rdbuf() const;
williamr@2
   205
  _STLP_DECLSPEC void freeze(bool = true);
williamr@2
   206
  _STLP_DECLSPEC int pcount() const;
williamr@2
   207
  _STLP_DECLSPEC char* str();
williamr@2
   208
williamr@2
   209
private:
williamr@2
   210
  strstreambuf _M_buf;
williamr@2
   211
};
williamr@2
   212
williamr@2
   213
_STLP_END_NAMESPACE