1 // -*- C++ -*- 2 //===----------------------------------------------------------------------===// 3 // 4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 5 // See https://llvm.org/LICENSE.txt for license information. 6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7 // 8 //===----------------------------------------------------------------------===// 9 10 #ifndef _LIBCPP___ITERATOR_OSTREAMBUF_ITERATOR_H 11 #define _LIBCPP___ITERATOR_OSTREAMBUF_ITERATOR_H 12 13 #include <__config> 14 #include <__iterator/iterator.h> 15 #include <__iterator/iterator_traits.h> 16 #include <iosfwd> // for forward declaration of basic_streambuf 17 18 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 19 #pragma GCC system_header 20 #endif 21 22 _LIBCPP_BEGIN_NAMESPACE_STD 23 24 _LIBCPP_SUPPRESS_DEPRECATED_PUSH 25 template <class _CharT, class _Traits> 26 class _LIBCPP_TEMPLATE_VIS ostreambuf_iterator 27 #if _LIBCPP_STD_VER <= 14 || !defined(_LIBCPP_ABI_NO_ITERATOR_BASES) 28 : public iterator<output_iterator_tag, void, void, void, void> 29 #endif 30 { 31 _LIBCPP_SUPPRESS_DEPRECATED_POP 32 public: 33 typedef output_iterator_tag iterator_category; 34 typedef void value_type; 35 #if _LIBCPP_STD_VER > 17 36 typedef ptrdiff_t difference_type; 37 #else 38 typedef void difference_type; 39 #endif 40 typedef void pointer; 41 typedef void reference; 42 typedef _CharT char_type; 43 typedef _Traits traits_type; 44 typedef basic_streambuf<_CharT, _Traits> streambuf_type; 45 typedef basic_ostream<_CharT, _Traits> ostream_type; 46 47 private: 48 streambuf_type* __sbuf_; 49 public: 50 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(ostream_type& __s) _NOEXCEPT 51 : __sbuf_(__s.rdbuf()) {} 52 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(streambuf_type* __s) _NOEXCEPT 53 : __sbuf_(__s) {} 54 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator=(_CharT __c) 55 { 56 if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sputc(__c), traits_type::eof())) 57 __sbuf_ = nullptr; 58 return *this; 59 } 60 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator*() {return *this;} 61 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++() {return *this;} 62 _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++(int) {return *this;} 63 _LIBCPP_INLINE_VISIBILITY bool failed() const _NOEXCEPT {return __sbuf_ == nullptr;} 64 65 template <class _Ch, class _Tr> 66 friend 67 _LIBCPP_HIDDEN 68 ostreambuf_iterator<_Ch, _Tr> 69 __pad_and_output(ostreambuf_iterator<_Ch, _Tr> __s, 70 const _Ch* __ob, const _Ch* __op, const _Ch* __oe, 71 ios_base& __iob, _Ch __fl); 72 }; 73 74 _LIBCPP_END_NAMESPACE_STD 75 76 #endif // _LIBCPP___ITERATOR_OSTREAMBUF_ITERATOR_H 77