williamr@2: /* williamr@2: * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved. williamr@2: williamr@2: * Redistribution and use in source and binary forms, with or without williamr@2: * modification, are permitted provided that the following conditions are met: williamr@2: williamr@2: * Redistributions of source code must retain the above copyright notice, this williamr@2: * list of conditions and the following disclaimer. williamr@2: * Redistributions in binary form must reproduce the above copyright notice, williamr@2: * this list of conditions and the following disclaimer in the documentation williamr@2: * and/or other materials provided with the distribution. williamr@2: * Neither the name of Nokia Corporation nor the names of its contributors williamr@2: * may be used to endorse or promote products derived from this software williamr@2: * without specific prior written permission. williamr@2: williamr@2: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" williamr@2: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE williamr@2: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE williamr@2: * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE williamr@2: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL williamr@2: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR williamr@2: * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER williamr@2: * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, williamr@2: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE williamr@2: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. williamr@2: * williamr@2: * Description: williamr@2: * williamr@2: */ williamr@2: williamr@2: #ifndef _STLP_INTERNAL_STREAMBUF williamr@2: #include williamr@2: #endif williamr@2: #ifndef _STLP_ISTREAM williamr@2: #include // Includes , , williamr@2: #endif williamr@2: #ifndef _STLP_STRING_H williamr@2: #include williamr@2: #endif williamr@2: williamr@2: _STLP_BEGIN_NAMESPACE williamr@2: williamr@2: #ifndef _STLP_USE_NAMESPACES williamr@2: # define strstream _STLP_strstream williamr@2: # define ostrstream _STLP_ostrstream williamr@2: # define istrstream _STLP_istrstream williamr@2: # define strstreambuf _STLP_strstreambuf williamr@2: #endif williamr@2: williamr@2: //---------------------------------------------------------------------- williamr@2: // Class strstreambuf, a streambuf class that manages an array of char. williamr@2: // Note that this class is not a template. williamr@2: #ifdef __SYMBIAN32__ williamr@2: class strstreambuf : public basic_streambuf > williamr@2: #else williamr@2: class _STLP_CLASS_DECLSPEC strstreambuf : public basic_streambuf > williamr@2: #endif williamr@2: { williamr@2: public: // Types. williamr@2: typedef char_traits _Traits; williamr@2: typedef basic_streambuf > _Base; williamr@2: typedef void* (*__alloc_fn)(size_t); williamr@2: typedef void (*__free_fn)(void*); williamr@2: public: // Constructor, destructor williamr@2: williamr@2: explicit strstreambuf(streamsize _Initial_capacity = 0); williamr@2: williamr@2: _STLP_DECLSPEC strstreambuf(__alloc_fn, __free_fn); williamr@2: williamr@2: _STLP_DECLSPEC strstreambuf(char* __get, streamsize __n, char* __put = 0); williamr@2: _STLP_DECLSPEC strstreambuf(signed char* __get, streamsize __n, signed char* __put = 0); williamr@2: _STLP_DECLSPEC strstreambuf(unsigned char* __get, streamsize __n, unsigned char* __put=0); williamr@2: williamr@2: _STLP_DECLSPEC strstreambuf(const char* __get, streamsize __n); williamr@2: _STLP_DECLSPEC strstreambuf(const signed char* __get, streamsize __n); williamr@2: _STLP_DECLSPEC strstreambuf(const unsigned char* __get, streamsize __n); williamr@2: williamr@2: virtual ~strstreambuf(); williamr@2: williamr@2: public: // strstreambuf operations. williamr@2: _STLP_DECLSPEC void freeze(bool = true); williamr@2: _STLP_DECLSPEC char* str(); williamr@2: _STLP_DECLSPEC int pcount() const; williamr@2: williamr@2: protected: // Overridden virtual member functions. williamr@2: virtual int_type overflow(int_type __c = _Traits::eof()); williamr@2: virtual int_type pbackfail(int_type __c = _Traits::eof()); williamr@2: virtual int_type underflow(); williamr@2: virtual _Base* setbuf(char* __buf, streamsize __n); williamr@2: virtual pos_type seekoff(off_type __off, ios_base::seekdir __dir, williamr@2: ios_base::openmode __mode williamr@2: = ios_base::in | ios_base::out); williamr@2: virtual pos_type seekpos(pos_type __pos, ios_base::openmode __mode williamr@2: = ios_base::in | ios_base::out); williamr@2: williamr@2: private: // Helper functions. williamr@2: // Dynamic allocation, possibly using _M_alloc_fun and _M_free_fun. williamr@2: char* _M_alloc(size_t); williamr@2: inline void _M_free(char*); williamr@2: williamr@2: // Helper function used in constructors. williamr@2: void _M_setup(char* __get, char* __put, streamsize __n); williamr@2: private: // Data members. williamr@2: __alloc_fn _M_alloc_fun; williamr@2: __free_fn _M_free_fun; williamr@2: bool _M_dynamic : 1; williamr@2: bool _M_frozen : 1; williamr@2: bool _M_constant : 1; williamr@2: #ifdef __SYMBIAN32__ williamr@2: char* _pfrozenendsave; williamr@2: char* _pgetfrozenendsave; williamr@2: #endif williamr@2: }; williamr@2: williamr@2: inline strstreambuf::~strstreambuf() williamr@2: { williamr@2: #ifdef __SYMBIAN32__ williamr@2: if (_M_dynamic && !_M_frozen) williamr@2: { williamr@2: if (_M_free_fun) williamr@2: _M_free_fun(eback()); williamr@2: else williamr@2: _M_free(eback()); williamr@2: } williamr@2: #else williamr@2: if (_M_dynamic && !_M_frozen) williamr@2: _M_free(eback()); williamr@2: #endif williamr@2: } williamr@2: williamr@2: inline void strstreambuf::_M_free(char* p) williamr@2: { williamr@2: if (p) williamr@2: if (_M_free_fun) williamr@2: _M_free_fun(p); williamr@2: else williamr@2: delete[] p; williamr@2: } williamr@2: williamr@2: williamr@2: //---------------------------------------------------------------------- williamr@2: // Class istrstream, an istream that manages a strstreambuf. williamr@2: williamr@2: #ifdef __SYMBIAN32__ williamr@2: NONSHARABLE_CLASS (istrstream) : public basic_istream > williamr@2: #else williamr@2: class _STLP_CLASS_DECLSPEC istrstream : public basic_istream > williamr@2: #endif williamr@2: { williamr@2: public: williamr@2: _STLP_DECLSPEC explicit istrstream(char*); williamr@2: _STLP_DECLSPEC explicit istrstream(const char*); williamr@2: _STLP_DECLSPEC istrstream(char* , streamsize); williamr@2: _STLP_DECLSPEC istrstream(const char*, streamsize); williamr@2: virtual ~istrstream(); williamr@2: williamr@2: _STLP_DECLSPEC strstreambuf* rdbuf() const; williamr@2: _STLP_DECLSPEC char* str(); williamr@2: williamr@2: private: williamr@2: strstreambuf _M_buf; williamr@2: }; williamr@2: williamr@2: //---------------------------------------------------------------------- williamr@2: // Class ostrstream williamr@2: #ifdef __SYMBIAN32__ williamr@2: NONSHARABLE_CLASS (ostrstream) : public basic_ostream > williamr@2: #else williamr@2: class _STLP_CLASS_DECLSPEC ostrstream : public basic_ostream > williamr@2: #endif williamr@2: { williamr@2: public: williamr@2: _STLP_DECLSPEC ostrstream(); williamr@2: _STLP_DECLSPEC ostrstream(char*, int, ios_base::openmode = ios_base::out); williamr@2: virtual ~ostrstream(); williamr@2: williamr@2: _STLP_DECLSPEC strstreambuf* rdbuf() const; williamr@2: _STLP_DECLSPEC void freeze(bool = true); williamr@2: _STLP_DECLSPEC char* str(); williamr@2: _STLP_DECLSPEC int pcount() const; williamr@2: williamr@2: private: williamr@2: strstreambuf _M_buf; williamr@2: }; williamr@2: williamr@2: //---------------------------------------------------------------------- williamr@2: // Class strstream williamr@2: #ifdef __SYMBIAN32__ williamr@2: NONSHARABLE_CLASS (strstream) : public basic_iostream > williamr@2: #else williamr@2: class _STLP_CLASS_DECLSPEC strstream : public basic_iostream > williamr@2: #endif williamr@2: { williamr@2: public: williamr@2: typedef char char_type; williamr@2: typedef char_traits::int_type int_type; williamr@2: typedef char_traits::pos_type pos_type; williamr@2: typedef char_traits::off_type off_type; williamr@2: williamr@2: _STLP_DECLSPEC strstream(); williamr@2: _STLP_DECLSPEC strstream(char*, int, ios_base::openmode = ios_base::in | ios_base::out); williamr@2: virtual ~strstream(); williamr@2: williamr@2: _STLP_DECLSPEC strstreambuf* rdbuf() const; williamr@2: _STLP_DECLSPEC void freeze(bool = true); williamr@2: _STLP_DECLSPEC int pcount() const; williamr@2: _STLP_DECLSPEC char* str(); williamr@2: williamr@2: private: williamr@2: strstreambuf _M_buf; williamr@2: }; williamr@2: williamr@2: _STLP_END_NAMESPACE