All pastes #393371 Raw Edit

kx_dbg

public text v1 · immutable
·published 2007-03-13 14:39 UTC
rendered paste body
#ifndef KX_DEBUG_FUNC_IMPLEMENTATION
#define KX_DEBUG_FUNC_IMPLEMENTATION

#include <stdarg.h>
#include <stdio.h>

template<int count>
struct SVaPassNext{
	SVaPassNext<count-1> big;
	DWORD dw;
};

template<> 
struct SVaPassNext<0>
{

};
//SVaPassNext - is generator of structure of any size at compile time.

class CVaPassNext{
public:
	SVaPassNext<50> svapassnext;
	CVaPassNext(va_list & args){
		try{//to avoid access violation
			memcpy(&svapassnext, args, sizeof(svapassnext));
		} catch (...) {}
	}
};
#define va_pass(valist) CVaPassNext(valist).svapassnext

inline void kx_dbg(int type, const char* szFormat, ...) {
	static char* prefix = "^4KORCZIS_DEBUG^1";
	static char printed[1024];
	static char message[1152];
	static va_list args;
	
	sprintf(printed,"^4KX^1");

	va_start(args, szFormat);
	sprintf(printed,szFormat, va_pass(args));
	va_end(args);
	sprintf(message,"%s %s", prefix, printed);

	switch(type)
	{
	default:
	case 0:
		TRACE_I(message);
		break;
	case 1:
		TRACE_W(message);
		break;
	case 2:
		TRACE_E(message);
		break;
	}
}


#endif // KX_DEBUG_FUNC_IMPLEMENTATION

pouziti:
//========================================================================================================================
#include <varargs.h>
#ifdef KORCZIS_DEBUG
	#include "kx_debug_funct_implementation.h"
#else
	inline void kx_dbg(int type, const char* szFormat , ...) {}
#endif
//========================================================================================================================

int main(int argc, char** argv)
{
	kx_dbg(0,"main(%d, %p)",argc,argv);
}