#pragma once #ifndef __PL_BIG_ENDIAN_H__ #define __PL_BIG_ENDIAN_H__ #include template struct BEInteger { public: BEInteger(); BEInteger(const BEInteger &other); explicit BEInteger(T i); operator T() const; BEInteger &operator=(T value); template BEInteger &operator+=(TOther value); template BEInteger &operator-=(TOther value); template BEInteger &operator*=(TOther value); template BEInteger &operator/=(TOther value); template BEInteger &operator%=(TOther value); BEInteger& operator--(); BEInteger operator--(int); BEInteger& operator++(); BEInteger operator++(int); private: T m_beValue; }; template struct BEInteger_SwapHelper { }; #include "ByteSwap.h" template<> struct BEInteger_SwapHelper { inline static void Swap(int16_t &v) { PortabilityLayer::ByteSwap::BigInt16(v); } }; template<> struct BEInteger_SwapHelper { inline static void Swap(int32_t &v) { PortabilityLayer::ByteSwap::BigInt32(v); } }; template<> struct BEInteger_SwapHelper { inline static void Swap(uint16_t &v) { PortabilityLayer::ByteSwap::BigUInt16(v); } }; template<> struct BEInteger_SwapHelper { inline static void Swap(uint32_t &v) { PortabilityLayer::ByteSwap::BigUInt32(v); } }; // Int16 template inline BEInteger::BEInteger() : m_beValue(0) { } template inline BEInteger::BEInteger(const BEInteger &other) : m_beValue(other.m_beValue) { } template inline BEInteger::BEInteger(T i) : m_beValue(i) { BEInteger_SwapHelper::Swap(m_beValue); } template inline BEInteger::operator T() const { int16_t result = m_beValue; BEInteger_SwapHelper::Swap(result); return result; } template inline BEInteger &BEInteger::operator=(T value) { BEInteger_SwapHelper::Swap(value); m_beValue = value; return *this; } template template BEInteger &BEInteger::operator+=(TOther value) { BEInteger_SwapHelper::Swap(m_beValue); m_beValue += value; BEInteger_SwapHelper::Swap(m_beValue); return *this; } template template BEInteger &BEInteger::operator-=(TOther value) { BEInteger_SwapHelper::Swap(m_beValue); m_beValue -= value; BEInteger_SwapHelper::Swap(m_beValue); return *this; } template template BEInteger &BEInteger::operator*=(TOther value) { BEInteger_SwapHelper::Swap(m_beValue); m_beValue *= value; BEInteger_SwapHelper::Swap(m_beValue); return *this; } template template BEInteger &BEInteger::operator/=(TOther value) { BEInteger_SwapHelper::Swap(m_beValue); m_beValue /= value; BEInteger_SwapHelper::Swap(m_beValue); return *this; } template template BEInteger &BEInteger::operator%=(TOther value) { BEInteger_SwapHelper::Swap(m_beValue); m_beValue %= value; BEInteger_SwapHelper::Swap(m_beValue); return *this; } template BEInteger& BEInteger::operator--() { BEInteger_SwapHelper::Swap(m_beValue); m_beValue--; BEInteger_SwapHelper::Swap(m_beValue); return *this; } template BEInteger BEInteger::operator--(int) { BEInteger orig(*this); --(*this); return orig; } template BEInteger& BEInteger::operator++() { BEInteger_SwapHelper::Swap(m_beValue); m_beValue++; BEInteger_SwapHelper::Swap(m_beValue); return *this; } template BEInteger BEInteger::operator++(int) { BEInteger orig(*this); ++(*this); return orig; } typedef BEInteger BEInt16_t; typedef BEInteger BEInt32_t; typedef BEInteger BEUInt16_t; typedef BEInteger BEUInt32_t; #endif