22 #include <sys/types.h>
69 #define NUM_LOG_LEVELS 10
73 #include <Availability.h>
75 #define __MAC_10_8 1080
77 #if __MAC_OS_X_VERSION_MIN_REQUIRED < __MAC_10_8
78 #define CONST_DIRENT_T struct dirent
80 #define CONST_DIRENT_T const struct dirent
81 #endif // Lion or earlier
83 #define CONST_DIRENT_T const struct dirent
86 #define SG_SET_LOCALE_C setlocale(LC_ALL, "C")
87 #define SG_RESET_LOCALE setlocale(LC_ALL, "")
89 #if !defined(SG_UNLIKELY)
91 #define SG_UNLIKELY(expr) __builtin_expect(expr, 0)
93 #define SG_UNLIKELY(expr) expr
98 #define __PRETTY_FUNCTION__ __FUNCTION__
103 #define SG_GCDEBUG(...) { \
104 if (SG_UNLIKELY(io->loglevel_above(MSG_GCDEBUG))) \
105 io->message(MSG_GCDEBUG, __PRETTY_FUNCTION__, __FILE__, __LINE__, __VA_ARGS__); \
108 #define SG_DEBUG(...) { \
109 if (SG_UNLIKELY(io->loglevel_above(MSG_DEBUG))) \
110 io->message(MSG_DEBUG, __PRETTY_FUNCTION__, __FILE__, __LINE__, __VA_ARGS__); \
113 #define SG_OBJ_DEBUG(o,...) { \
114 if (SG_UNLIKELY(o->io->loglevel_above(MSG_DEBUG))) \
115 o->io->message(MSG_DEBUG, __PRETTY_FUNCTION__, __FILE__, __LINE__, __VA_ARGS__); \
119 #define SG_INFO(...) { \
120 if (SG_UNLIKELY(io->loglevel_above(MSG_INFO))) \
121 io->message(MSG_INFO, __PRETTY_FUNCTION__, __FILE__, __LINE__, __VA_ARGS__); \
124 #define SG_CLASS_INFO(c, ...) { \
125 if (SG_UNLIKELY(c::io->loglevel_above(MSG_INFO))) \
126 c::io->message(MSG_INFO, __PRETTY_FUNCTION__, __FILE__, __LINE__, __VA_ARGS__); \
129 #define SG_WARNING(...) { io->message(MSG_WARN, __PRETTY_FUNCTION__, __FILE__, __LINE__, __VA_ARGS__); }
130 #define SG_ERROR(...) { io->message(MSG_ERROR, __PRETTY_FUNCTION__, __FILE__, __LINE__, __VA_ARGS__); }
131 #define SG_OBJ_ERROR(o, ...) { o->io->message(MSG_ERROR, __PRETTY_FUNCTION__, __FILE__, __LINE__, __VA_ARGS__); }
132 #define SG_CLASS_ERROR(c, ...) { c::io->message(MSG_ERROR, __PRETTY_FUNCTION__, __FILE__, __LINE__, __VA_ARGS__); }
133 #define SG_UNSTABLE(func, ...) { io->message(MSG_WARN, __PRETTY_FUNCTION__, __FILE__, __LINE__, \
134 __FILE__ ":" func ": Unstable method! Please report if it seems to " \
135 "work or not to the Shogun mailing list. Thanking you in " \
136 "anticipation. " __VA_ARGS__); }
138 #define SG_PRINT(...) { io->message(MSG_MESSAGEONLY, __PRETTY_FUNCTION__, __FILE__, __LINE__, __VA_ARGS__); }
139 #define SG_OBJ_PRINT(o, ...) { o->io->message(MSG_MESSAGEONLY, __PRETTY_FUNCTION__, __FILE__, __LINE__, __VA_ARGS__); }
140 #define SG_NOTIMPLEMENTED { io->not_implemented(__PRETTY_FUNCTION__, __FILE__, __LINE__); }
141 #define SG_DEPRECATED { io->deprecated(__PRETTY_FUNCTION__, __FILE__, __LINE__); }
143 #define SG_PROGRESS(...) { \
144 if (SG_UNLIKELY(io->get_show_progress())) \
145 io->progress(__VA_ARGS__); \
148 #define SG_OBJ_PROGRESS(o, ...) { \
149 if (SG_UNLIKELY(o->io->get_show_progress()))\
150 o->io->progress(__VA_ARGS__); \
153 #define SG_ABS_PROGRESS(...) { \
154 if (SG_UNLIKELY(io->get_show_progress())) \
155 io->absolute_progress(__VA_ARGS__); \
158 #define SG_DONE() { \
159 if (SG_UNLIKELY(io->get_show_progress())) \
164 #define SG_SGCDEBUG(...) { \
165 if (SG_UNLIKELY(sg_io->loglevel_above(MSG_GCDEBUG))) \
166 sg_io->message(MSG_GCDEBUG,__PRETTY_FUNCTION__, __FILE__, __LINE__, __VA_ARGS__);\
169 #define SG_SDEBUG(...) { \
170 if (SG_UNLIKELY(sg_io->loglevel_above(MSG_DEBUG))) \
171 sg_io->message(MSG_DEBUG,__PRETTY_FUNCTION__, __FILE__, __LINE__, __VA_ARGS__); \
174 #define SG_SINFO(...) { \
175 if (SG_UNLIKELY(sg_io->loglevel_above(MSG_INFO))) \
176 sg_io->message(MSG_INFO,__PRETTY_FUNCTION__, __FILE__, __LINE__, __VA_ARGS__); \
179 #define SG_SWARNING(...) { sg_io->message(MSG_WARN,__PRETTY_FUNCTION__, __FILE__, __LINE__, __VA_ARGS__); }
180 #define SG_SERROR(...) { sg_io->message(MSG_ERROR,__PRETTY_FUNCTION__, __FILE__, __LINE__, __VA_ARGS__); }
181 #define SG_SPRINT(...) { sg_io->message(MSG_MESSAGEONLY,__PRETTY_FUNCTION__, __FILE__, __LINE__, __VA_ARGS__); }
184 #define SG_SPROGRESS(...) { \
185 if (SG_UNLIKELY(sg_io->get_show_progress())) \
186 sg_io->progress(__VA_ARGS__); \
189 #define SG_SABS_PROGRESS(...) { \
190 if (SG_UNLIKELY(sg_io->get_show_progress())) \
191 sg_io->absolute_progress(__VA_ARGS__); \
194 #define SG_SDONE() { \
195 if (SG_UNLIKELY(sg_io->get_show_progress())) \
199 #define SG_SNOTIMPLEMENTED { sg_io->not_implemented(__PRETTY_FUNCTION__, __FILE__, __LINE__); }
200 #define SG_SDEPRECATED { sg_io->deprecated(__PRETTY_FUNCTION__, __FILE__, __LINE__); }
202 #define ASSERT(x) { \
203 if (SG_UNLIKELY(!(x))) \
204 SG_SERROR("assertion %s failed in %s file %s line %d\n",#x, __PRETTY_FUNCTION__, __FILE__, __LINE__) \
207 #define REQUIRE(x, ...) { \
208 if (SG_UNLIKELY(!(x))) \
209 SG_SERROR(__VA_ARGS__) \
213 #ifdef __clang_analyzer__
214 void _clang_fail(
void) __attribute__((analyzer_noreturn));
217 #undef SG_SERROR(...)
218 #define SG_ERROR(...) _clang_fail();
219 #define SG_SERROR(...) _clang_fail();
314 int32_t line,
const char *fmt, ... )
const;
327 const char* prefix=
"PROGRESS:\t");
341 const char* prefix=
"PROGRESS:\t");
350 inline void not_implemented(
const char*
function,
const char* file, int32_t line)
const
356 inline void deprecated(
const char*
function,
const char* file, int32_t line)
const
359 "This function is deprecated and will be removed soon.\n");
void set_loglevel(EMessageType level)
static char * skip_spaces(char *str)
FILE * get_target() const
int32_t ref_count() const
static uint32_t ss_length(substring s)
void buffered_message(EMessageType prio, const char *fmt,...) const
void set_target(FILE *target)
bool loglevel_above(EMessageType type) const
static char * skip_blanks(char *str)
static int filter(CONST_DIRENT_T *d)
struct Substring, specified by start position and end position.
void disable_syntax_highlighting()
static char file_buffer[FBUFSIZE]
file name buffer
void message(EMessageType prio, const char *function, const char *file, int32_t line, const char *fmt,...) const
void enable_syntax_highlighting()
static char * c_string_of_substring(substring s)
float64_t last_progress_time
static float32_t float_of_substring(substring s)
void set_target_to_stdout()
static uint32_t ulong_of_substring(substring s)
static const char * message_strings[NUM_LOG_LEVELS]
static void print_substring(substring s)
EMessageType get_loglevel() const
void not_implemented(const char *function, const char *file, int32_t line) const
float64_t progress_start_time
static int32_t int_of_substring(substring s)
bool get_show_progress() const
EMessageLocation location_info
static void set_dirname(const char *dirname)
const char * get_msg_intro(EMessageType prio) const
static char directory_name[FBUFSIZE]
directory name buffer
void progress(float64_t current_val, float64_t min_val=0.0, float64_t max_val=1.0, int32_t decimals=1, const char *prefix="PROGRESS:\t")
void absolute_progress(float64_t current_val, float64_t val, float64_t min_val=0.0, float64_t max_val=1.0, int32_t decimals=1, const char *prefix="PROGRESS:\t")
static char * concat_filename(const char *filename)
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()
static float64_t double_of_substring(substring s)
static const EMessageType levels[NUM_LOG_LEVELS]
bool get_syntax_highlight() const
static const char * message_strings_highlighted[NUM_LOG_LEVELS]
EMessageLocation get_location_info() const