📄 stlsysdef.h
字号:
//========================================================================================
// Copyright (C) 2009 by Ma Zhi-Hao, Key Lab.
// The Academy of Equipment Command & Technology, PLA
// HuaiRou, Beijing, 101416, China
// File :STLsysdef.h
// Version :1.0
// Email :snake_shooter@yeah.net
// Address : 164, P.O.Box 3380, Beijing
//========================================================================================
/** \file
* This is the basic header file of shooter library where some common macros is
* and defined and the environment is set up. You should include this file in
* each source files before using any other shooter header files.
*/
#ifndef __STLSYSDEF_H__
#define __STLSYSDEF_H__
#include <cstdlib>
#include <cstdio>
#include <cstdarg>
#include <cmath>
#include <cstring>
//======== Find out the compiler type ========//
// @{
#if defined(__MINGW32__) || defined(__CYGWIN32__)
# define STL_COMPILER_GNUC
# define STL_COMPILER_VER (((__GNUC__)*100) + \
(__GNUC_MINOR__*10) + \
__GNUC_PATCHLEVEL__)
#elif defined(__BORLANDC__)
# define STL_COMPILER_BORL
# define STL_COMPILER_VER __BCPLUSPLUS__
#elif defined(_MSC_VER)
# define STL_COMPILER_MSVC
# define STL_COMPILER_VER _MSC_VER
#else
# error "Unknown compiler!"
#endif
// @}
//======== Find out the platform type ========//
// @{
#if defined(__WIN32__) || defined(_WIN32)
# define STL_PLATFORM_WIN32
#else
# define STL_PLATFORM_UNIX
#endif
// @}
//======== Find out the processor architecture =========//
// @{
#if defined(_WIN64) || defined(__x86_64__) || defined(_M_X64)
# define STL_PROCESSOR_SIZE 64
#else
# define STL_PROCESSOR_SIZE 32
#endif
// @}
//======== Check if we can use __forceinline ========//
// @{
#ifndef STL_FORCEINLINE
#ifdef OGRE_COMPILER_MSVC
# if OGRE_COMP_VER >= 1200
# define STL_FORCEINLINE __forceinline
# endif
#elif defined(__MINGW32__)
# if !defined(STL_FORCEINLINE)
# define STL_FORCEINLINE __inline
# endif
#else
# define STL_FORCEINLINE __inline
#endif
#endif
// @}
/**\def STL_ALLOC_STACK_ARRAY(type, var, size)
* Dynamic stack memory allocation.
* \param type Type of the array elements.
* \param var Name of the array to be allocated.
* \param size Number of elements to be allocated.
*/
#if defined(STL_COMPILER_GNUC)
// In GNUC we are able to declare stack vars of dynamic size directly
# define STL_ALLOC_STACK_ARRAY(type, var, size) \
type var [size]
#else
# include <malloc.h>
# define STL_ALLOC_STACK_ARRAY(type, var, size) \
type *var = (type *)alloca ((size) * sizeof (type))
#endif
/**\def STL_FUNCTION_NAME
* Macro that resolves to a compiler-specific variable or string that contains
* the name of the current function.
*/
#if defined(STL_COMPILER_GNUC)
# define STL_FUNCTION_NAME __PRETTY_FUNCTION__
#elif defined(__FUNCTION__)
# define STL_FUNCTION_NAME __FUNCTION__
#else
# define STL_FUNCTION_NAME "<?\?\?>"
#endif
#ifndef STL_ABS
# define STL_ABS(x) ((x) < 0 ? -(x) : (x))
#endif
#ifndef STL_MIN
# define STL_MIN(a,b) ((a)<(b)?(a):(b))
#endif
#ifndef STL_MAX
# define STL_MAX(a,b) ((a)>(b)?(a):(b))
#endif
/// Query the sign of the given param.
#ifndef STL_SIGN
# define STL_SIGN(x) ((x) < 0 ? -1 : ((x) > 0 ? 1 : 0))
#endif
namespace shooter{
/** \name Specific sized types
* These types should be used ONLY when you need a variable of an explicit
* number of bits. For all other cases, you should use normal char, short,
* int, long, etc., types since they are treated as "natural" types and will
* generally have better performance characteristics than the explicitly-sized
* types. Use the explicitly-sized types sparingly.
* @{ */
/// unsigned 8-bit integer (0..255)
typedef unsigned char STLuint8;
/// signed 8-bit integer (-128..127)
typedef char STLint8;
/// unsigned 16-bit integer (0..65 535)
typedef unsigned short STLuint16;
/// signed 16-bit integer (-32 768..32 767)
typedef short STLint16;
/// unsigned 32-bit integer (0..4 294 967 295)
typedef unsigned int STLuint32;
/// signed 32-bit integer (-2 147 483 648..2 147 483 647)
typedef int STLint32;
#if defined(STL_COMPILER_MSVC)
/// unsigned 64-bit integer
typedef unsigned __int64 STLuint64;
/// signed 64-bit integer
typedef __int64 STLint64;
#else
/// unsigned 64 bit integer
typedef unsigned long long STLuint64;
/// signed 64 bit integer
typedef long long STLint64;
#endif
/**
* A time value measured in milliseconds (1/1000 of a second). Ticks do not
* represent wall clock time or any other Epoch-based time. Instead, ticks are
* useful only for measuring differences between points on a timeline, or for
* specifying intervals.
*/
typedef unsigned int STLticks;
/** \name Constants
* @{ */
/// Pi
const double STLC_PI = 3.1415926535897932384626433832795;
/// Pi * 2
const double STLC_TPI = STLC_PI * 2.0;
/// Pi / 2
const double STLC_HPI = STLC_PI / 2.0;
/// Constant convert radian to degree.
const double STLC_R2D = 180.0 / STLC_PI;
/// Constant convert degree to radian.
const double STLC_D2R = STLC_PI / 180.0;
/// e
const double STLC_E = 2.7182818284590452354;
/** @} */
}
//======== MSVC specified settings ========//
// @{
#ifdef STL_COMPILER_MSVC
#pragma warning(disable:4244)
#pragma warning(disable:4250)
#pragma warning(disable:4290)
#pragma warning(disable:4312)
#pragma warning(disable:4345)
#pragma warning(disable:4355)
#pragma warning(disable:4800)
#pragma warning(disable:4996)
#if (_MSC_VER < 1300)
#pragma warning(disable:4786)
#endif
#pragma inline_depth(255)
#pragma inline_recursion(on)
#pragma auto_inline(on)
#define strcasecmp _stricmp
#define strncasecmp _strnicmp
#define snprintf _snprintf
#define vsnprintf _vsnprintf
#if (_MSC_VER < 1300)
#include <memory.h>
#define memcpy fast_mem_copy
static inline void* fast_mem_copy (void *dest, const void *src, int count)
{
__asm
{
mov eax, count
mov esi, src
mov edi, dest
xor ecx, ecx
// Check for 'short' moves
cmp eax, 16
jl do_short
// Move enough bytes to align 'dest'
sub ecx, edi
and ecx, 3
je skip
sub eax, ecx
rep movsb
skip:
mov ecx, eax
and eax, 3
shr ecx, 2
rep movsd
test eax, eax
je end
do_short:
mov ecx, eax
rep movsb
end:
}
return dest;
}
#endif
#if (_MSC_VER >= 1400)
# ifndef _CRT_SECURE_NO_DEPRECATE
# define _CRT_SECURE_NO_DEPRECATE
# endif
# ifndef _CRT_NONSTDC_NO_DEPRECATE
# define _CRT_NONSTDC_NO_DEPRECATE
# endif
# undef _SECURE_SCL
# define _SECURE_SCL 0
#endif
#endif
// @}
//======== Borland C++ specified settings ========//
// @{
#ifdef STL_COMPILER_BORL
#define strcasecmp stricmp
#define strncasecmp strnicmp
#endif
// @}
#if defined(_DEBUG) || defined(STL_DEBUG) || defined(DEBUG)
# include <cassert>
# ifndef STL_DEBUG
# define STL_DEBUG
# endif
# ifndef STL_ASSERT
# define STL_ASSERT(x) assert(x)
# endif
# ifndef STL_ASSERT_MSG
# define STL_ASSERT_MSG(msg,x) STL_ASSERT(((msg) && (x)))
# endif
#else
# undef STL_ASSERT
# define STL_ASSERT(x) void(0)
# undef STL_ASSERT_MSG
# define STL_ASSERT_MSG(msg,x) void(0)
#endif
#endif /* __STLSYSDEF_H__ */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -