Permalink
Cannot retrieve contributors at this time
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?
dynarrc/dynarrc/common.h
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
94 lines (70 sloc)
2.17 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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) | |
// types | |
#define real_t float | |
// helper macros | |
// e.g.: structVar.member or structPtr->member | |
#define MEMBER(structVar, memberop, member) TOKEN_PASTE(TOKEN_PASTE(structVar, memberop), member) | |
// swap two integers, or pointers, without using temporary storage | |
__inline void int_swap(unsigned int *var1, unsigned int *var2) { | |
(*var1) = (*var1) ^ (*var2); | |
(*var2) = (*var1) ^ (*var2); | |
(*var1) = (*var1) ^ (*var2); | |
} | |
#ifndef TYPED_NAME | |
// prefix the name with the type | |
#define TYPED_NAME(type, name ) TOKEN_PASTE(type, name) | |
#endif | |
// inlining | |
#if defined(_MSC_VER) | |
// inlining | |
#define INLINE _inline /* use _inline (VC++ specific) */ | |
// #define INLINE __forceinline /* use __forceinline (VC++ specific) */ | |
//#elif __GNUC__ && !__GNUC_STDC_INLINE__ | |
//#define INLINE inline | |
#else | |
#define INLINE inline /* use standard inline */ | |
#endif | |
#endif // __dynarr_common_h__ |