32 #ifndef _STREAMBUF_ITERATOR_H
33 #define _STREAMBUF_ITERATOR_H 1
35 #pragma GCC system_header
40 _GLIBCXX_BEGIN_NAMESPACE(std)
44 template<typename _CharT, typename _Traits>
60 template<
typename _CharT2>
61 friend typename __gnu_cxx::__enable_if<__is_char<_CharT2>::__value,
66 template<
bool _IsMove,
typename _CharT2>
67 friend typename __gnu_cxx::__enable_if<__is_char<_CharT2>::__value,
72 template<
typename _CharT2>
73 friend typename __gnu_cxx::__enable_if<__is_char<_CharT2>::__value,
86 mutable streambuf_type* _M_sbuf;
87 mutable int_type _M_c;
92 : _M_sbuf(0), _M_c(traits_type::eof()) { }
96 : _M_sbuf(__s.rdbuf()), _M_c(traits_type::eof()) { }
100 : _M_sbuf(__s), _M_c(traits_type::eof()) { }
108 #ifdef _GLIBCXX_DEBUG_PEDANTIC
111 __glibcxx_requires_cond(!_M_at_eof(),
112 _M_message(__gnu_debug::__msg_deref_istreambuf)
113 ._M_iterator(*
this));
115 return traits_type::to_char_type(_M_get());
122 __glibcxx_requires_cond(!_M_at_eof(),
123 _M_message(__gnu_debug::__msg_inc_istreambuf)
124 ._M_iterator(*
this));
128 _M_c = traits_type::eof();
137 __glibcxx_requires_cond(!_M_at_eof(),
138 _M_message(__gnu_debug::__msg_inc_istreambuf)
139 ._M_iterator(*
this));
144 __old._M_c = _M_sbuf->
sbumpc();
145 _M_c = traits_type::eof();
156 {
return _M_at_eof() == __b._M_at_eof(); }
162 const int_type __eof = traits_type::eof();
163 int_type __ret = __eof;
166 if (!traits_type::eq_int_type(_M_c, __eof))
168 else if (!traits_type::eq_int_type((__ret = _M_sbuf->
sgetc()),
180 const int_type __eof = traits_type::eof();
181 return traits_type::eq_int_type(_M_get(), __eof);
185 template<
typename _CharT,
typename _Traits>
187 operator==(
const istreambuf_iterator<_CharT, _Traits>& __a,
188 const istreambuf_iterator<_CharT, _Traits>& __b)
189 {
return __a.equal(__b); }
191 template<
typename _CharT,
typename _Traits>
193 operator!=(
const istreambuf_iterator<_CharT, _Traits>& __a,
194 const istreambuf_iterator<_CharT, _Traits>& __b)
195 {
return !__a.equal(__b); }
198 template<
typename _CharT,
typename _Traits>
200 :
public iterator<output_iterator_tag, void, void, void, void>
212 template<
typename _CharT2>
213 friend typename __gnu_cxx::__enable_if<__is_char<_CharT2>::__value,
219 streambuf_type* _M_sbuf;
225 : _M_sbuf(__s.rdbuf()), _M_failed(!_M_sbuf) { }
229 : _M_sbuf(__s), _M_failed(!_M_sbuf) { }
233 operator=(_CharT __c)
236 _Traits::eq_int_type(_M_sbuf->
sputc(__c), _Traits::eof()))
258 failed()
const throw()
259 {
return _M_failed; }
264 if (__builtin_expect(!_M_failed,
true)
265 && __builtin_expect(this->_M_sbuf->
sputn(__ws, __len) != __len,
273 template<
typename _CharT>
274 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
275 ostreambuf_iterator<_CharT> >::__type
276 copy(istreambuf_iterator<_CharT> __first,
277 istreambuf_iterator<_CharT> __last,
278 ostreambuf_iterator<_CharT> __result)
280 if (__first._M_sbuf && !__last._M_sbuf && !__result._M_failed)
283 __copy_streambufs_eof(__first._M_sbuf, __result._M_sbuf, __ineof);
285 __result._M_failed =
true;
290 template<
bool _IsMove,
typename _CharT>
291 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
292 ostreambuf_iterator<_CharT> >::__type
293 __copy_move_a2(_CharT* __first, _CharT* __last,
294 ostreambuf_iterator<_CharT> __result)
298 __result._M_put(__first, __num);
302 template<
bool _IsMove,
typename _CharT>
303 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
304 ostreambuf_iterator<_CharT> >::__type
305 __copy_move_a2(
const _CharT* __first,
const _CharT* __last,
306 ostreambuf_iterator<_CharT> __result)
310 __result._M_put(__first, __num);
314 template<
bool _IsMove,
typename _CharT>
315 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
317 __copy_move_a2(istreambuf_iterator<_CharT> __first,
318 istreambuf_iterator<_CharT> __last, _CharT* __result)
320 typedef istreambuf_iterator<_CharT> __is_iterator_type;
321 typedef typename __is_iterator_type::traits_type traits_type;
322 typedef typename __is_iterator_type::streambuf_type streambuf_type;
323 typedef typename traits_type::int_type int_type;
325 if (__first._M_sbuf && !__last._M_sbuf)
327 streambuf_type* __sb = __first._M_sbuf;
328 int_type __c = __sb->sgetc();
329 while (!traits_type::eq_int_type(__c, traits_type::eof()))
331 const streamsize __n = __sb->egptr() - __sb->gptr();
334 traits_type::copy(__result, __sb->gptr(), __n);
337 __c = __sb->underflow();
341 *__result++ = traits_type::to_char_type(__c);
342 __c = __sb->snextc();
349 template<
typename _CharT>
350 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
351 istreambuf_iterator<_CharT> >::__type
352 find(istreambuf_iterator<_CharT> __first,
353 istreambuf_iterator<_CharT> __last,
const _CharT& __val)
355 typedef istreambuf_iterator<_CharT> __is_iterator_type;
356 typedef typename __is_iterator_type::traits_type traits_type;
357 typedef typename __is_iterator_type::streambuf_type streambuf_type;
358 typedef typename traits_type::int_type int_type;
360 if (__first._M_sbuf && !__last._M_sbuf)
362 const int_type __ival = traits_type::to_int_type(__val);
363 streambuf_type* __sb = __first._M_sbuf;
364 int_type __c = __sb->sgetc();
365 while (!traits_type::eq_int_type(__c, traits_type::eof())
366 && !traits_type::eq_int_type(__c, __ival))
368 streamsize __n = __sb->egptr() - __sb->gptr();
371 const _CharT* __p = traits_type::find(__sb->gptr(),
374 __n = __p - __sb->gptr();
379 __c = __sb->snextc();
382 if (!traits_type::eq_int_type(__c, traits_type::eof()))
390 _GLIBCXX_END_NAMESPACE