/* * ===================================================================================== * * Filename: Debug.hpp * * Description: * * Created: 14/12/2014 05:02:30 * * Author: Quentin Bazin, * * ===================================================================================== */ #ifndef DEBUG_HPP_ #define DEBUG_HPP_ #include #include #include #include #include #include "IntTypes.hpp" #define DEBUG_ENABLED #define DEBUG_COLOR #define _FILE (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__) #ifdef DEBUG_ENABLED #define DEBUG(args...) { std::cout << Debug::textColor(Debug::TextColor::Red, true) << _FILE << ":" << __LINE__ << ":" << Debug::textColor(); Debug::print(args); } #else #define DEBUG(args...) {} #endif namespace Debug { enum TextColor { White = 0, Red = 31, Blue = 36 }; inline std::string textColor(u8 color = TextColor::White, bool bold = false) { #ifdef DEBUG_COLOR return std::string("\33[0;") + ((color < 10) ? "0" : "") + std::to_string(color) + ";0" + ((bold) ? "1" : "0") + "m"; #else return std::string(""); #endif } template std::string makeString(Args &&...args) { std::ostringstream stream; std::vector tmp{0, ((void)(stream << args << " "), 0)...}; return stream.str(); } template void print(Args &&...args) { std::cerr << makeString(std::forward(args)...) << std::endl; } } #endif // DEBUG_HPP_