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