00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef _STLP_SSTREAM_H
00026 #define _STLP_SSTREAM_H
00027
00028 #ifndef _STLP_INTERNAL_STREAMBUF
00029 # include <stl/_streambuf.h>
00030 #endif
00031
00032 #ifndef _STLP_INTERNAL_ISTREAM_H
00033 # include <stl/_istream.h>
00034 #endif
00035
00036 #ifndef _STLP_STRING_H
00037 # include <stl/_string.h>
00038 #endif
00039
00040 _STLP_BEGIN_NAMESPACE
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054 template <class _CharT, class _Traits, class _Alloc>
00055 class basic_stringbuf : public basic_streambuf<_CharT, _Traits>
00056 {
00057 public:
00058 typedef _CharT char_type;
00059 typedef typename _Traits::int_type int_type;
00060 typedef typename _Traits::pos_type pos_type;
00061 typedef typename _Traits::off_type off_type;
00062 typedef _Traits traits_type;
00063
00064 typedef basic_streambuf<_CharT, _Traits> _Base;
00065 typedef basic_stringbuf<_CharT, _Traits, _Alloc> _Self;
00066 typedef basic_string<_CharT, _Traits, _Alloc> _String;
00067
00068 public:
00069 explicit basic_stringbuf(ios_base::openmode __mode
00070 = ios_base::in | ios_base::out);
00071 explicit basic_stringbuf(const _String& __s, ios_base::openmode __mode
00072 = ios_base::in | ios_base::out);
00073 virtual ~basic_stringbuf();
00074
00075 public:
00076 _String str() const { _M_append_buffer(); return _M_str; }
00077 void str(const _String& __s);
00078
00079 protected:
00080 virtual int_type underflow();
00081 virtual int_type uflow();
00082 virtual int_type pbackfail(int_type __c);
00083 virtual int_type overflow(int_type __c);
00084 int_type pbackfail() {return pbackfail(_Traits::eof());}
00085 int_type overflow() {return overflow(_Traits::eof());}
00086
00087 virtual streamsize xsputn(const char_type* __s, streamsize __n);
00088 virtual streamsize _M_xsputnc(char_type __c, streamsize __n);
00089
00090 virtual _Base* setbuf(_CharT* __buf, streamsize __n);
00091 virtual pos_type seekoff(off_type __off, ios_base::seekdir __dir,
00092 ios_base::openmode __mode
00093 = ios_base::in | ios_base::out);
00094 virtual pos_type seekpos(pos_type __pos, ios_base::openmode __mode
00095 = ios_base::in | ios_base::out);
00096
00097 private:
00098
00099 void _M_append_buffer() const;
00100
00101 private:
00102 ios_base::openmode _M_mode;
00103 mutable basic_string<_CharT, _Traits, _Alloc> _M_str;
00104
00105 enum _JustName { _S_BufSiz = 8 };
00106 _CharT _M_Buf[ 8 ];
00107 };
00108
00109 # if defined (_STLP_USE_TEMPLATE_EXPORT)
00110 _STLP_EXPORT_TEMPLATE_CLASS basic_stringbuf<char, char_traits<char>, allocator<char> >;
00111 # if !defined (_STLP_NO_WCHAR_T)
00112 _STLP_EXPORT_TEMPLATE_CLASS basic_stringbuf<wchar_t, char_traits<wchar_t>, allocator<wchar_t> >;
00113 # endif
00114 # endif
00115
00116
00117
00118
00119 template <class _CharT, class _Traits, class _Alloc>
00120 class basic_istringstream : public basic_istream<_CharT, _Traits>
00121 {
00122 public:
00123 typedef typename _Traits::char_type char_type;
00124 typedef typename _Traits::int_type int_type;
00125 typedef typename _Traits::pos_type pos_type;
00126 typedef typename _Traits::off_type off_type;
00127 typedef _Traits traits_type;
00128
00129 typedef basic_ios<_CharT, _Traits> _Basic_ios;
00130 typedef basic_istream<_CharT, _Traits> _Base;
00131 typedef basic_string<_CharT, _Traits, _Alloc> _String;
00132 typedef basic_stringbuf<_CharT, _Traits, _Alloc> _Buf;
00133
00134 public:
00135 basic_istringstream(ios_base::openmode __mode = ios_base::in);
00136 basic_istringstream(const _String& __str,
00137 ios_base::openmode __mode = ios_base::in);
00138 ~basic_istringstream();
00139
00140 public:
00141
00142 basic_stringbuf<_CharT, _Traits, _Alloc>* rdbuf() const
00143 { return __CONST_CAST(_Buf*,&_M_buf); }
00144
00145 _String str() const { return _M_buf.str(); }
00146 void str(const _String& __s) { _M_buf.str(__s); }
00147
00148 private:
00149 basic_stringbuf<_CharT, _Traits, _Alloc> _M_buf;
00150 };
00151
00152
00153
00154
00155
00156 template <class _CharT, class _Traits, class _Alloc>
00157 class basic_ostringstream : public basic_ostream<_CharT, _Traits>
00158 {
00159 public:
00160 typedef typename _Traits::char_type char_type;
00161 typedef typename _Traits::int_type int_type;
00162 typedef typename _Traits::pos_type pos_type;
00163 typedef typename _Traits::off_type off_type;
00164 typedef _Traits traits_type;
00165
00166 typedef basic_ios<_CharT, _Traits> _Basic_ios;
00167 typedef basic_ostream<_CharT, _Traits> _Base;
00168 typedef basic_string<_CharT, _Traits, _Alloc> _String;
00169 typedef basic_stringbuf<_CharT, _Traits, _Alloc> _Buf;
00170
00171 public:
00172 basic_ostringstream(ios_base::openmode __mode = ios_base::out);
00173 basic_ostringstream(const _String& __str,
00174 ios_base::openmode __mode = ios_base::out);
00175 ~basic_ostringstream();
00176
00177 public:
00178
00179 basic_stringbuf<_CharT, _Traits, _Alloc>* rdbuf() const
00180 { return __CONST_CAST(_Buf*,&_M_buf); }
00181
00182 _String str() const { return _M_buf.str(); }
00183 void str(const _String& __s) { _M_buf.str(__s); }
00184
00185
00186 private:
00187 basic_stringbuf<_CharT, _Traits, _Alloc> _M_buf;
00188 };
00189
00190
00191
00192
00193
00194 template <class _CharT, class _Traits, class _Alloc>
00195 class basic_stringstream : public basic_iostream<_CharT, _Traits>
00196 {
00197 public:
00198 typedef typename _Traits::char_type char_type;
00199 typedef typename _Traits::int_type int_type;
00200 typedef typename _Traits::pos_type pos_type;
00201 typedef typename _Traits::off_type off_type;
00202 typedef _Traits traits_type;
00203
00204 typedef basic_ios<_CharT, _Traits> _Basic_ios;
00205 typedef basic_iostream<_CharT, _Traits> _Base;
00206 typedef basic_string<_CharT, _Traits, _Alloc> _String;
00207 typedef basic_stringbuf<_CharT, _Traits, _Alloc> _Buf;
00208
00209 typedef ios_base::openmode openmode;
00210
00211 public:
00212 basic_stringstream(openmode __mod = ios_base::in | ios_base::out);
00213 basic_stringstream(const _String& __str,
00214 openmode __mod = ios_base::in | ios_base::out);
00215 ~basic_stringstream();
00216
00217 public:
00218
00219 basic_stringbuf<_CharT, _Traits, _Alloc>* rdbuf() const
00220 { return __CONST_CAST(_Buf*,&_M_buf); }
00221
00222 _String str() const { return _M_buf.str(); }
00223 void str(const _String& __s) { _M_buf.str(__s); }
00224
00225 private:
00226 basic_stringbuf<_CharT, _Traits, _Alloc> _M_buf;
00227 };
00228
00229
00230 # if defined (_STLP_USE_TEMPLATE_EXPORT)
00231 _STLP_EXPORT_TEMPLATE_CLASS basic_istringstream<char, char_traits<char>, allocator<char> >;
00232 _STLP_EXPORT_TEMPLATE_CLASS basic_ostringstream<char, char_traits<char>, allocator<char> >;
00233 _STLP_EXPORT_TEMPLATE_CLASS basic_stringstream<char, char_traits<char>, allocator<char> >;
00234 # if !defined (_STLP_NO_WCHAR_T)
00235 _STLP_EXPORT_TEMPLATE_CLASS basic_istringstream<wchar_t, char_traits<wchar_t>, allocator<wchar_t> >;
00236 _STLP_EXPORT_TEMPLATE_CLASS basic_ostringstream<wchar_t, char_traits<wchar_t>, allocator<wchar_t> >;
00237 _STLP_EXPORT_TEMPLATE_CLASS basic_stringstream<wchar_t, char_traits<wchar_t>, allocator<wchar_t> >;
00238 # endif
00239 # endif
00240
00241 _STLP_END_NAMESPACE
00242
00243 # if defined (_STLP_EXPOSE_STREAM_IMPLEMENTATION) && !defined (_STLP_LINK_TIME_INSTANTIATION)
00244 # include <stl/_sstream.c>
00245 # endif
00246
00247 #endif
00248
00249
00250
00251