2using System.Collections.Generic;
14 string m_strPreText =
"";
16 double m_dfProgress = 0;
17 bool m_bEnable =
true;
18 bool m_bEnableTrace =
false;
33 public Log(
string strSrc)
43 set { m_bEnable = value; }
51 get {
return m_bEnable; }
59 get {
return m_strPreText; }
60 set { m_strPreText = value; }
68 get {
return m_bEnableTrace; }
69 set { m_bEnableTrace = value; }
80 public void WriteLine(
string str,
bool bOverrideEnabled =
false,
bool bHeader =
false,
bool bError =
false,
bool bDisable =
false)
83 if (!m_bEnable && !bOverrideEnabled)
88 if (!bHeader && m_strPreText !=
null && m_strPreText.Length > 0)
89 strLine = m_strPreText + str;
94 OnWriteLine(
this,
new LogArg(m_strSource, strLine, m_dfProgress, bError, bOverrideEnabled, bDisable));
99 Trace.WriteLine(strLine);
101 Trace.WriteLine(m_dfProgress.ToString(
"P") +
" " + strLine);
116 strLine +=
"=============================================";
117 strLine += Environment.NewLine;
119 strLine += Environment.NewLine;
120 strLine +=
"=============================================";
121 strLine += Environment.NewLine;
132 string strErr = e.Message;
134 if (e.InnerException !=
null)
135 strErr +=
" " + e.InnerException.Message;
137 if (strErr.Trim().Length == 0)
138 strErr =
"No error message!";
140 WriteLine(
"ERROR! " + strErr,
false,
false,
true);
148 get {
return m_dfProgress; }
154 m_dfProgress = value;
170 if (typeof(T) == typeof(
float))
173 str =
"Float Values " + df1.ToString() +
" and " + df2.ToString() +
" are NOT FLOAT equal!";
182 str =
"Values " + df1.ToString() +
" and " + df2.ToString() +
" are NOT equal!";
184 throw new Exception(str);
198 float f1 = (float)df1;
199 float f2 = (float)df2;
200 float fErr = (float)dfErr;
201 float fDiff = Math.Abs(f1 - f2);
204 throw new Exception(
"Values " + f1.ToString() +
" and " + f2.ToString() +
" are NOT within the range " + fErr.ToString() +
" of one another. " + str);
214 public void EXPECT_NEAR(
double df1,
double df2,
double dfErr,
string str =
"")
216 double dfDiff = Math.Abs(df1 - df2);
219 throw new Exception(
"Values " + df1.ToString() +
" and " + df2.ToString() +
" are NOT within the range " + dfErr.ToString() +
" of one another. " + str);
227 public void CHECK(
bool b,
string str)
230 throw new Exception(str);
239 public void CHECK_EQ(
double df1,
double df2,
string str)
242 throw new Exception(str);
251 public void CHECK_NE(
double df1,
double df2,
string str)
254 throw new Exception(str);
263 public void CHECK_LE(
double df1,
double df2,
string str)
266 throw new Exception(str);
275 public void CHECK_LT(
double df1,
double df2,
string str)
278 throw new Exception(str);
287 public void CHECK_GE(
double df1,
double df2,
string str)
290 throw new Exception(str);
299 public void CHECK_GT(
double df1,
double df2,
string str)
302 throw new Exception(str);
311 public void CHECK_EQ(
float f1,
float f2,
string str)
314 throw new Exception(str);
323 public void CHECK_NE(
float f1,
float f2,
string str)
326 throw new Exception(str);
335 public void CHECK_LE(
float f1,
float f2,
string str)
338 throw new Exception(str);
347 public void CHECK_LT(
float f1,
float f2,
string str)
350 throw new Exception(str);
359 public void CHECK_GE(
float f1,
float f2,
string str)
362 throw new Exception(str);
371 public void CHECK_GT(
float f1,
float f2,
string str)
374 throw new Exception(str);
396 throw new Exception(str);
The LogArg is passed as an argument to the Log::OnWriteLine event.
The Log class provides general output in text form.
void CHECK(bool b, string str)
Test a flag for true.
void CHECK_LT(float f1, float f2, string str)
Test whether one number is less-than another.
bool IsEnabled
Returns whether or not the Log is enabled.
void CHECK_LE(float f1, float f2, string str)
Test whether one number is less-than or equal to another.
void WriteLine(string str, bool bOverrideEnabled=false, bool bHeader=false, bool bError=false, bool bDisable=false)
Write a line of output.
void EXPECT_EQUAL< T >(double df1, double df2, string str=null)
Test whether two values are equal using a given type 'T'.
bool Enable
Enables/disables the Log. When disabled, the Log does not output any data.
void CHECK_GE(float f1, float f2, string str)
Test whether one number is greater-than or equal to another.
void FAIL(string str)
Causes a failure which throws an exception with the desciptive text.
double Progress
Get/set the progress associated with the Log.
void CHECK_EQ(double df1, double df2, string str)
Test whether one number is equal to another.
void EXPECT_NEAR_FLOAT(double df1, double df2, double dfErr, string str="")
Test whether two numbers are within a range (dfErr) of one another using the float resolution.
EventHandler< LogProgressArg > OnProgress
The OnProgress event fires each time the Progress value is set.
void WriteHeader(string str)
Write a header as output.
string PreText
Get/set the pre-text prepended to each output line when set.
void WriteError(Exception e)
Write an error as output.
Log(string strSrc)
The Log constructor.
void CHECK_NE(double df1, double df2, string str)
Test whether one number is not-equal to another.
void CHECK_GT(float f1, float f2, string str)
Test whether one number is greater-than another.
void CHECK_GT(double df1, double df2, string str)
Test whether one number is greater than another.
void CHECK_NE(float f1, float f2, string str)
Test whether one number is not equal to another.
void CHECK_LE(double df1, double df2, string str)
Test whether one number is less than or equal to another.
bool EnableTrace
Enables/disables the Trace. When enabled, the .Net Trace.WriteLine is called in addition to the norma...
void CHECK_BOUNDS(float f1, float fmin, float fmax, string str)
Test whether a number falls within a set bound or not.
void CHECK_GE(double df1, double df2, string str)
Test whether one number is greater than or equal to another.
void CHECK_LT(double df1, double df2, string str)
Test whether one number is less than another.
EventHandler< LogArg > OnWriteLine
The OnWriteLine event fires each time the WriteLine, WriteHeader or WriteError functions are called.
void EXPECT_NEAR(double df1, double df2, double dfErr, string str="")
Test whether two numbers are within a range (dfErr) of one another using the double resolution.
void CHECK_EQ(float f1, float f2, string str)
Test whether one number is equal to another.
The LogProgressArg is passed as an argument to the Log::OnProgress event.
The MyCaffe.basecode contains all generic types used throughout MyCaffe.