Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-03 08:13:32

0001 // -*- C++ -*-
0002 //===----------------------------------------------------------------------===//
0003 //
0004 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0005 // See https://llvm.org/LICENSE.txt for license information.
0006 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0007 //
0008 //===----------------------------------------------------------------------===//
0009 
0010 #ifndef _LIBCPP___CXX03___ITERATOR_ISTREAMBUF_ITERATOR_H
0011 #define _LIBCPP___CXX03___ITERATOR_ISTREAMBUF_ITERATOR_H
0012 
0013 #include <__cxx03/__config>
0014 #include <__cxx03/__fwd/istream.h>
0015 #include <__cxx03/__fwd/streambuf.h>
0016 #include <__cxx03/__iterator/default_sentinel.h>
0017 #include <__cxx03/__iterator/iterator.h>
0018 #include <__cxx03/__iterator/iterator_traits.h>
0019 
0020 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0021 #  pragma GCC system_header
0022 #endif
0023 
0024 _LIBCPP_BEGIN_NAMESPACE_STD
0025 
0026 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
0027 template <class _CharT, class _Traits>
0028 class _LIBCPP_TEMPLATE_VIS istreambuf_iterator
0029 #if _LIBCPP_STD_VER <= 14 || !defined(_LIBCPP_ABI_NO_ITERATOR_BASES)
0030     : public iterator<input_iterator_tag, _CharT, typename _Traits::off_type, _CharT*, _CharT>
0031 #endif
0032 {
0033   _LIBCPP_SUPPRESS_DEPRECATED_POP
0034 
0035 public:
0036   typedef input_iterator_tag iterator_category;
0037   typedef _CharT value_type;
0038   typedef typename _Traits::off_type difference_type;
0039   typedef _CharT* pointer;
0040   typedef _CharT reference;
0041   typedef _CharT char_type;
0042   typedef _Traits traits_type;
0043   typedef typename _Traits::int_type int_type;
0044   typedef basic_streambuf<_CharT, _Traits> streambuf_type;
0045   typedef basic_istream<_CharT, _Traits> istream_type;
0046 
0047 private:
0048   mutable streambuf_type* __sbuf_;
0049 
0050   class __proxy {
0051     char_type __keep_;
0052     streambuf_type* __sbuf_;
0053     _LIBCPP_HIDE_FROM_ABI explicit __proxy(char_type __c, streambuf_type* __s) : __keep_(__c), __sbuf_(__s) {}
0054     friend class istreambuf_iterator;
0055 
0056   public:
0057     _LIBCPP_HIDE_FROM_ABI char_type operator*() const { return __keep_; }
0058   };
0059 
0060   _LIBCPP_HIDE_FROM_ABI bool __test_for_eof() const {
0061     if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sgetc(), traits_type::eof()))
0062       __sbuf_ = nullptr;
0063     return __sbuf_ == nullptr;
0064   }
0065 
0066 public:
0067   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR istreambuf_iterator() _NOEXCEPT : __sbuf_(nullptr) {}
0068 #if _LIBCPP_STD_VER >= 20
0069   _LIBCPP_HIDE_FROM_ABI constexpr istreambuf_iterator(default_sentinel_t) noexcept : istreambuf_iterator() {}
0070 #endif // _LIBCPP_STD_VER >= 20
0071   _LIBCPP_HIDE_FROM_ABI istreambuf_iterator(istream_type& __s) _NOEXCEPT : __sbuf_(__s.rdbuf()) {}
0072   _LIBCPP_HIDE_FROM_ABI istreambuf_iterator(streambuf_type* __s) _NOEXCEPT : __sbuf_(__s) {}
0073   _LIBCPP_HIDE_FROM_ABI istreambuf_iterator(const __proxy& __p) _NOEXCEPT : __sbuf_(__p.__sbuf_) {}
0074 
0075   _LIBCPP_HIDE_FROM_ABI char_type operator*() const { return static_cast<char_type>(__sbuf_->sgetc()); }
0076   _LIBCPP_HIDE_FROM_ABI istreambuf_iterator& operator++() {
0077     __sbuf_->sbumpc();
0078     return *this;
0079   }
0080   _LIBCPP_HIDE_FROM_ABI __proxy operator++(int) { return __proxy(__sbuf_->sbumpc(), __sbuf_); }
0081 
0082   _LIBCPP_HIDE_FROM_ABI bool equal(const istreambuf_iterator& __b) const {
0083     return __test_for_eof() == __b.__test_for_eof();
0084   }
0085 
0086 #if _LIBCPP_STD_VER >= 20
0087   friend _LIBCPP_HIDE_FROM_ABI bool operator==(const istreambuf_iterator& __i, default_sentinel_t) {
0088     return __i.__test_for_eof();
0089   }
0090 #endif // _LIBCPP_STD_VER >= 20
0091 };
0092 
0093 template <class _CharT, class _Traits>
0094 inline _LIBCPP_HIDE_FROM_ABI bool
0095 operator==(const istreambuf_iterator<_CharT, _Traits>& __a, const istreambuf_iterator<_CharT, _Traits>& __b) {
0096   return __a.equal(__b);
0097 }
0098 
0099 #if _LIBCPP_STD_VER <= 17
0100 template <class _CharT, class _Traits>
0101 inline _LIBCPP_HIDE_FROM_ABI bool
0102 operator!=(const istreambuf_iterator<_CharT, _Traits>& __a, const istreambuf_iterator<_CharT, _Traits>& __b) {
0103   return !__a.equal(__b);
0104 }
0105 #endif // _LIBCPP_STD_VER <= 17
0106 
0107 _LIBCPP_END_NAMESPACE_STD
0108 
0109 #endif // _LIBCPP___CXX03___ITERATOR_ISTREAMBUF_ITERATOR_H