Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygen_sstream.h
Go to the documentation of this file.
00001 /* 00002 * Copyright (c) 1999 00003 * Silicon Graphics Computer Systems, Inc. 00004 * 00005 * Copyright (c) 1999 00006 * Boris Fomitchev 00007 * 00008 * This material is provided "as is", with absolutely no warranty expressed 00009 * or implied. Any use is at your own risk. 00010 * 00011 * Permission to use or copy this software for any purpose is hereby granted 00012 * without fee, provided the above notices are retained on all copies. 00013 * Permission to modify the code and to distribute modified code is granted, 00014 * provided the above notices are retained, and a notice that the code was 00015 * modified is included with the above copyright notice. 00016 * 00017 */ 00018 00019 00020 // This header defines classes basic_stringbuf, basic_istringstream, 00021 // basic_ostringstream, and basic_stringstream. These classes 00022 // represent streamsbufs and streams whose sources or destinations are 00023 // C++ strings. 00024 00025 #ifndef _STLP_INTERNAL_SSTREAM 00026 #define _STLP_INTERNAL_SSTREAM 00027 00028 #ifndef _STLP_INTERNAL_STREAMBUF 00029 # include <stl/_streambuf.h> 00030 #endif 00031 00032 #ifndef _STLP_INTERNAL_ISTREAM 00033 # include <stl/_istream.h> // Includes <ostream>, <ios>, <iosfwd> 00034 #endif 00035 00036 #ifndef _STLP_INTERNAL_STRING_H 00037 # include <stl/_string.h> 00038 #endif 00039 00040 _STLP_BEGIN_NAMESPACE 00041 00042 //---------------------------------------------------------------------- 00043 // This version of basic_stringbuf relies on the internal details of 00044 // basic_string. It relies on the fact that, in this implementation, 00045 // basic_string's iterators are pointers. It also assumes (as allowed 00046 // by the standard) that _CharT is a POD type. 00047 00048 // We have a very small buffer for the put area, just so that we don't 00049 // have to use append() for every sputc. Conceptually, the buffer 00050 // immediately follows the end of the underlying string. We use this 00051 // buffer when appending to write-only streambufs, but we don't use it 00052 // for read-write streambufs. 00053 00054 template <class _CharT, class _Traits, class _Alloc> 00055 class basic_stringbuf : public basic_streambuf<_CharT, _Traits> { 00056 public: // Typedefs. 00057 typedef _CharT char_type; 00058 typedef typename _Traits::int_type int_type; 00059 typedef typename _Traits::pos_type pos_type; 00060 typedef typename _Traits::off_type off_type; 00061 typedef _Traits traits_type; 00062 00063 typedef basic_streambuf<_CharT, _Traits> _Base; 00064 typedef basic_stringbuf<_CharT, _Traits, _Alloc> _Self; 00065 typedef basic_string<_CharT, _Traits, _Alloc> _String; 00066 00067 public: // Constructors, destructor. 00068 explicit basic_stringbuf(ios_base::openmode __mode 00069 = ios_base::in | ios_base::out); 00070 explicit basic_stringbuf(const _String& __s, ios_base::openmode __mode 00071 = ios_base::in | ios_base::out); 00072 virtual ~basic_stringbuf(); 00073 00074 public: // Get or set the string. 00075 _String str() const { return _M_str; } 00076 void str(const _String& __s); 00077 00078 protected: // Overridden virtual member functions. 00079 virtual int_type underflow(); 00080 virtual int_type uflow(); 00081 virtual int_type pbackfail(int_type __c); 00082 virtual int_type overflow(int_type __c); 00083 int_type pbackfail() {return pbackfail(_Traits::eof());} 00084 int_type overflow() {return overflow(_Traits::eof());} 00085 00086 virtual streamsize xsputn(const char_type* __s, streamsize __n); 00087 virtual streamsize _M_xsputnc(char_type __c, streamsize __n); 00088 00089 virtual _Base* setbuf(_CharT* __buf, streamsize __n); 00090 virtual pos_type seekoff(off_type __off, ios_base::seekdir __dir, 00091 ios_base::openmode __mode 00092 = ios_base::in | ios_base::out); 00093 virtual pos_type seekpos(pos_type __pos, ios_base::openmode __mode 00094 = ios_base::in | ios_base::out); 00095 00096 private: // Helper functions. 00097 void _M_set_ptrs(); 00098 static _CharT* _S_start(const _String& __str) { return __CONST_CAST(_CharT*, __str.data()); } 00099 static _CharT* _S_finish(const _String& __str) { return __CONST_CAST(_CharT*, __str.data()) + __str.size(); } 00100 00101 private: 00102 ios_base::openmode _M_mode; 00103 _String _M_str; 00104 }; 00105 00106 #if defined (_STLP_USE_TEMPLATE_EXPORT) 00107 _STLP_EXPORT_TEMPLATE_CLASS basic_stringbuf<char, char_traits<char>, allocator<char> >; 00108 # if !defined (_STLP_NO_WCHAR_T) 00109 _STLP_EXPORT_TEMPLATE_CLASS basic_stringbuf<wchar_t, char_traits<wchar_t>, allocator<wchar_t> >; 00110 # endif 00111 #endif /* _STLP_USE_TEMPLATE_EXPORT */ 00112 00113 //---------------------------------------------------------------------- 00114 // Class basic_istringstream, an input stream that uses a stringbuf. 00115 00116 template <class _CharT, class _Traits, class _Alloc> 00117 class basic_istringstream : public basic_istream<_CharT, _Traits> { 00118 public: // Typedefs 00119 typedef typename _Traits::char_type char_type; 00120 typedef typename _Traits::int_type int_type; 00121 typedef typename _Traits::pos_type pos_type; 00122 typedef typename _Traits::off_type off_type; 00123 typedef _Traits traits_type; 00124 00125 typedef basic_ios<_CharT, _Traits> _Basic_ios; 00126 typedef basic_istream<_CharT, _Traits> _Base; 00127 typedef basic_string<_CharT, _Traits, _Alloc> _String; 00128 typedef basic_stringbuf<_CharT, _Traits, _Alloc> _Buf; 00129 00130 public: // Constructors, destructor. 00131 basic_istringstream(ios_base::openmode __mode = ios_base::in); 00132 basic_istringstream(const _String& __str, 00133 ios_base::openmode __mode = ios_base::in); 00134 ~basic_istringstream(); 00135 00136 public: // Member functions 00137 00138 basic_stringbuf<_CharT, _Traits, _Alloc>* rdbuf() const 00139 { return __CONST_CAST(_Buf*,&_M_buf); } 00140 00141 _String str() const { return _M_buf.str(); } 00142 void str(const _String& __s) { _M_buf.str(__s); } 00143 00144 private: 00145 basic_stringbuf<_CharT, _Traits, _Alloc> _M_buf; 00146 00147 #if defined (_STLP_MSVC) && (_STLP_MSVC >= 1300 && _STLP_MSVC <= 1310) 00148 typedef basic_istringstream<_CharT, _Traits> _Self; 00149 //explicitely defined as private to avoid warnings: 00150 basic_istringstream(_Self const&); 00151 _Self& operator = (_Self const&); 00152 #endif 00153 }; 00154 00155 00156 //---------------------------------------------------------------------- 00157 // Class basic_ostringstream, an output stream that uses a stringbuf. 00158 00159 template <class _CharT, class _Traits, class _Alloc> 00160 class basic_ostringstream : public basic_ostream<_CharT, _Traits> { 00161 public: // Typedefs 00162 typedef typename _Traits::char_type char_type; 00163 typedef typename _Traits::int_type int_type; 00164 typedef typename _Traits::pos_type pos_type; 00165 typedef typename _Traits::off_type off_type; 00166 typedef _Traits traits_type; 00167 00168 typedef basic_ios<_CharT, _Traits> _Basic_ios; 00169 typedef basic_ostream<_CharT, _Traits> _Base; 00170 typedef basic_string<_CharT, _Traits, _Alloc> _String; 00171 typedef basic_stringbuf<_CharT, _Traits, _Alloc> _Buf; 00172 00173 public: // Constructors, destructor. 00174 basic_ostringstream(ios_base::openmode __mode = ios_base::out); 00175 basic_ostringstream(const _String& __str, 00176 ios_base::openmode __mode = ios_base::out); 00177 ~basic_ostringstream(); 00178 00179 public: // Member functions. 00180 00181 basic_stringbuf<_CharT, _Traits, _Alloc>* rdbuf() const 00182 { return __CONST_CAST(_Buf*,&_M_buf); } 00183 00184 _String str() const { return _M_buf.str(); } 00185 void str(const _String& __s) { _M_buf.str(__s); } // dwa 02/07/00 - BUG STOMPER DAVE 00186 00187 00188 private: 00189 basic_stringbuf<_CharT, _Traits, _Alloc> _M_buf; 00190 00191 #if defined (_STLP_MSVC) && (_STLP_MSVC >= 1300 && _STLP_MSVC <= 1310) 00192 typedef basic_ostringstream<_CharT, _Traits> _Self; 00193 //explicitely defined as private to avoid warnings: 00194 basic_ostringstream(_Self const&); 00195 _Self& operator = (_Self const&); 00196 #endif 00197 }; 00198 00199 00200 //---------------------------------------------------------------------- 00201 // Class basic_stringstream, a bidirectional stream that uses a stringbuf. 00202 00203 template <class _CharT, class _Traits, class _Alloc> 00204 class basic_stringstream : public basic_iostream<_CharT, _Traits> { 00205 public: // Typedefs 00206 typedef typename _Traits::char_type char_type; 00207 typedef typename _Traits::int_type int_type; 00208 typedef typename _Traits::pos_type pos_type; 00209 typedef typename _Traits::off_type off_type; 00210 typedef _Traits traits_type; 00211 00212 typedef basic_ios<_CharT, _Traits> _Basic_ios; 00213 typedef basic_iostream<_CharT, _Traits> _Base; 00214 typedef basic_string<_CharT, _Traits, _Alloc> _String; 00215 typedef basic_stringbuf<_CharT, _Traits, _Alloc> _Buf; 00216 00217 typedef ios_base::openmode openmode; 00218 00219 public: // Constructors, destructor. 00220 basic_stringstream(openmode __mod = ios_base::in | ios_base::out); 00221 basic_stringstream(const _String& __str, 00222 openmode __mod = ios_base::in | ios_base::out); 00223 ~basic_stringstream(); 00224 00225 public: // Member functions. 00226 00227 basic_stringbuf<_CharT, _Traits, _Alloc>* rdbuf() const 00228 { return __CONST_CAST(_Buf*,&_M_buf); } 00229 00230 _String str() const { return _M_buf.str(); } 00231 void str(const _String& __s) { _M_buf.str(__s); } 00232 00233 private: 00234 basic_stringbuf<_CharT, _Traits, _Alloc> _M_buf; 00235 00236 #if defined (_STLP_MSVC) && (_STLP_MSVC >= 1300 && _STLP_MSVC <= 1310) 00237 typedef basic_stringstream<_CharT, _Traits> _Self; 00238 //explicitely defined as private to avoid warnings: 00239 basic_stringstream(_Self const&); 00240 _Self& operator = (_Self const&); 00241 #endif 00242 }; 00243 00244 00245 #if defined (_STLP_USE_TEMPLATE_EXPORT) 00246 _STLP_EXPORT_TEMPLATE_CLASS basic_istringstream<char, char_traits<char>, allocator<char> >; 00247 _STLP_EXPORT_TEMPLATE_CLASS basic_ostringstream<char, char_traits<char>, allocator<char> >; 00248 _STLP_EXPORT_TEMPLATE_CLASS basic_stringstream<char, char_traits<char>, allocator<char> >; 00249 # if !defined (_STLP_NO_WCHAR_T) 00250 _STLP_EXPORT_TEMPLATE_CLASS basic_istringstream<wchar_t, char_traits<wchar_t>, allocator<wchar_t> >; 00251 _STLP_EXPORT_TEMPLATE_CLASS basic_ostringstream<wchar_t, char_traits<wchar_t>, allocator<wchar_t> >; 00252 _STLP_EXPORT_TEMPLATE_CLASS basic_stringstream<wchar_t, char_traits<wchar_t>, allocator<wchar_t> >; 00253 # endif 00254 #endif /* _STLP_USE_TEMPLATE_EXPORT */ 00255 00256 _STLP_END_NAMESPACE 00257 00258 #if defined (_STLP_EXPOSE_STREAM_IMPLEMENTATION) && !defined (_STLP_LINK_TIME_INSTANTIATION) 00259 # include <stl/_sstream.c> 00260 #endif 00261 00262 #endif /* _STLP_INTERNAL_SSTREAM */ 00263 00264 // Local Variables: 00265 // mode:C++ 00266 // End: Generated on Sat May 26 2012 04:28:08 for ReactOS by
1.7.6.1
|