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 
00026 
00027 
00028 
00029 
00030 
00031 
00032 
00033 
00039 #ifndef _CPP_SSTREAM
00040 #define _CPP_SSTREAM    1
00041 
00042 #pragma GCC system_header
00043 
00044 #include <istream>
00045 #include <ostream>
00046 
00047 namespace std
00048 {
00049   template<typename _CharT, typename _Traits, typename _Alloc>
00050     class basic_stringbuf : public basic_streambuf<_CharT, _Traits>
00051     {
00052     public:
00053       
00054       typedef _CharT                    char_type;
00055       typedef _Traits                   traits_type;
00056 #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
00057 
00058       typedef _Alloc                        allocator_type;
00059 #endif
00060       typedef typename traits_type::int_type        int_type;
00061       typedef typename traits_type::pos_type        pos_type;
00062       typedef typename traits_type::off_type        off_type;
00063 
00064       
00065       typedef basic_streambuf<char_type, traits_type>   __streambuf_type;
00066       typedef basic_string<char_type, _Traits, _Alloc>  __string_type;
00067       typedef typename __string_type::size_type     __size_type;
00068 
00069     protected:
00070       
00071       __string_type         _M_string;
00072 
00073     public:
00074       
00075       explicit
00076       basic_stringbuf(ios_base::openmode __mode = ios_base::in | ios_base::out)
00077       : __streambuf_type(), _M_string()
00078       { _M_stringbuf_init(__mode); }
00079 
00080       explicit
00081       basic_stringbuf(const __string_type& __str,
00082               ios_base::openmode __mode = ios_base::in | ios_base::out)
00083       : __streambuf_type(), _M_string(__str.data(), __str.size())
00084       { _M_stringbuf_init(__mode); }
00085 
00086       
00087       __string_type
00088       str() const
00089       {
00090     if (_M_mode & ios_base::out)
00091       {
00092         
00093         
00094         
00095         
00096         __size_type __len = _M_string.size();
00097         if (_M_out_cur > _M_out_beg)
00098           __len = max(__size_type(_M_out_end - _M_out_beg), __len);
00099         return __string_type(_M_out_beg, _M_out_beg + __len);
00100       }
00101     else
00102       return _M_string;
00103       }
00104 
00105       void
00106       str(const __string_type& __s)
00107       {
00108     _M_string = __s;
00109     _M_stringbuf_init(_M_mode);
00110       }
00111 
00112     protected:
00113       
00114       void
00115       _M_stringbuf_init(ios_base::openmode __mode)
00116       {
00117     
00118     
00119     
00120     
00121     
00122     _M_buf_size = _M_string.size();
00123 
00124     
00125     
00126     
00127     
00128     _M_buf_size_opt = 512;
00129     _M_mode = __mode;
00130     if (_M_mode & (ios_base::ate | ios_base::app))
00131       _M_really_sync(0, _M_buf_size);
00132     else
00133       _M_really_sync(0, 0);
00134       }
00135 
00136       
00137       virtual int_type
00138       underflow()
00139       {
00140     if (_M_in_cur && _M_in_cur < _M_in_end)
00141       return traits_type::to_int_type(*gptr());
00142     else
00143       return traits_type::eof();
00144       }
00145 
00146       virtual int_type
00147       pbackfail(int_type __c = traits_type::eof());
00148 
00149       virtual int_type
00150       overflow(int_type __c = traits_type::eof());
00151 
00152       virtual __streambuf_type*
00153       setbuf(char_type* __s, streamsize __n)
00154       {
00155     if (__s && __n)
00156       {
00157         _M_string = __string_type(__s, __n);
00158         _M_really_sync(0, 0);
00159       }
00160     return this;
00161       }
00162 
00163       virtual pos_type
00164       seekoff(off_type __off, ios_base::seekdir __way,
00165           ios_base::openmode __mode = ios_base::in | ios_base::out);
00166 
00167       virtual pos_type
00168       seekpos(pos_type __sp,
00169           ios_base::openmode __mode = ios_base::in | ios_base::out);
00170 
00171       
00172       
00173       
00174       
00175       
00176       
00177       virtual int
00178       _M_really_sync(__size_type __i, __size_type __o)
00179       {
00180     char_type* __base = const_cast<char_type*>(_M_string.data());
00181     bool __testin = _M_mode & ios_base::in;
00182     bool __testout = _M_mode & ios_base::out;
00183     __size_type __len = _M_string.size();
00184 
00185     _M_buf = __base;
00186     if (__testin)
00187         this->setg(__base, __base + __i, __base + __len);
00188     if (__testout)
00189       {
00190         this->setp(__base, __base + __len);
00191         _M_out_cur += __o;
00192       }
00193     return 0;
00194       }
00195     };
00196 
00197 
00198   
00199   template<typename _CharT, typename _Traits, typename _Alloc>
00200     class basic_istringstream : public basic_istream<_CharT, _Traits>
00201     {
00202     public:
00203       
00204       typedef _CharT                    char_type;
00205       typedef _Traits                   traits_type;
00206 #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
00207 
00208       typedef _Alloc                        allocator_type;
00209 #endif
00210       typedef typename traits_type::int_type        int_type;
00211       typedef typename traits_type::pos_type        pos_type;
00212       typedef typename traits_type::off_type        off_type;
00213 
00214       
00215       typedef basic_string<_CharT, _Traits, _Alloc>     __string_type;
00216       typedef basic_stringbuf<_CharT, _Traits, _Alloc>  __stringbuf_type;
00217       typedef basic_istream<char_type, traits_type> __istream_type;
00218 
00219     private:
00220       __stringbuf_type  _M_stringbuf;
00221 
00222     public:
00223       
00224       explicit
00225       basic_istringstream(ios_base::openmode __mode = ios_base::in)
00226       : __istream_type(NULL), _M_stringbuf(__mode | ios_base::in)
00227       { this->init(&_M_stringbuf); }
00228 
00229       explicit
00230       basic_istringstream(const __string_type& __str,
00231               ios_base::openmode __mode = ios_base::in)
00232       : __istream_type(NULL), _M_stringbuf(__str, __mode | ios_base::in)
00233       { this->init(&_M_stringbuf); }
00234 
00235       ~basic_istringstream()
00236       { }
00237 
00238       
00239       __stringbuf_type*
00240       rdbuf() const
00241       { return const_cast<__stringbuf_type*>(&_M_stringbuf); }
00242 
00243       __string_type
00244       str() const
00245       { return _M_stringbuf.str(); }
00246 
00247       void
00248       str(const __string_type& __s)
00249       { _M_stringbuf.str(__s); }
00250     };
00251 
00252 
00253   
00254   template <typename _CharT, typename _Traits, typename _Alloc>
00255     class basic_ostringstream : public basic_ostream<_CharT, _Traits>
00256     {
00257     public:
00258       
00259       typedef _CharT                    char_type;
00260       typedef _Traits                   traits_type;
00261 #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
00262 
00263       typedef _Alloc                        allocator_type;
00264 #endif
00265       typedef typename traits_type::int_type        int_type;
00266       typedef typename traits_type::pos_type        pos_type;
00267       typedef typename traits_type::off_type        off_type;
00268 
00269       
00270       typedef basic_string<_CharT, _Traits, _Alloc>     __string_type;
00271       typedef basic_stringbuf<_CharT, _Traits, _Alloc>  __stringbuf_type;
00272       typedef basic_ostream<char_type, traits_type> __ostream_type;
00273 
00274     private:
00275       __stringbuf_type  _M_stringbuf;
00276 
00277     public:
00278      
00279       explicit
00280       basic_ostringstream(ios_base::openmode __mode = ios_base::out)
00281       : __ostream_type(NULL), _M_stringbuf(__mode | ios_base::out)
00282       { this->init(&_M_stringbuf); }
00283 
00284       explicit
00285       basic_ostringstream(const __string_type& __str,
00286               ios_base::openmode __mode = ios_base::out)
00287       : __ostream_type(NULL), _M_stringbuf(__str, __mode | ios_base::out)
00288       { this->init(&_M_stringbuf); }
00289 
00290       ~basic_ostringstream()
00291       { }
00292 
00293       
00294       __stringbuf_type*
00295       rdbuf() const
00296       { return const_cast<__stringbuf_type*>(&_M_stringbuf); }
00297 
00298       __string_type
00299       str() const
00300       { return _M_stringbuf.str(); }
00301 
00302       void
00303       str(const __string_type& __s)
00304       { _M_stringbuf.str(__s); }
00305     };
00306 
00307 
00308   
00309   template <typename _CharT, typename _Traits, typename _Alloc>
00310     class basic_stringstream : public basic_iostream<_CharT, _Traits>
00311     {
00312     public:
00313       
00314       typedef _CharT                    char_type;
00315       typedef _Traits                   traits_type;
00316 #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
00317 
00318       typedef _Alloc                        allocator_type;
00319 #endif
00320       typedef typename traits_type::int_type        int_type;
00321       typedef typename traits_type::pos_type        pos_type;
00322       typedef typename traits_type::off_type        off_type;
00323 
00324       
00325       typedef basic_string<_CharT, _Traits, _Alloc>     __string_type;
00326       typedef basic_stringbuf<_CharT, _Traits, _Alloc>  __stringbuf_type;
00327       typedef basic_iostream<char_type, traits_type>    __iostream_type;
00328 
00329     private:
00330       __stringbuf_type  _M_stringbuf;
00331 
00332     public:
00333       
00334       explicit
00335       basic_stringstream(ios_base::openmode __m = ios_base::out | ios_base::in)
00336       : __iostream_type(NULL), _M_stringbuf(__m)
00337       { this->init(&_M_stringbuf); }
00338 
00339       explicit
00340       basic_stringstream(const __string_type& __str,
00341              ios_base::openmode __m = ios_base::out | ios_base::in)
00342       : __iostream_type(NULL), _M_stringbuf(__str, __m)
00343       { this->init(&_M_stringbuf); }
00344 
00345       ~basic_stringstream()
00346       { }
00347 
00348       
00349       __stringbuf_type*
00350       rdbuf() const
00351       { return const_cast<__stringbuf_type*>(&_M_stringbuf); }
00352 
00353       __string_type
00354       str() const
00355       { return _M_stringbuf.str(); }
00356 
00357       void
00358       str(const __string_type& __s)
00359       { _M_stringbuf.str(__s); }
00360     };
00361 } 
00362 
00363 #ifdef _GLIBCPP_NO_TEMPLATE_EXPORT
00364 # define export
00365 #endif
00366 #ifdef  _GLIBCPP_FULLY_COMPLIANT_HEADERS
00367 # include <bits/sstream.tcc>
00368 #endif
00369 
00370 #endif