30 #ifndef _STREAMBUF_ITERATOR_H 31 #define _STREAMBUF_ITERATOR_H 1 33 #pragma GCC system_header 38 namespace std _GLIBCXX_VISIBILITY(default)
40 _GLIBCXX_BEGIN_NAMESPACE_VERSION
49 template<
typename _CharT,
typename _Traits>
50 class istreambuf_iterator
51 :
public iterator<input_iterator_tag, _CharT, typename _Traits::off_type,
53 #if __cplusplus >= 201103L
71 template<
typename _CharT2>
72 friend typename __gnu_cxx::__enable_if<__is_char<_CharT2>::__value,
77 template<
bool _IsMove,
typename _CharT2>
78 friend typename __gnu_cxx::__enable_if<__is_char<_CharT2>::__value,
83 template<
typename _CharT2>
84 friend typename __gnu_cxx::__enable_if<__is_char<_CharT2>::__value,
89 template<
typename _CharT2,
typename _Distance>
90 friend typename __gnu_cxx::__enable_if<__is_char<_CharT2>::__value,
110 #if __cplusplus >= 201103L 118 : _M_sbuf(__s.rdbuf()), _M_c(traits_type::eof()) { }
122 : _M_sbuf(__s), _M_c(traits_type::eof()) { }
124 #if __cplusplus >= 201103L 137 #ifdef _GLIBCXX_DEBUG_PEDANTIC 140 __glibcxx_requires_cond(!_S_is_eof(__c),
141 _M_message(__gnu_debug::__msg_deref_istreambuf)
142 ._M_iterator(*
this));
144 return traits_type::to_char_type(__c);
151 __glibcxx_requires_cond(_M_sbuf &&
152 (!_S_is_eof(_M_c) || !_S_is_eof(_M_sbuf->
sgetc())),
153 _M_message(__gnu_debug::__msg_inc_istreambuf)
154 ._M_iterator(*
this));
157 _M_c = traits_type::eof();
165 __glibcxx_requires_cond(_M_sbuf &&
166 (!_S_is_eof(_M_c) || !_S_is_eof(_M_sbuf->
sgetc())),
167 _M_message(__gnu_debug::__msg_inc_istreambuf)
168 ._M_iterator(*
this));
171 __old._M_c = _M_sbuf->
sbumpc();
172 _M_c = traits_type::eof();
182 {
return _M_at_eof() == __b._M_at_eof(); }
189 if (_M_sbuf && _S_is_eof(__ret) && _S_is_eof(__ret = _M_sbuf->
sgetc()))
196 {
return _S_is_eof(_M_get()); }
201 const int_type __eof = traits_type::eof();
202 return traits_type::eq_int_type(__c, __eof);
206 template<
typename _CharT,
typename _Traits>
208 operator==(
const istreambuf_iterator<_CharT, _Traits>& __a,
209 const istreambuf_iterator<_CharT, _Traits>& __b)
210 {
return __a.equal(__b); }
212 template<
typename _CharT,
typename _Traits>
214 operator!=(
const istreambuf_iterator<_CharT, _Traits>& __a,
215 const istreambuf_iterator<_CharT, _Traits>& __b)
216 {
return !__a.equal(__b); }
219 template<
typename _CharT,
typename _Traits>
220 class ostreambuf_iterator
221 :
public iterator<output_iterator_tag, void, void, void, void>
233 template<
typename _CharT2>
234 friend typename __gnu_cxx::__enable_if<__is_char<_CharT2>::__value,
246 : _M_sbuf(__s.rdbuf()), _M_failed(!_M_sbuf) { }
250 : _M_sbuf(__s), _M_failed(!_M_sbuf) { }
257 _Traits::eq_int_type(_M_sbuf->
sputc(__c), _Traits::eof()))
280 {
return _M_failed; }
285 if (__builtin_expect(!_M_failed,
true)
286 && __builtin_expect(this->_M_sbuf->
sputn(__ws, __len) != __len,
294 template<
typename _CharT>
295 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
296 ostreambuf_iterator<_CharT> >::__type
297 copy(istreambuf_iterator<_CharT> __first,
298 istreambuf_iterator<_CharT> __last,
299 ostreambuf_iterator<_CharT> __result)
301 if (__first._M_sbuf && !__last._M_sbuf && !__result._M_failed)
304 __copy_streambufs_eof(__first._M_sbuf, __result._M_sbuf, __ineof);
306 __result._M_failed =
true;
311 template<
bool _IsMove,
typename _CharT>
312 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
313 ostreambuf_iterator<_CharT> >::__type
314 __copy_move_a2(_CharT* __first, _CharT* __last,
315 ostreambuf_iterator<_CharT> __result)
319 __result._M_put(__first, __num);
323 template<
bool _IsMove,
typename _CharT>
324 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
325 ostreambuf_iterator<_CharT> >::__type
326 __copy_move_a2(
const _CharT* __first,
const _CharT* __last,
327 ostreambuf_iterator<_CharT> __result)
331 __result._M_put(__first, __num);
335 template<
bool _IsMove,
typename _CharT>
336 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
338 __copy_move_a2(istreambuf_iterator<_CharT> __first,
339 istreambuf_iterator<_CharT> __last, _CharT* __result)
341 typedef istreambuf_iterator<_CharT> __is_iterator_type;
342 typedef typename __is_iterator_type::traits_type traits_type;
343 typedef typename __is_iterator_type::streambuf_type streambuf_type;
344 typedef typename traits_type::int_type int_type;
346 if (__first._M_sbuf && !__last._M_sbuf)
348 streambuf_type* __sb = __first._M_sbuf;
349 int_type __c = __sb->sgetc();
350 while (!traits_type::eq_int_type(__c, traits_type::eof()))
352 const streamsize __n = __sb->egptr() - __sb->gptr();
355 traits_type::copy(__result, __sb->gptr(), __n);
356 __sb->__safe_gbump(__n);
358 __c = __sb->underflow();
362 *__result++ = traits_type::to_char_type(__c);
363 __c = __sb->snextc();
370 template<
typename _CharT>
371 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
372 istreambuf_iterator<_CharT> >::__type
373 find(istreambuf_iterator<_CharT> __first,
374 istreambuf_iterator<_CharT> __last,
const _CharT& __val)
376 typedef istreambuf_iterator<_CharT> __is_iterator_type;
377 typedef typename __is_iterator_type::traits_type traits_type;
378 typedef typename __is_iterator_type::streambuf_type streambuf_type;
379 typedef typename traits_type::int_type int_type;
380 const int_type __eof = traits_type::eof();
382 if (__first._M_sbuf && !__last._M_sbuf)
384 const int_type __ival = traits_type::to_int_type(__val);
385 streambuf_type* __sb = __first._M_sbuf;
386 int_type __c = __sb->sgetc();
387 while (!traits_type::eq_int_type(__c, __eof)
388 && !traits_type::eq_int_type(__c, __ival))
390 streamsize __n = __sb->egptr() - __sb->gptr();
393 const _CharT* __p = traits_type::find(__sb->gptr(),
396 __n = __p - __sb->gptr();
397 __sb->__safe_gbump(__n);
401 __c = __sb->snextc();
404 __first._M_c = __eof;
410 template<
typename _CharT,
typename _Distance>
411 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
413 advance(istreambuf_iterator<_CharT>& __i, _Distance __n)
418 __glibcxx_assert(__n > 0);
419 __glibcxx_requires_cond(!__i._M_at_eof(),
420 _M_message(__gnu_debug::__msg_inc_istreambuf)
423 typedef istreambuf_iterator<_CharT> __is_iterator_type;
424 typedef typename __is_iterator_type::traits_type traits_type;
425 typedef typename __is_iterator_type::streambuf_type streambuf_type;
426 typedef typename traits_type::int_type int_type;
427 const int_type __eof = traits_type::eof();
429 streambuf_type* __sb = __i._M_sbuf;
432 streamsize __size = __sb->egptr() - __sb->gptr();
435 __sb->__safe_gbump(__n);
439 __sb->__safe_gbump(__size);
441 if (traits_type::eq_int_type(__sb->underflow(), __eof))
443 __glibcxx_requires_cond(__n == 0,
444 _M_message(__gnu_debug::__msg_inc_istreambuf)
455 _GLIBCXX_END_NAMESPACE_VERSION
basic_streambuf< _CharT, _Traits > streambuf_type
Public typedefs.
The actual work of input and output (interface).
ISO C++ entities toplevel namespace is std.
istreambuf_iterator operator++(int)
Advance the iterator. Calls streambuf.sbumpc().
istreambuf_iterator(istream_type &__s) noexcept
Construct start of input stream iterator.
ostreambuf_iterator(ostream_type &__s) noexcept
Construct output iterator from ostream.
basic_streambuf< _CharT, _Traits > streambuf_type
Public typedefs.
istreambuf_iterator(streambuf_type *__s) noexcept
Construct start of streambuf iterator.
ptrdiff_t streamsize
Integral type for I/O operation counts and buffer sizes.
istreambuf_iterator & operator++()
Advance the iterator. Calls streambuf.sbumpc().
ostreambuf_iterator & operator++()
Return *this.
Template class basic_ostream.
int_type sgetc()
Getting the next character.
int_type sbumpc()
Getting the next character.
streamsize sputn(const char_type *__s, streamsize __n)
Entry point for all single-character output functions.
_Traits traits_type
Public typedefs.
Template class basic_istream.
_CharT char_type
Public typedefs.
_CharT char_type
Public typedefs.
basic_ostream< _CharT, _Traits > ostream_type
Public typedefs.
Provides output iterator semantics for streambufs.
char_type operator*() const
Return the current character pointed to by iterator. This returns streambuf.sgetc(). It cannot be assigned. NB: The result of operator*() on an end of stream is undefined.
_Traits::int_type int_type
Public typedefs.
_Traits traits_type
Public typedefs.
constexpr istreambuf_iterator() noexcept
Construct end of input stream iterator.
Provides input iterator semantics for streambufs.
bool failed() const noexcept
Return true if previous operator=() failed.
ostreambuf_iterator & operator=(_CharT __c)
Write character to streambuf. Calls streambuf.sputc().
bool equal(const istreambuf_iterator &__b) const
Return true both iterators are end or both are not end.
int_type sputc(char_type __c)
Entry point for all single-character output functions.
ostreambuf_iterator & operator*()
Return *this.
ostreambuf_iterator(streambuf_type *__s) noexcept
Construct output iterator from streambuf.
ostreambuf_iterator & operator++(int)
Return *this.
basic_istream< _CharT, _Traits > istream_type
Public typedefs.
_GLIBCXX17_CONSTEXPR void advance(_InputIterator &__i, _Distance __n)
A generalization of pointer arithmetic.