-
Notifications
You must be signed in to change notification settings - Fork 2
/
ErrorData.cpp
138 lines (114 loc) · 2.82 KB
/
ErrorData.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
// wxWindows includes
#include <wx/wx.h>
#include <wx/string.h>
// statsgen includes
#include "ErrorData.h"
#include "GlobalStatistics.h"
StatsgenDebugObject statsgenDebug;
StatsgenDebugObject::StatsgenDebugObject()
{
initiateDebugFile=true;
currentDebugLevel=0;
}
void StatsgenDebugObject::UpdateDebugConfig()
{
wxString configKey;
int debugIndex;
wxString configValue;
configKey="/Debug/DebugFile";
globalStatistics.configData.ReadTextValue(configKey,&debugFilename,"");
debugMaxLevel.Clear();
for (debugIndex=WINDOW_ID_PROGRESS_PANEL_GENERAL;
debugIndex<WINDOW_ID_PROGRESS_PANEL_MAX;
debugIndex++)
{
configKey.Printf("/Debug/DebugLevel%d",
debugIndex-WINDOW_ID_PROGRESS_PANEL_GENERAL);
globalStatistics.configData.ReadTextValue(configKey,&configValue,"0");
debugMaxLevel.Add(atoi(configValue.GetData()));
}
initiateDebugFile=true;
currentDebugLevel=0;
}
bool StatsgenDebugObject::DebugOn()
{
return ((currentDebugLevel!=0)&&(debugFilename.Length()!=0));
}
void StatsgenDebugObject::Debug(const char *classname,const char *functionname,
int debugLevel,const char *message)
{
if ((currentDebugLevel!=0)&&(strlen(debugFilename.GetData())!=0))
{
// debug enabled
if (currentDebugLevel>=debugLevel)
{
FILE *fp;
if (initiateDebugFile)
{
fp=fopen(debugFilename.GetData(),"w");
initiateDebugFile=false;
}
else
{
fp=fopen(debugFilename.GetData(),"a");
}
if (fp!=NULL)
{
fprintf(fp,"%s::%s():%s\n",
classname,functionname,message);
fclose(fp);
}
}
}
}
void StatsgenDebugObject::Debug(const char *classname,const char *functionname,
int debugLevel,wxString &message)
{
Debug(classname,functionname,debugLevel,message.GetData());
}
void StatsgenDebugObject::Entering(const char *classname,const char *functionname)
{
Debug(classname,functionname,DEBUG_SOMETIMES,"Entering");
}
void StatsgenDebugObject::Leaving(const char *classname,const char *functionname)
{
Debug(classname,functionname,DEBUG_SOMETIMES,"Leaving");
}
void StatsgenDebugObject::UpdateCurrentDebugLevel(int progressPanelID)
{
if (progressPanelID<WINDOW_ID_PROGRESS_PANEL_GENERAL)
{
progressPanelID=WINDOW_ID_PROGRESS_PANEL_GENERAL;
}
if (progressPanelID>=WINDOW_ID_PROGRESS_PANEL_MAX)
{
progressPanelID=WINDOW_ID_PROGRESS_PANEL_GENERAL;
}
currentDebugLevel=debugMaxLevel.Item(progressPanelID-WINDOW_ID_PROGRESS_PANEL_GENERAL);
}
ErrorData::ErrorData()
{
ClearError();
}
void ErrorData::ClearError()
{
errorCode=ERROR_CODE_OK;
}
ErrorCodes ErrorData::CurrentError()
{
return (errorCode);
}
bool ErrorData::IsOK()
{
return (errorCode==ERROR_CODE_OK);
}
void ErrorData::SetError(ErrorCodes error,char *description)
{
errorCode=error;
errorDescription=description;
}
void ErrorData::SetError(ErrorCodes error,wxString &description)
{
errorCode=error;
errorDescription=description;
}