|
From: julien r. <jul...@us...> - 2004-10-15 13:09:08
|
Update of /cvsroot/epfl/tgengine-0.1 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15342 Modified Files: console.cc console.h engine.cc engine.h log.cc log.h soundmanager.cc texture.cc Added Files: errbuffer.cc errbuffer.h logbuffer.cc logbuffer.h Log Message: classes facilitant la gestion des sorties (cout et cerr) --- NEW FILE: logbuffer.cc --- #include "logbuffer.h" #include "engine.h" namespace tg { LogBuffer::LogBuffer (char* file, bool console) { bConsole = console; bFile = false; pFile = NULL; if (file != NULL) { pFile = fopen(file, "w+t"); printf("Utilisation de %s pour ecrire les logs\n", file); bFile = true; fprintf(pFile, "LOG\n"); } else printf("Pas de fichier de log\n"); if (!pFile) { printf("Erreur lors de la creation du fichier de log : %s\n", file); bFile = false; } } LogBuffer::~LogBuffer () { fclose (pFile); } int LogBuffer::sync() { return 0; } int LogBuffer::overflow(int c) { if (bFile) { //apparement, n'envoie pas de eof(), envoie des \n if (traits_type::eq_int_type(traits_type::eof(), c)) fprintf(pFile, "\n"); else fprintf(pFile, "%c",(char)c); } if (bConsole) { if ((char)c == '\n') Engine::pConsole->NextLine(); else Engine::pConsole->Print((char)c); } printf ("%c", c); return 0; } } Index: log.cc =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/log.cc,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** log.cc 26 Sep 2004 13:15:18 -0000 1.1.1.1 --- log.cc 15 Oct 2004 13:08:33 -0000 1.2 *************** *** 27,31 **** { va_list arg; ! char buf[256]; va_start(arg, desc); --- 27,31 ---- { va_list arg; ! char buf[2048]; va_start(arg, desc); --- NEW FILE: logbuffer.h --- #ifndef _TGLOGBUFFER_H #define _TGLOGBUFFER_H #include <iostream> #include <fstream> #include "defs.h" namespace tg { class LogBuffer : public std::streambuf { public: /** * @param file le nom du fichier de sortie * @param console si on fait egalement les sorties sur la console */ LogBuffer(char* file, bool console); ~LogBuffer(); int sync (); int overflow (int c); protected: FILE* pFile; bool bConsole; bool bFile; }; } #endif Index: console.cc =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/console.cc,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** console.cc 27 Sep 2004 14:45:56 -0000 1.2 --- console.cc 15 Oct 2004 13:08:33 -0000 1.3 *************** *** 105,108 **** --- 105,117 ---- } } + + void Console::NextLineNoExecute () + { + if((sCurrentLine.size() > 0) && (sCurrentLine.find_first_not_of(" \t\n")!= std::string::npos)) + { + vHistory.push_back (sCurrentLine); + sCurrentLine.clear(); + } + } void Console::SetPrompt (const std::string& p) Index: soundmanager.cc =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/soundmanager.cc,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** soundmanager.cc 14 Oct 2004 13:46:47 -0000 1.5 --- soundmanager.cc 15 Oct 2004 13:08:33 -0000 1.6 *************** *** 689,691 **** } ! } \ No newline at end of file --- 689,692 ---- } ! } ! Index: engine.cc =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/engine.cc,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** engine.cc 10 Oct 2004 20:49:09 -0000 1.3 --- engine.cc 15 Oct 2004 13:08:33 -0000 1.4 *************** *** 26,34 **** pEndian = new BigEndian (); } } Engine::~Engine () { ! } --- 26,40 ---- pEndian = new BigEndian (); } + + pLog = new LogBuffer ("log.txt", true); + std::cout.rdbuf (pLog); + pErr = new ErrBuffer ("err.txt", true); + std::cerr.rdbuf (pErr); } Engine::~Engine () { ! delete pLog; ! delete pErr; } --- NEW FILE: errbuffer.h --- #ifndef _TGERRBUFFER_H #define _TGERRBUFFER_H #include <iostream> #include <fstream> #include "defs.h" namespace tg { class ErrBuffer : public std::streambuf { public: /** * @param file le nom du fichier de sortie * @param console si on fait egalement les sorties sur la console */ ErrBuffer(char* file, bool console); ~ErrBuffer(); int sync (); int overflow (int c); protected: FILE* pFile; bool bConsole; bool bFile; }; } #endif Index: log.h =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/log.h,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** log.h 26 Sep 2004 13:15:18 -0000 1.1.1.1 --- log.h 15 Oct 2004 13:08:33 -0000 1.2 *************** *** 21,25 **** ~Log (); ! void Report (const char *from, const char *desc, ...); protected: std::ofstream fFile; --- 21,53 ---- ~Log (); ! /** ! * Report : affiche un message. similaire à printf au niveau des paramètres et du formatage ! * @see printf ! */ ! void Report (const char* from, const char* desc, ...); ! ! /** ! * Error : signale une erreur et termine le programme ! ! * @see printf ! */ ! void Error (const char* from, const char* desc, ...); ! ! /** ! *Debug: affiche des messages de déverminage uniquement si TG_DEBUG ! * est dans les flags lors de la compilation ! * @see printf ! */ ! void Debug (const char* from, const char* desc, ...); ! ! /** ! * Re-definition de <<, qui font en fait un appel a report ! ! inline friend void operator << (const Vector3& v) { Report("(%f,%f,%f)", v.x, v.y, v.z); } ! inline friend void operator << (int i) { Report ("%i", i); } ! inline friend void operator << (unsigned int i); ! inline friend void operator << (float f); ! inline friend void operator << (char c); ! inline friend void operator << (char* s); ! */ protected: std::ofstream fFile; Index: console.h =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/console.h,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** console.h 26 Sep 2004 13:15:23 -0000 1.1.1.1 --- console.h 15 Oct 2004 13:08:33 -0000 1.2 *************** *** 41,44 **** --- 41,45 ---- void Print (char c); void NextLine (); + void NextLineNoExecute (); void SetPrompt (const std::string& p); std::string* GetPrompt () { return &sPrompt; } *************** *** 57,58 **** --- 58,60 ---- #endif + --- NEW FILE: errbuffer.cc --- #include "errbuffer.h" #include "engine.h" namespace tg { ErrBuffer::ErrBuffer (char* file, bool console) { bConsole = console; bFile = false; pFile = NULL; if (file != NULL) { pFile = fopen(file, "w+t"); printf("Utilisation de %s pour ecrire les logs\n", file); bFile = true; fprintf(pFile, "ERR\n"); } else printf("Pas de fichier de log\n"); if (!pFile) { printf("Erreur lors de la creation du fichier de log : %s\n", file); bFile = false; } } ErrBuffer::~ErrBuffer () { fclose (pFile); } int ErrBuffer::sync() { return 0; } int ErrBuffer::overflow(int c) { if (bFile) { //apparement, n'envoie pas de eof(), envoie des \n if (traits_type::eq_int_type(traits_type::eof(), c)) fprintf(pFile, "\n"); else fprintf(pFile, "%c",(char)c); } if (bConsole) { if ((char)c == '\n') Engine::pConsole->NextLine(); else Engine::pConsole->Print((char)c); } printf ("%c", c); return 0; } } Index: engine.h =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/engine.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** engine.h 28 Sep 2004 09:44:26 -0000 1.2 --- engine.h 15 Oct 2004 13:08:33 -0000 1.3 *************** *** 36,39 **** --- 36,41 ---- #include "tgendian.h" #include "defs.h" + #include "logbuffer.h" + #include "errbuffer.h" namespace tg *************** *** 96,99 **** --- 98,104 ---- int screenBpp; int videoFlags; + + LogBuffer* pLog; + ErrBuffer* pErr; const SDL_VideoInfo* vidInfo; Index: texture.cc =================================================================== RCS file: /cvsroot/epfl/tgengine-0.1/texture.cc,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** texture.cc 30 Sep 2004 09:23:16 -0000 1.6 --- texture.cc 15 Oct 2004 13:08:33 -0000 1.7 *************** *** 271,275 **** if(fd == NULL) { ! Log ("Impossible de charger le fichier %s", image); return false; } --- 271,275 ---- if(fd == NULL) { ! std::cerr << "Impossible de charger le fichier " << image << std::endl;; return false; } |