Index   Main   Namespaces   Classes   Hierarchy   Annotated   Files   Compound   Global   Pages  

SgDebug.h

Go to the documentation of this file.
00001 //----------------------------------------------------------------------------
00002 /** @file SgDebug.h
00003     Logging stream. */
00004 //----------------------------------------------------------------------------
00005 
00006 #ifndef SG_DEBUG_H
00007 #define SG_DEBUG_H
00008 
00009 #include <iosfwd>
00010 #include <sstream>
00011 
00012 //----------------------------------------------------------------------------
00013 
00014 /** Current logging stream. */
00015 std::ostream& SgDebug();
00016 
00017 /** Write warning prefix to logging stream and return it.
00018     Writes "WARNING: " to the logging stream and returns it for outputting
00019     the rest of the warning line. Lines beginning with this prefix are
00020     displayed in a different color than regular stderr output in GoGui. */
00021 std::ostream& SgWarning();
00022 
00023 //----------------------------------------------------------------------------
00024 
00025 /** Set logging stream to file. */
00026 void SgDebugToFile(const char* filename);
00027 
00028 /** Set logging stream to null stream.
00029     Discards everything written to SgDebug(). */
00030 void SgDebugToNull();
00031 
00032 /** Set logging stream to console window.
00033     @todo: Bad function name, uses std::cerr on Unix and std::cout on MAC */
00034 void SgDebugToWindow();
00035 
00036 std::ostream* SgSwapDebugStr(std::ostream* newStr);
00037 
00038 //----------------------------------------------------------------------------
00039 
00040 /** Temporarily redirect IO to file for lifetime of this object */
00041 class SgDebugToNewFile
00042 {
00043 public:
00044     explicit SgDebugToNewFile(const char* filename);
00045 
00046     explicit SgDebugToNewFile();
00047 
00048     void SetFile(const char* filename);
00049 
00050     ~SgDebugToNewFile();
00051 
00052 private:
00053     std::ostream* m_old;
00054 };
00055 
00056 //----------------------------------------------------------------------------
00057 
00058 /** Temporarily redirect IO to a string buffer for lifetime of this object */
00059 class SgDebugToString
00060 {
00061 public:
00062     /** Constructor.
00063         @param writeToOldDebugStr Also write the content of the string to the
00064         old stream, after it was reset in the desctructor. */
00065     SgDebugToString(bool writeToOldDebugStr);
00066 
00067     ~SgDebugToString();
00068 
00069     std::string GetString() const { return m_str.str(); }
00070 
00071 private:
00072     bool m_writeToOldDebugStr;
00073 
00074     std::ostringstream m_str;
00075 
00076     std::ostream* m_old;
00077 };
00078 
00079 //----------------------------------------------------------------------------
00080 
00081 #endif // SG_DEBUG_H


Sun Mar 13 2011 Doxygen 1.7.1