aboutsummaryrefslogtreecommitdiff
path: root/src/3rdParty/efsw/Debug.cpp
blob: 18cfd315bdc2be7afdd2702957bf899c51d86d1c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include <efsw/Debug.hpp>
#include <iostream>

#ifdef EFSW_COMPILER_MSVC
#define WIN32_LEAN_AND_MEAN
#include <crtdbg.h>
#include <windows.h>
#endif

#include <cassert>
#include <cstdarg>
#include <cstdio>

namespace efsw {

#ifdef DEBUG

void efREPORT_ASSERT( const char* File, int Line, const char* Exp ) {
#ifdef EFSW_COMPILER_MSVC
	_CrtDbgReport( _CRT_ASSERT, File, Line, "", Exp );

	DebugBreak();
#else
	std::cout << "ASSERT: " << Exp << " file: " << File << " line: " << Line << std::endl;

#if defined( EFSW_COMPILER_GCC ) && defined( EFSW_32BIT ) && !defined( EFSW_ARM )
	asm( "int3" );
#else
	assert( false );
#endif
#endif
}

void efPRINT( const char* format, ... ) {
	char buf[2048];
	va_list args;

	va_start( args, format );

#ifdef EFSW_COMPILER_MSVC
	_vsnprintf_s( buf, sizeof( buf ), sizeof( buf ) / sizeof( buf[0] ), format, args );
#else
	vsnprintf( buf, sizeof( buf ) / sizeof( buf[0] ), format, args );
#endif

	va_end( args );

#ifdef EFSW_COMPILER_MSVC
	OutputDebugStringA( buf );
#else
	std::cout << buf;
#endif
}

void efPRINTC( unsigned int cond, const char* format, ... ) {
	if ( 0 == cond )
		return;

	char buf[2048];
	va_list args;

	va_start( args, format );

#ifdef EFSW_COMPILER_MSVC
	_vsnprintf_s( buf, efARRAY_SIZE( buf ), efARRAY_SIZE( buf ), format, args );
#else
	vsnprintf( buf, sizeof( buf ) / sizeof( buf[0] ), format, args );
#endif

	va_end( args );

#ifdef EFSW_COMPILER_MSVC
	OutputDebugStringA( buf );
#else
	std::cout << buf;
#endif
}

#endif

} // namespace efsw