Skip to content
Permalink
2f30e5650e
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
66 lines (51 sloc) 1.49 KB
#ifndef __dynarr_common_h__
#define __dynarr_common_h__
// mark different regions of the code
#define _REGION_ 1
/* for token-pasting and string concatenation */
#define MACRO_EVAL2(x) (x)
#define MACRO_EVAL(x) MACRO_EVAL2(x)
#define _TOKEN_PASTE(x,y) x ## y
#define TOKEN_PASTE(x,y) _TOKEN_PASTE(x,y)
#define TO_STRING(x) TO_STRING2(x)
#define TO_STRING2(x) #x
// memory leak detection
#define DETECT_MEM_LEAK 1
// http://msdn.microsoft.com/en-us/library/e5ewb1h3(v=vs.90).aspx
#if DETECT_MEM_LEAK
#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
#define MEM_LEAK_CATCH() \
(_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF ))
#define MEM_LEAK_SHOW() _CrtDumpMemoryLeaks()
#else // DETECT_MEM_LEAK
#define MEM_LEAK_CATCH()
#define MEM_LEAK_SHOW()
#endif // DETECT_MEM_LEAK
/* Simple macros*/
// success and failure
#define SUCCESS 0
#define FAILURE -1
// off and on
#define OFF 0
#define ON 1
// param purpose specifier
#define PARAM_OUT
#define PARAM_IN
// free mem and set NULL
#define FREE_SAFE(x) \
( (x) ? ( free( (x) ) , (x) = NULL ) : (void) 0 )
#define DELETE_SAFE(x) \
( (x) ? ( delete (x) , (x) = NULL ) : (void) 0 )
#define DELETE_SAFE_ARR(x) \
( (x) ? ( delete[] (x) , (x) = NULL ) : (void) 0 )
// size of array
#define SIZE_ARR(a) ( ((a)!=NULL) ? sizeof(a) / sizeof((a)[0]) : 0)
// max nodes
#define MAXSEG MaxSeg
#define LOG_MAXSEG LogMaxSeg
#define MAXSEG_REMAINDER_BITMASK MaxSegRemainderBitMask
// types
#define real_t float
#endif // __dynarr_common_h__