Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
102 lines (72 sloc) 2.5 KB
#pragma once
#ifdef _WIN32
//////////////// On Windows, CRT memory leak detection /////////////
#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
#ifdef _DEBUG
#ifndef DBG_NEW
#define DBG_NEW new ( _NORMAL_BLOCK , __FILE__ , __LINE__ )
#define new DBG_NEW
#endif
#endif // _DEBUG
// enable dumping memory leaks on Windows
#define DETECT_MEM_LEAKS() \
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF)
#else // Non-Windows systems
// no support for memory leak detection on Non-Windows systems
#define DETECT_MEM_LEAKS()
#endif // _WIN32
#include <cassert>
/*--------- Availability of Google C++ Test Framework ----------*/
// whether using Google C++ Test Framework
#ifndef GTEST
#define GTEST 1
#endif
// you have to include test.h when you want to test
#include "test.h"
namespace yasi{
#define CONCAT_DETAIL(x,y) x ## y
#define CONCAT(x,y) CONCAT_DETAIL(x,y)
#define MAKE_UNIQUE(x) CONCAT(x, __COUNTER__ )
#define MAKE_UNIQUE2(x,y) MAKE_UNIQUE( CONCAT(x,y) )
#define MAKE_UNIQUE3(x,y, z) MAKE_UNIQUE2( CONCAT(x,y), z )
#define FREE_SAFE(x) {if( (x) != 0 ) free(x); (x) = 0; }
#define DELETE_SAFE(x) {if( (x) != 0 ) delete (x); (x) = 0; }
#define FREE_SAFE(x) {if( (x) != 0 ) free(x); (x) = 0; }
#define DELETE_ARR_SAFE(x) {if( (x) != 0 ) delete[] (x); (x) = 0; }
#define ARR_LENGTH(x) ( sizeof( (x) )/sizeof( (x)[0] ) )
#define IS_POW_OF_TWO(x) ( ((x) >= 1) && ( ((x) & ((x)-1)) == 0) )
// override keyword in C++11
#if __STDC_VERSION__ == 201112L
#pragma message(TO_STRING(__STDC_VERSION__))
// C++11 supported
#define override override
#else
#define override
#endif // C++11 support
// informative assert
#define YASI_ASSERT_FAILED_STR "ASSERT FAILED"
#if _DEBUG
#define ASSERT(condition) { \
/* print better message */ \
if(!(condition)){ \
std::cerr << YASI_ASSERT_FAILED_STR << ": " << #condition << " @ " << __FILE__ << " (" << __LINE__ << ")" << std::endl; \
} \
/* now call actual assert macro */ \
assert(condition); \
}
#define ASSERTMSG(condition, msg) { \
/* print better message */ \
if(!(condition)){ \
std::cerr << YASI_ASSERT_FAILED_STR << ": " << #condition << " @ " << __FILE__ << " (" << __LINE__ << ")" << std::endl; \
std::cerr << "Message: " << msg; \
} \
/* now call actual assert macro */ \
assert(condition); \
}
#else // _DEBUG
#define ASSERT(condition)
#define ASSERTMSG(condition, msg)
#endif
} // namespace yasi
You can’t perform that action at this time.