#ifndef DEBUG_H #define DEBUG_H #include #ifdef NDEBUG // No debug mode (release mode usually): ignore asserts #define ECCI_ASSERT(condition, message) do { } while (false) // Ignore debug messages #define ECCI_DEBUG(message) do { } while (false) #else // Compiling in debug mode // Process asserts. See http://stackoverflow.com/questions/3767869/adding-message-to-assert #define ECCI_ASSERT(condition, message) \ do \ { \ if (! (condition)) \ { \ std::cerr << "Assertion `" #condition "` failed in " << __FILE__ \ << " line " << __LINE__ << ": " << message << std::endl; \ std::exit(EXIT_FAILURE); \ } \ } while (false) /// Show normal log messsages only in debug mode #define ECCI_DEBUG(message) \ do \ { \ std::cerr << '\t' << __FILE__ << ':' << __LINE__ << ": " << message << std::endl; \ } while (false) #endif // NDEBUG /// If @a condition is false, shows @a message in error standar output #define ECCI_TEST(condition, message) \ do \ { \ if (! (condition)) \ std::cerr << __FILE__ << ':' << __LINE__ << ": " << message << std::endl; \ } while (false) /// If @a condition is false, shows @a message in error standar output and increases @a error_count #define ECCI_TEST2(error_count, condition, message) \ do \ { \ if (! (condition)) \ std::cerr << ++error_count << ". " << __FILE__ << ':' << __LINE__ << ": " << message << std::endl; \ } while (false) #endif // DEBUG_H