📄 bele.h
字号:
BE16& operator += (unsigned v) { set_be16(d, get_be16(d) + v); return *this; } BE16& operator -= (unsigned v) { set_be16(d, get_be16(d) - v); return *this; } BE16& operator *= (unsigned v) { set_be16(d, get_be16(d) * v); return *this; } BE16& operator /= (unsigned v) { set_be16(d, get_be16(d) / v); return *this; } BE16& operator &= (unsigned v) { set_be16(d, get_be16(d) & v); return *this; } BE16& operator |= (unsigned v) { set_be16(d, get_be16(d) | v); return *this; } BE16& operator ^= (unsigned v) { set_be16(d, get_be16(d) ^ v); return *this; } BE16& operator <<= (unsigned v) { set_be16(d, get_be16(d) << v); return *this; } BE16& operator >>= (unsigned v) { set_be16(d, get_be16(d) >> v); return *this; } operator unsigned () const { return get_be16(d); }}__attribute_packed;struct BE32{ unsigned char d[4]; //inline BE32() { } //BE32(unsigned v) { set_be32(d, v); } BE32& operator = (unsigned v) { set_be32(d, v); return *this; } BE32& operator += (unsigned v) { set_be32(d, get_be32(d) + v); return *this; } BE32& operator -= (unsigned v) { set_be32(d, get_be32(d) - v); return *this; } BE32& operator *= (unsigned v) { set_be32(d, get_be32(d) * v); return *this; } BE32& operator /= (unsigned v) { set_be32(d, get_be32(d) / v); return *this; } BE32& operator &= (unsigned v) { set_be32(d, get_be32(d) & v); return *this; } BE32& operator |= (unsigned v) { set_be32(d, get_be32(d) | v); return *this; } BE32& operator ^= (unsigned v) { set_be32(d, get_be32(d) ^ v); return *this; } BE32& operator <<= (unsigned v) { set_be32(d, get_be32(d) << v); return *this; } BE32& operator >>= (unsigned v) { set_be32(d, get_be32(d) >> v); return *this; } operator unsigned () const { return get_be32(d); }}__attribute_packed;struct BE64{ unsigned char d[8]; //inline BE64() { } //BE64(acc_uint64l_t v) { set_be64(d, v); } BE64& operator = (acc_uint64l_t v) { set_be64(d, v); return *this; } BE64& operator += (acc_uint64l_t v) { set_be64(d, get_be64(d) + v); return *this; } BE64& operator -= (acc_uint64l_t v) { set_be64(d, get_be64(d) - v); return *this; } BE64& operator *= (acc_uint64l_t v) { set_be64(d, get_be64(d) * v); return *this; } BE64& operator /= (acc_uint64l_t v) { set_be64(d, get_be64(d) / v); return *this; } BE64& operator &= (acc_uint64l_t v) { set_be64(d, get_be64(d) & v); return *this; } BE64& operator |= (acc_uint64l_t v) { set_be64(d, get_be64(d) | v); return *this; } BE64& operator ^= (acc_uint64l_t v) { set_be64(d, get_be64(d) ^ v); return *this; } BE64& operator <<= (unsigned v) { set_be64(d, get_be64(d) << v); return *this; } BE64& operator >>= (unsigned v) { set_be64(d, get_be64(d) >> v); return *this; } operator acc_uint64l_t () const { return get_be64(d); }}__attribute_packed;struct LE16{ unsigned char d[2]; //inline LE16() { } //LE16(unsigned v) { set_le16(d, v); } LE16& operator = (unsigned v) { set_le16(d, v); return *this; } LE16& operator += (unsigned v) { set_le16(d, get_le16(d) + v); return *this; } LE16& operator -= (unsigned v) { set_le16(d, get_le16(d) - v); return *this; } LE16& operator *= (unsigned v) { set_le16(d, get_le16(d) * v); return *this; } LE16& operator /= (unsigned v) { set_le16(d, get_le16(d) / v); return *this; } LE16& operator &= (unsigned v) { set_le16(d, get_le16(d) & v); return *this; } LE16& operator |= (unsigned v) { set_le16(d, get_le16(d) | v); return *this; } LE16& operator ^= (unsigned v) { set_le16(d, get_le16(d) ^ v); return *this; } LE16& operator <<= (unsigned v) { set_le16(d, get_le16(d) << v); return *this; } LE16& operator >>= (unsigned v) { set_le16(d, get_le16(d) >> v); return *this; } operator unsigned () const { return get_le16(d); }}__attribute_packed;struct LE32{ unsigned char d[4]; //inline LE32() { } //LE32(unsigned v) { set_le32(d, v); } LE32& operator = (unsigned v) { set_le32(d, v); return *this; } LE32& operator += (unsigned v) { set_le32(d, get_le32(d) + v); return *this; } LE32& operator -= (unsigned v) { set_le32(d, get_le32(d) - v); return *this; } LE32& operator *= (unsigned v) { set_le32(d, get_le32(d) * v); return *this; } LE32& operator /= (unsigned v) { set_le32(d, get_le32(d) / v); return *this; } LE32& operator &= (unsigned v) { set_le32(d, get_le32(d) & v); return *this; } LE32& operator |= (unsigned v) { set_le32(d, get_le32(d) | v); return *this; } LE32& operator ^= (unsigned v) { set_le32(d, get_le32(d) ^ v); return *this; } LE32& operator <<= (unsigned v) { set_le32(d, get_le32(d) << v); return *this; } LE32& operator >>= (unsigned v) { set_le32(d, get_le32(d) >> v); return *this; } operator unsigned () const { return get_le32(d); }}__attribute_packed;struct LE64{ unsigned char d[8]; //inline LE64() { } //LE64(acc_uint64l_t v) { set_le64(d, v); } LE64& operator = (acc_uint64l_t v) { set_le64(d, v); return *this; } LE64& operator += (acc_uint64l_t v) { set_le64(d, get_le64(d) + v); return *this; } LE64& operator -= (acc_uint64l_t v) { set_le64(d, get_le64(d) - v); return *this; } LE64& operator *= (acc_uint64l_t v) { set_le64(d, get_le64(d) * v); return *this; } LE64& operator /= (acc_uint64l_t v) { set_le64(d, get_le64(d) / v); return *this; } LE64& operator &= (acc_uint64l_t v) { set_le64(d, get_le64(d) & v); return *this; } LE64& operator |= (acc_uint64l_t v) { set_le64(d, get_le64(d) | v); return *this; } LE64& operator ^= (acc_uint64l_t v) { set_le64(d, get_le64(d) ^ v); return *this; } LE64& operator <<= (unsigned v) { set_le64(d, get_le64(d) << v); return *this; } LE64& operator >>= (unsigned v) { set_le64(d, get_le64(d) >> v); return *this; } operator acc_uint64l_t () const { return get_le64(d); }}__attribute_packed;/*************************************************************************// global operators**************************************************************************/template <class T>inline T* operator + (T* ptr, const BE16& v) { return ptr + (unsigned) v; }template <class T>inline T* operator + (const BE16& v, T* ptr) { return ptr + (unsigned) v; }template <class T>inline T* operator - (T* ptr, const BE16& v) { return ptr - (unsigned) v; }template <class T>inline T* operator + (T* ptr, const BE32& v) { return ptr + (unsigned) v; }template <class T>inline T* operator + (const BE32& v, T* ptr) { return ptr + (unsigned) v; }template <class T>inline T* operator - (T* ptr, const BE32& v) { return ptr - (unsigned) v; }// these are not implemented on purpose and will cause link-time errorstemplate <class T> T* operator + (T* ptr, const BE64& v);template <class T> T* operator + (const BE64& v, T* ptr);template <class T> T* operator - (T* ptr, const BE64& v);template <class T>inline T* operator + (T* ptr, const LE16& v) { return ptr + (unsigned) v; }template <class T>inline T* operator + (const LE16& v, T* ptr) { return ptr + (unsigned) v; }template <class T>inline T* operator - (T* ptr, const LE16& v) { return ptr - (unsigned) v; }template <class T>inline T* operator + (T* ptr, const LE32& v) { return ptr + (unsigned) v; }template <class T>inline T* operator + (const LE32& v, T* ptr) { return ptr + (unsigned) v; }template <class T>inline T* operator - (T* ptr, const LE32& v) { return ptr - (unsigned) v; }// these are not implemented on purpose and will cause link-time errorstemplate <class T> T* operator + (T* ptr, const LE64& v);template <class T> T* operator + (const LE64& v, T* ptr);template <class T> T* operator - (T* ptr, const LE64& v);/*************************************************************************// global overloads**************************************************************************/#if 1 && !defined(ALIGN_DOWN)inline unsigned ALIGN_DOWN(unsigned a, const LE32& b) { return ALIGN_DOWN(a, (unsigned) b); }inline unsigned ALIGN_DOWN(const LE32& a, unsigned b) { return ALIGN_DOWN((unsigned) a, b); }inline unsigned ALIGN_UP (unsigned a, const LE32& b) { return ALIGN_UP (a, (unsigned) b); }inline unsigned ALIGN_UP (const LE32& a, unsigned b) { return ALIGN_UP ((unsigned) a, b); }#endif#if !defined(UPX_MAX)inline unsigned UPX_MAX(unsigned a, const BE16& b) { return UPX_MAX(a, (unsigned) b); }inline unsigned UPX_MAX(const BE16& a, unsigned b) { return UPX_MAX((unsigned) a, b); }inline unsigned UPX_MIN(unsigned a, const BE16& b) { return UPX_MIN(a, (unsigned) b); }inline unsigned UPX_MIN(const BE16& a, unsigned b) { return UPX_MIN((unsigned) a, b); }inline unsigned UPX_MAX(unsigned a, const BE32& b) { return UPX_MAX(a, (unsigned) b); }inline unsigned UPX_MAX(const BE32& a, unsigned b) { return UPX_MAX((unsigned) a, b); }inline unsigned UPX_MIN(unsigned a, const BE32& b) { return UPX_MIN(a, (unsigned) b); }inline unsigned UPX_MIN(const BE32& a, unsigned b) { return UPX_MIN((unsigned) a, b); }inline unsigned UPX_MAX(unsigned a, const LE16& b) { return UPX_MAX(a, (unsigned) b); }inline unsigned UPX_MAX(const LE16& a, unsigned b) { return UPX_MAX((unsigned) a, b); }inline unsigned UPX_MIN(unsigned a, const LE16& b) { return UPX_MIN(a, (unsigned) b); }inline unsigned UPX_MIN(const LE16& a, unsigned b) { return UPX_MIN((unsigned) a, b); }inline unsigned UPX_MAX(unsigned a, const LE32& b) { return UPX_MAX(a, (unsigned) b); }inline unsigned UPX_MAX(const LE32& a, unsigned b) { return UPX_MAX((unsigned) a, b); }inline unsigned UPX_MIN(unsigned a, const LE32& b) { return UPX_MIN(a, (unsigned) b); }inline unsigned UPX_MIN(const LE32& a, unsigned b) { return UPX_MIN((unsigned) a, b); }#endif/*************************************************************************// misc**************************************************************************/// for use with qsort()extern "C" {int __acc_cdecl_qsort be16_compare(const void *, const void *);int __acc_cdecl_qsort be24_compare(const void *, const void *);int __acc_cdecl_qsort be32_compare(const void *, const void *);int __acc_cdecl_qsort be64_compare(const void *, const void *);int __acc_cdecl_qsort le16_compare(const void *, const void *);int __acc_cdecl_qsort le24_compare(const void *, const void *);int __acc_cdecl_qsort le32_compare(const void *, const void *);int __acc_cdecl_qsort le64_compare(const void *, const void *);int __acc_cdecl_qsort be16_compare_signed(const void *, const void *);int __acc_cdecl_qsort be24_compare_signed(const void *, const void *);int __acc_cdecl_qsort be32_compare_signed(const void *, const void *);int __acc_cdecl_qsort be64_compare_signed(const void *, const void *);int __acc_cdecl_qsort le16_compare_signed(const void *, const void *);int __acc_cdecl_qsort le24_compare_signed(const void *, const void *);int __acc_cdecl_qsort le32_compare_signed(const void *, const void *);int __acc_cdecl_qsort le64_compare_signed(const void *, const void *);} // extern "C"// just for testing...#if !defined(ACC_CFG_NO_UNALIGNED)#if 0 && (ACC_ARCH_AMD64 || ACC_ARCH_I386) && (ACC_CC_GNUC >= 0x030200) typedef acc_uint16e_t LE16_unaligned __attribute__((__aligned__(1))); typedef acc_uint32e_t LE32_unaligned __attribute__((__aligned__(1)));# ifndef LE16# define LE16 LE16_unaligned# endif# ifndef LE32# define LE32 LE32_unaligned# endif#endif#if 0 && (ACC_ARCH_I386) && (ACC_CC_INTELC) typedef __declspec(align(1)) acc_uint16e_t LE16_unaligned; typedef __declspec(align(1)) acc_uint32e_t LE32_unaligned;# ifndef LE16# define LE16 LE16_unaligned# endif# ifndef LE32# define LE32 LE32_unaligned# endif#endif#if 0 && (ACC_ARCH_AMD64 || ACC_ARCH_I386) && (ACC_CC_MSC) && (_MSC_VER >= 1200) typedef __declspec(align(1)) acc_uint16e_t LE16_unaligned; typedef __declspec(align(1)) acc_uint32e_t LE32_unaligned;# ifndef LE16# define LE16 LE16_unaligned# endif# ifndef LE32# define LE32 LE32_unaligned# endif# pragma warning(disable: 4244) // Wx: conversion, possible loss of data#endif#endif/*************************************************************************// Provide namespaces and classes to abtract endianness policies.//// CTP - Compile-Time Polymorphism (templates)// RTP - Run-Time Polymorphism (virtual functions)**************************************************************************/// forward declarationsnamespace N_BELE_CTP {class BEPolicy; class LEPolicy;extern const BEPolicy be_policy;extern const LEPolicy le_policy;}namespace N_BELE_RTP {class AbstractPolicy;class BEPolicy; class LEPolicy;extern const BEPolicy be_policy;extern const LEPolicy le_policy;}namespace N_BELE_CTP {#define BELE_CTP 1#include "bele_policy.h"#undef BELE_CTP}namespace N_BELE_RTP {#define BELE_RTP 1#include "bele_policy.h"#undef BELE_RTP}namespace N_BELE_CTP {template <class T>inline const N_BELE_RTP::AbstractPolicy* getRTP();template <>inline const N_BELE_RTP::AbstractPolicy* getRTP<BEPolicy>() { return &N_BELE_RTP::be_policy; }template <>inline const N_BELE_RTP::AbstractPolicy* getRTP<LEPolicy>() { return &N_BELE_RTP::le_policy; }}#endif /* already included *//*vi:ts=4:et:nowrap*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -