#ifndef NALL_VARINT_HPP #define NALL_VARINT_HPP #include #include #include namespace nall { template class uint_t { private: enum { bytes = (bits + 7) >> 3 }; //minimum number of bytes needed to store value typedef typename static_if< sizeof(int) >= bytes, unsigned int, typename static_if< sizeof(long) >= bytes, unsigned long, typename static_if< sizeof(long long) >= bytes, unsigned long long, void >::type >::type >::type T; static_assert(!std::is_same::value, ""); T data; public: inline operator T() const { return data; } inline T operator ++(int) { T r = data; data = uclip(data + 1); return r; } inline T operator --(int) { T r = data; data = uclip(data - 1); return r; } inline T operator ++() { return data = uclip(data + 1); } inline T operator --() { return data = uclip(data - 1); } inline T operator =(const T i) { return data = uclip(i); } inline T operator |=(const T i) { return data = uclip(data | i); } inline T operator ^=(const T i) { return data = uclip(data ^ i); } inline T operator &=(const T i) { return data = uclip(data & i); } inline T operator<<=(const T i) { return data = uclip(data << i); } inline T operator>>=(const T i) { return data = uclip(data >> i); } inline T operator +=(const T i) { return data = uclip(data + i); } inline T operator -=(const T i) { return data = uclip(data - i); } inline T operator *=(const T i) { return data = uclip(data * i); } inline T operator /=(const T i) { return data = uclip(data / i); } inline T operator %=(const T i) { return data = uclip(data % i); } inline uint_t() : data(0) {} inline uint_t(const T i) : data(uclip(i)) {} }; template class int_t { private: enum { bytes = (bits + 7) >> 3 }; //minimum number of bytes needed to store value typedef typename static_if< sizeof(int) >= bytes, signed int, typename static_if< sizeof(long) >= bytes, signed long, typename static_if< sizeof(long long) >= bytes, signed long long, void >::type >::type >::type T; static_assert(!std::is_same::value, ""); T data; public: inline operator T() const { return data; } inline T operator ++(int) { T r = data; data = sclip(data + 1); return r; } inline T operator --(int) { T r = data; data = sclip(data - 1); return r; } inline T operator ++() { return data = sclip(data + 1); } inline T operator --() { return data = sclip(data - 1); } inline T operator =(const T i) { return data = sclip(i); } inline T operator |=(const T i) { return data = sclip(data | i); } inline T operator ^=(const T i) { return data = sclip(data ^ i); } inline T operator &=(const T i) { return data = sclip(data & i); } inline T operator<<=(const T i) { return data = sclip(data << i); } inline T operator>>=(const T i) { return data = sclip(data >> i); } inline T operator +=(const T i) { return data = sclip(data + i); } inline T operator -=(const T i) { return data = sclip(data - i); } inline T operator *=(const T i) { return data = sclip(data * i); } inline T operator /=(const T i) { return data = sclip(data / i); } inline T operator %=(const T i) { return data = sclip(data % i); } inline int_t() : data(0) {} inline int_t(const T i) : data(sclip(i)) {} }; } #endif