//------------------------------------------------------------------------------ // Console outputs dedicated routines -- // (C) Piero Giubilato 2008-2010, Berkeley Lab -- //------------------------------------------------------------------------------ //______________________________________________________________________________ // {Trace} // [File name] "console_Out.h" // [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} //______________________________________________________________________________ // Description // Adds the color(new_Color) directive to the standard output, allowing // to change the foreground and background color of the std output. // // Important: // Correctly define a WINSDK variable in order to abilitate the color functions. // // Parameters for the color(new_Color) directive // Colors follow the standard numerical color coding, and can be // called both by number that by keyword: // BLACK = 0, LBLACK = 8 // BLUE = 1, LBLUE = 9 // GREEN = 2, LGREEN = 10 // CYAN = 3, LCYAN = 11 // RED = 4, LRED = 12 // PURPLE = 5, LPURPLE = 13 // YELLOW = 6, LYELLOW = 14 // WHITE = 7, LWITHE = 15 // The keyword L (light) can be added to get the maximum luminosity color // The keyword BG (background) can be used as multiplyer to set the background // color as well // // Examples // cout << color(WHITE) << "Usual white\n"; // cout << "This is white: " << color(L + YELLOW) << // "this is light yellow" << endl; // cout << color(L + WHITE) << "This is light white" << endl; // cout << color(12) << "This is light red\n"; // cout << color(L + RED) << "This is still light red\n"; // cout << color(LRED) << "This is still light red\n"; // cout << color(L + RED + BG * YELLOW) << // "This is light red on yellow background\n"; // cout << color(8 + BG * (L + 5)) << // "This is light black on light yellow background\n"; //______________________________________________________________________________ // Overloading check #ifndef console_Out_H #define console_Out_H #include // console_Out class class console_Out { private: // Singleton implementation static console_Out* inst_Handle; static int inst_Count; protected: // Force a singleton console_Out(); ~console_Out(); console_Out(const console_Out&) {}; console_Out& operator=(console_Out&) {}; public: // Singleton access static console_Out* instance_Load(); static void instance_Destroy(); // Overloaded operators //#ifdef WINSDK // template // inline std::basic_ostream<_Elem,_Traits>& operator<< // (std::basic_ostream<_Elem,_Traits>& oStream) // {std::cout << oStream}; //#endif // Standard print method void Print(char* text, int text_Color, bool auto_NL); void Print(char* text, int text_Color); void Print(char* text, bool auto_NL); void Print(char* text); void Print(double number, int text_Color, bool auto_NL); void Print(double number, int text_Color); void Print(double number, bool auto_NL); void Print(double number); }; // All subsequent statements are valid ONLY IF the WINSDK variable is defined #ifdef WINSDK // This library calls many others windows libs #include // Color constants definitions enum color { FG = 0, BG = 16, L = FOREGROUND_INTENSITY, BLACK = 0, BLUE = FOREGROUND_BLUE, GREEN = FOREGROUND_GREEN, CYAN = FOREGROUND_GREEN | FOREGROUND_BLUE, RED = FOREGROUND_RED, PURPLE = FOREGROUND_RED | FOREGROUND_BLUE, YELLOW = FOREGROUND_RED | FOREGROUND_GREEN, WHITE = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE, LBLACK = L | BLACK, LBLUE = L | BLUE, LGREEN = L | GREEN, LCYAN = L | CYAN, LRED = L | RED, LPURPLE = L | PURPLE, LYELLOW = L | YELLOW, LWHITE = L | WHITE }; // Overloads the << operator in case the color keyword is found, // setting the new color for the console standard output template inline std::basic_ostream<_Elem,_Traits>& operator<<(std::basic_ostream<_Elem,_Traits>& out_Stream, color new_Color) { // Get the console handle HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE); // Set the new console color SetConsoleTextAttribute(hStdout, new_Color); // Return the righmost stream object to the next operator(s) return out_Stream; }; // Definition for the clear directive (still to complete) inline std::ostream& clear(std::ostream &out_Stream) { // Get the console handle HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE); // Return the righmost stream object to the next operator(s) return out_Stream; }; // End of WINSDK defined IF #endif // Overloading check #endif