basiclog.h

Go to the documentation of this file.
00001 /********************************************************************************/
00002 /*                                                                              */
00003 /*  Netrinjo-Engine - a library for game-development                            */
00004 /*  Copyright (C) 2005 by Tobias Nadler                                         */
00005 /*                                                                              */
00006 /*  This library is free software; you can redistribute it and/or               */
00007 /*  modify it under the terms of the GNU Lesser General Public                  */
00008 /*  License as published by the Free Software Foundation; either                */
00009 /*  version 2.1 of the License, or (at your option) any later version.          */
00010 /*                                                                              */
00011 /*  This library is distributed in the hope that it will be useful,             */
00012 /*  but WITHOUT ANY WARRANTY; without even the implied warranty of              */
00013 /*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU           */
00014 /*  Lesser General Public License for more details.                             */
00015 /*                                                                              */
00016 /*  You should have received a copy of the GNU Lesser General Public            */
00017 /*  License along with this library; if not, write to the Free Software         */
00018 /*  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA   */
00019 /*                                                                              */
00020 /********************************************************************************/
00021 
00022 #ifndef BASICLOG_H
00023 #define BASICLOG_H
00024 
00036 #include <fstream>
00037 #include <iostream>
00038 #include "basicobject.h"
00039 
00054 class DECLSPEC BasicLog : public BasicObject
00055 {
00056 public:
00072     struct Logger
00073     {
00078         Logger( BasicLog *target, const char *strStart )
00079         {
00080             pTarget = target;
00081             pTarget->logBegin( strStart );
00082             bSuccess = false;
00083         }
00085         ~Logger()
00086         {
00087             pTarget->logEnd( bSuccess ? "done." : "failed." );
00088         }
00092         void line( const char * str )
00093         {
00094             pTarget->logLevelLine( str );
00095         }
00099         void append( const char * str )
00100         {
00101             pTarget->logString( str );
00102         }
00107         void succeede()
00108         {
00109             bSuccess = true;
00110         }
00111     private:
00112         BasicLog *pTarget;
00113         bool bSuccess;
00114     };
00121     DECLSPEC BasicLog( const char *name, BasicObject *parent, const char *filename );
00128     DECLSPEC BasicLog( const char *name, BasicObject *parent, std::ostream *strm = &std::cout );
00137     DECLSPEC BasicLog( TiXmlElement *el, BasicObject *p );
00138     virtual DECLSPEC ~BasicLog();
00139 
00144     DECLSPEC void logLine( const char *ln );
00145 
00149     DECLSPEC void logString( const char *str );
00154     DECLSPEC void logTime();
00155 
00161     DECLSPEC void logBegin( const char *ln );
00162 
00167     DECLSPEC void logLevel( const char *str );
00168 
00173     DECLSPEC void logLevelLine( const char *ln );
00174 
00180     DECLSPEC void logEnd( const char *ln );
00181 
00189     DECLSPEC bool setDebug( bool dodebug );
00190 
00194     DECLSPEC bool getDebug()    { return bDebug; }
00195 
00201     static DECLSPEC void logStdOut(const char *s);
00202 
00203 protected:
00212     DECLSPEC bool initLogFile( const char *fn );
00218     DECLSPEC void initLogStream( std::ostream *strm );
00219     virtual DECLSPEC void onInit();
00220     
00225     DECLSPEC bool bAutoLogTime;
00226 
00227 private:
00228     bool bDebug;
00229     std::ofstream osLogFile;
00230     std::ostream *pLog;
00231     int nLogSpaces;
00232 };
00233 
00234 #endif

Generated on Wed May 9 17:35:55 2007 for netrinjo by  doxygen 1.5.1