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


17 Jun 2010 Doxygen 1.4.7