1 //===- llvm/Support/Streams.h - Wrappers for iostreams ----------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by Bill Wendling and is distributed under the
6 // University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements a wrapper for the std::cout and std::cerr I/O streams.
11 // It prevents the need to include <iostream> to each file just to get I/O.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_SUPPORT_STREAMS_H
16 #define LLVM_SUPPORT_STREAMS_H
18 #include <ostream> // Doesn't have static d'tors!!
22 /// llvm_ostream - Acts like an ostream. It's a wrapper for the std::cerr and
23 /// std::cout ostreams. However, it doesn't require #including <iostream> in
24 /// every file, which increases static c'tors & d'tors in the object code.
29 llvm_ostream() : Stream(0) {}
30 llvm_ostream(std::ostream &OStream) : Stream(&OStream) {}
32 std::ostream* stream() const { return Stream; }
34 inline llvm_ostream &operator << (std::ostream& (*Func)(std::ostream&)) {
35 if (Stream) *Stream << Func;
39 template <typename Ty>
40 llvm_ostream &operator << (const Ty &Thing) {
41 if (Stream) *Stream << Thing;
45 bool operator == (const std::ostream &OS) { return &OS == Stream; }
46 bool operator == (const llvm_ostream &OS) { return OS.Stream == Stream; }
49 extern llvm_ostream llvm_null;
50 extern llvm_ostream llvm_cout;
51 extern llvm_ostream llvm_cerr;
53 } // End llvm namespace