From 6ca65dd97d252d1618dd9870bf119b2d482e7eaf Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Thu, 22 Jun 2017 12:37:04 +0200 Subject: 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 Reviewed-by: Thiago Macieira --- src/corelib/json/qjson_p.h | 91 +--------------------------------------------- 1 file changed, 2 insertions(+), 89 deletions(-) (limited to 'src/corelib/json/qjson_p.h') 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 qle_int; typedef q_littleendian qle_uint; template -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; template -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; typedef qle_uint offset; -- cgit v1.2.3