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 #ifndef _CPP_BITS_SBUF_ITER_H
00033 #define _CPP_BITS_SBUF_ITER_H 1
00034
00035 #pragma GCC system_header
00036
00037 namespace std
00038 {
00039 template<typename _CharT, typename _Traits>
00040 class ostreambuf_iterator
00041 : public iterator<output_iterator_tag, _CharT, void, void, void>
00042 {
00043 public:
00044
00045 typedef _CharT char_type;
00046 typedef _Traits traits_type;
00047 typedef basic_streambuf<_CharT, _Traits> streambuf_type;
00048 typedef basic_ostream<_CharT, _Traits> ostream_type;
00049
00050 inline
00051 ostreambuf_iterator(ostream_type& __s) throw ()
00052 : _M_sbuf(__s.rdbuf()), _M_failed(!_M_sbuf) { }
00053
00054 ostreambuf_iterator(streambuf_type* __s) throw ()
00055 : _M_sbuf(__s), _M_failed(!_M_sbuf) { }
00056
00057 ostreambuf_iterator&
00058 operator=(_CharT __c);
00059
00060 ostreambuf_iterator&
00061 operator*() throw()
00062 { return *this; }
00063
00064 ostreambuf_iterator&
00065 operator++(int) throw()
00066 { return *this; }
00067
00068 ostreambuf_iterator&
00069 operator++() throw()
00070 { return *this; }
00071
00072 bool
00073 failed() const throw()
00074 { return _M_failed; }
00075
00076 private:
00077 streambuf_type* _M_sbuf;
00078 bool _M_failed;
00079 };
00080
00081 template<typename _CharT, typename _Traits>
00082 inline ostreambuf_iterator<_CharT, _Traits>&
00083 ostreambuf_iterator<_CharT, _Traits>::operator=(_CharT __c)
00084 {
00085 if (!_M_failed &&
00086 _Traits::eq_int_type(_M_sbuf->sputc(__c),_Traits::eof()))
00087 _M_failed = true;
00088 return *this;
00089 }
00090
00091
00092
00093 template<class _CharT, class _Traits>
00094 class istreambuf_iterator
00095 : public iterator<input_iterator_tag, _CharT, typename _Traits::off_type,
00096 _CharT*, _CharT&>
00097 {
00098 public:
00099
00100
00101 typedef _CharT char_type;
00102 typedef _Traits traits_type;
00103 typedef typename _Traits::int_type int_type;
00104 typedef basic_streambuf<_CharT, _Traits> streambuf_type;
00105 typedef basic_istream<_CharT, _Traits> istream_type;
00106
00107 typedef istreambuf_iterator<_CharT, _Traits> __istreambufiter_type;
00108
00109 istreambuf_iterator() throw()
00110 : _M_sbuf(NULL), _M_c(-2) { }
00111
00112 istreambuf_iterator(istream_type& __s) throw()
00113 : _M_sbuf(__s.rdbuf()), _M_c(-2) { }
00114
00115 istreambuf_iterator(streambuf_type* __s) throw()
00116 : _M_sbuf(__s), _M_c(-2) { }
00117
00118
00119
00120
00121 char_type
00122 operator*() const
00123 {
00124
00125 char_type __ret;
00126 if (_M_sbuf && _M_c != static_cast<int_type>(-2))
00127 __ret = _M_c;
00128 else if (_M_sbuf)
00129 __ret = traits_type::to_char_type(_M_sbuf->sgetc());
00130 else
00131 __ret = static_cast<char_type>(traits_type::eof());
00132 return __ret;
00133 }
00134
00135 __istreambufiter_type&
00136 operator++()
00137 {
00138 if (_M_sbuf)
00139 _M_sbuf->sbumpc();
00140 _M_c = -2;
00141 return *this;
00142 }
00143
00144 #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
00145
00146
00147
00148 const __istreambufiter_type
00149 operator++(int)
00150 {
00151 if (_M_sbuf)
00152 _M_c = _M_sbuf->sbumpc();
00153 return *this;
00154 }
00155 #endif
00156
00157 bool
00158 equal(const __istreambufiter_type& __b)
00159 {
00160 int_type __eof = traits_type::eof();
00161 bool __thiseof = !_M_sbuf || _M_sbuf->sgetc() == __eof;
00162 bool __beof = !__b._M_sbuf
00163 || __b._M_sbuf->sgetc() == __eof;
00164 return (__thiseof && __beof || (!__thiseof && !__beof));
00165 }
00166
00167 #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
00168
00169
00170 bool
00171 equal(const __istreambufiter_type& __b) const
00172 {
00173 int_type __eof = traits_type::eof();
00174 bool __thiseof = !_M_sbuf || _M_sbuf->sgetc() == __eof;
00175 bool __beof = !__b._M_sbuf
00176 || __b._M_sbuf->sgetc() == __eof;
00177 return (__thiseof && __beof || (!__thiseof && !__beof));
00178 }
00179 #endif
00180
00181 private:
00182
00183
00184
00185
00186
00187
00188
00189 streambuf_type* _M_sbuf;
00190 int_type _M_c;
00191 };
00192
00193 template<typename _CharT, typename _Traits>
00194 inline bool
00195 operator==(const istreambuf_iterator<_CharT, _Traits>& __a,
00196 const istreambuf_iterator<_CharT, _Traits>& __b)
00197 { return __a.equal(__b); }
00198
00199 template<typename _CharT, typename _Traits>
00200 inline bool
00201 operator!=(const istreambuf_iterator<_CharT, _Traits>& __a,
00202 const istreambuf_iterator<_CharT, _Traits>& __b)
00203 { return !__a.equal(__b); }
00204
00205 }
00206
00207 #endif