Add ox::LittleEndian template

This commit is contained in:
Gary Talent 2018-02-17 00:47:28 -06:00
parent b8a6b47b29
commit 193492c518

View File

@ -60,36 +60,8 @@ inline uint64_t byteSwap(uint64_t i) {
/** /**
* Takes an int and byte swaps if the platform is big endian. * Takes an int and byte swaps if the platform is big endian.
*/ */
inline int8_t bigEndianAdapt(int8_t i) { template<typename T>
return i; inline T bigEndianAdapt(T i) {
}
/**
* Takes an int and byte swaps if the platform is big endian.
*/
inline int16_t bigEndianAdapt(int16_t i) {
#ifdef __BIG_ENDIAN__
return byteSwap(i);
#else
return i;
#endif
}
/**
* Takes an int and byte swaps if the platform is big endian.
*/
inline int32_t bigEndianAdapt(int32_t i) {
#ifdef __BIG_ENDIAN__
return byteSwap(i);
#else
return i;
#endif
}
/**
* Takes an int and byte swaps if the platform is big endian.
*/
inline int64_t bigEndianAdapt(int64_t i) {
#ifdef __BIG_ENDIAN__ #ifdef __BIG_ENDIAN__
return byteSwap(i); return byteSwap(i);
#else #else
@ -98,44 +70,35 @@ inline int64_t bigEndianAdapt(int64_t i) {
} }
/** template<typename T>
* Takes an int and byte swaps if the platform is big endian. class LittleEndian {
*/ private:
inline uint8_t bigEndianAdapt(uint8_t i) { T m_value;
return i;
}
/** public:
* Takes an int and byte swaps if the platform is big endian. inline LittleEndian() = default;
*/
inline uint16_t bigEndianAdapt(uint16_t i) {
#ifdef __BIG_ENDIAN__
return byteSwap(i);
#else
return i;
#endif
}
/** inline LittleEndian(T value) {
* Takes an int and byte swaps if the platform is big endian. m_value = ox::bigEndianAdapt(value);
*/ }
inline uint32_t bigEndianAdapt(uint32_t i) {
#ifdef __BIG_ENDIAN__
return byteSwap(i);
#else
return i;
#endif
}
/** inline T operator=(T value) {
* Takes an int and byte swaps if the platform is big endian. m_value = ox::bigEndianAdapt(value);
*/ return value;
inline uint64_t bigEndianAdapt(uint64_t i) { }
#ifdef __BIG_ENDIAN__
return byteSwap(i); inline operator T() {
#else return ox::bigEndianAdapt(m_value);
return i; }
#endif
} inline bool operator==(T value) {
return value == ox::bigEndianAdapt(m_value);
}
inline bool operator!=(T value) {
return value != ox::bigEndianAdapt(m_value);
}
};
} }