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