#ifndef MINBASE_MACROS_H
#define MINBASE_MACROS_H
#pragma once
#ifndef MINBASE_IDENTIFY_H
#error Must include minbase_identify.h
#endif
#ifndef MINBASE_DECLS_H
#error Must include minbase_decls.h
#endif
#define UID_PREFIX generated_id_
#define UID_CAT1(a,c) a ## c
#define UID_CAT2(a,c) UID_CAT1(a,c)
#define EXPAND_CONCAT(a,c) UID_CAT1(a,c)
#define UNIQUE_ID UID_CAT2(UID_PREFIX,__COUNTER__)
#if (_MSC_VER > 1500 || __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5) || defined(__clang__) )
#define PLAT_COMPILE_TIME_ASSERT( pred ) static_assert( pred, "Compile time assert constraint is not true: " #pred )
#else
#define PLAT_COMPILE_TIME_ASSERT( pred ) typedef int UNIQUE_ID[ (pred) ? 1 : -1]
#endif
#if !defined( COMPILE_TIME_ASSERT )
#define COMPILE_TIME_ASSERT( pred ) PLAT_COMPILE_TIME_ASSERT( pred )
#endif
#if !defined( ASSERT_INVARIANT )
#define ASSERT_INVARIANT( pred ) PLAT_COMPILE_TIME_ASSERT( pred )
#endif
#if defined(_WIN32)
#define PLAT_DLL_EXT "dll"
#elif IsLinux()
#define PLAT_DLL_EXT "so"
#elif IsOSX()
#define PLAT_DLL_EXT "dylib"
#endif
#if defined(_WIN32)
#define PLAT_PATH_SLASH "\\"
#elif IsPosix()
#define PLAT_PATH_SLASH "/"
#else
#error "?"
#endif
#if defined( _PS3 )
#include <sysutil/sysutil_gamecontent.h>
#define PATH_MAX CELL_GAME_PATH_MAX
#endif
#if (!defined(_WIN32) || defined(WINDED)) && IsPosix()
#define MAX_PATH PATH_MAX
#define _MAX_PATH PATH_MAX
#endif
#ifdef _WIN32
#ifndef MAX_PATH
#define MAX_PATH 260
#endif
#define MAX_UNICODE_PATH 32767
#else
#define MAX_UNICODE_PATH MAX_PATH
#endif
#define MAX_UNICODE_PATH_IN_UTF8 (MAX_UNICODE_PATH * 4)
#define VALVE_RAND_MAX 0x7fff
#if !defined(DBL_EPSILON) && !defined(_WIN32)
#define DBL_EPSILON 2.2204460492503131e-16
#endif
#define ALIGN_VALUE_FLOOR( val, alignment ) ( ( val ) & ~( ( alignment ) - 1 ) )
#define ALIGN_VALUE( val, alignment ) ALIGN_VALUE_FLOOR( ( val ) + ( ( alignment ) - 1 ), alignment )
#ifdef _WIN64
#define DebuggerBreak() do { __debugbreak(); } while(0)
#elif defined( COMPILER_GCC )
#if defined( _PS3 )
#if defined( _CERT )
#define DebuggerBreak() ((void)0)
#else
#define DebuggerBreak() do { __asm volatile ("tw 31,1,1"); } while(0)
#endif
#elif defined(__i386__) || defined(__x86_64__)
#define DebuggerBreak() do { __asm__ __volatile__ ( "int $3" ); } while(0)
#else
#define DebuggerBreak() do { } while(0)
#endif
#elif defined(_WIN32)
#define DebuggerBreak() do { __asm { int 3 }; } while(0)
#elif defined( COMPILER_SNC ) && defined( COMPILER_PS3 )
static volatile bool sPS3_SuppressAssertsInThisFile = false;
#define DebuggerBreak() if (!sPS3_SuppressAssertsInThisFile) __builtin_snpause();
#else
#define DebuggerBreak() do { __asm__ __volatile__ ( "int $3" ); } while(0)
#endif
#if defined(_WIN64)
extern "C"
{
unsigned __int64 __rdtsc();
}
#pragma intrinsic(__rdtsc)
#define PLAT_CPU_TIME() __rdtsc()
#elif defined(COMPILER_GCC) && ( defined(__i386__) || defined(__x86_64__) )
inline __attribute__ ((always_inline)) unsigned long long PLAT_CPU_TIME()
{
#ifdef PLATFORM_64BITS
unsigned long long Low, High;
__asm__ __volatile__ ( "rdtsc" : "=a" (Low), "=d" (High) );
return (High << 32) | Low;
#else
unsigned long long Val;
__asm__ __volatile__ ( "rdtsc" : "=A" (Val) );
return Val;
#endif
}
#elif defined(_WIN32)
FORCEINLINE unsigned __int64 PLAT_CPU_TIME()
{
__asm rdtsc
}
#elif IsPosix()
#include <sys/time.h>
FORCEINLINE unsigned long long PLAT_CPU_TIME()
{
struct timeval tv;
struct timezone tz;
gettimeofday(&tv, &tz);
return ((unsigned long long)tv.tv_sec)*1000000 + (unsigned long long)tv.tv_usec;
}
#endif
#define GET_OUTER( OuterType, OuterMember ) \
( ( OuterType * ) ( (uint8 *)this - offsetof( OuterType, OuterMember ) ) )
#define DISALLOW_COPY_CONSTRUCTORS(TypeName) \
TypeName(const TypeName&); \
void operator=(const TypeName&);
#ifdef ARRAYSIZE
#undef ARRAYSIZE
#define ARRAYSIZE Dont_Use_ARRAYSIZE_Use_V_ARRAYSIZE
#endif
#define RTL_NUMBER_OF_V1(A) (sizeof(A)/sizeof((A)[0]))
#if defined(__cplusplus) && \
!defined(MIDL_PASS) && \
!defined(RC_INVOKED) && \
!defined(SORTPP_PASS)
#if _MSC_FULL_VER >= 13009466 || defined(__clang__) || __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
#ifdef __GNUC__
#include <stddef.h>
#endif
extern "C++" template <typename T, size_t N>
char (*RtlpNumberOf( UNALIGNED T (&)[N] ))[N];
#ifndef RTL_NUMBER_OF_V2
#ifdef _PREFAST_
#define RTL_NUMBER_OF_V2(A) (sizeof(*RtlpNumberOf(A))+0)
#else
#define RTL_NUMBER_OF_V2(A) (sizeof(*RtlpNumberOf(A)))
#endif
#endif
#elif IsLinux()
template <typename T, unsigned int N>
int DetectIfIsPointer( T (&)[N] );
template <typename T>
char DetectIfIsPointer( T* );
short DetectIfIsPointer( const void* );
template<bool>
struct ErrorIfIsPointerNotArrayGivenToARRAYSIZE
{
enum { Value = 0 };
};
template<>
struct ErrorIfIsPointerNotArrayGivenToARRAYSIZE<false>
{
};
#define RTL_NUMBER_OF_V2(A) \
( ErrorIfIsPointerNotArrayGivenToARRAYSIZE< \
sizeof( DetectIfIsPointer( ( A ) ) ) == sizeof( int ) || \
( sizeof( DetectIfIsPointer( ( A ) ) ) == sizeof( short ) && \
( sizeof( A ) == 0 || sizeof( A ) >= sizeof( *A ) ) ) >::Value + \
RTL_NUMBER_OF_V1(A) )
#endif #endif
#ifndef RTL_NUMBER_OF_V2
#define RTL_NUMBER_OF_V2(A) RTL_NUMBER_OF_V1(A)
#endif
#define V_ARRAYSIZE(A) RTL_NUMBER_OF_V2(A)
#define _ARRAYSIZE(A) RTL_NUMBER_OF_V1(A)
#ifndef NOTE_UNUSED
#define NOTE_UNUSED(arg) ((void)arg)
#endif
#if !defined( UNREFERENCED_PARAMETER ) && !defined( _WIN32 )
#define UNREFERENCED_PARAMETER(parm) NOTE_UNUSED(parm)
#endif
#ifndef REFERENCE
#define REFERENCE(arg) NOTE_UNUSED(arg)
#endif
#define COMPILETIME_MIN( a, b ) ( ( ( a ) < ( b ) ) ? ( a ) : ( b ) )
#define COMPILETIME_MAX( a, b ) ( ( ( a ) > ( b ) ) ? ( a ) : ( b ) )
#endif