Home | History | Annotate | Download | only in Support
      1 //===- raw_ostream.h ------------------------------------------------------===//
      2 //
      3 //                     The MCLinker Project
      4 //
      5 // This file is distributed under the University of Illinois Open Source
      6 // License. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 #ifndef MCLD_RAW_OSTREAM_H
     10 #define MCLD_RAW_OSTREAM_H
     11 #ifdef ENABLE_UNITTEST
     12 #include <gtest.h>
     13 #endif
     14 #include <string>
     15 #include <llvm/Support/raw_ostream.h>
     16 
     17 namespace mcld {
     18 
     19 class raw_fd_ostream : public llvm::raw_fd_ostream
     20 {
     21 public:
     22   /// raw_fd_ostream - Open the specified file for writing. If an error occurs,
     23   /// information about the error is put into ErrorInfo, and the stream should
     24   /// be immediately destroyed; the string will be empty if no error occurred.
     25   /// This allows optional flags to control how the file will be opened.
     26   ///
     27   /// As a special case, if Filename is "-", then the stream will use
     28   /// STDOUT_FILENO instead of opening a file. Note that it will still consider
     29   /// itself to own the file descriptor. In particular, it will close the
     30   /// file descriptor when it is done (this is necessary to detect
     31   /// output errors).
     32   raw_fd_ostream(const char *pFilename,
     33                  std::string &pErrorInfo,
     34                  unsigned int pFlags = 0);
     35 
     36   /// raw_fd_ostream ctor - FD is the file descriptor that this writes to.  If
     37   /// ShouldClose is true, this closes the file when the stream is destroyed.
     38   raw_fd_ostream(int pFD, bool pShouldClose, bool pUnbuffered=false);
     39 
     40   virtual ~raw_fd_ostream();
     41 
     42   void setColor(bool pEnable = true);
     43 
     44 
     45   llvm::raw_ostream &changeColor(enum llvm::raw_ostream::Colors pColors,
     46                                  bool pBold=false,
     47                                  bool pBackground=false);
     48 
     49   llvm::raw_ostream &resetColor();
     50 
     51   llvm::raw_ostream &reverseColor();
     52 
     53   bool is_displayed() const;
     54 
     55 private:
     56   bool m_bConfigColor : 1;
     57   bool m_bSetColor : 1;
     58 
     59 };
     60 
     61 /// outs() - This returns a reference to a raw_ostream for standard output.
     62 /// Use it like: outs() << "foo" << "bar";
     63 mcld::raw_fd_ostream &outs();
     64 
     65 /// errs() - This returns a reference to a raw_ostream for standard error.
     66 /// Use it like: errs() << "foo" << "bar";
     67 mcld::raw_fd_ostream &errs();
     68 
     69 } // namespace of mcld
     70 
     71 #endif
     72 
     73