Replacing std::iostreams with llvm iostreams. Some of these changes involve
[oota-llvm.git] / include / llvm / Support / Streams.h
1 //===- llvm/Support/Streams.h - Wrappers for iostreams ----------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
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.
7 //
8 //===----------------------------------------------------------------------===//
9 //
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.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_SUPPORT_STREAMS_H
16 #define LLVM_SUPPORT_STREAMS_H
17
18 #include <ostream>              // Doesn't have static d'tors!!
19
20 namespace llvm {
21
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.
25   /// 
26   class llvm_ostream {
27     std::ostream* Stream;
28   public:
29     llvm_ostream() : Stream(0) {}
30     llvm_ostream(std::ostream &OStream) : Stream(&OStream) {}
31
32     std::ostream* stream() const { return Stream; }
33
34     inline llvm_ostream &operator << (std::ostream& (*Func)(std::ostream&)) {
35       if (Stream) *Stream << Func;
36       return *this;
37     }
38       
39     template <typename Ty>
40     llvm_ostream &operator << (const Ty &Thing) {
41       if (Stream) *Stream << Thing;
42       return *this;
43     }
44
45     bool operator == (const std::ostream &OS) { return &OS == Stream; }
46     bool operator == (const llvm_ostream &OS) { return OS.Stream == Stream; }
47   };
48
49   extern llvm_ostream llvm_null;
50   extern llvm_ostream llvm_cout;
51   extern llvm_ostream llvm_cerr;
52
53 } // End llvm namespace
54
55 #endif