Debian Codegraph @

mednafen/include/blargg_source.h

raw symbols SCIP
1 // Included at the beginning of library source files, after all other #include lines
2 #ifndef BLARGG_SOURCE_H
3 #define BLARGG_SOURCE_H
4
5 // If debugging is enabled, abort program if expr is false. Meant for checking
6 // internal state and consistency. A failed assertion indicates a bug in the module.
7 // void assert( bool expr );
8 #include <assert.h>
9
10 // If debugging is enabled and expr is false, abort program. Meant for checking
11 // caller-supplied parameters and operations that are outside the control of the
12 // module. A failed requirement indicates a bug outside the module.
13 // void require( bool expr );
14 #undef require
15 #define require( expr ) assert( expr )
16
17 // Like printf() except output goes to debug log file. Might be defined to do
18 // nothing (not even evaluate its arguments).
19 // void dprintf( const char* format, ... );
20 inline void blargg_dprintf_( const char*, ... ) { }
21 #undef dprintf
22 #define dprintf (1) ? (void) 0 : blargg_dprintf_
23
24 // If enabled, evaluate expr and if false, make debug log entry with source file
25 // and line. Meant for finding situations that should be examined further, but that
26 // don't indicate a problem. In all cases, execution continues normally.
27 #undef check
28 #define check( expr ) ((void) 0)
29
30 // If expr yields error string, return it from current function, otherwise continue.
31 #undef RETURN_ERR
32 #define RETURN_ERR( expr ) do { \
33 blargg_err_t blargg_return_err_ = (expr); \
34 if ( blargg_return_err_ ) return blargg_return_err_; \
35 } while ( 0 )
36
37 // If ptr is 0, return out of memory error string.
38 #undef CHECK_ALLOC
39 #define CHECK_ALLOC( ptr ) do { if ( (ptr) == 0 ) return "Out of memory"; } while ( 0 )
40
41 // Avoid any macros which evaluate their arguments multiple times
42 #undef min
43 #undef max
44
45 // using const references generates crappy code, and I am currenly only using these
46 // for built-in types, so they take arguments by value
47
48 template<class T>
49 inline T min( T x, T y )
50 {
51 if ( x < y )
52 return x;
53 return y;
54 }
55
56 template<class T>
57 inline T max( T x, T y )
58 {
59 if ( x < y )
60 return y;
61 return x;
62 }
63
64 // TODO: good idea? bad idea?
65 #undef byte
66 #define byte byte_
67 typedef unsigned char byte;
68
69 // deprecated
70 #define BLARGG_CHECK_ALLOC CHECK_ALLOC
71 #define BLARGG_RETURN_ERR RETURN_ERR
72
73 // BLARGG_SOURCE_BEGIN: If defined, #included, allowing redefition of dprintf and check
74 #ifdef BLARGG_SOURCE_BEGIN
75 #include BLARGG_SOURCE_BEGIN
76 #endif
77
78 #endif