⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cstdint.h

📁 C++封装的视频采集代码
💻 H
字号:
#ifndef __OXSEMI_CSTDINT_H__#define __OXSEMI_CSTDINT_H__#ifndef OXSEMI_INT64
#define OXSEMI_INT64
#endif

#ifndef OXSEMI_LONGLONG
#define OXSEMI_LONGLONG
#endif#if (defined(_MSC_VER) && (_MSC_VER >= 1100)) || (defined(__BORLANDC__) && (__BORLANDC__ >= 0x520) || OXSEMI_APPLE)#if !defined(OXSEMI_INT64)#define OXSEMI_INT64#endif#endif#ifdef OXSEMI_APPLE#if !defined(OXSEMI_LONGLONG)#define OXSEMI_LONGLONG#endif#endif#ifdef OXSEMI_HAS_STDINT_H// The following #include is an implementation artifact; not part of interface.# ifdef __hpux// HP-UX has a vaguely nice <stdint.h> in a non-standard location#   include <inttypes.h># else // __hpux#   include <cstdint># endif // __hpuxnamespace oxsemi{  using ::int8_t;  using ::int_least8_t;  using ::int_fast8_t;  using ::uint8_t;  using ::uint_least8_t;  using ::uint_fast8_t;  using ::int16_t;  using ::int_least16_t;  using ::int_fast16_t;  using ::uint16_t;  using ::uint_least16_t;  using ::uint_fast16_t;  using ::int32_t;  using ::int_least32_t;  using ::int_fast32_t;  using ::uint32_t;  using ::uint_least32_t;  using ::uint_fast32_t;# if defined(OXSEMI_INT64)  using ::int64_t;  using ::int_least64_t;  using ::int_fast64_t;  using ::uint64_t;  using ::uint_least64_t;  using ::uint_fast64_t;# endif //  defined(OXSEMI_INT64)  using ::intmax_t;  using ::uintmax_t;} // namespace oxsemi#else  // OXSEMI_HAS_STDINT_H# include <climits> // implementation artifact; not part of interfacenamespace oxsemi{//  These are fairly safe guesses for some 16-bit, and most 32-bit and 64-bit//  platforms.  For other systems, they will have to be hand tailored.////  Because the fast types are assumed to be the same as the undecorated types,//  it may be possible to hand tailor a more efficient implementation.  Such//  an optimization may be illusionary; on the Intel x86-family 386 on, for//  example, byte arithmetic and load/stores are as fast as "int" sized ones.//  8-bit types  ------------------------------------------------------------//# if UCHAR_MAX == 0xff     typedef signed char     int8_t;     typedef signed char     int_least8_t;     typedef signed char     int_fast8_t;     typedef unsigned char   uint8_t;     typedef unsigned char   uint_least8_t;     typedef unsigned char   uint_fast8_t;# else#    error defaults not correct; you must hand modify cstdint.h# endif//  16-bit types  -----------------------------------------------------------//# if USHRT_MAX == 0xffff     typedef short           int16_t;     typedef short           int_least16_t;     typedef short           int_fast16_t;     typedef unsigned short  uint16_t;     typedef unsigned short  uint_least16_t;     typedef unsigned short  uint_fast16_t;# else#    error defaults not correct; you must hand modify cstdint.h# endif//  32-bit types  -----------------------------------------------------------//# if ULONG_MAX == 0xffffffff     typedef long            int32_t;     typedef long            int_least32_t;     typedef long            int_fast32_t;     typedef unsigned long   uint32_t;     typedef unsigned long   uint_least32_t;     typedef unsigned long   uint_fast32_t;# elif UINT_MAX == 0xffffffff     typedef int             int32_t;     typedef int             int_least32_t;     typedef int             int_fast32_t;     typedef unsigned int    uint32_t;     typedef unsigned int    uint_least32_t;     typedef unsigned int    uint_fast32_t;# else#    error defaults not correct; you must hand modify cstdint.h# endif//  64-bit types + intmax_t and uintmax_t  ----------------------------------//# if defined(OXSEMI_LONGLONG) && (defined(ULLONG_MAX) || defined(ULONG_LONG_MAX) || defined(ULONGLONG_MAX))     typedef long long            intmax_t;     typedef unsigned long long   uintmax_t;     typedef long long            int64_t;     typedef long long            int_least64_t;     typedef long long            int_fast64_t;     typedef unsigned long long   uint64_t;     typedef unsigned long long   uint_least64_t;     typedef unsigned long long   uint_fast64_t;# elif ULONG_MAX != 0xffffffff#    if ULONG_MAX == 18446744073709551615 // 2**64 - 1     typedef long                 intmax_t;     typedef unsigned long        uintmax_t;     typedef long                 int64_t;     typedef long                 int_least64_t;     typedef long                 int_fast64_t;     typedef unsigned long        uint64_t;     typedef unsigned long        uint_least64_t;     typedef unsigned long        uint_fast64_t;#    else#       error defaults not correct; you must hand modify cstdint.h#    endif# elif (defined(_MSC_VER) && (_MSC_VER >= 1100)) || (defined(__BORLANDC__) && (__BORLANDC__ >= 0x520))     //     // we have Borland/Microsoft __int64:     //     typedef __int64             intmax_t;     typedef unsigned __int64    uintmax_t;     typedef __int64             int64_t;     typedef __int64             int_least64_t;     typedef __int64             int_fast64_t;     typedef unsigned __int64    uint64_t;     typedef unsigned __int64    uint_least64_t;     typedef unsigned __int64    uint_fast64_t;# else // assume no 64-bit integers     typedef int32_t              intmax_t;     typedef uint32_t             uintmax_t;# endif} // namespace oxsemi#endif // OXSEMI_HAS_STDINT_Hnamespace oxsemi{typedef uint8_t     U08;typedef int8_t      S08;typedef uint16_t    U16;typedef int16_t     S16;typedef uint32_t    U32;typedef int32_t     S32;#if defined(OXSEMI_INT64)typedef uint64_t    U64;typedef int64_t     S64;#endif //defined(OXSEMI_INT64)} // namespace oxseminamespace oxsemi{inline U08 get8le(const U08* in){    return (U08)in[0];}inline U16 get16le(const U08* in){    return ((U16)in[1] << 8) | (U16)in[0];}inline U32 get24le(const U08* in){    return ((U32)in[2] << 16) | ((U32)in[1] << 8) | (U32)in[0];}inline U32 get32le(const U08* in){    return ((U32)in[3] << 24) | ((U32)in[2] << 16) | ((U32)in[1] << 8) | (U32)in[0];}inline U64 get64le(const U08* in){    U64 temp    = get32le( in + 4 );    temp      <<= 32;    temp       |= get32le( in );    return temp;}inline void put8le(U08* out, U16 val){    out[0] = (U08)(val & 0xFF);}inline void put8le(U08* out, U32 val){    out[0] = (U08)(val & 0xFF);}inline void put16le(U16& out, U16 val){    U08* ptr = reinterpret_cast<U08*>(&out);    ptr[0] = (U08)(val & 0xFF);    ptr[1] = (U08)((val >> 8) & 0xFF);}inline void put16le(U16& out, U32 val){    U08* ptr = reinterpret_cast<U08*>(&out);    ptr[0] = (U08)(val & 0xFF);    ptr[1] = (U08)((val >> 8) & 0xFF);}inline void put16le(U08* out, U16 val){    out[0] = (U08)(val & 0xFF);    out[1] = (U08)((val >> 8) & 0xFF);}inline void put24le(U08* out, U32 val){    out[0] = (U08)(val & 0xFF);    out[1] = (U08)((val >> 8) & 0xFF);    out[2] = (U08)((val >> 16) & 0xFF);}inline void put32le(U08* out, U32 val){    out[0] = (U08)(val & 0xFF);    out[1] = (U08)((val >> 8) & 0xFF);    out[2] = (U08)((val >> 16) & 0xFF);    out[3] = (U08)((val >> 24) & 0xFF);}inline void put64le(U08* out, U64 val){    put32le( out,     (U32)val );    put32le( out + 4, (U32)(val >> 32) );}/*********************************************/inline U08 get8be(const U08* in){    return in[0];}inline U16 get16be(const U08* in){    return (U16)in[0] << 8 | (U16)in[1];}inline U32 get24be(const U08* in){    return ((U32)in[0] << 16) | ((U32)in[1] << 8) | ((U32)in[2]);}inline U32 get32be(const U08* in){    return ((U32)in[0] << 24) | ((U32)in[1] << 16) | ((U32)in[2] << 8) | (U32)in[3];}inline void put8be(U08* out, U08 val){    out[0] = val;}inline void put16be(U08* out, U16 val){    out[1] = (U08)(val & 0xFF);    out[0] = (U08)((val >> 8) & 0xFF);}inline void put24be(U08* out, U32 val){    out[2] = (U08)(val & 0xFF);    out[1] = (U08)((val >> 8) & 0xFF);    out[0] = (U08)((val >> 16) & 0xFF);}inline void put32be(U08* out, U32 val){    out[3] = (U08)(val & 0xFF);    out[2] = (U08)((val >> 8) & 0xFF);    out[1] = (U08)((val >> 16) & 0xFF);    out[0] = (U08)((val >> 24) & 0xFF);}// ****************************************************************************// ****************************************************************************// All these are to go into relevent files in the future...// add to clear ambiguaty for signed typesvoid inline put16be( unsigned char* p, short v )// {{{{    put16be( p, (unsigned short) v );}// }}}#if defined(OXSEMI_LONGLONG)// MAY NOT BE SAFE!! #$%@!void inline put64be( unsigned char* p, unsigned long long v )// {{{{    put32be( p  , (unsigned long) ( v >> 32  )  );    put32be( p+4, (unsigned long) ( v >> 0   )  );}// }}}// MAY NOT BE SAFE!! #$%@!unsigned long long inline get64be( const unsigned char* p )// {{{{    return ( ( (unsigned long long) get32be( p   ) ) << 32  ) +           ( ( (unsigned long long) get32be( p+4 ) ) << 0   );}#endif // defined(OXSEMI_LONGLONG)// }}}// ****************************************************************************// ****************************************************************************#ifdef OXSEMI_LITTLE_ENDIANinline U16 le_cast16(U08 val){    return val;}inline U08 le_lsb(U16 val){    return val & 0x00FF;}inline U08 le_msb(U16 val){    return (val >> 8) & 0xFF;}inline U16 le(U16 val){    return val;}inline U32 le(U32 val){    return val;}inline U16 get16(const U08* in){    return get16le(in);}inline U32 get32(const U08* in){    return get32le(in);}inline U32 get32le(const U32* in){    return *in;}inline void put16(U16& out, U16 val){    put16le(out, val);}inline void put32(U08* out, U32 val){    put32le(out, val);}inline void put32le(U32* out, U32 val){    *out = val;}#elif defined(OXSEMI_BIG_ENDIAN)inline U16 le_cast16(U08 val){    return (U16)val << 8;}inline U08 le_lsb(U16 val){    return (val >> 8) & 0xFF;}inline U08 le_msb(U16 val){    return val & 0x00FF;}inline U16 le(U16 val){    return ((val << 8) & 0xFF00) | ((val >> 8) & 0xFF);}inline U32 le(U32 val){    return ((val << 24) & 0xFF000000) | ((val << 8) & 0x00FF0000) | ((val >> 8) & 0xFF00) | ((val >> 24) & 0xFF);}inline U16 get16(const U08* in){    return get16be(in);}inline U32 get32(const U08* in){    return get32be(in);}inline U32 get32le(const U32* in){    return get32le(reinterpret_cast<const U08*>(in));}inline void put16(U08* out, U16 val){    put16be(out, val);}inline void put32(U08* out, U32 val){    put32be(out, val);}inline void put32le(U32* out, U32 val){    put32le(reinterpret_cast<U08*>(out), val);}#else   // defined(OXSEMI_BIG_ENDIAN)#error "platform not supported"#endif  // OXSEMI_LITTLE_ENDIAN} // namespace oxsemi#endif // __OXSEMI_CSTDINT_H__

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -