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,
58 #if __cplusplus < 201103L 60 #elif __cplusplus > 201703L 73 template<
typename _CharT2>
74 friend typename __gnu_cxx::__enable_if<__is_char<_CharT2>::__value,
79 template<
bool _IsMove,
typename _CharT2>
80 friend typename __gnu_cxx::__enable_if<__is_char<_CharT2>::__value,
85 #if __cplusplus >= 201103L 86 template<
typename _CharT2,
typename _Size>
87 friend __enable_if_t<__is_char<_CharT2>::__value, _CharT2*>
91 template<
typename _CharT2>
92 friend typename __gnu_cxx::__enable_if<__is_char<_CharT2>::__value,
97 template<
typename _CharT2,
typename _Distance>
98 friend typename __gnu_cxx::__enable_if<__is_char<_CharT2>::__value,
110 mutable streambuf_type* _M_sbuf;
116 : _M_sbuf(0), _M_c(traits_type::eof()) { }
118 #if __cplusplus >= 201103L 126 : _M_sbuf(__s.rdbuf()), _M_c(traits_type::eof()) { }
130 : _M_sbuf(__s), _M_c(traits_type::eof()) { }
132 #if __cplusplus >= 201103L 143 int_type __c = _M_get();
145 #ifdef _GLIBCXX_DEBUG_PEDANTIC 148 __glibcxx_requires_cond(!_S_is_eof(__c),
149 _M_message(__gnu_debug::__msg_deref_istreambuf)
150 ._M_iterator(*
this));
152 return traits_type::to_char_type(__c);
159 __glibcxx_requires_cond(_M_sbuf &&
160 (!_S_is_eof(_M_c) || !_S_is_eof(_M_sbuf->
sgetc())),
161 _M_message(__gnu_debug::__msg_inc_istreambuf)
162 ._M_iterator(*
this));
165 _M_c = traits_type::eof();
173 __glibcxx_requires_cond(_M_sbuf &&
174 (!_S_is_eof(_M_c) || !_S_is_eof(_M_sbuf->
sgetc())),
175 _M_message(__gnu_debug::__msg_inc_istreambuf)
176 ._M_iterator(*
this));
179 __old._M_c = _M_sbuf->
sbumpc();
180 _M_c = traits_type::eof();
190 {
return _M_at_eof() == __b._M_at_eof(); }
196 int_type __ret = _M_c;
197 if (_M_sbuf && _S_is_eof(__ret) && _S_is_eof(__ret = _M_sbuf->
sgetc()))
204 {
return _S_is_eof(_M_get()); }
207 _S_is_eof(int_type __c)
209 const int_type __eof = traits_type::eof();
210 return traits_type::eq_int_type(__c, __eof);
214 template<
typename _CharT,
typename _Traits>
218 {
return __a.equal(__b); }
220 template<
typename _CharT,
typename _Traits>
224 {
return !__a.equal(__b); }
227 template<
typename _CharT,
typename _Traits>
229 :
public iterator<output_iterator_tag, void, void, void, void>
235 #if __cplusplus > 201703L 244 template<
typename _CharT2>
245 friend typename __gnu_cxx::__enable_if<__is_char<_CharT2>::__value,
251 streambuf_type* _M_sbuf;
256 #if __cplusplus > 201703L 259 : _M_sbuf(
nullptr), _M_failed(true) { }
264 : _M_sbuf(__s.rdbuf()), _M_failed(!_M_sbuf) { }
268 : _M_sbuf(__s), _M_failed(!_M_sbuf) { }
275 _Traits::eq_int_type(_M_sbuf->
sputc(__c), _Traits::eof()))
298 {
return _M_failed; }
303 if (__builtin_expect(!_M_failed,
true)
304 && __builtin_expect(this->_M_sbuf->
sputn(__ws, __len) != __len,
312 template<
typename _CharT>
313 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
319 if (__first._M_sbuf && !__last._M_sbuf && !__result._M_failed)
322 __copy_streambufs_eof(__first._M_sbuf, __result._M_sbuf, __ineof);
324 __result._M_failed =
true;
329 template<
bool _IsMove,
typename _CharT>
330 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
332 __copy_move_a2(_CharT* __first, _CharT* __last,
337 __result._M_put(__first, __num);
341 template<
bool _IsMove,
typename _CharT>
342 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
344 __copy_move_a2(
const _CharT* __first,
const _CharT* __last,
349 __result._M_put(__first, __num);
353 template<
bool _IsMove,
typename _CharT>
354 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
360 typedef typename __is_iterator_type::traits_type
traits_type;
361 typedef typename __is_iterator_type::streambuf_type
streambuf_type;
362 typedef typename traits_type::int_type
int_type;
364 if (__first._M_sbuf && !__last._M_sbuf)
366 streambuf_type* __sb = __first._M_sbuf;
367 int_type __c = __sb->
sgetc();
368 while (!traits_type::eq_int_type(__c, traits_type::eof()))
373 traits_type::copy(__result, __sb->
gptr(), __n);
374 __sb->__safe_gbump(__n);
380 *__result++ = traits_type::to_char_type(__c);
388 #if __cplusplus >= 201103L 389 template<
typename _CharT,
typename _Size>
390 __enable_if_t<__is_char<_CharT>::__value, _CharT*>
396 __glibcxx_requires_cond(__it._M_sbuf,
397 _M_message(__gnu_debug::__msg_inc_istreambuf)
399 _CharT* __beg = __result;
400 __result += __it._M_sbuf->sgetn(__beg, __n);
401 __glibcxx_requires_cond(__result - __beg == __n,
402 _M_message(__gnu_debug::__msg_inc_istreambuf)
408 template<
typename _CharT>
409 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
415 typedef typename __is_iterator_type::traits_type
traits_type;
416 typedef typename __is_iterator_type::streambuf_type
streambuf_type;
417 typedef typename traits_type::int_type
int_type;
418 const int_type __eof = traits_type::eof();
420 if (__first._M_sbuf && !__last._M_sbuf)
422 const int_type __ival = traits_type::to_int_type(__val);
423 streambuf_type* __sb = __first._M_sbuf;
424 int_type __c = __sb->
sgetc();
425 while (!traits_type::eq_int_type(__c, __eof)
426 && !traits_type::eq_int_type(__c, __ival))
431 const _CharT* __p = traits_type::find(__sb->
gptr(),
434 __n = __p - __sb->
gptr();
435 __sb->__safe_gbump(__n);
442 __first._M_c = __eof;
448 template<
typename _CharT,
typename _Distance>
449 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
456 __glibcxx_assert(__n > 0);
457 __glibcxx_requires_cond(!__i._M_at_eof(),
458 _M_message(__gnu_debug::__msg_inc_istreambuf)
462 typedef typename __is_iterator_type::traits_type
traits_type;
463 typedef typename __is_iterator_type::streambuf_type
streambuf_type;
464 typedef typename traits_type::int_type
int_type;
465 const int_type __eof = traits_type::eof();
467 streambuf_type* __sb = __i._M_sbuf;
473 __sb->__safe_gbump(__n);
477 __sb->__safe_gbump(__size);
479 if (traits_type::eq_int_type(__sb->
underflow(), __eof))
481 __glibcxx_requires_cond(__n == 0,
482 _M_message(__gnu_debug::__msg_inc_istreambuf)
493 _GLIBCXX_END_NAMESPACE_VERSION
ostreambuf_iterator & operator=(_CharT __c)
Write character to streambuf. Calls streambuf.sputc().
istreambuf_iterator operator++(int)
Advance the iterator. Calls streambuf.sbumpc().
char_type * egptr() const
Access to the get area.
istreambuf_iterator(istream_type &__s) noexcept
Construct start of input stream iterator.
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.
Template class basic_ostream.
istreambuf_iterator(streambuf_type *__s) noexcept
Construct start of streambuf iterator.
virtual int_type underflow()
Fetches more data from the controlled sequence.
basic_streambuf< _CharT, _Traits > streambuf_type
Public typedefs.
_Traits::int_type int_type
Public typedefs.
Provides output iterator semantics for streambufs.
_Traits traits_type
Public typedefs.
int_type sputc(char_type __c)
Entry point for all single-character output functions.
ostreambuf_iterator & operator*()
Return *this.
_CharT * pointer
This type represents a pointer-to-value_type.
Template class basic_istream.
_Traits::off_type difference_type
Distance between iterators is represented as this type.
_CharT reference
This type represents a reference-to-value_type.
bool failed() const noexcept
Return true if previous operator=() failed.
bool equal(const istreambuf_iterator &__b) const
Return true both iterators are end or both are not end.
_Traits traits_type
Public typedefs.
ostreambuf_iterator(streambuf_type *__s) noexcept
Construct output iterator from streambuf.
The actual work of input and output (interface).
_CharT char_type
Public typedefs.
istreambuf_iterator & operator++()
Advance the iterator. Calls streambuf.sbumpc().
Provides input iterator semantics for streambufs.
int_type sgetc()
Getting the next character.
constexpr void advance(_InputIterator &__i, _Distance __n)
A generalization of pointer arithmetic.
ISO C++ entities toplevel namespace is std.
int_type snextc()
Getting the next character.
char_type * gptr() const
Access to the get area.
constexpr istreambuf_iterator() noexcept
Construct end of input stream iterator.
int_type sbumpc()
Getting the next character.
ostreambuf_iterator & operator++(int)
Return *this.
_CharT char_type
Public typedefs.
ostreambuf_iterator(ostream_type &__s) noexcept
Construct output iterator from ostream.
basic_istream< _CharT, _Traits > istream_type
Public typedefs.
ostreambuf_iterator & operator++()
Return *this.
ptrdiff_t streamsize
Integral type for I/O operation counts and buffer sizes.
streamsize sputn(const char_type *__s, streamsize __n)
Entry point for all single-character output functions.
basic_streambuf< _CharT, _Traits > streambuf_type
Public typedefs.
basic_ostream< _CharT, _Traits > ostream_type
Public typedefs.