21 #include <sys/types.h> 68 #define NUM_LOG_LEVELS 10 72 #include <Availability.h> 74 #define __MAC_10_8 1080 76 #if __MAC_OS_X_VERSION_MIN_REQUIRED < __MAC_10_8 77 #define CONST_DIRENT_T struct dirent 79 #define CONST_DIRENT_T const struct dirent 80 #endif // Lion or earlier 82 #define CONST_DIRENT_T const struct dirent 85 #define SG_SET_LOCALE_C setlocale(LC_ALL, "C") 86 #define SG_RESET_LOCALE setlocale(LC_ALL, "") 88 #if !defined(SG_UNLIKELY) 90 #define SG_UNLIKELY(expr) __builtin_expect(expr, 0) 92 #define SG_UNLIKELY(expr) expr 97 #define __PRETTY_FUNCTION__ __FUNCTION__ 102 #define SG_GCDEBUG(...) { \ 103 if (SG_UNLIKELY(io->loglevel_above(MSG_GCDEBUG))) \ 104 io->message(MSG_GCDEBUG, __PRETTY_FUNCTION__, __FILE__, __LINE__, __VA_ARGS__); \ 107 #define SG_DEBUG(...) { \ 108 if (SG_UNLIKELY(io->loglevel_above(MSG_DEBUG))) \ 109 io->message(MSG_DEBUG, __PRETTY_FUNCTION__, __FILE__, __LINE__, __VA_ARGS__); \ 112 #define SG_OBJ_DEBUG(o,...) { \ 113 if (SG_UNLIKELY(o->io->loglevel_above(MSG_DEBUG))) \ 114 o->io->message(MSG_DEBUG, __PRETTY_FUNCTION__, __FILE__, __LINE__, __VA_ARGS__); \ 118 #define SG_INFO(...) { \ 119 if (SG_UNLIKELY(io->loglevel_above(MSG_INFO))) \ 120 io->message(MSG_INFO, __PRETTY_FUNCTION__, __FILE__, __LINE__, __VA_ARGS__); \ 123 #define SG_CLASS_INFO(c, ...) { \ 124 if (SG_UNLIKELY(c::io->loglevel_above(MSG_INFO))) \ 125 c::io->message(MSG_INFO, __PRETTY_FUNCTION__, __FILE__, __LINE__, __VA_ARGS__); \ 128 #define SG_WARNING(...) { io->message(MSG_WARN, __PRETTY_FUNCTION__, __FILE__, __LINE__, __VA_ARGS__); } 129 #define SG_ERROR(...) { io->message(MSG_ERROR, __PRETTY_FUNCTION__, __FILE__, __LINE__, __VA_ARGS__); } 130 #define SG_OBJ_ERROR(o, ...) { o->io->message(MSG_ERROR, __PRETTY_FUNCTION__, __FILE__, __LINE__, __VA_ARGS__); } 131 #define SG_CLASS_ERROR(c, ...) { c::io->message(MSG_ERROR, __PRETTY_FUNCTION__, __FILE__, __LINE__, __VA_ARGS__); } 132 #define SG_UNSTABLE(func, ...) { io->message(MSG_WARN, __PRETTY_FUNCTION__, __FILE__, __LINE__, \ 133 __FILE__ ":" func ": Unstable method! Please report if it seems to " \ 134 "work or not to the Shogun mailing list. Thanking you in " \ 135 "anticipation. " __VA_ARGS__); } 137 #define SG_PRINT(...) { io->message(MSG_MESSAGEONLY, __PRETTY_FUNCTION__, __FILE__, __LINE__, __VA_ARGS__); } 138 #define SG_OBJ_PRINT(o, ...) { o->io->message(MSG_MESSAGEONLY, __PRETTY_FUNCTION__, __FILE__, __LINE__, __VA_ARGS__); } 139 #define SG_NOTIMPLEMENTED { io->not_implemented(__PRETTY_FUNCTION__, __FILE__, __LINE__); } 140 #define SG_DEPRECATED { io->deprecated(__PRETTY_FUNCTION__, __FILE__, __LINE__); } 142 #define SG_PROGRESS(...) { \ 143 if (SG_UNLIKELY(io->get_show_progress())) \ 144 io->progress(__VA_ARGS__); \ 147 #define SG_OBJ_PROGRESS(o, ...) { \ 148 if (SG_UNLIKELY(o->io->get_show_progress()))\ 149 o->io->progress(__VA_ARGS__); \ 152 #define SG_ABS_PROGRESS(...) { \ 153 if (SG_UNLIKELY(io->get_show_progress())) \ 154 io->absolute_progress(__VA_ARGS__); \ 157 #define SG_DONE() { \ 158 if (SG_UNLIKELY(io->get_show_progress())) \ 163 #define SG_SGCDEBUG(...) { \ 164 if (SG_UNLIKELY(sg_io->loglevel_above(MSG_GCDEBUG))) \ 165 sg_io->message(MSG_GCDEBUG,__PRETTY_FUNCTION__, __FILE__, __LINE__, __VA_ARGS__);\ 168 #define SG_SDEBUG(...) { \ 169 if (SG_UNLIKELY(sg_io->loglevel_above(MSG_DEBUG))) \ 170 sg_io->message(MSG_DEBUG,__PRETTY_FUNCTION__, __FILE__, __LINE__, __VA_ARGS__); \ 173 #define SG_SINFO(...) { \ 174 if (SG_UNLIKELY(sg_io->loglevel_above(MSG_INFO))) \ 175 sg_io->message(MSG_INFO,__PRETTY_FUNCTION__, __FILE__, __LINE__, __VA_ARGS__); \ 178 #define SG_SWARNING(...) { sg_io->message(MSG_WARN,__PRETTY_FUNCTION__, __FILE__, __LINE__, __VA_ARGS__); } 179 #define SG_SERROR(...) { sg_io->message(MSG_ERROR,__PRETTY_FUNCTION__, __FILE__, __LINE__, __VA_ARGS__); } 180 #define SG_SPRINT(...) { sg_io->message(MSG_MESSAGEONLY,__PRETTY_FUNCTION__, __FILE__, __LINE__, __VA_ARGS__); } 183 #define SG_SPROGRESS(...) { \ 184 if (SG_UNLIKELY(sg_io->get_show_progress())) \ 185 sg_io->progress(__VA_ARGS__); \ 188 #define SG_SABS_PROGRESS(...) { \ 189 if (SG_UNLIKELY(sg_io->get_show_progress())) \ 190 sg_io->absolute_progress(__VA_ARGS__); \ 193 #define SG_SDONE() { \ 194 if (SG_UNLIKELY(sg_io->get_show_progress())) \ 198 #define SG_SNOTIMPLEMENTED { sg_io->not_implemented(__PRETTY_FUNCTION__, __FILE__, __LINE__); } 199 #define SG_SDEPRECATED { sg_io->deprecated(__PRETTY_FUNCTION__, __FILE__, __LINE__); } 201 #define ASSERT(x) { \ 202 if (SG_UNLIKELY(!(x))) \ 203 SG_SERROR("assertion %s failed in %s file %s line %d\n",#x, __PRETTY_FUNCTION__, __FILE__, __LINE__) \ 206 #define REQUIRE(x, ...) { \ 207 if (SG_UNLIKELY(!(x))) \ 208 SG_SERROR(__VA_ARGS__) \ 212 #ifdef __clang_analyzer__ 213 void _clang_fail(
void) __attribute__((analyzer_noreturn));
216 #undef SG_SERROR(...) 217 #define SG_ERROR(...) _clang_fail(); 218 #define SG_SERROR(...) _clang_fail(); 273 return loglevel <= type;
282 return show_progress;
289 return location_info;
298 return syntax_highlight;
312 void message(
EMessageType prio,
const char*
function,
const char* file,
313 int32_t line,
const char *fmt, ... )
const;
326 const char* prefix=
"PROGRESS:\t");
337 void absolute_progress(
340 const char* prefix=
"PROGRESS:\t");
349 inline void not_implemented(
const char*
function,
const char* file, int32_t line)
const 351 message(
MSG_ERROR,
function, file, line,
"Sorry, not yet implemented .\n");
355 inline void deprecated(
const char*
function,
const char* file, int32_t line)
const 357 message(
MSG_WARN,
function, file, line,
358 "This function is deprecated and will be removed soon.\n");
366 void buffered_message(
EMessageType prio,
const char *fmt, ... )
const;
373 static char* skip_spaces(
char* str);
380 static char* skip_blanks(
char* str);
395 void set_target(FILE* target);
430 location_info = location;
439 syntax_highlight=
true;
448 syntax_highlight=
false;
460 strncpy(directory_name, dirname,
FBUFSIZE);
469 static char* concat_filename(
const char* filename);
483 static char* c_string_of_substring(
substring s);
489 static void print_substring(
substring s);
511 static int32_t int_of_substring(
substring s);
518 static uint32_t ulong_of_substring(
substring s);
537 int32_t ref_count()
const;
FILE * get_target() const
bool loglevel_above(EMessageType type) const
struct Substring, specified by start position and end position.
void disable_syntax_highlighting()
void enable_syntax_highlighting()
float64_t last_progress_time
void set_target_to_stdout()
void not_implemented(const char *function, const char *file, int32_t line) const
float64_t progress_start_time
bool get_show_progress() const
EMessageLocation location_info
static void set_dirname(const char *dirname)
all of classes and functions are contained in the shogun namespace
void deprecated(const char *function, const char *file, int32_t line) const
Class SGIO, used to do input output operations throughout shogun.
void set_location_info(EMessageLocation location)
void set_target_to_stderr()
bool get_syntax_highlight() const
EMessageLocation get_location_info() const