forked from cpluspluscom/ChessPlusPlus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
I've implemented a new class to handle the debugging file so that we don't have the messy "cout" statements everywhere.
- Loading branch information
1 parent
2c19792
commit 2249dc0
Showing
1 changed file
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#if !defined( _DEBUG_LOGGER_H ) | ||
#define _DEBUG_LOGGER_H | ||
|
||
#if defined _DEBUG | ||
|
||
#include <fstream> | ||
|
||
namespace chesspp | ||
{ | ||
///////////////////////////////////////////////////////////////////////////// | ||
// Name: DebugLogFile | ||
// Desc: A simple class that's used to output debugging information so that | ||
// we can avoid using the console. | ||
///////////////////////////////////////////////////////////////////////////// | ||
class DebugLogFile | ||
{ | ||
public: | ||
DebugLogFile( const char *FileName = "DebugOutput.txt" ); | ||
~DebugLogFile( ); | ||
|
||
void LogMessage( const char *Message ); | ||
|
||
private: | ||
// Disallow copying because we only need a single debug file. Objections? | ||
DebugLogFile( DebugLogFile & ); | ||
DebugLogFile &operator = ( DebugLogFile & ); | ||
|
||
std::ofstream OutFile_; | ||
}; | ||
|
||
inline DebugLogFile::DebugLogFile( const char *FileName ) | ||
: OutFile_( ( FileName ) ? FileName : "DefaultDebugFile.txt" ) | ||
{ | ||
} | ||
|
||
inline DebugLogFile::~DebugLogFile( ) | ||
{ | ||
OutFile_.close( ); | ||
} | ||
|
||
inline void DebugLogFile::LogMessage( const char *Message ) | ||
{ | ||
if( ( OutFile_.is_open( ) ) && ( Message ) ) | ||
{ | ||
OutFile_ << Message << '\n'; | ||
} | ||
} | ||
} | ||
|
||
#endif | ||
|
||
#endif |