72 lines · c
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-exception7//8//===----------------------------------------------------------------------===//9 10#ifndef _LIBCPP___ITERATOR_OSTREAMBUF_ITERATOR_H11#define _LIBCPP___ITERATOR_OSTREAMBUF_ITERATOR_H12 13#include <__config>14#include <__cstddef/ptrdiff_t.h>15#include <__fwd/ios.h>16#include <__fwd/ostream.h>17#include <__fwd/streambuf.h>18#include <__iterator/iterator.h>19#include <__iterator/iterator_traits.h>20#include <iosfwd> // for forward declaration of ostreambuf_iterator21 22#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)23# pragma GCC system_header24#endif25 26_LIBCPP_BEGIN_NAMESPACE_STD27 28template <class _CharT, class _Traits>29class ostreambuf_iterator30 : public __iterator_base<ostreambuf_iterator<_CharT, _Traits>, output_iterator_tag, void, void, void, void> {31public:32 typedef output_iterator_tag iterator_category;33 typedef void value_type;34#if _LIBCPP_STD_VER >= 2035 typedef ptrdiff_t difference_type;36#else37 typedef void difference_type;38#endif39 typedef void pointer;40 typedef void reference;41 typedef _CharT char_type;42 typedef _Traits traits_type;43 typedef basic_streambuf<_CharT, _Traits> streambuf_type;44 typedef basic_ostream<_CharT, _Traits> ostream_type;45 46private:47 streambuf_type* __sbuf_;48 49public:50 _LIBCPP_HIDE_FROM_ABI ostreambuf_iterator(ostream_type& __s) _NOEXCEPT : __sbuf_(__s.rdbuf()) {}51 _LIBCPP_HIDE_FROM_ABI ostreambuf_iterator(streambuf_type* __s) _NOEXCEPT : __sbuf_(__s) {}52 _LIBCPP_HIDE_FROM_ABI ostreambuf_iterator& operator=(_CharT __c) {53 if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sputc(__c), traits_type::eof()))54 __sbuf_ = nullptr;55 return *this;56 }57 _LIBCPP_HIDE_FROM_ABI ostreambuf_iterator& operator*() { return *this; }58 _LIBCPP_HIDE_FROM_ABI ostreambuf_iterator& operator++() { return *this; }59 _LIBCPP_HIDE_FROM_ABI ostreambuf_iterator& operator++(int) { return *this; }60 _LIBCPP_HIDE_FROM_ABI bool failed() const _NOEXCEPT { return __sbuf_ == nullptr; }61 62#if _LIBCPP_HAS_LOCALIZATION63 template <class _Ch, class _Tr>64 friend _LIBCPP_HIDE_FROM_ABI ostreambuf_iterator<_Ch, _Tr> __pad_and_output(65 ostreambuf_iterator<_Ch, _Tr> __s, const _Ch* __ob, const _Ch* __op, const _Ch* __oe, ios_base& __iob, _Ch __fl);66#endif // _LIBCPP_HAS_LOCALIZATION67};68 69_LIBCPP_END_NAMESPACE_STD70 71#endif // _LIBCPP___ITERATOR_OSTREAMBUF_ITERATOR_H72