-Added Debug class

This commit is contained in:
Harry van Haaren 2013-09-11 14:19:38 +01:00
parent 1685bafdb2
commit 27532b3fa4
4 changed files with 73 additions and 0 deletions

View file

@ -2,6 +2,9 @@
#ifndef LUPPP_CONFIG_H
#define LUPPP_CONFIG_H
/// PROGAM WIDE DEFINES
#define NAME "Luppp"
/// TEST OPTIONS
#define BUILD_TESTS 1
@ -23,6 +26,10 @@
#define DEBUG_STATE 1
/// COMPILE OPTIONS
#define DEBUG_KILL_ON_ERR 1
/// General Options
#define NTRACKS 8
#define NSCENES 10
@ -30,5 +37,9 @@
// nsamples remaining during recording before Looper requests larger buffer
#define LOOPER_SAMPLES_BEFORE_REQUEST 44100
/// include debug.hxx for printing convienience
#include "debug.hxx"
#endif // LUPPP_CONFIG_H

35
src/debug.cxx Normal file
View file

@ -0,0 +1,35 @@
#include "debug.hxx"
#include "config.hxx"
#include <cassert>
void luppp_debug( int warnLevel, const char* name, const char* file, const char* func, int line,
const char* format, ... )
{
if ( warnLevel == DEBUG_LEVEL_KILL )
{
printf( "[\033[1;31m%s\033[0m] %s : %s : %i ", NAME, file, func, line );
#ifdef DEBUG_KILL_ON_ERR
assert(false);
#endif
}
else if ( warnLevel == DEBUG_LEVEL_WARN )
{
printf( "[\033[1;33m%s\033[0m] %s : %s : %i ", NAME, file, func, line );
}
else // NOTE
{
printf( "[\033[1;32m%s\033[0m] %s : %s : %i ", NAME, file, func, line );
}
if ( format )
{
va_list args;
va_start( args, format );
printf( format, args );
va_end( args );
}
printf( "\033[0m\n" );
}

22
src/debug.hxx Normal file
View file

@ -0,0 +1,22 @@
#ifndef LUPPP_DEBUG_HXX
#define LUPPP_DEBUG_HXX
#include <stdio.h>
#include <stdarg.h>
enum DEBUG_LEVEL {
DEBUG_LEVEL_NOTE = 0,
DEBUG_LEVEL_WARN,
DEBUG_LEVEL_KILL
};
void luppp_debug( int warnLevel, const char* name, const char* file, const char* func, int line,
const char* format = 0, ... );
#define LUPPP_NOTE( format, args... ) luppp_debug( DEBUG_LEVEL_NOTE, NAME, __FILE__, __FUNCTION__, __LINE__, format, ## args )
#define LUPPP_WARN( format, args... ) luppp_debug( DEBUG_LEVEL_WARN, NAME, __FILE__, __FUNCTION__, __LINE__, format, ## args )
#define LUPPP_KILL( format, args... ) luppp_debug( DEBUG_LEVEL_KILL, NAME, __FILE__, __FUNCTION__, __LINE__, format, ## args )
#endif

View file

@ -23,6 +23,11 @@ const char* GridLogic::StateString[8] = {
GridLogic::GridLogic()
{
LUPPP_NOTE( "%s", "GridLogic() note" );
LUPPP_WARN( "%s", "GridLogic() warn" );
LUPPP_KILL( "%s", "GridLogic() kill" );
//luppp_debug( "GridLogic", __FILE__, __LINE__ );
//luppp_debug( "GridLogic", __FILE__, __LINE__, "%s", "Starting up..." );
sceneLaunch = 0;
}