16 #include <shogun/lib/config.h> 22 #include <sys/types.h> 67 #define NUM_LOG_LEVELS 10 71 #include <Availability.h> 73 #define __MAC_10_8 1080 75 #if __MAC_OS_X_VERSION_MIN_REQUIRED < __MAC_10_8 76 #define CONST_DIRENT_T struct dirent 78 #define CONST_DIRENT_T const struct dirent 79 #endif // Lion or earlier 81 #define CONST_DIRENT_T const struct dirent 84 #define SG_SET_LOCALE_C setlocale(LC_ALL, "C") 85 #define SG_RESET_LOCALE setlocale(LC_ALL, "") 87 #if !defined(SG_UNLIKELY) 89 #define SG_UNLIKELY(expr) __builtin_expect(expr, 0) 91 #define SG_UNLIKELY(expr) expr 96 #define __PRETTY_FUNCTION__ __FUNCTION__ 101 #define SG_GCDEBUG(...) { \ 102 if (SG_UNLIKELY(io->loglevel_above(MSG_GCDEBUG))) \ 103 io->message(MSG_GCDEBUG, __PRETTY_FUNCTION__, __FILE__, __LINE__, __VA_ARGS__); \ 106 #define SG_DEBUG(...) { \ 107 if (SG_UNLIKELY(io->loglevel_above(MSG_DEBUG))) \ 108 io->message(MSG_DEBUG, __PRETTY_FUNCTION__, __FILE__, __LINE__, __VA_ARGS__); \ 111 #define SG_OBJ_DEBUG(o,...) { \ 112 if (SG_UNLIKELY(o->io->loglevel_above(MSG_DEBUG))) \ 113 o->io->message(MSG_DEBUG, __PRETTY_FUNCTION__, __FILE__, __LINE__, __VA_ARGS__); \ 117 #define SG_INFO(...) { \ 118 if (SG_UNLIKELY(io->loglevel_above(MSG_INFO))) \ 119 io->message(MSG_INFO, __PRETTY_FUNCTION__, __FILE__, __LINE__, __VA_ARGS__); \ 122 #define SG_CLASS_INFO(c, ...) { \ 123 if (SG_UNLIKELY(c::io->loglevel_above(MSG_INFO))) \ 124 c::io->message(MSG_INFO, __PRETTY_FUNCTION__, __FILE__, __LINE__, __VA_ARGS__); \ 127 #define SG_WARNING(...) { io->message(MSG_WARN, __PRETTY_FUNCTION__, __FILE__, __LINE__, __VA_ARGS__); } 128 #define SG_ERROR(...) { io->message(MSG_ERROR, __PRETTY_FUNCTION__, __FILE__, __LINE__, __VA_ARGS__); } 129 #define SG_OBJ_ERROR(o, ...) { o->io->message(MSG_ERROR, __PRETTY_FUNCTION__, __FILE__, __LINE__, __VA_ARGS__); } 130 #define SG_CLASS_ERROR(c, ...) { c::io->message(MSG_ERROR, __PRETTY_FUNCTION__, __FILE__, __LINE__, __VA_ARGS__); } 131 #define SG_UNSTABLE(func, ...) { io->message(MSG_WARN, __PRETTY_FUNCTION__, __FILE__, __LINE__, \ 132 __FILE__ ":" func ": Unstable method! Please report if it seems to " \ 133 "work or not to the Shogun mailing list. Thanking you in " \ 134 "anticipation. " __VA_ARGS__); } 136 #define SG_PRINT(...) { io->message(MSG_MESSAGEONLY, __PRETTY_FUNCTION__, __FILE__, __LINE__, __VA_ARGS__); } 137 #define SG_OBJ_PRINT(o, ...) { o->io->message(MSG_MESSAGEONLY, __PRETTY_FUNCTION__, __FILE__, __LINE__, __VA_ARGS__); } 138 #define SG_NOTIMPLEMENTED { io->not_implemented(__PRETTY_FUNCTION__, __FILE__, __LINE__); } 139 #define SG_DEPRECATED { io->deprecated(__PRETTY_FUNCTION__, __FILE__, __LINE__); } 141 #define SG_PROGRESS(...) { \ 142 if (SG_UNLIKELY(io->get_show_progress())) \ 143 io->progress(__VA_ARGS__); \ 146 #define SG_OBJ_PROGRESS(o, ...) { \ 147 if (SG_UNLIKELY(o->io->get_show_progress()))\ 148 o->io->progress(__VA_ARGS__); \ 151 #define SG_ABS_PROGRESS(...) { \ 152 if (SG_UNLIKELY(io->get_show_progress())) \ 153 io->absolute_progress(__VA_ARGS__); \ 156 #define SG_DONE() { \ 157 if (SG_UNLIKELY(io->get_show_progress())) \ 162 #define SG_SGCDEBUG(...) { \ 163 if (SG_UNLIKELY(sg_io->loglevel_above(MSG_GCDEBUG))) \ 164 sg_io->message(MSG_GCDEBUG,__PRETTY_FUNCTION__, __FILE__, __LINE__, __VA_ARGS__);\ 167 #define SG_SDEBUG(...) { \ 168 if (SG_UNLIKELY(sg_io->loglevel_above(MSG_DEBUG))) \ 169 sg_io->message(MSG_DEBUG,__PRETTY_FUNCTION__, __FILE__, __LINE__, __VA_ARGS__); \ 172 #define SG_SINFO(...) { \ 173 if (SG_UNLIKELY(sg_io->loglevel_above(MSG_INFO))) \ 174 sg_io->message(MSG_INFO,__PRETTY_FUNCTION__, __FILE__, __LINE__, __VA_ARGS__); \ 177 #define SG_SWARNING(...) { sg_io->message(MSG_WARN,__PRETTY_FUNCTION__, __FILE__, __LINE__, __VA_ARGS__); } 178 #define SG_SERROR(...) { sg_io->message(MSG_ERROR,__PRETTY_FUNCTION__, __FILE__, __LINE__, __VA_ARGS__); } 179 #define SG_SPRINT(...) { sg_io->message(MSG_MESSAGEONLY,__PRETTY_FUNCTION__, __FILE__, __LINE__, __VA_ARGS__); } 182 #define SG_SPROGRESS(...) { \ 183 if (SG_UNLIKELY(sg_io->get_show_progress())) \ 184 sg_io->progress(__VA_ARGS__); \ 187 #define SG_SABS_PROGRESS(...) { \ 188 if (SG_UNLIKELY(sg_io->get_show_progress())) \ 189 sg_io->absolute_progress(__VA_ARGS__); \ 192 #define SG_SDONE() { \ 193 if (SG_UNLIKELY(sg_io->get_show_progress())) \ 197 #define SG_SNOTIMPLEMENTED { sg_io->not_implemented(__PRETTY_FUNCTION__, __FILE__, __LINE__); } 198 #define SG_SDEPRECATED { sg_io->deprecated(__PRETTY_FUNCTION__, __FILE__, __LINE__); } 200 #define ASSERT(x) { \ 201 if (SG_UNLIKELY(!(x))) \ 202 SG_SERROR("assertion %s failed in %s file %s line %d\n",#x, __PRETTY_FUNCTION__, __FILE__, __LINE__) \ 205 #define REQUIRE(x, ...) { \ 206 if (SG_UNLIKELY(!(x))) \ 207 SG_SERROR(__VA_ARGS__) \ 211 #ifdef __clang_analyzer__ 212 void _clang_fail(
void) __attribute__((analyzer_noreturn));
215 #undef SG_SERROR(...) 216 #define SG_ERROR(...) _clang_fail(); 217 #define SG_SERROR(...) _clang_fail(); 272 return loglevel <= type;
281 return show_progress;
288 return location_info;
294 return last_progress;
303 return syntax_highlight;
317 void message(
EMessageType prio,
const char*
function,
const char* file,
318 int32_t line,
const char *fmt, ... )
const;
331 const char* prefix=
"PROGRESS:\t");
342 void absolute_progress(
345 const char* prefix=
"PROGRESS:\t");
354 inline void not_implemented(
const char*
function,
const char* file, int32_t line)
const 356 message(
MSG_ERROR,
function, file, line,
"Sorry, not yet implemented .\n");
360 inline void deprecated(
const char*
function,
const char* file, int32_t line)
const 362 message(
MSG_WARN,
function, file, line,
363 "This function is deprecated and will be removed soon.\n");
371 void buffered_message(
EMessageType prio,
const char *fmt, ... )
const;
378 static char* skip_spaces(
char* str);
385 static char* skip_blanks(
char* str);
400 void set_target(FILE* target);
435 location_info = location;
444 syntax_highlight=
true;
453 syntax_highlight=
false;
466 strncpy_s(directory_name,
FBUFSIZE, dirname, strlen(dirname));
468 strncpy(directory_name, dirname,
FBUFSIZE);
478 static char* concat_filename(
const char* filename);
492 static char* c_string_of_substring(
substring s);
498 static void print_substring(
substring s);
520 static int32_t int_of_substring(
substring s);
527 static uint32_t ulong_of_substring(
substring s);
546 int32_t ref_count()
const;
bool loglevel_above(EMessageType type) const
bool get_show_progress() const
void deprecated(const char *function, const char *file, int32_t line) const
struct Substring, specified by start position and end position.
void disable_syntax_highlighting()
bool get_syntax_highlight() const
void enable_syntax_highlighting()
float64_t last_progress_time
void set_target_to_stdout()
float64_t progress_start_time
EMessageLocation location_info
static void set_dirname(const char *dirname)
all of classes and functions are contained in the shogun namespace
void not_implemented(const char *function, const char *file, int32_t line) const
float64_t get_last_progress() const
EMessageLocation get_location_info() const
Class SGIO, used to do input output operations throughout shogun.
void set_location_info(EMessageLocation location)
void set_target_to_stderr()
FILE * get_target() const