improve constness for operators on PropertyFlags<>

This commit is contained in:
ZappoMan 2014-09-11 12:13:34 -07:00
parent 13cffa6e44
commit 7cadc3433a

View file

@ -49,7 +49,7 @@ public:
Enum lastFlag() const { return (Enum)_maxFlag; } Enum lastFlag() const { return (Enum)_maxFlag; }
void setHasProperty(Enum flag, bool value = true); void setHasProperty(Enum flag, bool value = true);
bool getHasProperty(Enum flag); bool getHasProperty(Enum flag) const;
QByteArray encode(); QByteArray encode();
void decode(const QByteArray& fromEncoded); void decode(const QByteArray& fromEncoded);
@ -61,42 +61,42 @@ public:
PropertyFlags& operator=(const PropertyFlags& other); PropertyFlags& operator=(const PropertyFlags& other);
PropertyFlags& operator|=(PropertyFlags other); PropertyFlags& operator|=(const PropertyFlags& other);
PropertyFlags& operator|=(Enum flag); PropertyFlags& operator|=(Enum flag);
PropertyFlags& operator&=(PropertyFlags other); PropertyFlags& operator&=(const PropertyFlags& other);
PropertyFlags& operator&=(Enum flag); PropertyFlags& operator&=(Enum flag);
PropertyFlags& operator+=(PropertyFlags other); PropertyFlags& operator+=(const PropertyFlags& other);
PropertyFlags& operator+=(Enum flag); PropertyFlags& operator+=(Enum flag);
PropertyFlags& operator-=(PropertyFlags other); PropertyFlags& operator-=(const PropertyFlags& other);
PropertyFlags& operator-=(Enum flag); PropertyFlags& operator-=(Enum flag);
PropertyFlags& operator<<=(PropertyFlags other); PropertyFlags& operator<<=(const PropertyFlags& other);
PropertyFlags& operator<<=(Enum flag); PropertyFlags& operator<<=(Enum flag);
PropertyFlags operator|(PropertyFlags other) const; PropertyFlags operator|(const PropertyFlags& other) const;
PropertyFlags operator|(Enum flag) const; PropertyFlags operator|(Enum flag) const;
PropertyFlags operator&(PropertyFlags other) const; PropertyFlags operator&(const PropertyFlags& other) const;
PropertyFlags operator&(Enum flag) const; PropertyFlags operator&(Enum flag) const;
PropertyFlags operator+(PropertyFlags other) const; PropertyFlags operator+(const PropertyFlags& other) const;
PropertyFlags operator+(Enum flag) const; PropertyFlags operator+(Enum flag) const;
PropertyFlags operator-(PropertyFlags other) const; PropertyFlags operator-(const PropertyFlags& other) const;
PropertyFlags operator-(Enum flag) const; PropertyFlags operator-(Enum flag) const;
PropertyFlags operator<<(PropertyFlags other) const; PropertyFlags operator<<(const PropertyFlags& other) const;
PropertyFlags operator<<(Enum flag) const; PropertyFlags operator<<(Enum flag) const;
// NOTE: due to the nature of the compact storage of these property flags, and the fact that the upper bound of the // NOTE: due to the nature of the compact storage of these property flags, and the fact that the upper bound of the
// enum is not know, these operators will only perform their bitwise operations on the set of properties that have // enum is not know, these operators will only perform their bitwise operations on the set of properties that have
// been previously set // been previously set
PropertyFlags& operator^=(PropertyFlags other); PropertyFlags& operator^=(const PropertyFlags& other);
PropertyFlags& operator^=(Enum flag); PropertyFlags& operator^=(Enum flag);
PropertyFlags operator^(PropertyFlags other) const; PropertyFlags operator^(const PropertyFlags& other) const;
PropertyFlags operator^(Enum flag) const; PropertyFlags operator^(Enum flag) const;
PropertyFlags operator~() const; PropertyFlags operator~() const;
@ -146,7 +146,7 @@ template<typename Enum> inline void PropertyFlags<Enum>::setHasProperty(Enum fla
} }
} }
template<typename Enum> inline bool PropertyFlags<Enum>::getHasProperty(Enum flag) { template<typename Enum> inline bool PropertyFlags<Enum>::getHasProperty(Enum flag) const {
if (flag > _maxFlag) { if (flag > _maxFlag) {
return _trailingFlipped; // usually false return _trailingFlipped; // usually false
} }
@ -253,7 +253,7 @@ template<typename Enum> inline PropertyFlags<Enum>& PropertyFlags<Enum>::operato
return *this; return *this;
} }
template<typename Enum> inline PropertyFlags<Enum>& PropertyFlags<Enum>::operator|=(PropertyFlags other) { template<typename Enum> inline PropertyFlags<Enum>& PropertyFlags<Enum>::operator|=(const PropertyFlags& other) {
_flags |= other._flags; _flags |= other._flags;
_maxFlag = std::max(_maxFlag, other._maxFlag); _maxFlag = std::max(_maxFlag, other._maxFlag);
_minFlag = std::min(_minFlag, other._minFlag); _minFlag = std::min(_minFlag, other._minFlag);
@ -268,7 +268,7 @@ template<typename Enum> inline PropertyFlags<Enum>& PropertyFlags<Enum>::operato
return *this; return *this;
} }
template<typename Enum> inline PropertyFlags<Enum>& PropertyFlags<Enum>::operator&=(PropertyFlags other) { template<typename Enum> inline PropertyFlags<Enum>& PropertyFlags<Enum>::operator&=(const PropertyFlags& other) {
_flags &= other._flags; _flags &= other._flags;
shinkIfNeeded(); shinkIfNeeded();
return *this; return *this;
@ -281,7 +281,7 @@ template<typename Enum> inline PropertyFlags<Enum>& PropertyFlags<Enum>::operato
return *this; return *this;
} }
template<typename Enum> inline PropertyFlags<Enum>& PropertyFlags<Enum>::operator^=(PropertyFlags other) { template<typename Enum> inline PropertyFlags<Enum>& PropertyFlags<Enum>::operator^=(const PropertyFlags& other) {
_flags ^= other._flags; _flags ^= other._flags;
shinkIfNeeded(); shinkIfNeeded();
return *this; return *this;
@ -294,7 +294,7 @@ template<typename Enum> inline PropertyFlags<Enum>& PropertyFlags<Enum>::operato
return *this; return *this;
} }
template<typename Enum> inline PropertyFlags<Enum>& PropertyFlags<Enum>::operator+=(PropertyFlags other) { template<typename Enum> inline PropertyFlags<Enum>& PropertyFlags<Enum>::operator+=(const PropertyFlags& other) {
for(int flag = (int)other.firstFlag(); flag <= (int)other.lastFlag(); flag++) { for(int flag = (int)other.firstFlag(); flag <= (int)other.lastFlag(); flag++) {
if (other.getHasProperty((Enum)flag)) { if (other.getHasProperty((Enum)flag)) {
setHasProperty((Enum)flag, true); setHasProperty((Enum)flag, true);
@ -308,7 +308,7 @@ template<typename Enum> inline PropertyFlags<Enum>& PropertyFlags<Enum>::operato
return *this; return *this;
} }
template<typename Enum> inline PropertyFlags<Enum>& PropertyFlags<Enum>::operator-=(PropertyFlags other) { template<typename Enum> inline PropertyFlags<Enum>& PropertyFlags<Enum>::operator-=(const PropertyFlags& other) {
for(int flag = (int)other.firstFlag(); flag <= (int)other.lastFlag(); flag++) { for(int flag = (int)other.firstFlag(); flag <= (int)other.lastFlag(); flag++) {
if (other.getHasProperty((Enum)flag)) { if (other.getHasProperty((Enum)flag)) {
setHasProperty((Enum)flag, false); setHasProperty((Enum)flag, false);
@ -322,7 +322,7 @@ template<typename Enum> inline PropertyFlags<Enum>& PropertyFlags<Enum>::operato
return *this; return *this;
} }
template<typename Enum> inline PropertyFlags<Enum>& PropertyFlags<Enum>::operator<<=(PropertyFlags other) { template<typename Enum> inline PropertyFlags<Enum>& PropertyFlags<Enum>::operator<<=(const PropertyFlags& other) {
for(int flag = (int)other.firstFlag(); flag <= (int)other.lastFlag(); flag++) { for(int flag = (int)other.firstFlag(); flag <= (int)other.lastFlag(); flag++) {
if (other.getHasProperty((Enum)flag)) { if (other.getHasProperty((Enum)flag)) {
setHasProperty((Enum)flag, true); setHasProperty((Enum)flag, true);
@ -336,7 +336,7 @@ template<typename Enum> inline PropertyFlags<Enum>& PropertyFlags<Enum>::operato
return *this; return *this;
} }
template<typename Enum> inline PropertyFlags<Enum> PropertyFlags<Enum>::operator|(PropertyFlags other) const { template<typename Enum> inline PropertyFlags<Enum> PropertyFlags<Enum>::operator|(const PropertyFlags& other) const {
PropertyFlags result(*this); PropertyFlags result(*this);
result |= other; result |= other;
return result; return result;
@ -349,7 +349,7 @@ template<typename Enum> inline PropertyFlags<Enum> PropertyFlags<Enum>::operator
return result; return result;
} }
template<typename Enum> inline PropertyFlags<Enum> PropertyFlags<Enum>::operator&(PropertyFlags other) const { template<typename Enum> inline PropertyFlags<Enum> PropertyFlags<Enum>::operator&(const PropertyFlags& other) const {
PropertyFlags result(*this); PropertyFlags result(*this);
result &= other; result &= other;
return result; return result;
@ -362,7 +362,7 @@ template<typename Enum> inline PropertyFlags<Enum> PropertyFlags<Enum>::operator
return result; return result;
} }
template<typename Enum> inline PropertyFlags<Enum> PropertyFlags<Enum>::operator^(PropertyFlags other) const { template<typename Enum> inline PropertyFlags<Enum> PropertyFlags<Enum>::operator^(const PropertyFlags& other) const {
PropertyFlags result(*this); PropertyFlags result(*this);
result ^= other; result ^= other;
return result; return result;
@ -375,7 +375,7 @@ template<typename Enum> inline PropertyFlags<Enum> PropertyFlags<Enum>::operator
return result; return result;
} }
template<typename Enum> inline PropertyFlags<Enum> PropertyFlags<Enum>::operator+(PropertyFlags other) const { template<typename Enum> inline PropertyFlags<Enum> PropertyFlags<Enum>::operator+(const PropertyFlags& other) const {
PropertyFlags result(*this); PropertyFlags result(*this);
result += other; result += other;
return result; return result;
@ -387,7 +387,7 @@ template<typename Enum> inline PropertyFlags<Enum> PropertyFlags<Enum>::operator
return result; return result;
} }
template<typename Enum> inline PropertyFlags<Enum> PropertyFlags<Enum>::operator-(PropertyFlags other) const { template<typename Enum> inline PropertyFlags<Enum> PropertyFlags<Enum>::operator-(const PropertyFlags& other) const {
PropertyFlags result(*this); PropertyFlags result(*this);
result -= other; result -= other;
return result; return result;
@ -399,7 +399,7 @@ template<typename Enum> inline PropertyFlags<Enum> PropertyFlags<Enum>::operator
return result; return result;
} }
template<typename Enum> inline PropertyFlags<Enum> PropertyFlags<Enum>::operator<<(PropertyFlags other) const { template<typename Enum> inline PropertyFlags<Enum> PropertyFlags<Enum>::operator<<(const PropertyFlags& other) const {
PropertyFlags result(*this); PropertyFlags result(*this);
result <<= other; result <<= other;
return result; return result;