diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2017-06-22 12:37:04 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2017-06-27 22:16:56 +0000 |
commit | 6ca65dd97d252d1618dd9870bf119b2d482e7eaf (patch) | |
tree | 3fb0e8923c9145270605dfb5d5b7e86ba81ea031 /src/corelib/json | |
parent | 01d5aaa0f6bded240e9b0c8fb32a91d2afe8ae4d (diff) |
Move qle_bitfield to qendian_p.h
Makes the qle_bitfield template more generic and moves it to qendian_p.h
It is also hardened to be more reliable.
Change-Id: I53214ec99cceee4f5e8934ae688c99e555a5fb42
Reviewed-by: Ville Voutilainen <ville.voutilainen@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/json')
-rw-r--r-- | src/corelib/json/qjson_p.h | 91 |
1 files changed, 2 insertions, 89 deletions
diff --git a/src/corelib/json/qjson_p.h b/src/corelib/json/qjson_p.h index 5d600843aa..131528376b 100644 --- a/src/corelib/json/qjson_p.h +++ b/src/corelib/json/qjson_p.h @@ -140,97 +140,10 @@ typedef q_littleendian<int> qle_int; typedef q_littleendian<unsigned int> qle_uint; template<int pos, int width> -class qle_bitfield -{ -public: - uint val; - - enum { - mask = ((1u << width) - 1) << pos - }; - - void operator =(uint t) { - uint i = qFromLittleEndian(val); - i &= ~mask; - i |= t << pos; - val = qToLittleEndian(i); - } - operator uint() const { - uint t = qFromLittleEndian(val); - t &= mask; - t >>= pos; - return t; - } - bool operator !() const { - return !operator uint(); - } - - bool operator ==(uint t) { return uint(*this) == t; } - bool operator !=(uint t) { return uint(*this) != t; } - bool operator <(uint t) { return uint(*this) < t; } - bool operator >(uint t) { return uint(*this) > t; } - bool operator <=(uint t) { return uint(*this) <= t; } - bool operator >=(uint t) { return uint(*this) >= t; } - qle_bitfield &operator +=(uint i) { - *this = (uint(*this) + i); - return *this; - } - qle_bitfield &operator -=(uint i) { - *this = (uint(*this) - i); - return *this; - } - qle_bitfield &operator |=(uint i) { - *this = (uint(*this) | i); - return *this; - } - qle_bitfield &operator &=(uint i) { - *this = (uint(*this) & i); - return *this; - } -}; +using qle_bitfield = QLEIntegerBitfield<uint, pos, width>; template<int pos, int width> -class qle_signedbitfield -{ -public: - uint val; - - enum { - mask = ((1u << width) - 1) << pos - }; - - void operator =(int t) { - uint i = qFromLittleEndian(val); - i &= ~mask; - i |= t << pos; - val = qToLittleEndian(i); - } - operator int() const { - uint i = qFromLittleEndian(val); - i <<= 32 - width - pos; - int t = (int) i; - t >>= 32 - width; - return t; - } - bool operator !() const { - return !operator int(); - } - - bool operator ==(int t) { return int(*this) == t; } - bool operator !=(int t) { return int(*this) != t; } - bool operator <(int t) { return int(*this) < t; } - bool operator >(int t) { return int(*this) > t; } - bool operator <=(int t) { return int(*this) <= t; } - bool operator >=(int t) { return int(*this) >= t; } - qle_signedbitfield &operator +=(int i) { - *this = (int(*this) + i); - return *this; - } - qle_signedbitfield &operator -=(int i) { - *this = (int(*this) - i); - return *this; - } -}; +using qle_signedbitfield = QLEIntegerBitfield<int, pos, width>; typedef qle_uint offset; |