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,
55 #ifdef __GXX_EXPERIMENTAL_CXX0X__
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 template<
typename _CharT2>
86 friend typename __gnu_cxx::__enable_if<__is_char<_CharT2>::__value,
107 #ifdef __GXX_EXPERIMENTAL_CXX0X__
115 : _M_sbuf(__s.rdbuf()), _M_c(traits_type::eof()) { }
119 : _M_sbuf(__s), _M_c(traits_type::eof()) { }
127 #ifdef _GLIBCXX_DEBUG_PEDANTIC
130 __glibcxx_requires_cond(!_M_at_eof(),
131 _M_message(__gnu_debug::__msg_deref_istreambuf)
132 ._M_iterator(*
this));
134 return traits_type::to_char_type(_M_get());
141 __glibcxx_requires_cond(!_M_at_eof(),
142 _M_message(__gnu_debug::__msg_inc_istreambuf)
143 ._M_iterator(*
this));
147 _M_c = traits_type::eof();
156 __glibcxx_requires_cond(!_M_at_eof(),
157 _M_message(__gnu_debug::__msg_inc_istreambuf)
158 ._M_iterator(*
this));
163 __old._M_c = _M_sbuf->
sbumpc();
164 _M_c = traits_type::eof();
175 {
return _M_at_eof() == __b._M_at_eof(); }
181 const int_type __eof = traits_type::eof();
185 if (!traits_type::eq_int_type(_M_c, __eof))
187 else if (!traits_type::eq_int_type((__ret = _M_sbuf->
sgetc()),
199 const int_type __eof = traits_type::eof();
200 return traits_type::eq_int_type(_M_get(), __eof);
204 template<
typename _CharT,
typename _Traits>
206 operator==(
const istreambuf_iterator<_CharT, _Traits>& __a,
207 const istreambuf_iterator<_CharT, _Traits>& __b)
208 {
return __a.equal(__b); }
210 template<
typename _CharT,
typename _Traits>
212 operator!=(
const istreambuf_iterator<_CharT, _Traits>& __a,
213 const istreambuf_iterator<_CharT, _Traits>& __b)
214 {
return !__a.equal(__b); }
217 template<
typename _CharT,
typename _Traits>
218 class ostreambuf_iterator
219 :
public iterator<output_iterator_tag, void, void, void, void>
231 template<
typename _CharT2>
232 friend typename __gnu_cxx::__enable_if<__is_char<_CharT2>::__value,
244 : _M_sbuf(__s.rdbuf()), _M_failed(!_M_sbuf) { }
248 : _M_sbuf(__s), _M_failed(!_M_sbuf) { }
255 _Traits::eq_int_type(_M_sbuf->
sputc(__c), _Traits::eof()))
278 {
return _M_failed; }
283 if (__builtin_expect(!_M_failed,
true)
284 && __builtin_expect(this->_M_sbuf->
sputn(__ws, __len) != __len,
292 template<
typename _CharT>
293 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
294 ostreambuf_iterator<_CharT> >::__type
295 copy(istreambuf_iterator<_CharT> __first,
296 istreambuf_iterator<_CharT> __last,
297 ostreambuf_iterator<_CharT> __result)
299 if (__first._M_sbuf && !__last._M_sbuf && !__result._M_failed)
302 __copy_streambufs_eof(__first._M_sbuf, __result._M_sbuf, __ineof);
304 __result._M_failed =
true;
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(_CharT* __first, _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,
323 ostreambuf_iterator<_CharT> >::__type
324 __copy_move_a2(
const _CharT* __first,
const _CharT* __last,
325 ostreambuf_iterator<_CharT> __result)
329 __result._M_put(__first, __num);
333 template<
bool _IsMove,
typename _CharT>
334 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
336 __copy_move_a2(istreambuf_iterator<_CharT> __first,
337 istreambuf_iterator<_CharT> __last, _CharT* __result)
339 typedef istreambuf_iterator<_CharT> __is_iterator_type;
340 typedef typename __is_iterator_type::traits_type traits_type;
341 typedef typename __is_iterator_type::streambuf_type streambuf_type;
342 typedef typename traits_type::int_type int_type;
344 if (__first._M_sbuf && !__last._M_sbuf)
346 streambuf_type* __sb = __first._M_sbuf;
347 int_type __c = __sb->sgetc();
348 while (!traits_type::eq_int_type(__c, traits_type::eof()))
350 const streamsize __n = __sb->egptr() - __sb->gptr();
353 traits_type::copy(__result, __sb->gptr(), __n);
354 __sb->__safe_gbump(__n);
356 __c = __sb->underflow();
360 *__result++ = traits_type::to_char_type(__c);
361 __c = __sb->snextc();
368 template<
typename _CharT>
369 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
370 istreambuf_iterator<_CharT> >::__type
371 find(istreambuf_iterator<_CharT> __first,
372 istreambuf_iterator<_CharT> __last,
const _CharT& __val)
374 typedef istreambuf_iterator<_CharT> __is_iterator_type;
375 typedef typename __is_iterator_type::traits_type traits_type;
376 typedef typename __is_iterator_type::streambuf_type streambuf_type;
377 typedef typename traits_type::int_type int_type;
379 if (__first._M_sbuf && !__last._M_sbuf)
381 const int_type __ival = traits_type::to_int_type(__val);
382 streambuf_type* __sb = __first._M_sbuf;
383 int_type __c = __sb->sgetc();
384 while (!traits_type::eq_int_type(__c, traits_type::eof())
385 && !traits_type::eq_int_type(__c, __ival))
387 streamsize __n = __sb->egptr() - __sb->gptr();
390 const _CharT* __p = traits_type::find(__sb->gptr(),
393 __n = __p - __sb->gptr();
394 __sb->__safe_gbump(__n);
398 __c = __sb->snextc();
401 if (!traits_type::eq_int_type(__c, traits_type::eof()))
411 _GLIBCXX_END_NAMESPACE_VERSION
basic_streambuf< _CharT, _Traits > streambuf_type
Public typedefs.
istreambuf_iterator(streambuf_type *__s) _GLIBCXX_USE_NOEXCEPT
Construct start of streambuf iterator.
constexpr istreambuf_iterator() _GLIBCXX_USE_NOEXCEPT
Construct end of input stream iterator.
ostreambuf_iterator & operator++(int)
Return *this.
int_type sbumpc()
Getting the next character.
_CharT char_type
Public typedefs.
Template class basic_ostream.This is the base class for all output streams. It provides text formatti...
ostreambuf_iterator & operator*()
Return *this.
ostreambuf_iterator(ostream_type &__s) _GLIBCXX_USE_NOEXCEPT
Construct output iterator from ostream.
_Traits traits_type
Public typedefs.
istreambuf_iterator operator++(int)
Advance the iterator. Calls streambuf.sbumpc().
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.
int_type sputc(char_type __c)
Entry point for all single-character output functions.
ostreambuf_iterator & operator=(_CharT __c)
Write character to streambuf. Calls streambuf.sputc().
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 traits_type
Public typedefs.
ptrdiff_t streamsize
Integral type for I/O operation counts and buffer sizes.
Template class basic_istream.This is the base class for all input streams. It provides text formattin...
streamsize sputn(const char_type *__s, streamsize __n)
Entry point for all single-character output functions.
ostreambuf_iterator & operator++()
Return *this.
ostreambuf_iterator(streambuf_type *__s) _GLIBCXX_USE_NOEXCEPT
Construct output iterator from streambuf.
istreambuf_iterator(istream_type &__s) _GLIBCXX_USE_NOEXCEPT
Construct start of input stream iterator.
_CharT char_type
Public typedefs.
istreambuf_iterator & operator++()
Advance the iterator. Calls streambuf.sbumpc().
basic_ostream< _CharT, _Traits > ostream_type
Public typedefs.
_Traits::int_type int_type
Public typedefs.
basic_istream< _CharT, _Traits > istream_type
Public typedefs.
The actual work of input and output (interface).This is a base class. Derived stream buffers each con...
bool failed() const _GLIBCXX_USE_NOEXCEPT
Return true if previous operator=() failed.
Provides input iterator semantics for streambufs.
Provides output iterator semantics for streambufs.
int_type sgetc()
Getting the next character.