X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=include%2Fllvm%2FSupport%2FStreams.h;h=445ab98c476d7711a325eb10851944a80d2f59d1;hb=0fd38069cb6699ce21eb159f22d3f23c012c9e81;hp=c4afc86baae0ed9f26cd559c91f212c4c022a39e;hpb=e81561909d128c6e2d8033cb5465a49b2596b26a;p=oota-llvm.git diff --git a/include/llvm/Support/Streams.h b/include/llvm/Support/Streams.h index c4afc86baae..445ab98c476 100644 --- a/include/llvm/Support/Streams.h +++ b/include/llvm/Support/Streams.h @@ -2,8 +2,8 @@ // // The LLVM Compiler Infrastructure // -// This file was developed by Bill Wendling and is distributed under the -// University of Illinois Open Source License. See LICENSE.TXT for details. +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// // @@ -15,15 +15,18 @@ #ifndef LLVM_SUPPORT_STREAMS_H #define LLVM_SUPPORT_STREAMS_H -#include +#include namespace llvm { + /// FlushStream - Function called by BaseStream to flush an ostream. + void FlushStream(std::ostream &S); + /// BaseStream - Acts like the STL streams. It's a wrapper for the std::cerr, /// std::cout, std::cin, etc. streams. However, it doesn't require #including - /// in every file (doing so increases static c'tors & d'tors in the - /// object code). - /// + /// @verbatim @endverbatm in every file (doing so increases static + /// c'tors & d'tors in the object code). + /// template class BaseStream { StreamTy *Stream; @@ -34,11 +37,21 @@ namespace llvm { StreamTy *stream() const { return Stream; } + inline BaseStream &operator << (std::ios_base &(*Func)(std::ios_base&)) { + if (Stream) *Stream << Func; + return *this; + } + inline BaseStream &operator << (StreamTy &(*Func)(StreamTy&)) { if (Stream) *Stream << Func; return *this; } + void flush() { + if (Stream) + FlushStream(*Stream); + } + template BaseStream &operator << (const Ty &Thing) { if (Stream) *Stream << Thing; @@ -46,11 +59,19 @@ namespace llvm { } template - BaseStream &operator >> (const Ty &Thing) { + BaseStream &operator >> (Ty &Thing) { if (Stream) *Stream >> Thing; return *this; } + template + BaseStream &write(const Ty &A, unsigned N) { + if (Stream) Stream->write(A, N); + return *this; + } + + operator StreamTy* () { return Stream; } + bool operator == (const StreamTy &S) { return &S == Stream; } bool operator != (const StreamTy &S) { return !(*this == S); } bool operator == (const BaseStream &S) { return S.Stream == Stream; } @@ -61,7 +82,6 @@ namespace llvm { typedef BaseStream IStream; typedef BaseStream StringStream; - extern OStream NullStream; extern OStream cout; extern OStream cerr; extern IStream cin;