diff options
Diffstat (limited to 'indra/llcommon')
-rw-r--r-- | indra/llcommon/lltrace.h | 36 | ||||
-rw-r--r-- | indra/llcommon/lltracerecording.h | 2 | ||||
-rw-r--r-- | indra/llcommon/llunit.h | 376 |
3 files changed, 288 insertions, 126 deletions
diff --git a/indra/llcommon/lltrace.h b/indra/llcommon/lltrace.h index 3e19c83bd7..1c6726605a 100644 --- a/indra/llcommon/lltrace.h +++ b/indra/llcommon/lltrace.h @@ -46,6 +46,30 @@ namespace LLTrace { class Recording; + typedef LLUnit::Bytes<F64> Bytes; + typedef LLUnit::Kilobytes<F64> Kilobytes; + typedef LLUnit::Megabytes<F64> Megabytes; + typedef LLUnit::Gigabytes<F64> Gigabytes; + typedef LLUnit::Bits<F64> Bits; + typedef LLUnit::Kilobits<F64> Kilobits; + typedef LLUnit::Megabits<F64> Megabits; + typedef LLUnit::Gigabits<F64> Gigabits; + + typedef LLUnit::Seconds<F64> Seconds; + typedef LLUnit::Milliseconds<F64> Milliseconds; + typedef LLUnit::Minutes<F64> Minutes; + typedef LLUnit::Hours<F64> Hours; + typedef LLUnit::Days<F64> Days; + typedef LLUnit::Weeks<F64> Weeks; + typedef LLUnit::Milliseconds<F64> Milliseconds; + typedef LLUnit::Microseconds<F64> Microseconds; + typedef LLUnit::Nanoseconds<F64> Nanoseconds; + + typedef LLUnit::Meters<F64> Meters; + typedef LLUnit::Kilometers<F64> Kilometers; + typedef LLUnit::Centimeters<F64> Centimeters; + typedef LLUnit::Millimeters<F64> Millimeters; + void init(); void cleanup(); @@ -353,15 +377,15 @@ namespace LLTrace template <typename T> class LL_COMMON_API Measurement <T, typename T::is_unit_t> - : public Measurement<typename T::value_t> + : public Measurement<typename T::storage_t> { public: typedef typename T::storage_t storage_t; typedef typename T::base_unit_t base_unit_t; - typedef Measurement<typename T::value_t> base_measurement_t; + typedef Measurement<typename T::storage_t> base_measurement_t; Measurement(const char* name, const char* description = NULL) - : Measurement<typename T::value_t>(name) + : Measurement<typename T::storage_t>(name, description) {} template<typename UNIT_T> @@ -393,15 +417,15 @@ namespace LLTrace template <typename T> class LL_COMMON_API Count <T, typename T::is_unit_t> - : public Count<typename T::value_t> + : public Count<typename T::storage_t> { public: typedef typename T::storage_t storage_t; typedef typename T::base_unit_t base_unit_t; - typedef Count<typename T::value_t> base_count_t; + typedef Count<typename T::storage_t> base_count_t; Count(const char* name, const char* description = NULL) - : Count<typename T::value_t>(name) + : Count<typename T::storage_t>(name) {} template<typename UNIT_T> diff --git a/indra/llcommon/lltracerecording.h b/indra/llcommon/lltracerecording.h index bd4b944e5a..5e7b0752c6 100644 --- a/indra/llcommon/lltracerecording.h +++ b/indra/llcommon/lltracerecording.h @@ -214,7 +214,7 @@ namespace LLTrace return mRecordingPeriods[(mCurPeriod + mNumPeriods - 1) % mNumPeriods]; } - Recording getCurRecordingPeriod() + Recording& getCurRecordingPeriod() { return mRecordingPeriods[mCurPeriod]; } diff --git a/indra/llcommon/llunit.h b/indra/llcommon/llunit.h index e8f6b2b2ba..d980989c91 100644 --- a/indra/llcommon/llunit.h +++ b/indra/llcommon/llunit.h @@ -34,60 +34,43 @@ template<typename STORAGE_TYPE, typename BASE_UNIT, typename DERIVED_UNIT = BASE struct LLUnitType : public BASE_UNIT { typedef DERIVED_UNIT unit_t; - typedef typename BASE_UNIT::value_t value_t; + + typedef typename STORAGE_TYPE storage_t; typedef void is_unit_t; LLUnitType() {} - explicit LLUnitType(value_t value) + explicit LLUnitType(storage_t value) : BASE_UNIT(convertToBase(value)) {} + // implicit downcast operator unit_t& () { return static_cast<unit_t&>(*this); } - value_t value() const + storage_t value() const { return convertToDerived(mBaseValue); } template<typename CONVERTED_TYPE> - value_t value() const + storage_t value() const { return CONVERTED_TYPE(*this).value(); } - static value_t convertToBase(value_t derived_value) - { - return (value_t)((F32)derived_value * unit_t::conversionToBaseFactor()); - } - - static value_t convertToDerived(value_t base_value) - { - return (value_t)((F32)base_value / unit_t::conversionToBaseFactor()); - } - - unit_t operator + (const unit_t other) const - { - return unit_t(mBaseValue + other.mBaseValue); - } - - unit_t operator - (const unit_t other) const - { - return unit_t(mBaseValue - other.mBaseValue); - } - - unit_t operator * (value_t multiplicand) const +protected: + static storage_t convertToBase(storage_t derived_value) { - return unit_t(mBaseValue * multiplicand); + return (storage_t)((F32)derived_value * unit_t::conversionToBaseFactor()); } - unit_t operator / (value_t divisor) const + static storage_t convertToDerived(storage_t base_value) { - return unit_t(mBaseValue / divisor); + return (storage_t)((F32)base_value / unit_t::conversionToBaseFactor()); } }; @@ -96,43 +79,40 @@ template<typename STORAGE_TYPE, typename T> struct LLUnitType<STORAGE_TYPE, T, T> { typedef T unit_t; - typedef typename STORAGE_TYPE value_t; + typedef STORAGE_TYPE storage_t; typedef void is_unit_t; + typedef T base_unit_t; LLUnitType() : mBaseValue() {} - explicit LLUnitType(value_t value) + explicit LLUnitType(storage_t value) : mBaseValue(value) {} - unit_t& operator=(value_t value) + unit_t& operator=(storage_t value) { setBaseValue(value); return *this; } + //implicit downcast operator unit_t& () { return static_cast<unit_t&>(*this); } - value_t value() const { return mBaseValue; } + storage_t value() const { return mBaseValue; } - static value_t convertToBase(value_t derived_value) + static storage_t convertToBase(storage_t derived_value) { - return (value_t)derived_value; + return (storage_t)derived_value; } - static value_t convertToDerived(value_t base_value) + static storage_t convertToDerived(storage_t base_value) { - return (value_t)base_value; - } - - unit_t operator + (const unit_t other) const - { - return unit_t(mBaseValue + other.mBaseValue); + return (storage_t)base_value; } void operator += (const unit_t other) @@ -140,108 +120,266 @@ struct LLUnitType<STORAGE_TYPE, T, T> mBaseValue += other.mBaseValue; } - unit_t operator - (const unit_t other) const - { - return unit_t(mBaseValue - other.mBaseValue); - } - void operator -= (const unit_t other) { mBaseValue -= other.mBaseValue; } - unit_t operator * (value_t multiplicand) const - { - return unit_t(mBaseValue * multiplicand); - } - - void operator *= (value_t multiplicand) + void operator *= (storage_t multiplicand) { mBaseValue *= multiplicand; } - unit_t operator / (value_t divisor) const - { - return unit_t(mBaseValue / divisor); - } - - void operator /= (value_t divisor) + void operator /= (storage_t divisor) { mBaseValue /= divisor; } protected: - void setBaseValue(value_t value) + void setBaseValue(storage_t value) { mBaseValue = value; } - value_t mBaseValue; + storage_t mBaseValue; }; -#define LL_DECLARE_BASE_UNIT(unit_name) \ - struct unit_name : public LLUnitType<F64, unit_name> \ - { \ - typedef unit_name base_unit_t; \ - typedef LLUnitType<F64, unit_name> unit_t; \ - typedef F64 storage_t; \ - \ - unit_name(F64 value) \ - : LLUnitType(value) \ - {} \ - \ - unit_name() \ - {} \ - \ - template <typename SOURCE_STORAGE_TYPE, typename SOURCE_TYPE> \ - unit_name(const LLUnitType<SOURCE_STORAGE_TYPE, unit_name, SOURCE_TYPE>& source) \ - { \ - setBaseValue((F64)source.unit_name::unit_t::value()); \ - } \ - \ - using LLUnitType::operator +; \ - using LLUnitType::operator +=; \ - using LLUnitType::operator -; \ - using LLUnitType::operator -=; \ - using LLUnitType::operator *; \ - using LLUnitType::operator *=; \ - using LLUnitType::operator /; \ - using LLUnitType::operator /=; \ +// +// 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) +{ + 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()); +} + +// +// 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) +{ + 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()); +} + +// +// 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) +{ + 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); +} + +// +// 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) +{ + 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); +} + +// +// operator < +// +template<typename STORAGE_TYPE, typename BASE_UNIT, typename DERIVED_UNIT> +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 <= +// +template<typename STORAGE_TYPE, typename BASE_UNIT, typename DERIVED_UNIT> +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 > +// +template<typename STORAGE_TYPE, typename BASE_UNIT, typename DERIVED_UNIT> +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 >= +// +template<typename STORAGE_TYPE, typename BASE_UNIT, typename DERIVED_UNIT> +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 == +// +template<typename STORAGE_TYPE, typename BASE_UNIT, typename DERIVED_UNIT> +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 != +// +template<typename STORAGE_TYPE, typename BASE_UNIT, typename DERIVED_UNIT> +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(); +} + +#define LL_DECLARE_BASE_UNIT(unit_name) \ + template<typename STORAGE> \ + struct unit_name : public LLUnitType<STORAGE, unit_name<STORAGE>, unit_name<STORAGE> > \ + { \ + typedef LLUnitType<STORAGE, unit_name> unit_t; \ + \ + unit_name(storage_t value = 0) \ + : LLUnitType(value) \ + {} \ + \ + template <typename SOURCE_STORAGE_TYPE, typename SOURCE_TYPE> \ + unit_name(LLUnitType<SOURCE_STORAGE_TYPE, unit_name<SOURCE_STORAGE_TYPE>, SOURCE_TYPE> source) \ + { \ + setBaseValue((storage_t)source.unit_name<SOURCE_STORAGE_TYPE>::unit_t::value()); \ + } \ + \ }; -#define LL_DECLARE_DERIVED_UNIT(base_unit, derived_unit, conversion_factor) \ - struct derived_unit : public LLUnitType<F64, base_unit, derived_unit> \ - { \ - typedef base_unit base_unit_t; \ - typedef LLUnitType<F64, base_unit, derived_unit> unit_t; \ - typedef F64 storage_t; \ - \ - derived_unit(value_t value) \ - : LLUnitType(value) \ - {} \ - \ - derived_unit() \ - {} \ - \ - template <typename SOURCE_STORAGE_TYPE, typename SOURCE_TYPE> \ - derived_unit(const LLUnitType<SOURCE_STORAGE_TYPE, base_unit, SOURCE_TYPE>& source) \ - { \ - setBaseValue((F64)source.base_unit::unit_t::value()); \ - } \ - \ - static F32 conversionToBaseFactor() { return (F32)(conversion_factor); } \ - \ - using LLUnitType::operator +; \ - using LLUnitType::operator +=; \ - using LLUnitType::operator -; \ - using LLUnitType::operator -=; \ - using LLUnitType::operator *; \ - using LLUnitType::operator *=; \ - using LLUnitType::operator /; \ - using LLUnitType::operator /=; \ +#define LL_DECLARE_DERIVED_UNIT(base_unit, derived_unit, conversion_factor) \ + template<typename STORAGE> \ + struct derived_unit : public LLUnitType<STORAGE, base_unit<STORAGE>, derived_unit<STORAGE> > \ + { \ + typedef LLUnitType<STORAGE, base_unit<STORAGE>, derived_unit<STORAGE> > unit_t; \ + \ + derived_unit(storage_t value = 0) \ + : LLUnitType(value) \ + {} \ + \ + template <typename SOURCE_STORAGE_TYPE, typename SOURCE_TYPE> \ + derived_unit(LLUnitType<SOURCE_STORAGE_TYPE, base_unit<SOURCE_STORAGE_TYPE>, SOURCE_TYPE> source) \ + { \ + setBaseValue((storage_t)source.base_unit<SOURCE_STORAGE_TYPE>::unit_t::value()); \ + } \ + \ + static F32 conversionToBaseFactor() { return (F32)(conversion_factor); } \ + \ }; -namespace LLUnits +namespace LLUnit { LL_DECLARE_BASE_UNIT(Bytes); LL_DECLARE_DERIVED_UNIT(Bytes, Kilobytes, 1024); |