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()) { }
132 #ifdef _GLIBCXX_DEBUG_PEDANTIC 135 __glibcxx_requires_cond(!_S_is_eof(__c),
136 _M_message(__gnu_debug::__msg_deref_istreambuf)
137 ._M_iterator(*
this));
139 return traits_type::to_char_type(__c);
146 __glibcxx_requires_cond(_M_sbuf &&
147 (!_S_is_eof(_M_c) || !_S_is_eof(_M_sbuf->
sgetc())),
148 _M_message(__gnu_debug::__msg_inc_istreambuf)
149 ._M_iterator(*
this));
152 _M_c = traits_type::eof();
160 __glibcxx_requires_cond(_M_sbuf &&
161 (!_S_is_eof(_M_c) || !_S_is_eof(_M_sbuf->
sgetc())),
162 _M_message(__gnu_debug::__msg_inc_istreambuf)
163 ._M_iterator(*
this));
166 __old._M_c = _M_sbuf->
sbumpc();
167 _M_c = traits_type::eof();
177 {
return _M_at_eof() == __b._M_at_eof(); }
184 if (_M_sbuf && _S_is_eof(__ret) && _S_is_eof(__ret = _M_sbuf->
sgetc()))
191 {
return _S_is_eof(_M_get()); }
196 const int_type __eof = traits_type::eof();
197 return traits_type::eq_int_type(__c, __eof);
201 template<
typename _CharT,
typename _Traits>
203 operator==(
const istreambuf_iterator<_CharT, _Traits>& __a,
204 const istreambuf_iterator<_CharT, _Traits>& __b)
205 {
return __a.equal(__b); }
207 template<
typename _CharT,
typename _Traits>
209 operator!=(
const istreambuf_iterator<_CharT, _Traits>& __a,
210 const istreambuf_iterator<_CharT, _Traits>& __b)
211 {
return !__a.equal(__b); }
214 template<
typename _CharT,
typename _Traits>
215 class ostreambuf_iterator
216 :
public iterator<output_iterator_tag, void, void, void, void>
228 template<
typename _CharT2>
229 friend typename __gnu_cxx::__enable_if<__is_char<_CharT2>::__value,
241 : _M_sbuf(__s.rdbuf()), _M_failed(!_M_sbuf) { }
245 : _M_sbuf(__s), _M_failed(!_M_sbuf) { }
252 _Traits::eq_int_type(_M_sbuf->
sputc(__c), _Traits::eof()))
275 {
return _M_failed; }
280 if (__builtin_expect(!_M_failed,
true)
281 && __builtin_expect(this->_M_sbuf->
sputn(__ws, __len) != __len,
289 template<
typename _CharT>
290 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
291 ostreambuf_iterator<_CharT> >::__type
292 copy(istreambuf_iterator<_CharT> __first,
293 istreambuf_iterator<_CharT> __last,
294 ostreambuf_iterator<_CharT> __result)
296 if (__first._M_sbuf && !__last._M_sbuf && !__result._M_failed)
299 __copy_streambufs_eof(__first._M_sbuf, __result._M_sbuf, __ineof);
301 __result._M_failed =
true;
306 template<
bool _IsMove,
typename _CharT>
307 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
308 ostreambuf_iterator<_CharT> >::__type
309 __copy_move_a2(_CharT* __first, _CharT* __last,
310 ostreambuf_iterator<_CharT> __result)
314 __result._M_put(__first, __num);
318 template<
bool _IsMove,
typename _CharT>
319 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
320 ostreambuf_iterator<_CharT> >::__type
321 __copy_move_a2(
const _CharT* __first,
const _CharT* __last,
322 ostreambuf_iterator<_CharT> __result)
326 __result._M_put(__first, __num);
330 template<
bool _IsMove,
typename _CharT>
331 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
333 __copy_move_a2(istreambuf_iterator<_CharT> __first,
334 istreambuf_iterator<_CharT> __last, _CharT* __result)
336 typedef istreambuf_iterator<_CharT> __is_iterator_type;
337 typedef typename __is_iterator_type::traits_type traits_type;
338 typedef typename __is_iterator_type::streambuf_type streambuf_type;
339 typedef typename traits_type::int_type int_type;
341 if (__first._M_sbuf && !__last._M_sbuf)
343 streambuf_type* __sb = __first._M_sbuf;
344 int_type __c = __sb->sgetc();
345 while (!traits_type::eq_int_type(__c, traits_type::eof()))
347 const streamsize __n = __sb->egptr() - __sb->gptr();
350 traits_type::copy(__result, __sb->gptr(), __n);
351 __sb->__safe_gbump(__n);
353 __c = __sb->underflow();
357 *__result++ = traits_type::to_char_type(__c);
358 __c = __sb->snextc();
365 template<
typename _CharT>
366 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
367 istreambuf_iterator<_CharT> >::__type
368 find(istreambuf_iterator<_CharT> __first,
369 istreambuf_iterator<_CharT> __last,
const _CharT& __val)
371 typedef istreambuf_iterator<_CharT> __is_iterator_type;
372 typedef typename __is_iterator_type::traits_type traits_type;
373 typedef typename __is_iterator_type::streambuf_type streambuf_type;
374 typedef typename traits_type::int_type int_type;
375 const int_type __eof = traits_type::eof();
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, __eof)
383 && !traits_type::eq_int_type(__c, __ival))
385 streamsize __n = __sb->egptr() - __sb->gptr();
388 const _CharT* __p = traits_type::find(__sb->gptr(),
391 __n = __p - __sb->gptr();
392 __sb->__safe_gbump(__n);
396 __c = __sb->snextc();
399 __first._M_c = __eof;
405 template<
typename _CharT,
typename _Distance>
406 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
408 advance(istreambuf_iterator<_CharT>& __i, _Distance __n)
413 __glibcxx_assert(__n > 0);
414 __glibcxx_requires_cond(!__i._M_at_eof(),
415 _M_message(__gnu_debug::__msg_inc_istreambuf)
418 typedef istreambuf_iterator<_CharT> __is_iterator_type;
419 typedef typename __is_iterator_type::traits_type traits_type;
420 typedef typename __is_iterator_type::streambuf_type streambuf_type;
421 typedef typename traits_type::int_type int_type;
422 const int_type __eof = traits_type::eof();
424 streambuf_type* __sb = __i._M_sbuf;
427 streamsize __size = __sb->egptr() - __sb->gptr();
430 __sb->__safe_gbump(__n);
434 __sb->__safe_gbump(__size);
436 if (traits_type::eq_int_type(__sb->underflow(), __eof))
438 __glibcxx_requires_cond(__n == 0,
439 _M_message(__gnu_debug::__msg_inc_istreambuf)
450 _GLIBCXX_END_NAMESPACE_VERSION
ostreambuf_iterator & operator*()
Return *this.
_CharT char_type
Public typedefs.
bool equal(const istreambuf_iterator &__b) const
Return true both iterators are end or both are not end.
basic_streambuf< _CharT, _Traits > streambuf_type
Public typedefs.
_Traits traits_type
Public typedefs.
Provides output iterator semantics for streambufs.
ptrdiff_t streamsize
Integral type for I/O operation counts and buffer sizes.
_Traits traits_type
Public typedefs.
ostreambuf_iterator & operator=(_CharT __c)
Write character to streambuf. Calls streambuf.sputc().
_GLIBCXX17_CONSTEXPR void advance(_InputIterator &__i, _Distance __n)
A generalization of pointer arithmetic.
constexpr istreambuf_iterator() noexcept
Construct end of input stream iterator.
basic_istream< _CharT, _Traits > istream_type
Public typedefs.
Template class basic_istream.
int_type sbumpc()
Getting the next character.
The actual work of input and output (interface).
ISO C++ entities toplevel namespace is std.
ostreambuf_iterator(ostream_type &__s) noexcept
Construct output iterator from ostream.
streamsize sputn(const char_type *__s, streamsize __n)
Entry point for all single-character output functions.
Provides input iterator semantics for streambufs.
ostreambuf_iterator & operator++()
Return *this.
basic_streambuf< _CharT, _Traits > streambuf_type
Public typedefs.
istreambuf_iterator(streambuf_type *__s) noexcept
Construct start of streambuf iterator.
ostreambuf_iterator(streambuf_type *__s) noexcept
Construct output iterator from streambuf.
Template class basic_ostream.
bool failed() const noexcept
Return true if previous operator=() failed.
int_type sputc(char_type __c)
Entry point for all single-character output functions.
int_type sgetc()
Getting the next character.
ostreambuf_iterator & operator++(int)
Return *this.
istreambuf_iterator operator++(int)
Advance the iterator. Calls streambuf.sbumpc().
istreambuf_iterator(istream_type &__s) noexcept
Construct start of input stream iterator.
basic_ostream< _CharT, _Traits > ostream_type
Public typedefs.
istreambuf_iterator & operator++()
Advance the iterator. Calls streambuf.sbumpc().
char_type operator*() const
Return the current character pointed to by iterator. This returns streambuf.sgetc()....
_CharT char_type
Public typedefs.
_Traits::int_type int_type
Public typedefs.