Main Page   Class Hierarchy   Compound List   File List   Compound Members  

baTraceStream.cpp

00001 //////////////////////////////////////////////////////////////////////
00002 // Copyright (c) 2001-2002 David Pritchard <drpritch@alumni.uwaterloo.ca>
00003 // 
00004 // This program is free software; you can redistribute it and/or
00005 // modify it under the terms of the GNU Lesser General Public License
00006 // as published by the Free Software Foundation; either
00007 // version 2 of the License, or (at your option) any later
00008 // version.
00009 // 
00010 // This program is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU Lesser General Public License for more details.
00014 // 
00015 // You should have received a copy of the GNU Lesser General Public License
00016 // along with this program; if not, write to the Free Software
00017 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00018 
00019 #include <freecloth/base/baTraceStream.h>
00020 #include <freecloth/base/debug.h>
00021 #include <freecloth/base/fstream>
00022 
00023 FREECLOTH_NAMESPACE_START
00024 
00025 #ifndef NDEBUG
00026 ////////////////////////////////////////////////////////////////////////////////
00027 // CLASS BaTraceStream::Imp
00028 
00029 class BaTraceStream::Imp {
00030 public:
00031     // ----- member functions -----
00032     Imp();
00033 
00034     // ----- data members -----
00035     std::ofstream   _stream;
00036     UInt32          _nbIndents;
00037 };
00038 
00039 //------------------------------------------------------------------------------
00040 
00041 BaTraceStream::Imp::Imp()
00042     : _stream( "debug_trace.txt" ),
00043     _nbIndents( 0 )
00044 {
00045     // FIXME: include date, time, etc. in header
00046     _stream << "// debug_trace.txt  " << std::endl;
00047     _stream << std::endl;
00048 }
00049 
00050 ////////////////////////////////////////////////////////////////////////////////
00051 // CLASS BaTraceStream
00052 
00053 BaTraceStream BaTraceStream::_theTraceStream;
00054 
00055 //------------------------------------------------------------------------------
00056 
00057 BaTraceStream& BaTraceStream::theTraceStream()
00058 {
00059     return _theTraceStream;
00060 }
00061 
00062 //------------------------------------------------------------------------------
00063 
00064 // FIXME: don't generate file for non-debug builds.
00065 BaTraceStream::BaTraceStream()
00066     : _imp( new Imp )
00067 {
00068 }
00069 
00070 //------------------------------------------------------------------------------
00071 
00072 BaTraceStream::~BaTraceStream()
00073 {
00074     delete _imp;
00075 }
00076 
00077 //------------------------------------------------------------------------------
00078 
00079 std::ostream& BaTraceStream::getStream()
00080 {
00081     return _imp->_stream;
00082 }
00083 
00084 //------------------------------------------------------------------------------
00085 
00086 String BaTraceStream::startl( BaTraceStream::LineType lineType ) const
00087 {
00088     String retVal;
00089     for ( UInt32 i = 0; i < _imp->_nbIndents; ++i ) {
00090         retVal += "  ";
00091     }
00092     switch ( lineType ) {
00093         case LINE_NORMAL: {
00094             retVal += "| ";
00095         } break;
00096 
00097         case LINE_INDENT: {
00098             retVal += "\\ ";
00099         } break;
00100 
00101         case LINE_UNINDENT: {
00102             retVal += "/ ";
00103         } break;
00104     }
00105     return retVal;
00106 }
00107 
00108 //------------------------------------------------------------------------------
00109 
00110 void BaTraceStream::indent()
00111 {
00112     ++_imp->_nbIndents;
00113 }
00114 
00115 //------------------------------------------------------------------------------
00116 
00117 void BaTraceStream::unindent()
00118 {
00119     DGFX_ASSERT( _imp->_nbIndents > 0 );
00120     --_imp->_nbIndents;
00121 }
00122 #endif
00123 
00124 FREECLOTH_NAMESPACE_END

Generated on Fri May 2 16:51:11 2003 for Freecloth by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002