32 #ifndef _STREAMBUF_ITERATOR_H
33 #define _STREAMBUF_ITERATOR_H 1
35 #pragma GCC system_header
40 namespace std _GLIBCXX_VISIBILITY(default)
42 _GLIBCXX_BEGIN_NAMESPACE_VERSION
51 template<
typename _CharT,
typename _Traits>
52 class istreambuf_iterator
53 :
public iterator<input_iterator_tag, _CharT, typename _Traits::off_type,
67 template<
typename _CharT2>
68 friend typename __gnu_cxx::__enable_if<__is_char<_CharT2>::__value,
73 template<
bool _IsMove,
typename _CharT2>
74 friend typename __gnu_cxx::__enable_if<__is_char<_CharT2>::__value,
79 template<
typename _CharT2>
80 friend typename __gnu_cxx::__enable_if<__is_char<_CharT2>::__value,
103 : _M_sbuf(__s.rdbuf()), _M_c(traits_type::eof()) { }
107 : _M_sbuf(__s), _M_c(traits_type::eof()) { }
115 #ifdef _GLIBCXX_DEBUG_PEDANTIC
118 __glibcxx_requires_cond(!_M_at_eof(),
119 _M_message(__gnu_debug::__msg_deref_istreambuf)
120 ._M_iterator(*
this));
122 return traits_type::to_char_type(_M_get());
129 __glibcxx_requires_cond(!_M_at_eof(),
130 _M_message(__gnu_debug::__msg_inc_istreambuf)
131 ._M_iterator(*
this));
135 _M_c = traits_type::eof();
144 __glibcxx_requires_cond(!_M_at_eof(),
145 _M_message(__gnu_debug::__msg_inc_istreambuf)
146 ._M_iterator(*
this));
151 __old._M_c = _M_sbuf->
sbumpc();
152 _M_c = traits_type::eof();
163 {
return _M_at_eof() == __b._M_at_eof(); }
169 const int_type __eof = traits_type::eof();
173 if (!traits_type::eq_int_type(_M_c, __eof))
175 else if (!traits_type::eq_int_type((__ret = _M_sbuf->
sgetc()),
187 const int_type __eof = traits_type::eof();
188 return traits_type::eq_int_type(_M_get(), __eof);
192 template<
typename _CharT,
typename _Traits>
194 operator==(
const istreambuf_iterator<_CharT, _Traits>& __a,
195 const istreambuf_iterator<_CharT, _Traits>& __b)
196 {
return __a.equal(__b); }
198 template<
typename _CharT,
typename _Traits>
200 operator!=(
const istreambuf_iterator<_CharT, _Traits>& __a,
201 const istreambuf_iterator<_CharT, _Traits>& __b)
202 {
return !__a.equal(__b); }
205 template<
typename _CharT,
typename _Traits>
206 class ostreambuf_iterator
207 :
public iterator<output_iterator_tag, void, void, void, void>
219 template<
typename _CharT2>
220 friend typename __gnu_cxx::__enable_if<__is_char<_CharT2>::__value,
232 : _M_sbuf(__s.rdbuf()), _M_failed(!_M_sbuf) { }
236 : _M_sbuf(__s), _M_failed(!_M_sbuf) { }
243 _Traits::eq_int_type(_M_sbuf->
sputc(__c), _Traits::eof()))
266 {
return _M_failed; }
271 if (__builtin_expect(!_M_failed,
true)
272 && __builtin_expect(this->_M_sbuf->
sputn(__ws, __len) != __len,
280 template<
typename _CharT>
281 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
282 ostreambuf_iterator<_CharT> >::__type
283 copy(istreambuf_iterator<_CharT> __first,
284 istreambuf_iterator<_CharT> __last,
285 ostreambuf_iterator<_CharT> __result)
287 if (__first._M_sbuf && !__last._M_sbuf && !__result._M_failed)
290 __copy_streambufs_eof(__first._M_sbuf, __result._M_sbuf, __ineof);
292 __result._M_failed =
true;
297 template<
bool _IsMove,
typename _CharT>
298 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
299 ostreambuf_iterator<_CharT> >::__type
300 __copy_move_a2(_CharT* __first, _CharT* __last,
301 ostreambuf_iterator<_CharT> __result)
305 __result._M_put(__first, __num);
309 template<
bool _IsMove,
typename _CharT>
310 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
311 ostreambuf_iterator<_CharT> >::__type
312 __copy_move_a2(
const _CharT* __first,
const _CharT* __last,
313 ostreambuf_iterator<_CharT> __result)
317 __result._M_put(__first, __num);
321 template<
bool _IsMove,
typename _CharT>
322 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
324 __copy_move_a2(istreambuf_iterator<_CharT> __first,
325 istreambuf_iterator<_CharT> __last, _CharT* __result)
327 typedef istreambuf_iterator<_CharT> __is_iterator_type;
328 typedef typename __is_iterator_type::traits_type traits_type;
329 typedef typename __is_iterator_type::streambuf_type streambuf_type;
330 typedef typename traits_type::int_type int_type;
332 if (__first._M_sbuf && !__last._M_sbuf)
334 streambuf_type* __sb = __first._M_sbuf;
335 int_type __c = __sb->sgetc();
336 while (!traits_type::eq_int_type(__c, traits_type::eof()))
338 const streamsize __n = __sb->egptr() - __sb->gptr();
341 traits_type::copy(__result, __sb->gptr(), __n);
342 __sb->__safe_gbump(__n);
344 __c = __sb->underflow();
348 *__result++ = traits_type::to_char_type(__c);
349 __c = __sb->snextc();
356 template<
typename _CharT>
357 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
358 istreambuf_iterator<_CharT> >::__type
359 find(istreambuf_iterator<_CharT> __first,
360 istreambuf_iterator<_CharT> __last,
const _CharT& __val)
362 typedef istreambuf_iterator<_CharT> __is_iterator_type;
363 typedef typename __is_iterator_type::traits_type traits_type;
364 typedef typename __is_iterator_type::streambuf_type streambuf_type;
365 typedef typename traits_type::int_type int_type;
367 if (__first._M_sbuf && !__last._M_sbuf)
369 const int_type __ival = traits_type::to_int_type(__val);
370 streambuf_type* __sb = __first._M_sbuf;
371 int_type __c = __sb->sgetc();
372 while (!traits_type::eq_int_type(__c, traits_type::eof())
373 && !traits_type::eq_int_type(__c, __ival))
375 streamsize __n = __sb->egptr() - __sb->gptr();
378 const _CharT* __p = traits_type::find(__sb->gptr(),
381 __n = __p - __sb->gptr();
382 __sb->__safe_gbump(__n);
386 __c = __sb->snextc();
389 if (!traits_type::eq_int_type(__c, traits_type::eof()))
399 _GLIBCXX_END_NAMESPACE_VERSION
_Traits::int_type int_type
Public typedefs.
ostreambuf_iterator & operator*()
Return *this.
Controlling output.This is the base class for all output streams. It provides text formatting of all ...
istreambuf_iterator operator++(int)
Advance the iterator. Calls streambuf.sbumpc().
int_type sgetc()
Getting the next character.
constexpr istreambuf_iterator()
Construct end of input stream iterator.
ostreambuf_iterator(streambuf_type *__s)
Construct output iterator from streambuf.
int_type sputc(char_type __c)
Entry point for all single-character output functions.
basic_streambuf< _CharT, _Traits > streambuf_type
Public typedefs.
basic_istream< _CharT, _Traits > istream_type
Public typedefs.
ptrdiff_t streamsize
Integral type for I/O operation counts and buffer sizes.
_CharT char_type
Public typedefs.
_Traits traits_type
Public typedefs.
Controlling input.This is the base class for all input streams. It provides text formatting of all bu...
Provides input iterator semantics for streambufs.
istreambuf_iterator(istream_type &__s)
Construct start of input stream iterator.
_CharT char_type
Public typedefs.
streamsize sputn(const char_type *__s, streamsize __n)
Entry point for all single-character output functions.
ostreambuf_iterator & operator++()
Return *this.
istreambuf_iterator(streambuf_type *__s)
Construct start of streambuf iterator.
bool failed() const
Return true if previous operator=() failed.
basic_streambuf< _CharT, _Traits > streambuf_type
Public typedefs.
bool equal(const istreambuf_iterator &__b) const
Return true both iterators are end or both are not end.
Provides output iterator semantics for streambufs.
basic_ostream< _CharT, _Traits > ostream_type
Public typedefs.
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(ostream_type &__s)
Construct output iterator from ostream.
The actual work of input and output (interface).This is a base class. Derived stream buffers each con...
istreambuf_iterator & operator++()
Advance the iterator. Calls streambuf.sbumpc().
ostreambuf_iterator & operator=(_CharT __c)
Write character to streambuf. Calls streambuf.sputc().
int_type sbumpc()
Getting the next character.
ostreambuf_iterator & operator++(int)
Return *this.
_Traits traits_type
Public typedefs.