summaryrefslogtreecommitdiff
path: root/indra/llcommon/llunit.h
diff options
context:
space:
mode:
Diffstat (limited to 'indra/llcommon/llunit.h')
-rw-r--r--indra/llcommon/llunit.h141
1 files changed, 35 insertions, 106 deletions
diff --git a/indra/llcommon/llunit.h b/indra/llcommon/llunit.h
index 98e4de32fa..4519905707 100644
--- a/indra/llcommon/llunit.h
+++ b/indra/llcommon/llunit.h
@@ -51,6 +51,11 @@ struct LLUnitType : public BASE_UNIT
return static_cast<unit_t&>(*this);
}
+ operator storage_t () const
+ {
+ return value();
+ }
+
storage_t value() const
{
return convertToDerived(mBaseValue);
@@ -102,6 +107,11 @@ struct LLUnitType<STORAGE_TYPE, T, T>
return static_cast<unit_t&>(*this);
}
+ operator storage_t () const
+ {
+ return value();
+ }
+
storage_t value() const { return mBaseValue; }
template<typename CONVERTED_TYPE>
@@ -110,7 +120,6 @@ struct LLUnitType<STORAGE_TYPE, T, T>
return CONVERTED_TYPE(*this).value();
}
-
static storage_t convertToBase(storage_t derived_value)
{
return (storage_t)derived_value;
@@ -150,99 +159,77 @@ protected:
storage_t mBaseValue;
};
-//
-// operator +
-//
template<typename STORAGE_TYPE, typename BASE_UNIT, typename DERIVED_UNIT>
-DERIVED_UNIT operator + (typename LLUnitType<STORAGE_TYPE, BASE_UNIT, DERIVED_UNIT>::storage_t first, LLUnitType<STORAGE_TYPE, BASE_UNIT, DERIVED_UNIT> second)
+struct LLUnitTypeWrapper
+: public LLUnitType<STORAGE_TYPE, BASE_UNIT, DERIVED_UNIT>
{
- return DERIVED_UNIT(first + second.value());
-}
+ typedef LLUnitType<STORAGE_TYPE, BASE_UNIT, DERIVED_UNIT> unit_t;
+ LLUnitTypeWrapper(const unit_t& other)
+ : unit_t(other)
+ {}
+};
-template<typename STORAGE_TYPE, typename BASE_UNIT, typename DERIVED_UNIT>
-DERIVED_UNIT operator + (LLUnitType<STORAGE_TYPE, BASE_UNIT, DERIVED_UNIT> first, typename LLUnitType<STORAGE_TYPE, BASE_UNIT, DERIVED_UNIT>::storage_t second)
-{
- return DERIVED_UNIT(first.value() + second);
-}
-template<typename STORAGE_TYPE, typename BASE_UNIT, typename DERIVED_UNIT, typename OTHER_DERIVED_UNIT>
-DERIVED_UNIT operator + (LLUnitType<STORAGE_TYPE, BASE_UNIT, DERIVED_UNIT> first, LLUnitType<STORAGE_TYPE, BASE_UNIT, OTHER_DERIVED_UNIT> second)
+//
+// operator +
+//
+template<typename STORAGE_TYPE, typename BASE_UNIT, typename DERIVED_UNIT, typename STORAGE_TYPE2, typename BASE_UNIT2, typename DERIVED_UNIT2>
+DERIVED_UNIT operator + (typename LLUnitType<STORAGE_TYPE, BASE_UNIT, DERIVED_UNIT>::storage_t first, LLUnitType<STORAGE_TYPE2, BASE_UNIT2, DERIVED_UNIT2> second)
{
- return DERIVED_UNIT(first.value() + second.value());
+ return DERIVED_UNIT(first + LLUnitType<STORAGE_TYPE, BASE_UNIT, DERIVED_UNIT>(second).value());
}
+
//
// operator -
//
-template<typename STORAGE_TYPE, typename BASE_UNIT, typename DERIVED_UNIT>
+template<typename STORAGE_TYPE, typename BASE_UNIT, typename DERIVED_UNIT, typename STORAGE_TYPE2, typename BASE_UNIT2, typename DERIVED_UNIT2>
DERIVED_UNIT operator - (typename LLUnitType<STORAGE_TYPE, BASE_UNIT, DERIVED_UNIT>::storage_t first, LLUnitType<STORAGE_TYPE, BASE_UNIT, DERIVED_UNIT> second)
{
- return DERIVED_UNIT(first - second.value());
-}
-
-template<typename STORAGE_TYPE, typename BASE_UNIT, typename DERIVED_UNIT>
-DERIVED_UNIT operator - (LLUnitType<STORAGE_TYPE, BASE_UNIT, DERIVED_UNIT> first, typename LLUnitType<STORAGE_TYPE, BASE_UNIT, DERIVED_UNIT>::storage_t second)
-{
- return DERIVED_UNIT(first.value() - second);
-}
-
-template<typename STORAGE_TYPE, typename BASE_UNIT, typename DERIVED_UNIT, typename OTHER_DERIVED_UNIT>
-DERIVED_UNIT operator - (LLUnitType<STORAGE_TYPE, BASE_UNIT, DERIVED_UNIT> first, LLUnitType<STORAGE_TYPE, BASE_UNIT, OTHER_DERIVED_UNIT> second)
-{
- return DERIVED_UNIT(first.value() - second.value());
+ return DERIVED_UNIT(first - LLUnitType<STORAGE_TYPE, BASE_UNIT, DERIVED_UNIT>(second).value());
}
//
// operator *
//
template<typename STORAGE_TYPE, typename BASE_UNIT, typename DERIVED_UNIT>
-DERIVED_UNIT operator * (typename LLUnitType<STORAGE_TYPE, BASE_UNIT, DERIVED_UNIT>::storage_t first, LLUnitType<STORAGE_TYPE, BASE_UNIT, DERIVED_UNIT> second)
+DERIVED_UNIT operator * (STORAGE_TYPE first, LLUnitType<STORAGE_TYPE, BASE_UNIT, DERIVED_UNIT> second)
{
return DERIVED_UNIT(first * second.value());
}
template<typename STORAGE_TYPE, typename BASE_UNIT, typename DERIVED_UNIT>
-DERIVED_UNIT operator * (LLUnitType<STORAGE_TYPE, BASE_UNIT, DERIVED_UNIT> first, typename LLUnitType<STORAGE_TYPE, BASE_UNIT, DERIVED_UNIT>::storage_t second)
+DERIVED_UNIT operator * (LLUnitType<STORAGE_TYPE, BASE_UNIT, DERIVED_UNIT> first, STORAGE_TYPE second)
{
return DERIVED_UNIT(first.value() * second);
}
+
//
// operator /
//
template<typename STORAGE_TYPE, typename BASE_UNIT, typename DERIVED_UNIT>
-DERIVED_UNIT operator / (typename LLUnitType<STORAGE_TYPE, BASE_UNIT, DERIVED_UNIT>::storage_t first, LLUnitType<STORAGE_TYPE, BASE_UNIT, DERIVED_UNIT> second)
+DERIVED_UNIT operator / (STORAGE_TYPE first, LLUnitTypeWrapper<STORAGE_TYPE, BASE_UNIT, DERIVED_UNIT> second)
{
- return DERIVED_UNIT(first * second.value());
+ return DERIVED_UNIT(first / second.value());
}
template<typename STORAGE_TYPE, typename BASE_UNIT, typename DERIVED_UNIT>
-DERIVED_UNIT operator / (LLUnitType<STORAGE_TYPE, BASE_UNIT, DERIVED_UNIT> first, typename LLUnitType<STORAGE_TYPE, BASE_UNIT, DERIVED_UNIT>::storage_t second)
+DERIVED_UNIT operator / (LLUnitTypeWrapper<STORAGE_TYPE, BASE_UNIT, DERIVED_UNIT> first, STORAGE_TYPE second)
{
- return DERIVED_UNIT(first.value() * second);
+ return DERIVED_UNIT(first.value() / second);
}
//
// operator <
//
-template<typename STORAGE_TYPE, typename BASE_UNIT, typename DERIVED_UNIT>
+template<typename STORAGE_TYPE, typename BASE_UNIT, typename DERIVED_UNIT, typename STORAGE_TYPE2, typename BASE_UNIT2, typename DERIVED_UNIT2>
+
bool operator < (typename LLUnitType<STORAGE_TYPE, BASE_UNIT, DERIVED_UNIT>::storage_t first, LLUnitType<STORAGE_TYPE, BASE_UNIT, DERIVED_UNIT> second)
{
return first < second.value();
}
-template<typename STORAGE_TYPE, typename BASE_UNIT, typename DERIVED_UNIT>
-bool operator < (LLUnitType<STORAGE_TYPE, BASE_UNIT, DERIVED_UNIT> first, typename LLUnitType<STORAGE_TYPE, BASE_UNIT, DERIVED_UNIT>::storage_t second)
-{
- return first.value() < second;
-}
-
-template<typename STORAGE_TYPE, typename BASE_UNIT, typename DERIVED_UNIT, typename OTHER_DERIVED_UNIT>
-bool operator < (LLUnitType<STORAGE_TYPE, BASE_UNIT, DERIVED_UNIT> first, LLUnitType<STORAGE_TYPE, BASE_UNIT, OTHER_DERIVED_UNIT> second)
-{
- return first.value() < second.value();
-}
-
//
// operator <=
//
@@ -252,17 +239,6 @@ bool operator <= (typename LLUnitType<STORAGE_TYPE, BASE_UNIT, DERIVED_UNIT>::st
return first <= second.value();
}
-template<typename STORAGE_TYPE, typename BASE_UNIT, typename DERIVED_UNIT>
-bool operator <= (LLUnitType<STORAGE_TYPE, BASE_UNIT, DERIVED_UNIT> first, typename LLUnitType<STORAGE_TYPE, BASE_UNIT, DERIVED_UNIT>::storage_t second)
-{
- return first.value() <= second;
-}
-
-template<typename STORAGE_TYPE, typename BASE_UNIT, typename DERIVED_UNIT, typename OTHER_DERIVED_UNIT>
-bool operator <= (LLUnitType<STORAGE_TYPE, BASE_UNIT, DERIVED_UNIT> first, LLUnitType<STORAGE_TYPE, BASE_UNIT, OTHER_DERIVED_UNIT> second)
-{
- return first.value() <= second.value();
-}
//
// operator >
@@ -273,17 +249,6 @@ bool operator > (typename LLUnitType<STORAGE_TYPE, BASE_UNIT, DERIVED_UNIT>::sto
return first > second.value();
}
-template<typename STORAGE_TYPE, typename BASE_UNIT, typename DERIVED_UNIT>
-bool operator > (LLUnitType<STORAGE_TYPE, BASE_UNIT, DERIVED_UNIT> first, typename LLUnitType<STORAGE_TYPE, BASE_UNIT, DERIVED_UNIT>::storage_t second)
-{
- return first.value() > second;
-}
-
-template<typename STORAGE_TYPE, typename BASE_UNIT, typename DERIVED_UNIT, typename OTHER_DERIVED_UNIT>
-bool operator > (LLUnitType<STORAGE_TYPE, BASE_UNIT, DERIVED_UNIT> first, LLUnitType<STORAGE_TYPE, BASE_UNIT, OTHER_DERIVED_UNIT> second)
-{
- return first.value() > second.value();
-}
//
// operator >=
//
@@ -293,18 +258,6 @@ bool operator >= (typename LLUnitType<STORAGE_TYPE, BASE_UNIT, DERIVED_UNIT>::st
return first >= second.value();
}
-template<typename STORAGE_TYPE, typename BASE_UNIT, typename DERIVED_UNIT>
-bool operator >= (LLUnitType<STORAGE_TYPE, BASE_UNIT, DERIVED_UNIT> first, typename LLUnitType<STORAGE_TYPE, BASE_UNIT, DERIVED_UNIT>::storage_t second)
-{
- return first.value() >= second;
-}
-
-template<typename STORAGE_TYPE, typename BASE_UNIT, typename DERIVED_UNIT, typename OTHER_DERIVED_UNIT>
-bool operator >= (LLUnitType<STORAGE_TYPE, BASE_UNIT, DERIVED_UNIT> first, LLUnitType<STORAGE_TYPE, BASE_UNIT, OTHER_DERIVED_UNIT> second)
-{
- return first.value() >= second.value();
-}
-
//
// operator ==
//
@@ -314,18 +267,6 @@ bool operator == (typename LLUnitType<STORAGE_TYPE, BASE_UNIT, DERIVED_UNIT>::st
return first == second.value();
}
-template<typename STORAGE_TYPE, typename BASE_UNIT, typename DERIVED_UNIT>
-bool operator == (LLUnitType<STORAGE_TYPE, BASE_UNIT, DERIVED_UNIT> first, typename LLUnitType<STORAGE_TYPE, BASE_UNIT, DERIVED_UNIT>::storage_t second)
-{
- return first.value() == second;
-}
-
-template<typename STORAGE_TYPE, typename BASE_UNIT, typename DERIVED_UNIT, typename OTHER_DERIVED_UNIT>
-bool operator == (LLUnitType<STORAGE_TYPE, BASE_UNIT, DERIVED_UNIT> first, LLUnitType<STORAGE_TYPE, BASE_UNIT, OTHER_DERIVED_UNIT> second)
-{
- return first.value() == second.value();
-}
-
//
// operator !=
//
@@ -335,18 +276,6 @@ bool operator != (typename LLUnitType<STORAGE_TYPE, BASE_UNIT, DERIVED_UNIT>::st
return first != second.value();
}
-template<typename STORAGE_TYPE, typename BASE_UNIT, typename DERIVED_UNIT>
-bool operator != (LLUnitType<STORAGE_TYPE, BASE_UNIT, DERIVED_UNIT> first, typename LLUnitType<STORAGE_TYPE, BASE_UNIT, DERIVED_UNIT>::storage_t second)
-{
- return first.value() != second;
-}
-
-template<typename STORAGE_TYPE, typename BASE_UNIT, typename DERIVED_UNIT, typename OTHER_DERIVED_UNIT>
-bool operator != (LLUnitType<STORAGE_TYPE, BASE_UNIT, DERIVED_UNIT> first, LLUnitType<STORAGE_TYPE, BASE_UNIT, OTHER_DERIVED_UNIT> second)
-{
- return first.value() != second.value();
-}
-
#define LL_DECLARE_BASE_UNIT(unit_name) \
template<typename STORAGE> \
struct unit_name : public LLUnitType<STORAGE, unit_name<STORAGE>, unit_name<STORAGE> > \