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