summaryrefslogtreecommitdiff
path: root/library/globalFunctions.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'library/globalFunctions.cpp')
-rw-r--r--library/globalFunctions.cpp76
1 files changed, 76 insertions, 0 deletions
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 <wx/msgdlg.h>
+#include <wx/file.h>
+
inline
int globalFunctions::round(const double d)
@@ -123,3 +126,76 @@ void globalFunctions::writeInt(wxOutputStream& stream, const int number)
const char* buffer = reinterpret_cast<const char*>(&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(" | ");
+}
bgstack15