#ifndef _H_DEBUGGING
#define _H_DEBUGGING
#include <Security/utilities.h>
#include <cstdarg>
#include <typeinfo>
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;
};
string makeTypeName(const type_info &info);
template <class Object>
string typeName(const Object &obj)
{
return makeTypeName(typeid(obj));
}
#else // NDEBUG
#if __GNUC__ > 2
inline void debug(const char *, const char *, ...) { }
#else
extern "C" inline void debug() { }
#endif
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; }
extern "C" inline void dump() { }
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;
#endif //_H_DEBUGGING