williamr@4: /* williamr@4: * © Portions copyright (c) 2006-2007 Nokia Corporation. All rights reserved. williamr@4: * williamr@4: * Copyright (c) 1999 williamr@4: * Silicon Graphics Computer Systems, Inc. williamr@4: * williamr@4: * Copyright (c) 1999 williamr@4: * Boris Fomitchev williamr@4: * williamr@4: * This material is provided "as is", with absolutely no warranty expressed williamr@4: * or implied. Any use is at your own risk. williamr@4: * williamr@4: * Permission to use or copy this software for any purpose is hereby granted williamr@4: * without fee, provided the above notices are retained on all copies. williamr@4: * Permission to modify the code and to distribute modified code is granted, williamr@4: * provided the above notices are retained, and a notice that the code was williamr@4: * modified is included with the above copyright notice. williamr@4: * williamr@4: */ williamr@4: williamr@4: williamr@4: williamr@4: #ifndef _STLP_INTERNAL_STREAMBUF williamr@4: #include williamr@4: #endif williamr@4: #ifndef _STLP_ISTREAM williamr@4: #include // Includes , , williamr@4: #endif williamr@4: #ifndef _STLP_STRING_H williamr@4: #include williamr@4: #endif williamr@4: williamr@4: _STLP_BEGIN_NAMESPACE williamr@4: williamr@4: #ifndef _STLP_USE_NAMESPACES williamr@4: # define strstream _STLP_strstream williamr@4: # define ostrstream _STLP_ostrstream williamr@4: # define istrstream _STLP_istrstream williamr@4: # define strstreambuf _STLP_strstreambuf williamr@4: #endif williamr@4: williamr@4: //---------------------------------------------------------------------- williamr@4: // Class strstreambuf, a streambuf class that manages an array of char. williamr@4: // Note that this class is not a template. williamr@4: #ifdef __SYMBIAN32__ williamr@4: class strstreambuf : public basic_streambuf > williamr@4: #else williamr@4: class _STLP_CLASS_DECLSPEC strstreambuf : public basic_streambuf > williamr@4: #endif williamr@4: { williamr@4: public: // Types. williamr@4: typedef char_traits _Traits; williamr@4: typedef basic_streambuf > _Base; williamr@4: typedef void* (*__alloc_fn)(size_t); williamr@4: typedef void (*__free_fn)(void*); williamr@4: public: // Constructor, destructor williamr@4: williamr@4: explicit strstreambuf(streamsize _Initial_capacity = 0); williamr@4: williamr@4: _STLP_DECLSPEC strstreambuf(__alloc_fn, __free_fn); williamr@4: williamr@4: _STLP_DECLSPEC strstreambuf(char* __get, streamsize __n, char* __put = 0); williamr@4: _STLP_DECLSPEC strstreambuf(signed char* __get, streamsize __n, signed char* __put = 0); williamr@4: _STLP_DECLSPEC strstreambuf(unsigned char* __get, streamsize __n, unsigned char* __put=0); williamr@4: williamr@4: _STLP_DECLSPEC strstreambuf(const char* __get, streamsize __n); williamr@4: _STLP_DECLSPEC strstreambuf(const signed char* __get, streamsize __n); williamr@4: _STLP_DECLSPEC strstreambuf(const unsigned char* __get, streamsize __n); williamr@4: williamr@4: virtual ~strstreambuf(); williamr@4: williamr@4: public: // strstreambuf operations. williamr@4: _STLP_DECLSPEC void freeze(bool = true); williamr@4: _STLP_DECLSPEC char* str(); williamr@4: _STLP_DECLSPEC int pcount() const; williamr@4: williamr@4: protected: // Overridden virtual member functions. williamr@4: virtual int_type overflow(int_type __c = _Traits::eof()); williamr@4: virtual int_type pbackfail(int_type __c = _Traits::eof()); williamr@4: virtual int_type underflow(); williamr@4: virtual _Base* setbuf(char* __buf, streamsize __n); williamr@4: virtual pos_type seekoff(off_type __off, ios_base::seekdir __dir, williamr@4: ios_base::openmode __mode williamr@4: = ios_base::in | ios_base::out); williamr@4: virtual pos_type seekpos(pos_type __pos, ios_base::openmode __mode williamr@4: = ios_base::in | ios_base::out); williamr@4: williamr@4: private: // Helper functions. williamr@4: // Dynamic allocation, possibly using _M_alloc_fun and _M_free_fun. williamr@4: char* _M_alloc(size_t); williamr@4: inline void _M_free(char*); williamr@4: williamr@4: // Helper function used in constructors. williamr@4: void _M_setup(char* __get, char* __put, streamsize __n); williamr@4: private: // Data members. williamr@4: __alloc_fn _M_alloc_fun; williamr@4: __free_fn _M_free_fun; williamr@4: bool _M_dynamic : 1; williamr@4: bool _M_frozen : 1; williamr@4: bool _M_constant : 1; williamr@4: #ifdef __SYMBIAN32__ williamr@4: char* _pfrozenendsave; williamr@4: char* _pgetfrozenendsave; williamr@4: #endif williamr@4: }; williamr@4: williamr@4: inline strstreambuf::~strstreambuf() williamr@4: { williamr@4: #ifdef __SYMBIAN32__ williamr@4: if (_M_dynamic && !_M_frozen) williamr@4: { williamr@4: if (_M_free_fun) williamr@4: _M_free_fun(eback()); williamr@4: else williamr@4: _M_free(eback()); williamr@4: } williamr@4: #else williamr@4: if (_M_dynamic && !_M_frozen) williamr@4: _M_free(eback()); williamr@4: #endif williamr@4: } williamr@4: williamr@4: inline void strstreambuf::_M_free(char* p) williamr@4: { williamr@4: if (p) williamr@4: if (_M_free_fun) williamr@4: _M_free_fun(p); williamr@4: else williamr@4: delete[] p; williamr@4: } williamr@4: williamr@4: williamr@4: //---------------------------------------------------------------------- williamr@4: // Class istrstream, an istream that manages a strstreambuf. williamr@4: williamr@4: #ifdef __SYMBIAN32__ williamr@4: NONSHARABLE_CLASS (istrstream) : public basic_istream > williamr@4: #else williamr@4: class _STLP_CLASS_DECLSPEC istrstream : public basic_istream > williamr@4: #endif williamr@4: { williamr@4: public: williamr@4: _STLP_DECLSPEC explicit istrstream(char*); williamr@4: _STLP_DECLSPEC explicit istrstream(const char*); williamr@4: _STLP_DECLSPEC istrstream(char* , streamsize); williamr@4: _STLP_DECLSPEC istrstream(const char*, streamsize); williamr@4: virtual ~istrstream(); williamr@4: williamr@4: _STLP_DECLSPEC strstreambuf* rdbuf() const; williamr@4: _STLP_DECLSPEC char* str(); williamr@4: williamr@4: private: williamr@4: strstreambuf _M_buf; williamr@4: }; williamr@4: williamr@4: //---------------------------------------------------------------------- williamr@4: // Class ostrstream williamr@4: #ifdef __SYMBIAN32__ williamr@4: NONSHARABLE_CLASS (ostrstream) : public basic_ostream > williamr@4: #else williamr@4: class _STLP_CLASS_DECLSPEC ostrstream : public basic_ostream > williamr@4: #endif williamr@4: { williamr@4: public: williamr@4: _STLP_DECLSPEC ostrstream(); williamr@4: _STLP_DECLSPEC ostrstream(char*, int, ios_base::openmode = ios_base::out); williamr@4: virtual ~ostrstream(); williamr@4: williamr@4: _STLP_DECLSPEC strstreambuf* rdbuf() const; williamr@4: _STLP_DECLSPEC void freeze(bool = true); williamr@4: _STLP_DECLSPEC char* str(); williamr@4: _STLP_DECLSPEC int pcount() const; williamr@4: williamr@4: private: williamr@4: strstreambuf _M_buf; williamr@4: }; williamr@4: williamr@4: //---------------------------------------------------------------------- williamr@4: // Class strstream williamr@4: #ifdef __SYMBIAN32__ williamr@4: NONSHARABLE_CLASS (strstream) : public basic_iostream > williamr@4: #else williamr@4: class _STLP_CLASS_DECLSPEC strstream : public basic_iostream > williamr@4: #endif williamr@4: { williamr@4: public: williamr@4: typedef char char_type; williamr@4: typedef char_traits::int_type int_type; williamr@4: typedef char_traits::pos_type pos_type; williamr@4: typedef char_traits::off_type off_type; williamr@4: williamr@4: _STLP_DECLSPEC strstream(); williamr@4: _STLP_DECLSPEC strstream(char*, int, ios_base::openmode = ios_base::in | ios_base::out); williamr@4: virtual ~strstream(); williamr@4: williamr@4: _STLP_DECLSPEC strstreambuf* rdbuf() const; williamr@4: _STLP_DECLSPEC void freeze(bool = true); williamr@4: _STLP_DECLSPEC int pcount() const; williamr@4: _STLP_DECLSPEC char* str(); williamr@4: williamr@4: private: williamr@4: strstreambuf _M_buf; williamr@4: }; williamr@4: williamr@4: _STLP_END_NAMESPACE