#ifndef _H_DEBUGGING
#define _H_DEBUGGING
#include <Security/utilities.h>
#include <cstdarg>
#ifdef _CPP_DEBUGGING
#pragma export on
#endif
namespace Security {
namespace Debug {
#if !defined(NDEBUG)
void debug(const char *scope, const char *format, ...) __attribute__((format(printf,2,3)));
void vdebug(const char *scope, const char *format, va_list args);
bool debugging(const char *scope);
bool dumping(const char *scope);
void dump(const char *format, ...) __attribute((format(printf,1,2)));
void dumpData(const void *data, size_t length);
void dumpData(const char *title, const void *data, size_t length);
template <class Data> inline void dumpData(const Data &obj)
{ dumpData(obj.data(), obj.length()); }
template <class Data> inline void dumpData(const char *title, const Data &obj)
{ dumpData(title, obj.data(), obj.length()); }
#if defined(DEBUGDUMP)
# define IFDUMP(code) code
# define IFDUMPING(scope,code) if (Debug::dumping(scope)) code; else
#else
# define IFDUMP(code)
# define IFDUMPING(scope,code)
#endif
class Scope {
public:
Scope(const char *string) { mScope = string; }
void operator () (const char *format, ...);
private:
const char *mScope;
};
#else // NDEBUG
inline void debug(const char *, const char *, ...) { }
inline void vdebug(const char *, const char *, va_list) { }
inline bool debugging(const char *) { return false; }
class Scope {
public:
Scope(const char *) { }
void operator () (const char *, ...) { }
};
inline bool dumping(const char *) { return false; }
inline void dump(const char *, ...) { }
inline void dumpData(const void *, size_t) { }
void dumpData(const char *, const void *, size_t);
template <class Data> inline void dumpData(const Data &) { }
template <class Data> inline void dumpData(const char *, const Data &) { }
#if defined(DEBUGDUMP)
# undef DEBUGDUMP
#endif
# define IFDUMP(code)
# define IFDUMPING(scope,code)
#endif // NDEBUG
}
}
using Security::Debug::debug;
#ifdef _CPP_DEBUGGING
#pragma export off
#endif
#endif //_H_DEBUGGING