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.h115
1 files changed, 71 insertions, 44 deletions
diff --git a/indra/llcommon/llunit.h b/indra/llcommon/llunit.h
index 731cc0eded..f81e746c77 100644
--- a/indra/llcommon/llunit.h
+++ b/indra/llcommon/llunit.h
@@ -139,6 +139,22 @@ protected:
};
template<typename STORAGE_TYPE, typename UNIT_TYPE>
+std::ostream& operator <<(std::ostream& s, const LLUnit<STORAGE_TYPE, UNIT_TYPE>& unit)
+{
+ s << unit.value() << UNIT_TYPE::getUnitLabel();
+ return s;
+}
+
+template<typename STORAGE_TYPE, typename UNIT_TYPE>
+std::istream& operator >>(std::istream& s, LLUnit<STORAGE_TYPE, UNIT_TYPE>& unit)
+{
+ STORAGE_TYPE val;
+ s >> val;
+ unit = val;
+ return s;
+}
+
+template<typename STORAGE_TYPE, typename UNIT_TYPE>
struct LLUnitImplicit : public LLUnit<STORAGE_TYPE, UNIT_TYPE>
{
typedef LLUnitImplicit<STORAGE_TYPE, UNIT_TYPE> self_t;
@@ -162,6 +178,21 @@ struct LLUnitImplicit : public LLUnit<STORAGE_TYPE, UNIT_TYPE>
}
};
+template<typename STORAGE_TYPE, typename UNIT_TYPE>
+std::ostream& operator <<(std::ostream& s, const LLUnitImplicit<STORAGE_TYPE, UNIT_TYPE>& unit)
+{
+ s << unit.value() << UNIT_TYPE::getUnitLabel();
+ return s;
+}
+
+template<typename STORAGE_TYPE, typename UNIT_TYPE>
+std::istream& operator >>(std::istream& s, LLUnitImplicit<STORAGE_TYPE, UNIT_TYPE>& unit)
+{
+ STORAGE_TYPE val;
+ s >> val;
+ unit = val;
+ return s;
+}
template<typename S, typename T>
struct LLIsSameType
@@ -188,7 +219,7 @@ LL_FORCE_INLINE void ll_convert_units(LLUnit<S1, T1> in, LLUnit<S2, T2>& out, ..
{
// T1 and T2 fully reduced and equal...just copy
- out = (S2)in.value();
+ out = LLUnit<S2, T2>((S2)in.value());
}
else
{
@@ -434,33 +465,33 @@ template<typename VALUE_TYPE>
struct LLUnitLinearOps
{
typedef LLUnitLinearOps<VALUE_TYPE> self_t;
- LLUnitLinearOps(VALUE_TYPE val) : mValue (val) {}
+ LLUnitLinearOps(VALUE_TYPE val) : mResult (val) {}
- operator VALUE_TYPE() const { return mValue; }
- VALUE_TYPE mValue;
+ operator VALUE_TYPE() const { return mResult; }
+ VALUE_TYPE mResult;
template<typename T>
self_t operator * (T other)
{
- return mValue * other;
+ return mResult * other;
}
template<typename T>
self_t operator / (T other)
{
- return mValue / other;
+ return mResult / other;
}
template<typename T>
self_t operator + (T other)
{
- return mValue + other;
+ return mResult + other;
}
template<typename T>
self_t operator - (T other)
{
- return mValue - other;
+ return mResult - other;
}
};
@@ -469,32 +500,32 @@ struct LLUnitInverseLinearOps
{
typedef LLUnitInverseLinearOps<VALUE_TYPE> self_t;
- LLUnitInverseLinearOps(VALUE_TYPE val) : mValue (val) {}
- operator VALUE_TYPE() const { return mValue; }
- VALUE_TYPE mValue;
+ LLUnitInverseLinearOps(VALUE_TYPE val) : mResult (val) {}
+ operator VALUE_TYPE() const { return mResult; }
+ VALUE_TYPE mResult;
template<typename T>
self_t operator * (T other)
{
- return mValue / other;
+ return mResult / other;
}
template<typename T>
self_t operator / (T other)
{
- return mValue * other;
+ return mResult * other;
}
template<typename T>
self_t operator + (T other)
{
- return mValue - other;
+ return mResult - other;
}
template<typename T>
self_t operator - (T other)
{
- return mValue + other;
+ return mResult + other;
}
};
@@ -508,35 +539,31 @@ struct base_unit_name
template<typename STORAGE_T, typename UNIT_T> \
static LLUnit<STORAGE_T, base_unit_name> fromValue(LLUnit<STORAGE_T, UNIT_T> value) \
{ return LLUnit<STORAGE_T, base_unit_name>(value); } \
-}; \
-template<typename T> std::ostream& operator<<(std::ostream& s, const LLUnit<T, base_unit_name>& val) \
-{ s << val.value() << base_unit_name::getUnitLabel; return s; }
-
-
-#define LL_DECLARE_DERIVED_UNIT(unit_name, unit_label, base_unit_name, conversion_operation) \
-struct unit_name \
-{ \
- typedef base_unit_name base_unit_t; \
- static const char* getUnitLabel() { return unit_label; } \
- template<typename T> \
- static LLUnit<T, unit_name> fromValue(T value) { return LLUnit<T, unit_name>(value); } \
- template<typename STORAGE_T, typename UNIT_T> \
- static LLUnit<STORAGE_T, unit_name> fromValue(LLUnit<STORAGE_T, UNIT_T> value) \
- { return LLUnit<STORAGE_T, unit_name>(value); } \
-}; \
-template<typename T> std::ostream& operator<<(std::ostream& s, const LLUnit<T, unit_name>& val) \
-{ s << val.value() << unit_name::getUnitLabel; return s; } \
- \
-template<typename S1, typename S2> \
-void ll_convert_units(LLUnit<S1, unit_name> in, LLUnit<S2, base_unit_name>& out) \
-{ \
- out = (S2)(LLUnitLinearOps<S1>(in.value()) conversion_operation).mValue; \
-} \
- \
-template<typename S1, typename S2> \
-void ll_convert_units(LLUnit<S1, base_unit_name> in, LLUnit<S2, unit_name>& out) \
-{ \
- out = (S2)(LLUnitInverseLinearOps<S1>(in.value()) conversion_operation).mValue; \
+}
+
+
+#define LL_DECLARE_DERIVED_UNIT(unit_name, unit_label, base_unit_name, conversion_operation) \
+struct unit_name \
+{ \
+ typedef base_unit_name base_unit_t; \
+ static const char* getUnitLabel() { return unit_label; } \
+ template<typename T> \
+ static LLUnit<T, unit_name> fromValue(T value) { return LLUnit<T, unit_name>(value); } \
+ template<typename STORAGE_T, typename UNIT_T> \
+ static LLUnit<STORAGE_T, unit_name> fromValue(LLUnit<STORAGE_T, UNIT_T> value) \
+ { return LLUnit<STORAGE_T, unit_name>(value); } \
+}; \
+ \
+template<typename S1, typename S2> \
+void ll_convert_units(LLUnit<S1, unit_name> in, LLUnit<S2, base_unit_name>& out) \
+{ \
+ out = LLUnit<S2, base_unit_name>((S2)(LLUnitLinearOps<S1>(in.value()) conversion_operation)); \
+} \
+ \
+template<typename S1, typename S2> \
+void ll_convert_units(LLUnit<S1, base_unit_name> in, LLUnit<S2, unit_name>& out) \
+{ \
+ out = LLUnit<S2, unit_name>((S2)(LLUnitInverseLinearOps<S1>(in.value()) conversion_operation)); \
}
//