Path: blob/main/contrib/llvm-project/llvm/tools/llvm-cov/RenderingSupport.h
35230 views
//===- RenderingSupport.h - output stream rendering support functions ----===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#ifndef LLVM_COV_RENDERINGSUPPORT_H9#define LLVM_COV_RENDERINGSUPPORT_H1011#include "llvm/Support/raw_ostream.h"12#include <utility>1314namespace llvm {1516/// A helper class that resets the output stream's color if needed17/// when destroyed.18class ColoredRawOstream {19ColoredRawOstream(const ColoredRawOstream &OS) = delete;2021public:22raw_ostream &OS;23bool IsColorUsed;2425ColoredRawOstream(raw_ostream &OS, bool IsColorUsed)26: OS(OS), IsColorUsed(IsColorUsed) {}2728ColoredRawOstream(ColoredRawOstream &&Other)29: OS(Other.OS), IsColorUsed(Other.IsColorUsed) {30// Reset the other IsColorUsed so that the other object won't reset the31// color when destroyed.32Other.IsColorUsed = false;33}3435~ColoredRawOstream() {36if (IsColorUsed)37OS.resetColor();38}39};4041template <typename T>42inline raw_ostream &operator<<(const ColoredRawOstream &OS, T &&Value) {43return OS.OS << std::forward<T>(Value);44}4546/// Change the color of the output stream if the `IsColorUsed` flag47/// is true. Returns an object that resets the color when destroyed.48inline ColoredRawOstream colored_ostream(raw_ostream &OS,49raw_ostream::Colors Color,50bool IsColorUsed = true,51bool Bold = false, bool BG = false) {52if (IsColorUsed)53OS.changeColor(Color, Bold, BG);54return ColoredRawOstream(OS, IsColorUsed);55}5657} // namespace llvm5859#endif // LLVM_COV_RENDERINGSUPPORT_H606162