epoc32/include/stdapis/stlport/stl/_strstream.h
branchSymbian2
changeset 2 2fe1408b6811
parent 0 061f57f2323e
     1.1 --- a/epoc32/include/stdapis/stlport/stl/_strstream.h	Tue Nov 24 13:55:44 2009 +0000
     1.2 +++ b/epoc32/include/stdapis/stlport/stl/_strstream.h	Tue Mar 16 16:12:26 2010 +0000
     1.3 @@ -1,1 +1,213 @@
     1.4 -_strstream.h
     1.5 +/*
     1.6 +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
     1.7 +
     1.8 +* Redistribution and use in source and binary forms, with or without 
     1.9 +* modification, are permitted provided that the following conditions are met:
    1.10 +
    1.11 +* Redistributions of source code must retain the above copyright notice, this 
    1.12 +* list of conditions and the following disclaimer.
    1.13 +* Redistributions in binary form must reproduce the above copyright notice, 
    1.14 +* this list of conditions and the following disclaimer in the documentation 
    1.15 +* and/or other materials provided with the distribution.
    1.16 +* Neither the name of Nokia Corporation nor the names of its contributors 
    1.17 +* may be used to endorse or promote products derived from this software 
    1.18 +* without specific prior written permission.
    1.19 +
    1.20 +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
    1.21 +* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
    1.22 +* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
    1.23 +* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 
    1.24 +* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
    1.25 +* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
    1.26 +* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
    1.27 +* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 
    1.28 +* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
    1.29 +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    1.30 +*
    1.31 +* Description:
    1.32 +*
    1.33 +*/
    1.34 +
    1.35 +#ifndef _STLP_INTERNAL_STREAMBUF
    1.36 +#include <stl/_streambuf.h>
    1.37 +#endif
    1.38 +#ifndef _STLP_ISTREAM
    1.39 +#include <istream>              // Includes <ostream>, <ios>, <iosfwd>
    1.40 +#endif
    1.41 +#ifndef _STLP_STRING_H
    1.42 +#include <stl/_string.h>
    1.43 +#endif
    1.44 +
    1.45 +_STLP_BEGIN_NAMESPACE
    1.46 +
    1.47 +#ifndef _STLP_USE_NAMESPACES
    1.48 +# define strstream _STLP_strstream 
    1.49 +# define ostrstream _STLP_ostrstream
    1.50 +# define istrstream _STLP_istrstream
    1.51 +# define strstreambuf _STLP_strstreambuf
    1.52 +#endif
    1.53 +
    1.54 +//----------------------------------------------------------------------
    1.55 +// Class strstreambuf, a streambuf class that manages an array of char.
    1.56 +// Note that this class is not a template.
    1.57 +#ifdef __SYMBIAN32__
    1.58 +class strstreambuf : public basic_streambuf<char, char_traits<char> > 
    1.59 +#else
    1.60 +class _STLP_CLASS_DECLSPEC strstreambuf : public basic_streambuf<char, char_traits<char> >
    1.61 +#endif
    1.62 +{
    1.63 +public:                         // Types.
    1.64 +  typedef char_traits<char>              _Traits;
    1.65 +  typedef basic_streambuf<char, char_traits<char> > _Base;
    1.66 +  typedef void* (*__alloc_fn)(size_t);
    1.67 +  typedef void (*__free_fn)(void*);
    1.68 +public:                         // Constructor, destructor
    1.69 +
    1.70 +  explicit strstreambuf(streamsize _Initial_capacity = 0);
    1.71 +
    1.72 +  _STLP_DECLSPEC strstreambuf(__alloc_fn, __free_fn);
    1.73 +
    1.74 +  _STLP_DECLSPEC strstreambuf(char* __get, streamsize __n, char* __put = 0);
    1.75 +  _STLP_DECLSPEC strstreambuf(signed char* __get, streamsize __n, signed char* __put = 0);
    1.76 +  _STLP_DECLSPEC strstreambuf(unsigned char* __get, streamsize __n, unsigned char* __put=0);
    1.77 +
    1.78 +  _STLP_DECLSPEC strstreambuf(const char* __get, streamsize __n);
    1.79 +  _STLP_DECLSPEC strstreambuf(const signed char* __get, streamsize __n);
    1.80 +  _STLP_DECLSPEC strstreambuf(const unsigned char* __get, streamsize __n);
    1.81 +
    1.82 +  virtual ~strstreambuf();
    1.83 +
    1.84 +public:                         // strstreambuf operations.
    1.85 +  _STLP_DECLSPEC void freeze(bool = true);
    1.86 +  _STLP_DECLSPEC char* str();
    1.87 +  _STLP_DECLSPEC int pcount() const;
    1.88 +
    1.89 +protected:                      // Overridden virtual member functions.
    1.90 +  virtual int_type overflow(int_type __c  = _Traits::eof());
    1.91 +  virtual int_type pbackfail(int_type __c = _Traits::eof());
    1.92 +  virtual int_type underflow();
    1.93 +  virtual _Base* setbuf(char* __buf, streamsize __n);
    1.94 +  virtual pos_type seekoff(off_type __off, ios_base::seekdir __dir,
    1.95 +                           ios_base::openmode __mode 
    1.96 +                                      = ios_base::in | ios_base::out);
    1.97 +  virtual pos_type seekpos(pos_type __pos, ios_base::openmode __mode 
    1.98 +                                      = ios_base::in | ios_base::out);
    1.99 +
   1.100 +private:                        // Helper functions.
   1.101 +  // Dynamic allocation, possibly using _M_alloc_fun and _M_free_fun.
   1.102 +  char* _M_alloc(size_t);
   1.103 +  inline void  _M_free(char*);
   1.104 +
   1.105 +  // Helper function used in constructors.
   1.106 +  void _M_setup(char* __get, char* __put, streamsize __n);
   1.107 +private:                        // Data members.
   1.108 +  __alloc_fn _M_alloc_fun;
   1.109 +  __free_fn  _M_free_fun;
   1.110 +  bool _M_dynamic  : 1;
   1.111 +  bool _M_frozen   : 1;
   1.112 +  bool _M_constant : 1;
   1.113 +#ifdef __SYMBIAN32__
   1.114 +  char* _pfrozenendsave;
   1.115 +  char* _pgetfrozenendsave;
   1.116 +#endif
   1.117 +};
   1.118 +
   1.119 +inline strstreambuf::~strstreambuf()
   1.120 +{
   1.121 +#ifdef __SYMBIAN32__
   1.122 +  if (_M_dynamic && !_M_frozen)
   1.123 +  {
   1.124 +  	if (_M_free_fun)
   1.125 +  		_M_free_fun(eback());
   1.126 +  	else
   1.127 +  		_M_free(eback());
   1.128 +  }
   1.129 +#else  
   1.130 +	if (_M_dynamic && !_M_frozen)
   1.131 +        _M_free(eback());
   1.132 +#endif	
   1.133 +}
   1.134 +
   1.135 +inline void strstreambuf::_M_free(char* p)
   1.136 +{
   1.137 +  if (p)
   1.138 +    if (_M_free_fun)
   1.139 +      _M_free_fun(p);
   1.140 +    else
   1.141 +      delete[] p;
   1.142 +}
   1.143 +
   1.144 +
   1.145 +//----------------------------------------------------------------------
   1.146 +// Class istrstream, an istream that manages a strstreambuf.
   1.147 +
   1.148 +#ifdef __SYMBIAN32__
   1.149 +NONSHARABLE_CLASS (istrstream) : public basic_istream<char, char_traits<char> >
   1.150 +#else
   1.151 +class _STLP_CLASS_DECLSPEC istrstream : public basic_istream<char, char_traits<char> >
   1.152 +#endif
   1.153 +{
   1.154 +public:
   1.155 +  _STLP_DECLSPEC explicit istrstream(char*);
   1.156 +  _STLP_DECLSPEC explicit istrstream(const char*);
   1.157 +  _STLP_DECLSPEC istrstream(char* , streamsize);
   1.158 +  _STLP_DECLSPEC istrstream(const char*, streamsize);
   1.159 +  virtual ~istrstream();
   1.160 +  
   1.161 +  _STLP_DECLSPEC strstreambuf* rdbuf() const;
   1.162 +  _STLP_DECLSPEC char* str();
   1.163 +
   1.164 +private:
   1.165 +  strstreambuf _M_buf;
   1.166 +};
   1.167 +
   1.168 +//----------------------------------------------------------------------
   1.169 +// Class ostrstream
   1.170 +#ifdef __SYMBIAN32__
   1.171 +NONSHARABLE_CLASS (ostrstream) : public basic_ostream<char, char_traits<char> >
   1.172 +#else
   1.173 +class _STLP_CLASS_DECLSPEC ostrstream : public basic_ostream<char, char_traits<char> >
   1.174 +#endif
   1.175 +{
   1.176 +public:
   1.177 +  _STLP_DECLSPEC ostrstream();
   1.178 +  _STLP_DECLSPEC ostrstream(char*, int, ios_base::openmode = ios_base::out);
   1.179 +  virtual ~ostrstream();
   1.180 +
   1.181 +  _STLP_DECLSPEC strstreambuf* rdbuf() const;
   1.182 +  _STLP_DECLSPEC void freeze(bool = true);
   1.183 +  _STLP_DECLSPEC char* str();
   1.184 +  _STLP_DECLSPEC int pcount() const;
   1.185 +
   1.186 +private:
   1.187 +  strstreambuf _M_buf;
   1.188 +};
   1.189 +
   1.190 +//----------------------------------------------------------------------
   1.191 +// Class strstream
   1.192 +#ifdef __SYMBIAN32__
   1.193 +NONSHARABLE_CLASS (strstream) : public basic_iostream<char, char_traits<char> >
   1.194 +#else
   1.195 +class _STLP_CLASS_DECLSPEC strstream : public basic_iostream<char, char_traits<char> >
   1.196 +#endif
   1.197 +{
   1.198 +public:
   1.199 +  typedef char                        char_type;
   1.200 +  typedef char_traits<char>::int_type int_type;
   1.201 +  typedef char_traits<char>::pos_type pos_type;
   1.202 +  typedef char_traits<char>::off_type off_type;
   1.203 +
   1.204 +  _STLP_DECLSPEC strstream();
   1.205 +  _STLP_DECLSPEC strstream(char*, int, ios_base::openmode = ios_base::in | ios_base::out);
   1.206 +  virtual ~strstream();
   1.207 +
   1.208 +  _STLP_DECLSPEC strstreambuf* rdbuf() const;
   1.209 +  _STLP_DECLSPEC void freeze(bool = true);
   1.210 +  _STLP_DECLSPEC int pcount() const;
   1.211 +  _STLP_DECLSPEC char* str();
   1.212 +
   1.213 +private:
   1.214 +  strstreambuf _M_buf;
   1.215 +};
   1.216 +
   1.217 +_STLP_END_NAMESPACE