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,
97 mutable streambuf_type* _M_sbuf;
98 mutable int_type _M_c;
103 : _M_sbuf(0), _M_c(traits_type::eof()) { }
105 #if __cplusplus >= 201103L 113 : _M_sbuf(__s.rdbuf()), _M_c(traits_type::eof()) { }
117 : _M_sbuf(__s), _M_c(traits_type::eof()) { }
125 #ifdef _GLIBCXX_DEBUG_PEDANTIC 128 __glibcxx_requires_cond(!_M_at_eof(),
129 _M_message(__gnu_debug::__msg_deref_istreambuf)
130 ._M_iterator(*
this));
132 return traits_type::to_char_type(_M_get());
139 __glibcxx_requires_cond(!_M_at_eof(),
140 _M_message(__gnu_debug::__msg_inc_istreambuf)
141 ._M_iterator(*
this));
145 _M_c = traits_type::eof();
154 __glibcxx_requires_cond(!_M_at_eof(),
155 _M_message(__gnu_debug::__msg_inc_istreambuf)
156 ._M_iterator(*
this));
161 __old._M_c = _M_sbuf->
sbumpc();
162 _M_c = traits_type::eof();
173 {
return _M_at_eof() == __b._M_at_eof(); }
179 const int_type __eof = traits_type::eof();
180 int_type __ret = __eof;
183 if (!traits_type::eq_int_type(_M_c, __eof))
185 else if (!traits_type::eq_int_type((__ret = _M_sbuf->
sgetc()),
197 const int_type __eof = traits_type::eof();
198 return traits_type::eq_int_type(_M_get(), __eof);
202 template<
typename _CharT,
typename _Traits>
206 {
return __a.equal(__b); }
208 template<
typename _CharT,
typename _Traits>
212 {
return !__a.equal(__b); }
215 template<
typename _CharT,
typename _Traits>
217 :
public iterator<output_iterator_tag, void, void, void, void>
229 template<
typename _CharT2>
230 friend typename __gnu_cxx::__enable_if<__is_char<_CharT2>::__value,
236 streambuf_type* _M_sbuf;
242 : _M_sbuf(__s.rdbuf()), _M_failed(!_M_sbuf) { }
246 : _M_sbuf(__s), _M_failed(!_M_sbuf) { }
253 _Traits::eq_int_type(_M_sbuf->
sputc(__c), _Traits::eof()))
276 {
return _M_failed; }
281 if (__builtin_expect(!_M_failed,
true)
282 && __builtin_expect(this->_M_sbuf->
sputn(__ws, __len) != __len,
290 template<
typename _CharT>
291 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
297 if (__first._M_sbuf && !__last._M_sbuf && !__result._M_failed)
300 __copy_streambufs_eof(__first._M_sbuf, __result._M_sbuf, __ineof);
302 __result._M_failed =
true;
307 template<
bool _IsMove,
typename _CharT>
308 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
310 __copy_move_a2(_CharT* __first, _CharT* __last,
315 __result._M_put(__first, __num);
319 template<
bool _IsMove,
typename _CharT>
320 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
322 __copy_move_a2(
const _CharT* __first,
const _CharT* __last,
327 __result._M_put(__first, __num);
331 template<
bool _IsMove,
typename _CharT>
332 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
338 typedef typename __is_iterator_type::traits_type
traits_type;
339 typedef typename __is_iterator_type::streambuf_type
streambuf_type;
340 typedef typename traits_type::int_type
int_type;
342 if (__first._M_sbuf && !__last._M_sbuf)
344 streambuf_type* __sb = __first._M_sbuf;
345 int_type __c = __sb->
sgetc();
346 while (!traits_type::eq_int_type(__c, traits_type::eof()))
351 traits_type::copy(__result, __sb->
gptr(), __n);
352 __sb->__safe_gbump(__n);
358 *__result++ = traits_type::to_char_type(__c);
366 template<
typename _CharT>
367 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
373 typedef typename __is_iterator_type::traits_type
traits_type;
374 typedef typename __is_iterator_type::streambuf_type
streambuf_type;
375 typedef typename traits_type::int_type
int_type;
377 if (__first._M_sbuf && !__last._M_sbuf)
379 const int_type __ival = traits_type::to_int_type(__val);
380 streambuf_type* __sb = __first._M_sbuf;
381 int_type __c = __sb->
sgetc();
382 while (!traits_type::eq_int_type(__c, traits_type::eof())
383 && !traits_type::eq_int_type(__c, __ival))
388 const _CharT* __p = traits_type::find(__sb->
gptr(),
391 __n = __p - __sb->
gptr();
392 __sb->__safe_gbump(__n);
399 if (!traits_type::eq_int_type(__c, traits_type::eof()))
409 _GLIBCXX_END_NAMESPACE_VERSION
streamsize sputn(const char_type *__s, streamsize __n)
Entry point for all single-character output functions.
char_type * egptr() const
Access to the get area.
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.
ostreambuf_iterator & operator++()
Return *this.
Provides input iterator semantics for streambufs.
_CharT char_type
Public typedefs.
int_type sbumpc()
Getting the next character.
_Traits traits_type
Public typedefs.
char_type * gptr() const
Access to the get area.
istreambuf_iterator(streambuf_type *__s) noexcept
Construct start of streambuf iterator.
istreambuf_iterator & operator++()
Advance the iterator. Calls streambuf.sbumpc().
The actual work of input and output (interface).
Provides output iterator semantics for streambufs.
_CharT char_type
Public typedefs.
ptrdiff_t streamsize
Integral type for I/O operation counts and buffer sizes.
bool equal(const istreambuf_iterator &__b) const
Return true both iterators are end or both are not end.
virtual int_type underflow()
Fetches more data from the controlled sequence.
_Traits::int_type int_type
Public typedefs.
istreambuf_iterator(istream_type &__s) noexcept
Construct start of input stream iterator.
basic_istream< _CharT, _Traits > istream_type
Public typedefs.
Template class basic_ostream.
ostreambuf_iterator & operator=(_CharT __c)
Write character to streambuf. Calls streambuf.sputc().
int_type snextc()
Getting the next character.
int_type sputc(char_type __c)
Entry point for all single-character output functions.
int_type sgetc()
Getting the next character.
_Traits traits_type
Public typedefs.
ostreambuf_iterator & operator++(int)
Return *this.
ostreambuf_iterator(ostream_type &__s) noexcept
Construct output iterator from ostream.
constexpr istreambuf_iterator() noexcept
Construct end of input stream iterator.
basic_ostream< _CharT, _Traits > ostream_type
Public typedefs.
Template class basic_istream.
istreambuf_iterator operator++(int)
Advance the iterator. Calls streambuf.sbumpc().
basic_streambuf< _CharT, _Traits > streambuf_type
Public typedefs.
bool failed() const noexcept
Return true if previous operator=() failed.
basic_streambuf< _CharT, _Traits > streambuf_type
Public typedefs.
ISO C++ entities toplevel namespace is std.
ostreambuf_iterator(streambuf_type *__s) noexcept
Construct output iterator from streambuf.
ostreambuf_iterator & operator*()
Return *this.