1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/epoc32/include/stdapis/stlport/stl/_strstream.h Wed Mar 31 12:33:34 2010 +0100
1.3 @@ -0,0 +1,205 @@
1.4 +/*
1.5 + * © Portions copyright (c) 2006-2007 Nokia Corporation. All rights reserved.
1.6 + *
1.7 + * Copyright (c) 1999
1.8 + * Silicon Graphics Computer Systems, Inc.
1.9 + *
1.10 + * Copyright (c) 1999
1.11 + * Boris Fomitchev
1.12 + *
1.13 + * This material is provided "as is", with absolutely no warranty expressed
1.14 + * or implied. Any use is at your own risk.
1.15 + *
1.16 + * Permission to use or copy this software for any purpose is hereby granted
1.17 + * without fee, provided the above notices are retained on all copies.
1.18 + * Permission to modify the code and to distribute modified code is granted,
1.19 + * provided the above notices are retained, and a notice that the code was
1.20 + * modified is included with the above copyright notice.
1.21 + *
1.22 + */
1.23 +
1.24 +
1.25 +
1.26 +#ifndef _STLP_INTERNAL_STREAMBUF
1.27 +#include <stl/_streambuf.h>
1.28 +#endif
1.29 +#ifndef _STLP_ISTREAM
1.30 +#include <istream> // Includes <ostream>, <ios>, <iosfwd>
1.31 +#endif
1.32 +#ifndef _STLP_STRING_H
1.33 +#include <stl/_string.h>
1.34 +#endif
1.35 +
1.36 +_STLP_BEGIN_NAMESPACE
1.37 +
1.38 +#ifndef _STLP_USE_NAMESPACES
1.39 +# define strstream _STLP_strstream
1.40 +# define ostrstream _STLP_ostrstream
1.41 +# define istrstream _STLP_istrstream
1.42 +# define strstreambuf _STLP_strstreambuf
1.43 +#endif
1.44 +
1.45 +//----------------------------------------------------------------------
1.46 +// Class strstreambuf, a streambuf class that manages an array of char.
1.47 +// Note that this class is not a template.
1.48 +#ifdef __SYMBIAN32__
1.49 +class strstreambuf : public basic_streambuf<char, char_traits<char> >
1.50 +#else
1.51 +class _STLP_CLASS_DECLSPEC strstreambuf : public basic_streambuf<char, char_traits<char> >
1.52 +#endif
1.53 +{
1.54 +public: // Types.
1.55 + typedef char_traits<char> _Traits;
1.56 + typedef basic_streambuf<char, char_traits<char> > _Base;
1.57 + typedef void* (*__alloc_fn)(size_t);
1.58 + typedef void (*__free_fn)(void*);
1.59 +public: // Constructor, destructor
1.60 +
1.61 + explicit strstreambuf(streamsize _Initial_capacity = 0);
1.62 +
1.63 + _STLP_DECLSPEC strstreambuf(__alloc_fn, __free_fn);
1.64 +
1.65 + _STLP_DECLSPEC strstreambuf(char* __get, streamsize __n, char* __put = 0);
1.66 + _STLP_DECLSPEC strstreambuf(signed char* __get, streamsize __n, signed char* __put = 0);
1.67 + _STLP_DECLSPEC strstreambuf(unsigned char* __get, streamsize __n, unsigned char* __put=0);
1.68 +
1.69 + _STLP_DECLSPEC strstreambuf(const char* __get, streamsize __n);
1.70 + _STLP_DECLSPEC strstreambuf(const signed char* __get, streamsize __n);
1.71 + _STLP_DECLSPEC strstreambuf(const unsigned char* __get, streamsize __n);
1.72 +
1.73 + virtual ~strstreambuf();
1.74 +
1.75 +public: // strstreambuf operations.
1.76 + _STLP_DECLSPEC void freeze(bool = true);
1.77 + _STLP_DECLSPEC char* str();
1.78 + _STLP_DECLSPEC int pcount() const;
1.79 +
1.80 +protected: // Overridden virtual member functions.
1.81 + virtual int_type overflow(int_type __c = _Traits::eof());
1.82 + virtual int_type pbackfail(int_type __c = _Traits::eof());
1.83 + virtual int_type underflow();
1.84 + virtual _Base* setbuf(char* __buf, streamsize __n);
1.85 + virtual pos_type seekoff(off_type __off, ios_base::seekdir __dir,
1.86 + ios_base::openmode __mode
1.87 + = ios_base::in | ios_base::out);
1.88 + virtual pos_type seekpos(pos_type __pos, ios_base::openmode __mode
1.89 + = ios_base::in | ios_base::out);
1.90 +
1.91 +private: // Helper functions.
1.92 + // Dynamic allocation, possibly using _M_alloc_fun and _M_free_fun.
1.93 + char* _M_alloc(size_t);
1.94 + inline void _M_free(char*);
1.95 +
1.96 + // Helper function used in constructors.
1.97 + void _M_setup(char* __get, char* __put, streamsize __n);
1.98 +private: // Data members.
1.99 + __alloc_fn _M_alloc_fun;
1.100 + __free_fn _M_free_fun;
1.101 + bool _M_dynamic : 1;
1.102 + bool _M_frozen : 1;
1.103 + bool _M_constant : 1;
1.104 +#ifdef __SYMBIAN32__
1.105 + char* _pfrozenendsave;
1.106 + char* _pgetfrozenendsave;
1.107 +#endif
1.108 +};
1.109 +
1.110 +inline strstreambuf::~strstreambuf()
1.111 +{
1.112 +#ifdef __SYMBIAN32__
1.113 + if (_M_dynamic && !_M_frozen)
1.114 + {
1.115 + if (_M_free_fun)
1.116 + _M_free_fun(eback());
1.117 + else
1.118 + _M_free(eback());
1.119 + }
1.120 +#else
1.121 + if (_M_dynamic && !_M_frozen)
1.122 + _M_free(eback());
1.123 +#endif
1.124 +}
1.125 +
1.126 +inline void strstreambuf::_M_free(char* p)
1.127 +{
1.128 + if (p)
1.129 + if (_M_free_fun)
1.130 + _M_free_fun(p);
1.131 + else
1.132 + delete[] p;
1.133 +}
1.134 +
1.135 +
1.136 +//----------------------------------------------------------------------
1.137 +// Class istrstream, an istream that manages a strstreambuf.
1.138 +
1.139 +#ifdef __SYMBIAN32__
1.140 +NONSHARABLE_CLASS (istrstream) : public basic_istream<char, char_traits<char> >
1.141 +#else
1.142 +class _STLP_CLASS_DECLSPEC istrstream : public basic_istream<char, char_traits<char> >
1.143 +#endif
1.144 +{
1.145 +public:
1.146 + _STLP_DECLSPEC explicit istrstream(char*);
1.147 + _STLP_DECLSPEC explicit istrstream(const char*);
1.148 + _STLP_DECLSPEC istrstream(char* , streamsize);
1.149 + _STLP_DECLSPEC istrstream(const char*, streamsize);
1.150 + virtual ~istrstream();
1.151 +
1.152 + _STLP_DECLSPEC strstreambuf* rdbuf() const;
1.153 + _STLP_DECLSPEC char* str();
1.154 +
1.155 +private:
1.156 + strstreambuf _M_buf;
1.157 +};
1.158 +
1.159 +//----------------------------------------------------------------------
1.160 +// Class ostrstream
1.161 +#ifdef __SYMBIAN32__
1.162 +NONSHARABLE_CLASS (ostrstream) : public basic_ostream<char, char_traits<char> >
1.163 +#else
1.164 +class _STLP_CLASS_DECLSPEC ostrstream : public basic_ostream<char, char_traits<char> >
1.165 +#endif
1.166 +{
1.167 +public:
1.168 + _STLP_DECLSPEC ostrstream();
1.169 + _STLP_DECLSPEC ostrstream(char*, int, ios_base::openmode = ios_base::out);
1.170 + virtual ~ostrstream();
1.171 +
1.172 + _STLP_DECLSPEC strstreambuf* rdbuf() const;
1.173 + _STLP_DECLSPEC void freeze(bool = true);
1.174 + _STLP_DECLSPEC char* str();
1.175 + _STLP_DECLSPEC int pcount() const;
1.176 +
1.177 +private:
1.178 + strstreambuf _M_buf;
1.179 +};
1.180 +
1.181 +//----------------------------------------------------------------------
1.182 +// Class strstream
1.183 +#ifdef __SYMBIAN32__
1.184 +NONSHARABLE_CLASS (strstream) : public basic_iostream<char, char_traits<char> >
1.185 +#else
1.186 +class _STLP_CLASS_DECLSPEC strstream : public basic_iostream<char, char_traits<char> >
1.187 +#endif
1.188 +{
1.189 +public:
1.190 + typedef char char_type;
1.191 + typedef char_traits<char>::int_type int_type;
1.192 + typedef char_traits<char>::pos_type pos_type;
1.193 + typedef char_traits<char>::off_type off_type;
1.194 +
1.195 + _STLP_DECLSPEC strstream();
1.196 + _STLP_DECLSPEC strstream(char*, int, ios_base::openmode = ios_base::in | ios_base::out);
1.197 + virtual ~strstream();
1.198 +
1.199 + _STLP_DECLSPEC strstreambuf* rdbuf() const;
1.200 + _STLP_DECLSPEC void freeze(bool = true);
1.201 + _STLP_DECLSPEC int pcount() const;
1.202 + _STLP_DECLSPEC char* str();
1.203 +
1.204 +private:
1.205 + strstreambuf _M_buf;
1.206 +};
1.207 +
1.208 +_STLP_END_NAMESPACE