59 lines
1.7 KiB
C++
59 lines
1.7 KiB
C++
#ifndef UTILS_H
|
|
#define UTILS_H
|
|
|
|
#include <string>
|
|
|
|
inline std::string basedir(const std::string &path)
|
|
{
|
|
int idx1 = static_cast<int>(path.rfind("/"));
|
|
int idx2 = static_cast<int>(path.rfind("\\"));
|
|
std::string r;
|
|
if (idx1 == std::string::npos && idx2 == std::string::npos) {
|
|
r = "";
|
|
} else {
|
|
int idx;
|
|
if (idx1 == std::string::npos) {
|
|
idx = idx2;
|
|
} else if (idx2 == std::string::npos) {
|
|
idx = idx1;
|
|
} else if (idx1 < idx2) {
|
|
idx = idx2;
|
|
} else {
|
|
idx = idx1;
|
|
}
|
|
r = path.substr(0, idx);
|
|
}
|
|
return r;
|
|
}
|
|
|
|
int logLevel();
|
|
void setLogLevel(int l);
|
|
const char *logIndicator(int l);
|
|
|
|
#define LOG_ERROR 1
|
|
#define LOG_WARNING 2
|
|
#define LOG_INFO 3
|
|
#define LOG_DEBUG 4
|
|
|
|
#define MKLOGSTMT(level, code) if (logLevel() >= level) { fprintf(stderr, "%s: ", logIndicator(level));code;fflush(stderr); }
|
|
#define MKL0(level, msg) MKLOGSTMT(level, fprintf(stderr, msg))
|
|
#define MKL1(level, msg, a) MKLOGSTMT(level, fprintf(stderr, msg, a))
|
|
#define MKL2(level, msg, a, b) MKLOGSTMT(level, fprintf(stderr, msg, a, b))
|
|
|
|
#define ERROR0(msg) MKL0(LOG_ERROR, msg)
|
|
#define WARN0(msg) MKL0(LOG_WARNING, msg)
|
|
#define INFO0(msg) MKL0(LOG_INFO, msg)
|
|
#define DEBUG0(msg) MKL0(LOG_DEBUG, msg)
|
|
|
|
#define ERROR1(msg, a) MKL1(LOG_ERROR, msg, a)
|
|
#define WARN1(msg, a) MKL1(LOG_WARNING, msg, a)
|
|
#define INFO1(msg, a) MKL1(LOG_INFO, msg, a)
|
|
#define DEBUG1(msg, a) MKL1(LOG_DEBUG, msg, a)
|
|
|
|
#define ERROR2(msg, a, b) MKL2(LOG_ERROR, msg, a, b)
|
|
#define WARN2(msg, a, b) MKL2(LOG_WARNING, msg, a, b)
|
|
#define INFO2(msg, a, b) MKL2(LOG_INFO, msg, a, b)
|
|
#define DEBUG2(msg, a, b) MKL2(LOG_DEBUG, msg, a, b)
|
|
|
|
#endif // UTILS_H
|