Program Listing for File sampler_tools.h¶
↰ Return to documentation for file (src/sampler_tools.h
)
#ifndef SAMPLER_TOOLS_
#define SAMPLER_TOOLS_
#define ESCAPE_CHAR "\033["
#define PRINT_BOLD "1"
#define ITEM_SEP ";"
#define END_ESCAPE "m"
#define RESET_CONSOLE_COLOR (ESCAPE_CHAR "0" END_ESCAPE)
#include <sysexits.h>
#include <sys/stat.h>
#include <iostream>
#include <string>
#include <sstream>
#include "solver_config.h"
#include "statistics.h"
#define STR_DECIMAL_BASE 10
#if defined(WIN32) || defined(_WIN32)
#define FILE_PATH_SEPARATOR "\\"
#else
#define FILE_PATH_SEPARATOR "/"
#endif
enum PrintColor {
// INVERT_COLORS = 7,
COLOR_BLACK = 30,
COLOR_RED = 31,
COLOR_GREEN = 32,
COLOR_YELLOW = 33,
COLOR_BLUE = 34,
COLOR_MAGENTA = 35,
COLOR_CYAN = 36,
// COLOR_WHITE = 37
};
inline void PrintInColor(std::ostream &out, const std::string &msg,
const PrintColor color = COLOR_BLACK, bool bold = true) {
out << ESCAPE_CHAR;
if (bold)
out << PRINT_BOLD ITEM_SEP;
out << color;
out << END_ESCAPE << msg << RESET_CONSOLE_COLOR << std::endl;
}
inline void PrintInColor(const std::string &msg,
PrintColor color = COLOR_BLACK, bool bold = true) {
PrintInColor(std::cout, msg, color, bold);
}
inline void PrintInColor(std::ostream &out, const std::stringstream &msg,
const PrintColor color = COLOR_BLACK, bool bold = true) {
PrintInColor(out, msg.str(), color, bold);
}
inline void PrintInColor(const std::stringstream &msg,
PrintColor color = COLOR_BLACK, bool bold = true) {
PrintInColor(std::cout, msg.str(), color, bold);
}
inline void PrintWarning(const std::string &msg) {
PrintInColor(std::cout, "WARNING: " + msg, COLOR_YELLOW);
}
inline void PrintError(const std::string &msg) {
PrintInColor(std::cerr, "ERROR: " + msg, COLOR_RED);
}
inline void PrintError(const std::stringstream &msg) { PrintError(msg.str()); }
inline void ExitWithError(const std::string &msg, const int err_code=EXIT_FAILURE) {
PrintError(msg);
exit(err_code);
}
inline void ExitInvalidParam(const std::string &msg) {
ExitWithError(msg, EX_DATAERR);
}
inline const bool FileExists(const std::string &file_path) {
struct stat buffer;
return (stat(file_path.c_str(), &buffer) == 0);
}
#endif // SAMPLER_TOOLS_