1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/epoc32/include/tools/stlport/stl/_sstream.h Wed Mar 31 12:33:34 2010 +0100
1.3 @@ -0,0 +1,269 @@
1.4 +/*
1.5 + * Copyright (c) 1999
1.6 + * Silicon Graphics Computer Systems, Inc.
1.7 + *
1.8 + * Copyright (c) 1999
1.9 + * Boris Fomitchev
1.10 + *
1.11 + * This material is provided "as is", with absolutely no warranty expressed
1.12 + * or implied. Any use is at your own risk.
1.13 + *
1.14 + * Permission to use or copy this software for any purpose is hereby granted
1.15 + * without fee, provided the above notices are retained on all copies.
1.16 + * Permission to modify the code and to distribute modified code is granted,
1.17 + * provided the above notices are retained, and a notice that the code was
1.18 + * modified is included with the above copyright notice.
1.19 + *
1.20 + */
1.21 +
1.22 +
1.23 +// This header defines classes basic_stringbuf, basic_istringstream,
1.24 +// basic_ostringstream, and basic_stringstream. These classes
1.25 +// represent streamsbufs and streams whose sources or destinations are
1.26 +// C++ strings.
1.27 +
1.28 +#ifndef _STLP_INTERNAL_SSTREAM
1.29 +#define _STLP_INTERNAL_SSTREAM
1.30 +
1.31 +#ifndef _STLP_INTERNAL_STREAMBUF
1.32 +# include <stl/_streambuf.h>
1.33 +#endif
1.34 +
1.35 +#ifndef _STLP_INTERNAL_ISTREAM
1.36 +# include <stl/_istream.h> // Includes <ostream>, <ios>, <iosfwd>
1.37 +#endif
1.38 +
1.39 +#ifndef _STLP_INTERNAL_STRING_H
1.40 +# include <stl/_string.h>
1.41 +#endif
1.42 +
1.43 +_STLP_BEGIN_NAMESPACE
1.44 +
1.45 +//----------------------------------------------------------------------
1.46 +// This version of basic_stringbuf relies on the internal details of
1.47 +// basic_string. It relies on the fact that, in this implementation,
1.48 +// basic_string's iterators are pointers. It also assumes (as allowed
1.49 +// by the standard) that _CharT is a POD type.
1.50 +
1.51 +// We have a very small buffer for the put area, just so that we don't
1.52 +// have to use append() for every sputc. Conceptually, the buffer
1.53 +// immediately follows the end of the underlying string. We use this
1.54 +// buffer when appending to write-only streambufs, but we don't use it
1.55 +// for read-write streambufs.
1.56 +
1.57 +template <class _CharT, class _Traits, class _Alloc>
1.58 +class basic_stringbuf : public basic_streambuf<_CharT, _Traits> {
1.59 +public: // Typedefs.
1.60 + typedef _CharT char_type;
1.61 + typedef typename _Traits::int_type int_type;
1.62 + typedef typename _Traits::pos_type pos_type;
1.63 + typedef typename _Traits::off_type off_type;
1.64 + typedef _Traits traits_type;
1.65 +
1.66 + typedef basic_streambuf<_CharT, _Traits> _Base;
1.67 + typedef basic_stringbuf<_CharT, _Traits, _Alloc> _Self;
1.68 + typedef basic_string<_CharT, _Traits, _Alloc> _String;
1.69 +
1.70 +public: // Constructors, destructor.
1.71 + explicit basic_stringbuf(ios_base::openmode __mode
1.72 + = ios_base::in | ios_base::out);
1.73 + explicit basic_stringbuf(const _String& __s, ios_base::openmode __mode
1.74 + = ios_base::in | ios_base::out);
1.75 + virtual ~basic_stringbuf();
1.76 +
1.77 +public: // Get or set the string.
1.78 + _String str() const { _M_append_buffer(); return _M_str; }
1.79 + void str(const _String& __s);
1.80 +
1.81 +protected: // Overridden virtual member functions.
1.82 + virtual int_type underflow();
1.83 + virtual int_type uflow();
1.84 + virtual int_type pbackfail(int_type __c);
1.85 + virtual int_type overflow(int_type __c);
1.86 + int_type pbackfail() {return pbackfail(_Traits::eof());}
1.87 + int_type overflow() {return overflow(_Traits::eof());}
1.88 +
1.89 + virtual streamsize xsputn(const char_type* __s, streamsize __n);
1.90 + virtual streamsize _M_xsputnc(char_type __c, streamsize __n);
1.91 +
1.92 + virtual _Base* setbuf(_CharT* __buf, streamsize __n);
1.93 + virtual pos_type seekoff(off_type __off, ios_base::seekdir __dir,
1.94 + ios_base::openmode __mode
1.95 + = ios_base::in | ios_base::out);
1.96 + virtual pos_type seekpos(pos_type __pos, ios_base::openmode __mode
1.97 + = ios_base::in | ios_base::out);
1.98 +
1.99 +private: // Helper functions.
1.100 + // Append the internal buffer to the string if necessary.
1.101 + void _M_append_buffer() const;
1.102 + void _M_set_ptrs();
1.103 +
1.104 +private:
1.105 + ios_base::openmode _M_mode;
1.106 + mutable basic_string<_CharT, _Traits, _Alloc> _M_str;
1.107 +
1.108 + enum _JustName { _S_BufSiz = 8 };
1.109 + _CharT _M_Buf[ 8 /* _S_BufSiz */];
1.110 +};
1.111 +
1.112 +#if defined (_STLP_USE_TEMPLATE_EXPORT)
1.113 +_STLP_EXPORT_TEMPLATE_CLASS basic_stringbuf<char, char_traits<char>, allocator<char> >;
1.114 +# if !defined (_STLP_NO_WCHAR_T)
1.115 +_STLP_EXPORT_TEMPLATE_CLASS basic_stringbuf<wchar_t, char_traits<wchar_t>, allocator<wchar_t> >;
1.116 +# endif
1.117 +#endif /* _STLP_USE_TEMPLATE_EXPORT */
1.118 +
1.119 +//----------------------------------------------------------------------
1.120 +// Class basic_istringstream, an input stream that uses a stringbuf.
1.121 +
1.122 +template <class _CharT, class _Traits, class _Alloc>
1.123 +class basic_istringstream : public basic_istream<_CharT, _Traits> {
1.124 +public: // Typedefs
1.125 + typedef typename _Traits::char_type char_type;
1.126 + typedef typename _Traits::int_type int_type;
1.127 + typedef typename _Traits::pos_type pos_type;
1.128 + typedef typename _Traits::off_type off_type;
1.129 + typedef _Traits traits_type;
1.130 +
1.131 + typedef basic_ios<_CharT, _Traits> _Basic_ios;
1.132 + typedef basic_istream<_CharT, _Traits> _Base;
1.133 + typedef basic_string<_CharT, _Traits, _Alloc> _String;
1.134 + typedef basic_stringbuf<_CharT, _Traits, _Alloc> _Buf;
1.135 +
1.136 +public: // Constructors, destructor.
1.137 + basic_istringstream(ios_base::openmode __mode = ios_base::in);
1.138 + basic_istringstream(const _String& __str,
1.139 + ios_base::openmode __mode = ios_base::in);
1.140 + ~basic_istringstream();
1.141 +
1.142 +public: // Member functions
1.143 +
1.144 + basic_stringbuf<_CharT, _Traits, _Alloc>* rdbuf() const
1.145 + { return __CONST_CAST(_Buf*,&_M_buf); }
1.146 +
1.147 + _String str() const { return _M_buf.str(); }
1.148 + void str(const _String& __s) { _M_buf.str(__s); }
1.149 +
1.150 +private:
1.151 + basic_stringbuf<_CharT, _Traits, _Alloc> _M_buf;
1.152 +
1.153 +#if defined (_STLP_MSVC) && (_STLP_MSVC >= 1300 && _STLP_MSVC <= 1310)
1.154 + typedef basic_istringstream<_CharT, _Traits> _Self;
1.155 + //explicitely defined as private to avoid warnings:
1.156 + basic_istringstream(_Self const&);
1.157 + _Self& operator = (_Self const&);
1.158 +#endif
1.159 +};
1.160 +
1.161 +
1.162 +//----------------------------------------------------------------------
1.163 +// Class basic_ostringstream, an output stream that uses a stringbuf.
1.164 +
1.165 +template <class _CharT, class _Traits, class _Alloc>
1.166 +class basic_ostringstream : public basic_ostream<_CharT, _Traits> {
1.167 +public: // Typedefs
1.168 + typedef typename _Traits::char_type char_type;
1.169 + typedef typename _Traits::int_type int_type;
1.170 + typedef typename _Traits::pos_type pos_type;
1.171 + typedef typename _Traits::off_type off_type;
1.172 + typedef _Traits traits_type;
1.173 +
1.174 + typedef basic_ios<_CharT, _Traits> _Basic_ios;
1.175 + typedef basic_ostream<_CharT, _Traits> _Base;
1.176 + typedef basic_string<_CharT, _Traits, _Alloc> _String;
1.177 + typedef basic_stringbuf<_CharT, _Traits, _Alloc> _Buf;
1.178 +
1.179 +public: // Constructors, destructor.
1.180 + basic_ostringstream(ios_base::openmode __mode = ios_base::out);
1.181 + basic_ostringstream(const _String& __str,
1.182 + ios_base::openmode __mode = ios_base::out);
1.183 + ~basic_ostringstream();
1.184 +
1.185 +public: // Member functions.
1.186 +
1.187 + basic_stringbuf<_CharT, _Traits, _Alloc>* rdbuf() const
1.188 + { return __CONST_CAST(_Buf*,&_M_buf); }
1.189 +
1.190 + _String str() const { return _M_buf.str(); }
1.191 + void str(const _String& __s) { _M_buf.str(__s); } // dwa 02/07/00 - BUG STOMPER DAVE
1.192 +
1.193 +
1.194 +private:
1.195 + basic_stringbuf<_CharT, _Traits, _Alloc> _M_buf;
1.196 +
1.197 +#if defined (_STLP_MSVC) && (_STLP_MSVC >= 1300 && _STLP_MSVC <= 1310)
1.198 + typedef basic_ostringstream<_CharT, _Traits> _Self;
1.199 + //explicitely defined as private to avoid warnings:
1.200 + basic_ostringstream(_Self const&);
1.201 + _Self& operator = (_Self const&);
1.202 +#endif
1.203 +};
1.204 +
1.205 +
1.206 +//----------------------------------------------------------------------
1.207 +// Class basic_stringstream, a bidirectional stream that uses a stringbuf.
1.208 +
1.209 +template <class _CharT, class _Traits, class _Alloc>
1.210 +class basic_stringstream : public basic_iostream<_CharT, _Traits> {
1.211 +public: // Typedefs
1.212 + typedef typename _Traits::char_type char_type;
1.213 + typedef typename _Traits::int_type int_type;
1.214 + typedef typename _Traits::pos_type pos_type;
1.215 + typedef typename _Traits::off_type off_type;
1.216 + typedef _Traits traits_type;
1.217 +
1.218 + typedef basic_ios<_CharT, _Traits> _Basic_ios;
1.219 + typedef basic_iostream<_CharT, _Traits> _Base;
1.220 + typedef basic_string<_CharT, _Traits, _Alloc> _String;
1.221 + typedef basic_stringbuf<_CharT, _Traits, _Alloc> _Buf;
1.222 +
1.223 + typedef ios_base::openmode openmode;
1.224 +
1.225 +public: // Constructors, destructor.
1.226 + basic_stringstream(openmode __mod = ios_base::in | ios_base::out);
1.227 + basic_stringstream(const _String& __str,
1.228 + openmode __mod = ios_base::in | ios_base::out);
1.229 + ~basic_stringstream();
1.230 +
1.231 +public: // Member functions.
1.232 +
1.233 + basic_stringbuf<_CharT, _Traits, _Alloc>* rdbuf() const
1.234 + { return __CONST_CAST(_Buf*,&_M_buf); }
1.235 +
1.236 + _String str() const { return _M_buf.str(); }
1.237 + void str(const _String& __s) { _M_buf.str(__s); }
1.238 +
1.239 +private:
1.240 + basic_stringbuf<_CharT, _Traits, _Alloc> _M_buf;
1.241 +
1.242 +#if defined (_STLP_MSVC) && (_STLP_MSVC >= 1300 && _STLP_MSVC <= 1310)
1.243 + typedef basic_stringstream<_CharT, _Traits> _Self;
1.244 + //explicitely defined as private to avoid warnings:
1.245 + basic_stringstream(_Self const&);
1.246 + _Self& operator = (_Self const&);
1.247 +#endif
1.248 +};
1.249 +
1.250 +
1.251 +#if defined (_STLP_USE_TEMPLATE_EXPORT)
1.252 +_STLP_EXPORT_TEMPLATE_CLASS basic_istringstream<char, char_traits<char>, allocator<char> >;
1.253 +_STLP_EXPORT_TEMPLATE_CLASS basic_ostringstream<char, char_traits<char>, allocator<char> >;
1.254 +_STLP_EXPORT_TEMPLATE_CLASS basic_stringstream<char, char_traits<char>, allocator<char> >;
1.255 +# if !defined (_STLP_NO_WCHAR_T)
1.256 +_STLP_EXPORT_TEMPLATE_CLASS basic_istringstream<wchar_t, char_traits<wchar_t>, allocator<wchar_t> >;
1.257 +_STLP_EXPORT_TEMPLATE_CLASS basic_ostringstream<wchar_t, char_traits<wchar_t>, allocator<wchar_t> >;
1.258 +_STLP_EXPORT_TEMPLATE_CLASS basic_stringstream<wchar_t, char_traits<wchar_t>, allocator<wchar_t> >;
1.259 +# endif
1.260 +#endif /* _STLP_USE_TEMPLATE_EXPORT */
1.261 +
1.262 +_STLP_END_NAMESPACE
1.263 +
1.264 +#if defined (_STLP_EXPOSE_STREAM_IMPLEMENTATION) && !defined (_STLP_LINK_TIME_INSTANTIATION)
1.265 +# include <stl/_sstream.c>
1.266 +#endif
1.267 +
1.268 +#endif /* _STLP_INTERNAL_SSTREAM */
1.269 +
1.270 +// Local Variables:
1.271 +// mode:C++
1.272 +// End: