25 #include <sys/types.h>
70 #define NUM_LOG_LEVELS 10
74 #include <Availability.h>
76 #define __MAC_10_8 1080
78 #if __MAC_OS_X_VERSION_MIN_REQUIRED < __MAC_10_8
79 #define CONST_DIRENT_T struct dirent
81 #define CONST_DIRENT_T const struct dirent
82 #endif // Lion or earlier
84 #define CONST_DIRENT_T const struct dirent
87 #define SG_SET_LOCALE_C setlocale(LC_ALL, "C")
88 #define SG_RESET_LOCALE setlocale(LC_ALL, "")
90 #if !defined(SG_UNLIKELY)
92 #define SG_UNLIKELY(expr) __builtin_expect(expr, 0)
94 #define SG_UNLIKELY(expr) expr
99 #define __PRETTY_FUNCTION__ __FUNCTION__
104 #define SG_GCDEBUG(...) { \
105 if (SG_UNLIKELY(io->loglevel_above(MSG_GCDEBUG))) \
106 io->message(MSG_GCDEBUG, __PRETTY_FUNCTION__, __FILE__, __LINE__, __VA_ARGS__); \
109 #define SG_DEBUG(...) { \
110 if (SG_UNLIKELY(io->loglevel_above(MSG_DEBUG))) \
111 io->message(MSG_DEBUG, __PRETTY_FUNCTION__, __FILE__, __LINE__, __VA_ARGS__); \
114 #define SG_OBJ_DEBUG(o,...) { \
115 if (SG_UNLIKELY(o->io->loglevel_above(MSG_DEBUG))) \
116 o->io->message(MSG_DEBUG, __PRETTY_FUNCTION__, __FILE__, __LINE__, __VA_ARGS__); \
120 #define SG_INFO(...) { \
121 if (SG_UNLIKELY(io->loglevel_above(MSG_INFO))) \
122 io->message(MSG_INFO, __PRETTY_FUNCTION__, __FILE__, __LINE__, __VA_ARGS__); \
125 #define SG_CLASS_INFO(c, ...) { \
126 if (SG_UNLIKELY(c::io->loglevel_above(MSG_INFO))) \
127 c::io->message(MSG_INFO, __PRETTY_FUNCTION__, __FILE__, __LINE__, __VA_ARGS__); \
130 #define SG_WARNING(...) { io->message(MSG_WARN, __PRETTY_FUNCTION__, __FILE__, __LINE__, __VA_ARGS__); }
131 #define SG_ERROR(...) { io->message(MSG_ERROR, __PRETTY_FUNCTION__, __FILE__, __LINE__, __VA_ARGS__); }
132 #define SG_OBJ_ERROR(o, ...) { o->io->message(MSG_ERROR, __PRETTY_FUNCTION__, __FILE__, __LINE__, __VA_ARGS__); }
133 #define SG_CLASS_ERROR(c, ...) { c::io->message(MSG_ERROR, __PRETTY_FUNCTION__, __FILE__, __LINE__, __VA_ARGS__); }
134 #define SG_UNSTABLE(func, ...) { io->message(MSG_WARN, __PRETTY_FUNCTION__, __FILE__, __LINE__, \
135 __FILE__ ":" func ": Unstable method! Please report if it seems to " \
136 "work or not to the Shogun mailing list. Thanking you in " \
137 "anticipation. " __VA_ARGS__); }
139 #define SG_PRINT(...) { io->message(MSG_MESSAGEONLY, __PRETTY_FUNCTION__, __FILE__, __LINE__, __VA_ARGS__); }
140 #define SG_OBJ_PRINT(o, ...) { o->io->message(MSG_MESSAGEONLY, __PRETTY_FUNCTION__, __FILE__, __LINE__, __VA_ARGS__); }
141 #define SG_NOTIMPLEMENTED { io->not_implemented(__PRETTY_FUNCTION__, __FILE__, __LINE__); }
142 #define SG_DEPRECATED { io->deprecated(__PRETTY_FUNCTION__, __FILE__, __LINE__); }
144 #define SG_PROGRESS(...) { \
145 if (SG_UNLIKELY(io->get_show_progress())) \
146 io->progress(__VA_ARGS__); \
149 #define SG_OBJ_PROGRESS(o, ...) { \
150 if (SG_UNLIKELY(o->io->get_show_progress()))\
151 o->io->progress(__VA_ARGS__); \
154 #define SG_ABS_PROGRESS(...) { \
155 if (SG_UNLIKELY(io->get_show_progress())) \
156 io->absolute_progress(__VA_ARGS__); \
159 #define SG_DONE() { \
160 if (SG_UNLIKELY(io->get_show_progress())) \
165 #define SG_SGCDEBUG(...) { \
166 if (SG_UNLIKELY(sg_io->loglevel_above(MSG_GCDEBUG))) \
167 sg_io->message(MSG_GCDEBUG,__PRETTY_FUNCTION__, __FILE__, __LINE__, __VA_ARGS__);\
170 #define SG_SDEBUG(...) { \
171 if (SG_UNLIKELY(sg_io->loglevel_above(MSG_DEBUG))) \
172 sg_io->message(MSG_DEBUG,__PRETTY_FUNCTION__, __FILE__, __LINE__, __VA_ARGS__); \
175 #define SG_SINFO(...) { \
176 if (SG_UNLIKELY(sg_io->loglevel_above(MSG_INFO))) \
177 sg_io->message(MSG_INFO,__PRETTY_FUNCTION__, __FILE__, __LINE__, __VA_ARGS__); \
180 #define SG_SWARNING(...) { sg_io->message(MSG_WARN,__PRETTY_FUNCTION__, __FILE__, __LINE__, __VA_ARGS__); }
181 #define SG_SERROR(...) { sg_io->message(MSG_ERROR,__PRETTY_FUNCTION__, __FILE__, __LINE__, __VA_ARGS__); }
182 #define SG_SPRINT(...) { sg_io->message(MSG_MESSAGEONLY,__PRETTY_FUNCTION__, __FILE__, __LINE__, __VA_ARGS__); }
185 #define SG_SPROGRESS(...) { \
186 if (SG_UNLIKELY(sg_io->get_show_progress())) \
187 sg_io->progress(__VA_ARGS__); \
190 #define SG_SABS_PROGRESS(...) { \
191 if (SG_UNLIKELY(sg_io->get_show_progress())) \
192 sg_io->absolute_progress(__VA_ARGS__); \
195 #define SG_SDONE() { \
196 if (SG_UNLIKELY(sg_io->get_show_progress())) \
200 #define SG_SNOTIMPLEMENTED { sg_io->not_implemented(__PRETTY_FUNCTION__, __FILE__, __LINE__); }
201 #define SG_SDEPRECATED { sg_io->deprecated(__PRETTY_FUNCTION__, __FILE__, __LINE__); }
203 #define ASSERT(x) { \
204 if (SG_UNLIKELY(!(x))) \
205 SG_SERROR("assertion %s failed in %s file %s line %d\n",#x, __PRETTY_FUNCTION__, __FILE__, __LINE__) \
208 #define REQUIRE(x, ...) { \
209 if (SG_UNLIKELY(!(x))) \
210 SG_SERROR(__VA_ARGS__) \
214 #ifdef __clang_analyzer__
215 void _clang_fail(
void) __attribute__((analyzer_noreturn));
218 #undef SG_SERROR(...)
219 #define SG_ERROR(...) _clang_fail();
220 #define SG_SERROR(...) _clang_fail();
315 int32_t line,
const char *fmt, ... )
const;
328 const char* prefix=
"PROGRESS:\t");
342 const char* prefix=
"PROGRESS:\t");
351 inline void not_implemented(
const char*
function,
const char* file, int32_t line)
const
357 inline void deprecated(
const char*
function,
const char* file, int32_t line)
const
360 "This function is deprecated and will be removed soon.\n");