📄 xptypes.h
字号:
#ifndef _XP_TYPES_H___
#define _XP_TYPES_H___
#define XP_BYTES_PER_BYTE 1L
#define XP_BYTES_PER_SHORT 2L
#define XP_BYTES_PER_INT 4L
#define XP_BYTES_PER_INT64 8L
#define XP_BYTES_PER_LONG 4L
#define XP_BYTES_PER_FLOAT 4L
#define XP_BYTES_PER_DOUBLE 8L
#define XP_BYTES_PER_WORD 4L
#define XP_BYTES_PER_DWORD 8L
/***********************************************************************
** MACROS: XP_BEGIN_EXTERN_C
** XP_END_EXTERN_C
** DESCRIPTION:
** Macro shorthands for conditional C++ extern block delimiters.
***********************************************************************/
#ifdef __cplusplus
#define XP_BEGIN_EXTERN_C extern "C" {
#define XP_END_EXTERN_C }
#else
#define XP_BEGIN_EXTERN_C
#define XP_END_EXTERN_C
#endif
XP_BEGIN_EXTERN_C
/************************************************************************
** TYPES: XPUint8
** XPInt8
** DESCRIPTION:
** The int8 types are known to be 8 bits each. There is no type that
** is equivalent to a plain "char".
************************************************************************/
#if XP_BYTES_PER_BYTE == 1
typedef unsigned char XPUint8;
/*
** Some cfront-based C++ compilers do not like 'signed char' and
** issue the warning message:
** warning: "signed" not implemented (ignored)
** For these compilers, we have to define XPInt8 as plain 'char'.
** Make sure that plain 'char' is indeed signed under these compilers.
*/
#if (defined(HPUX) && defined(__cplusplus) \
&& !defined(__GNUC__) && __cplusplus < 199707L) \
|| (defined(SCO) && defined(__cplusplus) \
&& !defined(__GNUC__) && __cplusplus == 1L)
typedef char XPInt8;
#else
typedef signed char XPInt8;
#endif
#else
#error No suitable type for XPInt8/XPUint8
#endif
/************************************************************************
** TYPES: XPUint16
** XPInt16
** DESCRIPTION:
** The int16 types are known to be 16 bits each.
************************************************************************/
#if XP_BYTES_PER_SHORT == 2
typedef unsigned short XPUint16;
typedef short XPInt16;
#else
#error No suitable type for XPInt16/XPUint16
#endif
/************************************************************************
** TYPES: XPUint32
** XPInt32
** DESCRIPTION:
** The int32 types are known to be 32 bits each.
************************************************************************/
#if XP_BYTES_PER_INT == 4
typedef unsigned int XPUint32;
typedef int XPInt32;
#define XP_INT32(x) x
#define XP_UINT32(x) x ## U
#elif XP_BYTES_PER_LONG == 4
typedef unsigned long XPUint32;
typedef long XPInt32;
#define XP_INT32(x) x ## L
#define XP_UINT32(x) x ## UL
#else
#error No suitable type for XPInt32/XPUint32
#endif
/************************************************************************
** TYPES: XPUint64
** XPInt64
** DESCRIPTION:
** The int64 types are known to be 64 bits each. Care must be used when
** declaring variables of type XPUint64 or XPInt64. Different hardware
** architectures and even different compilers have varying support for
** 64 bit values. The only guaranteed portability requires the use of
** the LL_ macros (see prlong.h).
************************************************************************/
#ifdef HAVE_LONG_LONG
#if XP_BYTES_PER_LONG == 8
typedef long XPInt64;
typedef unsigned long XPUint64;
#elif defined(WIN16)
typedef __int64 XPInt64;
typedef unsigned __int64 XPUint64;
#elif defined(WIN32)
typedef __int64 XPInt64;
typedef unsigned __int64 XPUint64;
#else
typedef long long XPInt64;
typedef unsigned long long XPUint64;
#endif /* XP_BYTES_PER_LONG == 8 */
#else /* !HAVE_LONG_LONG */
typedef struct {
#ifdef IS_LITTLE_ENDIAN
XPUint32 lo, hi;
#else
XPUint32 hi, lo;
#endif
} XPInt64;
typedef XPInt64 XPUint64;
#endif /* !HAVE_LONG_LONG */
/************************************************************************
** TYPES: XPUintn
** XPIntn
** DESCRIPTION:
** The XPIntn types are most appropriate for automatic variables. They are
** guaranteed to be at least 16 bits, though various architectures may
** define them to be wider (e.g., 32 or even 64 bits). These types are
** never valid for fields of a structure.
************************************************************************/
#if XP_BYTES_PER_INT >= 2
typedef int XPIntn;
typedef unsigned int XPUintn;
#else
#error 'sizeof(int)' not sufficient for platform use
#endif
/************************************************************************
** TYPES: XPFloat64
** DESCRIPTION:
** floating point type is always 64 bits.
************************************************************************/
typedef double XPFloat64;
/************************************************************************
** TYPES: XPBool
** DESCRIPTION:
** Use XPBool for variables and parameter types. Use XP_FALSE and XP_TRUE
** for clarity of target type in assignments and actual arguments. Use
** 'if (bool)', 'while (!bool)', '(bool) ? x : y' etc., to test booleans
** juast as you would C int-valued conditions.
************************************************************************/
typedef XPIntn XPBool;
#define XP_TRUE (XPIntn)1
#define XP_FALSE (XPIntn)0
XP_END_EXTERN_C
/**
* A "unique identifier". This is modeled after OSF DCE UUIDs.
*/
struct XPID
{
XPUint32 m0;
XPUint16 m1;
XPUint16 m2;
XPUint8 m3[8];
};
typedef XPID XPIID;
typedef XPID XPCID;
typedef XPID XPSID;
#define XPSIDREF const XPSID&
#define XPREFIID const XPIID&
#define XPSTDMETHODCALLTYPE __stdcall
#define XPRESULT XPUint32
#define XP_IMPL_IID(_IID) static const XPIID& IID() { static XPIID iid = _IID; return iid; }
XPBool XPIsEqualGUID(XPREFIID rguid1, XPREFIID rguid2)
{
return (
((XPUint32 *) &rguid1)[0] == ((XPUint32 *) &rguid2)[0] &&
((XPUint32 *) &rguid1)[1] == ((XPUint32 *) &rguid2)[1] &&
((XPUint32 *) &rguid1)[2] == ((XPUint32 *) &rguid2)[2] &&
((XPUint32 *) &rguid1)[3] == ((XPUint32 *) &rguid2)[3]);
}
__inline XPBool operator==(const XPIID& guidOne, const XPIID& guidOther)
{
return XPIsEqualGUID(guidOne,guidOther);
}
__inline XPBool operator!=(const XPIID& guidOne, const XPIID& guidOther)
{
return !(guidOne == guidOther);
}
#endif /* _XP_TYPES_H___ */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -