================ @@ -0,0 +1,158 @@ +//===- raw_ostream_proxy.h - Proxies for raw output streams -----*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_SUPPORT_RAW_OSTREAM_PROXY_H +#define LLVM_SUPPORT_RAW_OSTREAM_PROXY_H + +#include "llvm/Support/raw_ostream.h" + +namespace llvm { + +/// Common bits for \a raw_ostream_proxy_adaptor<>, split out to dedup in +/// template instantions. +class raw_ostream_proxy_adaptor_base { +protected: + raw_ostream_proxy_adaptor_base() = delete; + raw_ostream_proxy_adaptor_base(const raw_ostream_proxy_adaptor_base &) = + delete; + + explicit raw_ostream_proxy_adaptor_base(raw_ostream &OS) + : OS(&OS), PreferredBufferSize(OS.GetBufferSize()) { + // Drop OS's buffer to make this->flush() forward. This proxy will add a + // buffer in its place. + OS.SetUnbuffered(); + } + + ~raw_ostream_proxy_adaptor_base() { + assert(!OS && "Derived objects should call resetProxiedOS()"); + } + + /// Stop proxying the stream, taking the derived object by reference as \p + /// ThisProxyOS. Updates \p ThisProxyOS to stop buffering before setting \a + /// OS to \c nullptr, ensuring that future writes crash immediately. + void resetProxiedOS(raw_ostream &ThisProxyOS) { ---------------- zmodem wrote:
The parameter is confusing to me. Is ThisProxyOS always going to be == OS here? If not, how are they related? If yes, why take the parameter? https://github.com/llvm/llvm-project/pull/68447 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits