33 #if defined(DBG_ENABLED) && defined(NDEBUG)
443 : line(ln), func(fn), file(fl), src(s) {}
449 : line(0), func(0), file(0), src(0) {}
566 #if defined(__GNUC__)
567 #define DBG_FUNCTION __FUNCTION__
569 #define DBG_FUNCTION 0
572 #if !defined(DBG_SOURCE)
583 (::dbg::source_pos(__LINE__, DBG_FUNCTION, __FILE__, DBG_SOURCE))
616 void enable(
level lvl,
bool enabled);
651 void enable_all(
level lvl,
bool enabled);
703 inline std::ostream &out(
level lvl)
729 void attach_ostream(
level lvl, std::ostream &o);
757 void detach_ostream(
level lvl, std::ostream &o);
780 void detach_all_ostreams(
level lvl);
799 inline std::ostream &info_out()
801 return out(dbg::info);
810 inline std::ostream &warning_out()
812 return out(dbg::warning);
821 inline std::ostream &error_out()
823 return out(dbg::error);
832 inline std::ostream &fatal_out()
834 return out(dbg::fatal);
843 inline std::ostream &trace_out()
845 return out(dbg::tracing);
861 void set_prefix(
const char *prefix);
874 void enable_level_prefix(
bool enabled);
891 void enable_time_prefix(
bool enabled);
923 prefix() : l(none) {}
928 prefix(
level lvl) : l(lvl) {}
939 std::ostream &operator<<(std::ostream &s,
const prefix &p);
966 indent() : l(none) {}
971 indent(
level lvl) : l(lvl) {}
982 std::ostream &operator<<(std::ostream &s,
const indent &i);
1004 std::ostream &operator<<(std::ostream &s,
const source_pos &pos);
1080 void set_assertion_period(
dbgclock_t period);
1095 struct assert_info :
public source_pos
1105 assert_info(
bool a,
const char *t,
1108 : source_pos(line, func, file, spos), asserted(a), text(t) {}
1115 assert_info(
bool a,
const char *b,
const source_pos &sp)
1116 : source_pos(sp), asserted(a), text(b) {}
1123 #define DBG_STRING(a) #a
1131 #define DBG_ASSERTION(a) \
1132 ::dbg::assert_info(a, DBG_STRING(a), DBG_HERE)
1173 inline void assertion(
level lvl,
const assert_info &ai)
1175 assertion(lvl, 0, ai);
1185 inline void assertion(
dbg_source src,
const assert_info &ai)
1187 assertion(warning, src, ai);
1196 inline void assertion(
const assert_info &ai)
1198 assertion(warning, 0, ai);
1233 inline void sentinel(
level lvl,
const source_pos &here)
1235 sentinel(lvl, 0, here);
1245 inline void sentinel(
dbg_source src,
const source_pos &here)
1247 sentinel(warning, src, here);
1256 inline void sentinel(
const source_pos &here)
1258 sentinel(warning, 0, here);
1291 void unimplemented(
level lvl,
dbg_source src,
const source_pos &here);
1300 inline void unimplemented(
level lvl,
const source_pos &here)
1302 unimplemented(lvl, 0, here);
1312 inline void unimplemented(
dbg_source src,
const source_pos &here)
1314 unimplemented(warning, src, here);
1323 inline void unimplemented(
const source_pos &here)
1325 unimplemented(warning, 0, here);
1349 void check_ptr(
level lvl,
dbg_source src,
const void *p,
const source_pos &here);
1359 inline void check_ptr(
level lvl,
const void *p,
const source_pos &here)
1361 check_ptr(lvl, 0, p, here);
1372 inline void check_ptr(
dbg_source src,
const void *p,
const source_pos &here)
1374 check_ptr(warning, src, p, here);
1384 inline void check_ptr(
const void *p,
const source_pos &here)
1386 check_ptr(warning, 0, p, here);
1405 inline unsigned int array_size(T &array)
1407 return sizeof(array)/
sizeof(array[0]);
1425 int index,
int bound,
const source_pos &here);
1443 int index,
int minbound,
int maxbound,
1444 const source_pos &here)
1446 check_bounds(lvl, src, index-minbound, maxbound, here);
1469 int index, T &array,
const source_pos &here)
1471 check_bounds(lvl, src, index, array_size(array), here);
1484 void check_bounds(
level lvl,
int index, T &array,
const source_pos &here)
1486 check_bounds(lvl, 0, index, array_size(array), here);
1499 void check_bounds(
dbg_source src,
int index, T &array,
1500 const source_pos &here)
1502 check_bounds(warning, src, index, array_size(array), here);
1514 void check_bounds(
int index, T &array,
const source_pos &here)
1516 check_bounds(warning, 0, index, array_size(array), here);
1607 trace(
const source_pos &here);
1613 trace(
dbg_source src,
const source_pos &here);
1619 trace(
const trace &);
1620 trace &operator=(
const trace &);
1627 const source_pos m_pos;
1690 template <
class obj_t>
1699 typedef bool (obj_t::*fn_t)();
1707 post_mem_fun(
level lvl, obj_t *obj, fn_t fn,
const source_pos &pos)
1708 : m_lvl(lvl), m_src(0), m_obj(obj), m_fn(fn), m_pos(pos) {}
1718 obj_t *obj, fn_t fn,
const source_pos &pos)
1719 : m_lvl(lvl), m_src(src), m_obj(obj), m_fn(fn), m_pos(pos) {}
1729 post_mem_fun(obj_t *obj, fn_t fn,
const source_pos &pos)
1730 : m_lvl(dbg::warning), m_src(0),
1731 m_obj(obj), m_fn(fn), m_pos(pos) {}
1742 post_mem_fun(
dbg_source src, obj_t *obj, fn_t fn,
1743 const source_pos &pos)
1744 : m_lvl(dbg::warning), m_src(src),
1745 m_obj(obj), m_fn(fn), m_pos(pos) {}
1752 assertion(m_lvl, m_src,
1753 assert_info((m_obj->*m_fn)(),
"post condition",
1754 m_pos.line, m_pos.func, m_pos.file, m_pos.src));
1763 const source_pos m_pos;
1785 typedef bool (*fn_t)();
1792 post(
level lvl, fn_t fn,
const source_pos &pos)
1793 : m_lvl(lvl), m_src(0), m_fn(fn), m_pos(pos) {}
1802 : m_lvl(lvl), m_src(src), m_fn(fn), m_pos(pos) {}
1811 post(fn_t fn,
const source_pos &pos)
1812 : m_lvl(dbg::warning), m_src(0), m_fn(fn), m_pos(pos) {}
1822 post(
dbg_source src, fn_t fn,
const source_pos &pos)
1823 : m_lvl(dbg::warning), m_src(src), m_fn(fn), m_pos(pos) {}
1830 assertion(m_lvl, m_src,
1831 assert_info(m_fn(),
"post condition",
1832 m_pos.line, m_pos.func, m_pos.file, m_pos.src));
1840 const source_pos m_pos;
1866 template <
bool expression>
1867 class compile_assertion;
1869 class compile_assertion<true> {};
1885 #define DBG_HERE ((void*)0)
1886 #define DBG_ASSERTION(a) ((void*)0)
1902 null_stream &operator<<(
const void *) {
return *
this; }
1905 template <
class otype>
1906 null_stream &operator<<(
const otype &) {
return *
this; }
1909 template <
class otype>
1910 null_stream &operator<<(otype &) {
return *
this; }
1911 null_stream &operator<<(std::ostream& (*)(std::ostream&))
1920 inline void enable(
level,
bool) {}
1922 inline void enable_all(
level,
bool) {}
1924 inline null_stream out(
level) {
return null_stream();}
1925 inline void attach_ostream(
level, std::ostream &) {}
1927 inline void detach_ostream(
level, std::ostream &) {}
1929 inline void detach_all_ostreams(
level) {}
1931 inline null_stream info_out() {
return null_stream();}
1932 inline null_stream warning_out() {
return null_stream();}
1933 inline null_stream error_out() {
return null_stream();}
1934 inline null_stream fatal_out() {
return null_stream();}
1935 inline null_stream trace_out() {
return null_stream();}
1936 inline void set_prefix(
const char *) {}
1937 inline void enable_level_prefix(
bool) {}
1938 inline void enable_time_prefix(
bool) {}
1941 inline void set_assertion_period(
dbgclock_t) {}
1943 inline void assertion(
level,
void *) {}
1945 inline void assertion(
void *) {}
1947 inline void sentinel(
level,
void *) {}
1949 inline void sentinel(
void *) {}
1951 inline void unimplemented(
level,
void *) {}
1952 inline void unimplemented(
dbg_source,
void *) {}
1953 inline void unimplemented(
void *) {}
1955 inline void check_ptr(
level,
const void *,
void *) {}
1956 inline void check_ptr(
dbg_source,
const void *,
void *) {}
1957 inline void check_ptr(
const void *,
void *) {}
1958 inline void check_bounds(
level,
void *,
int,
int,
void *) {}
1962 inline void check_bounds(
level,
int,
void *,
void*) {}
1963 inline void check_bounds(
void *,
int,
void *,
void *) {}
1964 inline void check_bounds(
int,
void *,
void *) {}
1969 trace(
const char *fn_name) {}
1971 trace(
void *here) {}
1976 template <
class obj_t>
1980 typedef bool (obj_t::*fn_t)();
1990 typedef bool(*fn_t)();
1993 post(fn_t,
void *) {}
1998 template <
bool expression>