From cbb59ba3fb48fb87065469eaa1b4a34a18851b9e Mon Sep 17 00:00:00 2001 From: Daniel Wilhelm Date: Fri, 18 Apr 2014 16:54:32 +0200 Subject: 1.12 --- library/globalFunctions.cpp | 76 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) (limited to 'library/globalFunctions.cpp') diff --git a/library/globalFunctions.cpp b/library/globalFunctions.cpp index 67b56819..07c34af0 100644 --- a/library/globalFunctions.cpp +++ b/library/globalFunctions.cpp @@ -1,5 +1,8 @@ #include "globalFunctions.h" #include "resources.h" +#include +#include + inline int globalFunctions::round(const double d) @@ -123,3 +126,76 @@ void globalFunctions::writeInt(wxOutputStream& stream, const int number) const char* buffer = reinterpret_cast(&number); stream.Write(buffer, sizeof(int)); } + + +//############################################################################ +Performance::Performance() : + resultWasShown(false) +{ + timer.Start(); +} + + +Performance::~Performance() +{ + if (!resultWasShown) + showResult(); +} + + +void Performance::showResult() +{ + resultWasShown = true; + wxMessageBox(globalFunctions::numberToWxString(unsigned(timer.Time())) + wxT(" ms")); + timer.Start(); //reset timer +} + + +//############################################################################ +DebugLog::DebugLog() : + lineCount(0), + logFile(NULL) +{ + logFile = new wxFile; + logfileName = assembleFileName(); + logFile->Open(logfileName.c_str(), wxFile::write); +} + + +DebugLog::~DebugLog() +{ + delete logFile; //automatically closes file handle +} + + +wxString DebugLog::assembleFileName() +{ + wxString tmp = wxDateTime::Now().FormatISOTime(); + tmp.Replace(wxT(":"), wxEmptyString); + return wxString(wxT("DEBUG_")) + wxDateTime::Now().FormatISODate() + wxChar('_') + tmp + wxT(".log"); +} + + +void DebugLog::write(const wxString& logText) +{ + ++lineCount; + if (lineCount % 10000 == 0) //prevent logfile from becoming too big + { + logFile->Close(); + wxRemoveFile(logfileName); + + logfileName = assembleFileName(); + logFile->Open(logfileName.c_str(), wxFile::write); + } + + logFile->Write(wxString(wxT("[")) + wxDateTime::Now().FormatTime() + wxT("] ")); + logFile->Write(logText + wxChar('\n')); +} + +//DebugLog logDebugInfo; + + +wxString getCodeLocation(const wxString file, const int line) +{ + return wxString(file).AfterLast(GlobalResources::fileNameSeparator) + wxT(", LINE ") + globalFunctions::numberToWxString(line) + wxT(" | "); +} -- cgit