The 'Debug Class' can apply to any program tbh, essentially all it does is print important output (e.g. "Engine has fucked up!") to a File or Console by default, the reason a Singleton is good for this is because it grants you access to the same File or Output Stream, etc..eatcomics wrote:So question, would I be better off using a debug singleton, or a debug class that everything inherits from??? I would really love to hear an answer and explanation :D Seeing as how I'm going to be doing some 3D stuff, and would really love to be able to have some good debug...
This example is similar to my engine's Log class, check it out->
Code: Select all
#define DEBUG_F "Program_Debug.txt"
#define ERROR_F "Program_Error.txt"
class Debug {
public:
// De/Constructor //
Debug();
~Debug();
// Debug Functions //
void Write(const char* FileName, char* Data) {
ofstream Temp(FileName, ios_base::app);
Temp << Data;
Temp.close();
}
// Other Debug Functions //
Debug* GetDebug() {
return this;
}
};
Code: Select all
template<class T>
class Singleton
{
private:
// De/Constructor //
Singleton();
~Singleton();
Singleton(Singleton const&);
Singleton& operator=(Singleton const&);
public:
// Meyers - Singleton Function //
static T* GetInstance()
{
static T sInstance;
return &sInstance;
}
};
Code: Select all
class Engine {
Debug* test;
..etc
}
Code: Select all
Engine::Engine() {
test = Singleton<Debug>::GetInstance();
}
void Engine::Initialize() {
// Initialize Some Shit //
test->GetDebug()->Write(DEBUG_F, "Engine Initialized\n");
}