//------------------------------------------------------------------------------ // Console outputs dedicated routines -- // (C) Piero Giubilato 2008-2010, Berkeley Lab -- //------------------------------------------------------------------------------ //______________________________________________________________________________ // {Trace} // [File name] "console_Out.cpp" // [Author] "Piero Giubilato" // [Version] "1.2" // [Modified by] "Piero Giubilato" // [Last revision] "28 Jan 2009" // [Language] "C++" // [Compiler] "Visual C++ 9.x" // [Member of] "Cool SEAL" // [Project] "SEAL" // [Description] "Provides basic print and color managment for console ouput." // [Key documentation] // "Visual C++ Reference Help" // "Visual C++ SDK Help" // {Trace} //______________________________________________________________________________ // Standard libs #include // Application components #include "global.h" #include "console_Out.h" //______________________________________________________________________________ // Static member instantiation // Singleton console_Out* console_Out::inst_Handle = 0; int console_Out::inst_Count = 0; //______________________________________________________________________________ // Provides a safe self-destruction mechanism in case of missed destruction class ConsoleCleaner { public: ~ConsoleCleaner() {console_Out::instance_Destroy();} } ConsoleCleanerInst; //______________________________________________________________________________ console_Out* console_Out::instance_Load() { // Loads one instance of the class dbg_Print("console_Out::instance_Load:()", DBG_LVL_ZERO); // Just loads one class instance if (inst_Count == 0) { inst_Handle = new console_Out(); inst_Count ++; } // Returns the instance handle return inst_Handle; } //______________________________________________________________________________ void console_Out::instance_Destroy() { // Kills the active instance dbg_Print("console_Out::instance_Destroy:()", DBG_LVL_ZERO); // Deletes the current class instance if (inst_Handle) { inst_Handle = 0; inst_Count = 0; } } //______________________________________________________________________________ console_Out::console_Out() { // Default constructor dbg_Print("console_Out::console_Out:()", DBG_LVL_ZERO); } //______________________________________________________________________________ console_Out::~console_Out() { // Default destructor dbg_Print("console_Out::~console_Out:()", DBG_LVL_ZERO); } //______________________________________________________________________________ void console_Out::Print(char* text, int text_Color, bool auto_NL) { // Basic printing method (Full overload). Prints on the standard output. // Use colors only if WINSDK defined #ifdef WINSDK // Add colors to the standard output std::cout << color(text_Color) << text << color(WHITE); if(auto_NL) std::cout << std::endl; #else // Use plain output otherwise cout << text; if(auto_NL) cout << endl; #endif } //______________________________________________________________________________ void console_Out::Print(char* text, int text_Color) { // Basic printing method (Without auto_NL download) Print(text, text_Color, false); } //______________________________________________________________________________ void console_Out::Print(char* text, bool auto_NL) { // Basic printing method (Without text_Color download) Print(text, 7, auto_NL); } //______________________________________________________________________________ void console_Out::Print(char* text) { // Basic printing method (Text only download) Print(text, 7, false); } //______________________________________________________________________________ void console_Out::Print(double number, int text_Color, bool auto_NL) { // Basic printing method (Number only download) // Note: it is faster to rewrite the #ifdef than using // number to string conversion functions! // Use colors only if WINSDK defined #ifdef WINSDK // Add colors to the standard output std::cout << color(text_Color) << number << color(WHITE); if(auto_NL) std::cout << std::endl; #else // Use plain output otherwise cout << number; if(auto_NL) cout << endl; #endif } //______________________________________________________________________________ void console_Out::Print(double number, int text_Color) { // Basic printing method (Number without auto_NL download) Print(number, text_Color, false); } //______________________________________________________________________________ void console_Out::Print(double number, bool auto_NL) { // Basic printing method (Number without text_Color download) Print(number, 7, auto_NL); } //______________________________________________________________________________ void console_Out::Print(double number) { // Basic printing method (number only download) Print(number, 7, false); }