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