From 25e2fbe419655b2f8ce22dbafa1de6bc655b1567 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Tue, 27 Aug 2013 18:08:32 -0700 Subject: got comparisons between implicit and explicit units working right --- indra/llcommon/llunittype.h | 44 ++++++++++++++++++++++++++++++----- indra/llcommon/tests/llunits_test.cpp | 10 ++++++++ 2 files changed, 48 insertions(+), 6 deletions(-) (limited to 'indra') diff --git a/indra/llcommon/llunittype.h b/indra/llcommon/llunittype.h index 50037ccade..663641d6b1 100644 --- a/indra/llcommon/llunittype.h +++ b/indra/llcommon/llunittype.h @@ -169,11 +169,13 @@ struct LLUnit { return mValue <= convert(other).value(); } + template LL_FORCE_INLINE bool operator > (LLUnit other) const { return mValue > convert(other).value(); } + template LL_FORCE_INLINE bool operator >= (LLUnit other) const { @@ -283,7 +285,12 @@ struct LLUnitImplicit : public LLUnit base_t::mValue -= convert(other).value(); } - using base_t::operator ==; + template + LL_FORCE_INLINE bool operator == (LLUnit other) const + { + return mValue == convert(other).value(); + } + template LL_FORCE_INLINE bool operator == (LLUnitImplicit other) const { @@ -296,7 +303,12 @@ struct LLUnitImplicit : public LLUnit return mValue == other; } - using base_t::operator !=; + template + LL_FORCE_INLINE bool operator != (LLUnit other) const + { + return mValue != convert(other).value(); + } + template LL_FORCE_INLINE bool operator != (LLUnitImplicit other) const { @@ -309,7 +321,12 @@ struct LLUnitImplicit : public LLUnit return mValue != other; } - using base_t::operator <; + template + LL_FORCE_INLINE bool operator < (LLUnit other) const + { + return mValue < convert(other).value(); + } + template LL_FORCE_INLINE bool operator < (LLUnitImplicit other) const { @@ -322,7 +339,12 @@ struct LLUnitImplicit : public LLUnit return mValue < other; } - using base_t::operator <=; + template + LL_FORCE_INLINE bool operator <= (LLUnit other) const + { + return mValue <= convert(other).value(); + } + template LL_FORCE_INLINE bool operator <= (LLUnitImplicit other) const { @@ -335,7 +357,12 @@ struct LLUnitImplicit : public LLUnit return mValue <= other; } - using base_t::operator >; + template + LL_FORCE_INLINE bool operator > (LLUnit other) const + { + return mValue > convert(other).value(); + } + template LL_FORCE_INLINE bool operator > (LLUnitImplicit other) const { @@ -348,7 +375,12 @@ struct LLUnitImplicit : public LLUnit return mValue > other; } - using base_t::operator >=; + template + LL_FORCE_INLINE bool operator >= (LLUnit other) const + { + return mValue >= convert(other).value(); + } + template LL_FORCE_INLINE bool operator >= (LLUnitImplicit other) const { diff --git a/indra/llcommon/tests/llunits_test.cpp b/indra/llcommon/tests/llunits_test.cpp index 59876ce3b4..d5b7c08672 100644 --- a/indra/llcommon/tests/llunits_test.cpp +++ b/indra/llcommon/tests/llunits_test.cpp @@ -274,6 +274,16 @@ namespace tut quatloos_implicit -= F32Quatloos(10); ensure("can subtract-assign explicit units", quatloos_implicit == 16); + + // comparisons + ensure("can compare greater than implicit unit", quatloos_implicit > F32QuatloosImplicit(0.f)); + ensure("can compare greater than non-implicit unit", quatloos_implicit > F32Quatloos(0.f)); + ensure("can compare greater than or equal to implicit unit", quatloos_implicit >= F32QuatloosImplicit(0.f)); + ensure("can compare greater than or equal to non-implicit unit", quatloos_implicit >= F32Quatloos(0.f)); + ensure("can compare less than implicit unit", quatloos_implicit < F32QuatloosImplicit(0.f)); + ensure("can compare less than non-implicit unit", quatloos_implicit < F32Quatloos(0.f)); + ensure("can compare less than or equal to implicit unit", quatloos_implicit <= F32QuatloosImplicit(0.f)); + ensure("can compare less than or equal to non-implicit unit", quatloos_implicit <= F32Quatloos(0.f)); } // precision tests -- cgit v1.2.3