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