summaryrefslogtreecommitdiff
path: root/indra/llcommon/llunit.h
diff options
context:
space:
mode:
authorRichard Linden <none@none>2013-08-26 18:00:24 -0700
committerRichard Linden <none@none>2013-08-26 18:00:24 -0700
commit8535b87544cc2e71896716a4cd1c3c2445ff4af0 (patch)
treef37bc39df9f6ddf30533a2dfa6f294ebda0a4b41 /indra/llcommon/llunit.h
parent662d6a17712fbba5cea0d9cf20f5a2f32e2dd537 (diff)
removed some unecessary template parameters from LLUnit member functions
forced unit conversion code to inline unit conversion now no longer converts all the way to base and back, but tries to find equivalent units as early as possible fixed another llinfos instance scene monitor now outputs n/a for invalid samples
Diffstat (limited to 'indra/llcommon/llunit.h')
-rw-r--r--indra/llcommon/llunit.h40
1 files changed, 17 insertions, 23 deletions
diff --git a/indra/llcommon/llunit.h b/indra/llcommon/llunit.h
index bfc011bb55..1ef4924578 100644
--- a/indra/llcommon/llunit.h
+++ b/indra/llcommon/llunit.h
@@ -82,24 +82,16 @@ struct LLUnit
typedef STORAGE_TYPE storage_t;
// value initialization
- explicit LLUnit(storage_t value = storage_t())
+ LL_FORCE_INLINE explicit LLUnit(storage_t value = storage_t())
: mValue(value)
{}
// unit initialization and conversion
template<typename OTHER_STORAGE, typename OTHER_UNIT>
- LLUnit(LLUnit<OTHER_STORAGE, OTHER_UNIT> other)
+ LL_FORCE_INLINE LLUnit(LLUnit<OTHER_STORAGE, OTHER_UNIT> other)
: mValue(convert(other).mValue)
{}
- // unit assignment
- template<typename OTHER_STORAGE, typename OTHER_UNIT>
- self_t& operator = (LLUnit<OTHER_STORAGE, OTHER_UNIT> other)
- {
- mValue = convert(other).mValue;
- return *this;
- }
-
storage_t value() const
{
return mValue;
@@ -122,14 +114,12 @@ struct LLUnit
*this = LLUnit<storage_t, NEW_UNIT_TYPE>(value);
}
- template<typename OTHER_STORAGE, typename OTHER_UNIT>
- void operator += (LLUnit<OTHER_STORAGE, OTHER_UNIT> other)
+ void operator += (self_t other)
{
mValue += convert(other).mValue;
}
- template<typename OTHER_STORAGE, typename OTHER_UNIT>
- void operator -= (LLUnit<OTHER_STORAGE, OTHER_UNIT> other)
+ void operator -= (self_t other)
{
mValue -= convert(other).mValue;
}
@@ -139,8 +129,7 @@ struct LLUnit
mValue *= multiplicand;
}
- template<typename OTHER_UNIT, typename OTHER_STORAGE>
- void operator *= (LLUnit<OTHER_STORAGE, OTHER_UNIT> multiplicand)
+ void operator *= (self_t multiplicand)
{
// spurious use of dependent type to stop gcc from triggering the static assertion before instantiating the template
LL_BAD_TEMPLATE_INSTANTIATION(OTHER_UNIT, "Multiplication of unit types not supported.");
@@ -151,15 +140,14 @@ struct LLUnit
mValue /= divisor;
}
- template<typename OTHER_UNIT, typename OTHER_STORAGE>
- void operator /= (LLUnit<OTHER_STORAGE, OTHER_UNIT> divisor)
+ void operator /= (self_t divisor)
{
// spurious use of dependent type to stop gcc from triggering the static assertion before instantiating the template
LL_BAD_TEMPLATE_INSTANTIATION(OTHER_UNIT, "Illegal in-place division of unit types.");
}
template<typename SOURCE_STORAGE, typename SOURCE_UNITS>
- static self_t convert(LLUnit<SOURCE_STORAGE, SOURCE_UNITS> v)
+ LL_FORCE_INLINE static self_t convert(LLUnit<SOURCE_STORAGE, SOURCE_UNITS> v)
{
typedef typename LLResultTypePromote<STORAGE_TYPE, SOURCE_STORAGE>::type_t result_storage_t;
LLUnit<result_storage_t, UNIT_TYPE> result;
@@ -258,7 +246,7 @@ std::istream& operator >>(std::istream& s, LLUnitImplicit<STORAGE_TYPE, UNIT_TYP
}
template<typename S1, typename T1, typename S2, typename T2>
-LL_FORCE_INLINE S2 ll_convert_units(LLUnit<S1, T1> in, LLUnit<S2, T2>& out, ...)
+LL_FORCE_INLINE S2 ll_convert_units(LLUnit<S1, T1> in, LLUnit<S2, T2>& out)
{
S2 divisor(1);
@@ -272,7 +260,7 @@ LL_FORCE_INLINE S2 ll_convert_units(LLUnit<S1, T1> in, LLUnit<S2, T2>& out, ...)
// T1 and T2 same type, just assign
out.value((S2)in.value());
}
- else if (LLIsSameType<T2, typename T2::base_unit_t>::value)
+ else if (T1::sLevel > T2::sLevel)
{
// reduce T1
LLUnit<S2, typename T1::base_unit_t> new_in;
@@ -301,6 +289,10 @@ struct LLStorageType<LLUnit<STORAGE_TYPE, UNIT_TYPE> >
typedef STORAGE_TYPE type_t;
};
+// all of these operators need to perform type promotion on the storage type of the units, so they
+// cannot be expressed as operations on identical types with implicit unit conversion
+// e.g. typeof(S32Bytes(x) + F32Megabytes(y)) <==> F32Bytes
+
//
// operator +
//
@@ -677,6 +669,7 @@ struct LLUnitInverseLinearOps
#define LL_DECLARE_BASE_UNIT(base_unit_name, unit_label) \
struct base_unit_name \
{ \
+ static const int sLevel = 0; \
typedef base_unit_name base_unit_t; \
static const char* getUnitLabel() { return unit_label; } \
template<typename T> \
@@ -690,6 +683,7 @@ struct base_unit_name
#define LL_DECLARE_DERIVED_UNIT(base_unit_name, conversion_operation, unit_name, unit_label) \
struct unit_name \
{ \
+ static const int sLevel = base_unit_name::sLevel + 1; \
typedef base_unit_name base_unit_t; \
static const char* getUnitLabel() { return unit_label; } \
template<typename T> \
@@ -700,7 +694,7 @@ struct unit_name
}; \
\
template<typename S1, typename S2> \
-S2 ll_convert_units(LLUnit<S1, unit_name> in, LLUnit<S2, base_unit_name>& out) \
+LL_FORCE_INLINE S2 ll_convert_units(LLUnit<S1, unit_name> in, LLUnit<S2, base_unit_name>& out) \
{ \
typedef typename LLResultTypePromote<S1, S2>::type_t result_storage_t; \
LLUnitLinearOps<result_storage_t> op = \
@@ -710,7 +704,7 @@ S2 ll_convert_units(LLUnit<S1, unit_name> in, LLUnit<S2, base_unit_name>& out)
} \
\
template<typename S1, typename S2> \
-S2 ll_convert_units(LLUnit<S1, base_unit_name> in, LLUnit<S2, unit_name>& out) \
+LL_FORCE_INLINE S2 ll_convert_units(LLUnit<S1, base_unit_name> in, LLUnit<S2, unit_name>& out) \
{ \
typedef typename LLResultTypePromote<S1, S2>::type_t result_storage_t; \
LLUnitInverseLinearOps<result_storage_t> op = \