]>
git.proxmox.com Git - rustc.git/blob - src/llvm/tools/llvm-cov/RenderingSupport.h
1 //===- RenderingSupport.h - output stream rendering support functions ----===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLVM_COV_RENDERINGSUPPORT_H
11 #define LLVM_COV_RENDERINGSUPPORT_H
13 #include "llvm/Support/raw_ostream.h"
18 /// \brief A helper class that resets the output stream's color if needed
20 class ColoredRawOstream
{
21 ColoredRawOstream(const ColoredRawOstream
&OS
) LLVM_DELETED_FUNCTION
;
27 ColoredRawOstream(raw_ostream
&OS
, bool IsColorUsed
)
28 : OS(OS
), IsColorUsed(IsColorUsed
) {}
30 ColoredRawOstream(ColoredRawOstream
&&Other
)
31 : OS(Other
.OS
), IsColorUsed(Other
.IsColorUsed
) {
32 // Reset the other IsColorUsed so that the other object won't reset the
33 // color when destroyed.
34 Other
.IsColorUsed
= false;
37 ~ColoredRawOstream() {
44 inline raw_ostream
&operator<<(const ColoredRawOstream
&OS
, T
&&Value
) {
45 return OS
.OS
<< std::forward
<T
>(Value
);
48 /// \brief Change the color of the output stream if the `IsColorUsed` flag
49 /// is true. Returns an object that resets the color when destroyed.
50 inline ColoredRawOstream
colored_ostream(raw_ostream
&OS
,
51 raw_ostream::Colors Color
,
52 bool IsColorUsed
= true,
53 bool Bold
= false, bool BG
= false) {
55 OS
.changeColor(Color
, Bold
, BG
);
56 return ColoredRawOstream(OS
, IsColorUsed
);
60 #endif // LLVM_COV_RENDERINGSUPPORT_H