summaryrefslogtreecommitdiff
path: root/indra/llcommon
diff options
context:
space:
mode:
Diffstat (limited to 'indra/llcommon')
-rwxr-xr-xindra/llcommon/CMakeLists.txt3
-rwxr-xr-xindra/llcommon/llcriticaldamp.h2
-rwxr-xr-xindra/llcommon/lldate.h2
-rwxr-xr-xindra/llcommon/llerror.h12
-rwxr-xr-xindra/llcommon/llfasttimer.cpp2
-rwxr-xr-xindra/llcommon/llmemory.h2
-rwxr-xr-xindra/llcommon/llpreprocessor.h6
-rwxr-xr-xindra/llcommon/llprocessor.h2
-rwxr-xr-xindra/llcommon/lltimer.h2
-rw-r--r--indra/llcommon/lltraceaccumulators.h2
-rw-r--r--indra/llcommon/llunittype.h (renamed from indra/llcommon/llunit.h)112
-rw-r--r--indra/llcommon/tests/lltrace_test.cpp8
-rw-r--r--indra/llcommon/tests/llunits_test.cpp73
13 files changed, 99 insertions, 129 deletions
diff --git a/indra/llcommon/CMakeLists.txt b/indra/llcommon/CMakeLists.txt
index 62880b07f6..e138a54d29 100755
--- a/indra/llcommon/CMakeLists.txt
+++ b/indra/llcommon/CMakeLists.txt
@@ -209,7 +209,8 @@ set(llcommon_HEADER_FILES
lltracerecording.h
lltracethreadrecorder.h
lltreeiterators.h
- llunit.h
+ llunits.h
+ llunittype.h
lluri.h
lluuid.h
llwin32headers.h
diff --git a/indra/llcommon/llcriticaldamp.h b/indra/llcommon/llcriticaldamp.h
index a02a2a0dcf..1fb6a1af29 100755
--- a/indra/llcommon/llcriticaldamp.h
+++ b/indra/llcommon/llcriticaldamp.h
@@ -31,7 +31,7 @@
#include <vector>
#include "llframetimer.h"
-#include "llunit.h"
+#include "llunits.h"
class LL_COMMON_API LLSmoothInterpolation
{
diff --git a/indra/llcommon/lldate.h b/indra/llcommon/lldate.h
index aecf3b765e..be2cd2d051 100755
--- a/indra/llcommon/lldate.h
+++ b/indra/llcommon/lldate.h
@@ -33,7 +33,7 @@
#include <string>
#include "stdtypes.h"
-#include "llunit.h"
+#include "llunits.h"
/**
* @class LLDate
diff --git a/indra/llcommon/llerror.h b/indra/llcommon/llerror.h
index 0d6f1810d2..1ddb4874a0 100755
--- a/indra/llcommon/llerror.h
+++ b/indra/llcommon/llerror.h
@@ -357,12 +357,12 @@ typedef LLError::NoClassInfo _LL_CLASS_TO_LOG;
#define LL_WARNS_ONCE(...) lllog(LLError::LEVEL_WARN, true, ##__VA_ARGS__)
// DEPRECATED: Use the new macros that allow tags and *look* like macros.
-#define lldebugs LL_COMPILE_TIME_WARNING("Warning: lldebugs deprecated, use LL_DEBUGS() instead"); LL_DEBUGS()
-#define llinfos LL_COMPILE_TIME_WARNING("Warning: llinfos deprecated, use LL_INFOS() instead"); LL_INFOS()
-#define llwarns LL_COMPILE_TIME_WARNING("Warning: llwarns deprecated, use LL_WARNS() instead"); LL_WARNS()
-#define llerrs LL_COMPILE_TIME_WARNING("Warning: llerrs deprecated, use LL_ERRS() instead"); LL_ERRS()
-#define llcont LL_COMPILE_TIME_WARNING("Warning: llcont deprecated, use LL_CONT instead"); LL_CONT
-#define llendl LL_COMPILE_TIME_WARNING("Warning: llendl deprecated, use LL_ENDL instead"); LL_ENDL
+#define lldebugs LL_COMPILE_TIME_MESSAGE("Warning: lldebugs deprecated, use LL_DEBUGS() instead"); LL_DEBUGS()
+#define llinfos LL_COMPILE_TIME_MESSAGE("Warning: llinfos deprecated, use LL_INFOS() instead"); LL_INFOS()
+#define llwarns LL_COMPILE_TIME_MESSAGE("Warning: llwarns deprecated, use LL_WARNS() instead"); LL_WARNS()
+#define llerrs LL_COMPILE_TIME_MESSAGE("Warning: llerrs deprecated, use LL_ERRS() instead"); LL_ERRS()
+#define llcont LL_COMPILE_TIME_MESSAGE("Warning: llcont deprecated, use LL_CONT instead"); LL_CONT
+#define llendl LL_COMPILE_TIME_MESSAGE("Warning: llendl deprecated, use LL_ENDL instead"); LL_ENDL
#endif // LL_LLERROR_H
diff --git a/indra/llcommon/llfasttimer.cpp b/indra/llcommon/llfasttimer.cpp
index ae3234a87a..2235eb1a08 100755
--- a/indra/llcommon/llfasttimer.cpp
+++ b/indra/llcommon/llfasttimer.cpp
@@ -32,7 +32,7 @@
#include "llsingleton.h"
#include "lltreeiterators.h"
#include "llsdserialize.h"
-#include "llunit.h"
+#include "llunits.h"
#include "llsd.h"
#include "lltracerecording.h"
#include "lltracethreadrecorder.h"
diff --git a/indra/llcommon/llmemory.h b/indra/llcommon/llmemory.h
index 23be1e5b2d..d3c5e5235d 100755
--- a/indra/llcommon/llmemory.h
+++ b/indra/llcommon/llmemory.h
@@ -27,7 +27,7 @@
#define LLMEMORY_H
#include "linden_common.h"
-#include "llunit.h"
+#include "llunits.h"
#if !LL_WINDOWS
#include <stdint.h>
#endif
diff --git a/indra/llcommon/llpreprocessor.h b/indra/llcommon/llpreprocessor.h
index f00885ae2f..0fcc872690 100755
--- a/indra/llcommon/llpreprocessor.h
+++ b/indra/llcommon/llpreprocessor.h
@@ -193,12 +193,10 @@
#define LL_TO_STRING(x) LL_TO_STRING_HELPER(x)
#define LL_FILE_LINENO(msg) __FILE__ "(" LL_TO_STRING(__LINE__) ") : " msg
#if LL_WINDOWS
-#define LL_COMPILE_TIME_WARNING(msg) __pragma(message(LL_FILE_LINENO(msg)))
-#define LL_COMPILE_TIME_ERROR(msg) static_assert(false, msg)
+#define LL_COMPILE_TIME_MESSAGE(msg) __pragma(message(LL_FILE_LINENO(msg)))
#else
// no way to get gcc 4.2 to print a user-defined diagnostic message only when a macro is used
-#define LL_COMPILE_TIME_WARNING(msg)
-#define LL_COMPILE_TIME_ERROR(msg)
+#define LL_COMPILE_TIME_MESSAGE(msg)
#endif
#endif // not LL_LINDEN_PREPROCESSOR_H
diff --git a/indra/llcommon/llprocessor.h b/indra/llcommon/llprocessor.h
index 4956a39700..90e5bc59ee 100755
--- a/indra/llcommon/llprocessor.h
+++ b/indra/llcommon/llprocessor.h
@@ -27,7 +27,7 @@
#ifndef LLPROCESSOR_H
#define LLPROCESSOR_H
-#include "llunit.h"
+#include "llunits.h"
class LLProcessorInfoImpl;
diff --git a/indra/llcommon/lltimer.h b/indra/llcommon/lltimer.h
index 8b3930e2fa..4e58102094 100755
--- a/indra/llcommon/lltimer.h
+++ b/indra/llcommon/lltimer.h
@@ -37,7 +37,7 @@
#include <string>
#include <list>
// units conversions
-#include "llunit.h"
+#include "llunits.h"
#ifndef USEC_PER_SEC
const U32 USEC_PER_SEC = 1000000;
#endif
diff --git a/indra/llcommon/lltraceaccumulators.h b/indra/llcommon/lltraceaccumulators.h
index bf195f72b1..e0f60800e3 100644
--- a/indra/llcommon/lltraceaccumulators.h
+++ b/indra/llcommon/lltraceaccumulators.h
@@ -31,7 +31,7 @@
#include "stdtypes.h"
#include "llpreprocessor.h"
-#include "llunit.h"
+#include "llunits.h"
#include "lltimer.h"
#include "llrefcount.h"
#include "llthreadlocalstorage.h"
diff --git a/indra/llcommon/llunit.h b/indra/llcommon/llunittype.h
index 798d97a46e..949e4492c7 100644
--- a/indra/llcommon/llunit.h
+++ b/indra/llcommon/llunittype.h
@@ -24,8 +24,8 @@
* $/LicenseInfo$
*/
-#ifndef LL_LLUNIT_H
-#define LL_LLUNIT_H
+#ifndef LL_UNITTYPE_H
+#define LL_UNITTYPE_H
#include "stdtypes.h"
#include "llpreprocessor.h"
@@ -684,7 +684,7 @@ struct base_unit_name
}
-#define LL_DECLARE_DERIVED_UNIT(base_unit_name, conversion_operation, unit_name, unit_label) \
+#define LL_DECLARE_DERIVED_UNIT(unit_name, unit_label, base_unit_name, conversion_operation) \
struct unit_name \
{ \
static const int sLevel = base_unit_name::sLevel + 1; \
@@ -701,8 +701,8 @@ template<typename S1, typename S2>
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 = \
- LLUnitLinearOps<result_storage_t>(in.value()) conversion_operation; \
+ LLUnitInverseLinearOps<result_storage_t> op = \
+ LLUnitInverseLinearOps<result_storage_t>(in.value()) conversion_operation; \
out = LLUnit<S2, base_unit_name>((S2)op.mValue); \
return op.mDivisor; \
} \
@@ -711,8 +711,8 @@ template<typename S1, typename S2>
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 = \
- LLUnitInverseLinearOps<result_storage_t>(in.value()) conversion_operation; \
+ LLUnitLinearOps<result_storage_t> op = \
+ LLUnitLinearOps<result_storage_t>(in.value()) conversion_operation; \
out = LLUnit<S2, unit_name>((S2)op.mValue); \
return op.mDivisor; \
}
@@ -731,100 +731,4 @@ LL_FORCE_INLINE S2 ll_convert_units(LLUnit<S1, base_unit_name> in, LLUnit<S2, un
typedef LLUnit<U64, ns::unit_name> U64##unit_name; \
typedef LLUnitImplicit<U64, ns::unit_name> U64##unit_name##Implicit
-//
-// Unit declarations
-//
-
-namespace LLUnits
-{
-LL_DECLARE_BASE_UNIT(Bytes, "B");
-// technically, these are kibibytes, mibibytes, etc. but we should stick with commonly accepted terminology
-LL_DECLARE_DERIVED_UNIT(Bytes, * 1024, Kilobytes, "KB");
-LL_DECLARE_DERIVED_UNIT(Kilobytes, * 1024, Megabytes, "MB");
-LL_DECLARE_DERIVED_UNIT(Megabytes, * 1024, Gigabytes, "GB");
-}
-
-LL_DECLARE_UNIT_TYPEDEFS(LLUnits, Bytes);
-LL_DECLARE_UNIT_TYPEDEFS(LLUnits, Kilobytes);
-LL_DECLARE_UNIT_TYPEDEFS(LLUnits, Megabytes);
-LL_DECLARE_UNIT_TYPEDEFS(LLUnits, Gigabytes);
-
-namespace LLUnits
-{
-// technically, these are kibibits, mibibits, etc. but we should stick with commonly accepted terminology
-LL_DECLARE_DERIVED_UNIT(Bytes, / 8, Bits, "b");
-LL_DECLARE_DERIVED_UNIT(Bits, * 1024, Kilobits, "Kb");
-LL_DECLARE_DERIVED_UNIT(Kilobits, * 1024, Megabits, "Mb");
-LL_DECLARE_DERIVED_UNIT(Megabits, * 1024, Gigabits, "Gb");
-}
-
-LL_DECLARE_UNIT_TYPEDEFS(LLUnits, Bits);
-LL_DECLARE_UNIT_TYPEDEFS(LLUnits, Kilobits);
-LL_DECLARE_UNIT_TYPEDEFS(LLUnits, Megabits);
-LL_DECLARE_UNIT_TYPEDEFS(LLUnits, Gigabits);
-
-namespace LLUnits
-{
-LL_DECLARE_BASE_UNIT(Seconds, "s");
-LL_DECLARE_DERIVED_UNIT(Seconds, * 60, Minutes, "min");
-LL_DECLARE_DERIVED_UNIT(Minutes, * 60, Hours, "h");
-LL_DECLARE_DERIVED_UNIT(Hours, * 24, Days, "d");
-LL_DECLARE_DERIVED_UNIT(Seconds, / 1000, Milliseconds, "ms");
-LL_DECLARE_DERIVED_UNIT(Milliseconds, / 1000, Microseconds, "\x09\x3cs");
-LL_DECLARE_DERIVED_UNIT(Microseconds, / 1000, Nanoseconds, "ns");
-}
-
-LL_DECLARE_UNIT_TYPEDEFS(LLUnits, Seconds);
-LL_DECLARE_UNIT_TYPEDEFS(LLUnits, Minutes);
-LL_DECLARE_UNIT_TYPEDEFS(LLUnits, Hours);
-LL_DECLARE_UNIT_TYPEDEFS(LLUnits, Days);
-LL_DECLARE_UNIT_TYPEDEFS(LLUnits, Milliseconds);
-LL_DECLARE_UNIT_TYPEDEFS(LLUnits, Microseconds);
-LL_DECLARE_UNIT_TYPEDEFS(LLUnits, Nanoseconds);
-
-namespace LLUnits
-{
-LL_DECLARE_BASE_UNIT(Meters, "m");
-LL_DECLARE_DERIVED_UNIT(Meters, * 1000, Kilometers, "km");
-LL_DECLARE_DERIVED_UNIT(Meters, / 100, Centimeters, "cm");
-LL_DECLARE_DERIVED_UNIT(Meters, / 1000, Millimeters, "mm");
-}
-
-LL_DECLARE_UNIT_TYPEDEFS(LLUnits, Meters);
-LL_DECLARE_UNIT_TYPEDEFS(LLUnits, Kilometers);
-LL_DECLARE_UNIT_TYPEDEFS(LLUnits, Centimeters);
-LL_DECLARE_UNIT_TYPEDEFS(LLUnits, Millimeters);
-
-namespace LLUnits
-{
-// rare units
-LL_DECLARE_BASE_UNIT(Hertz, "Hz");
-LL_DECLARE_DERIVED_UNIT(Hertz, * 1000, Kilohertz, "KHz");
-LL_DECLARE_DERIVED_UNIT(Kilohertz, * 1000, Megahertz, "MHz");
-LL_DECLARE_DERIVED_UNIT(Megahertz, * 1000, Gigahertz, "GHz");
-
-LL_DECLARE_BASE_UNIT(Radians, "rad");
-LL_DECLARE_DERIVED_UNIT(Radians, / 57.29578f, Degrees, "deg");
-
-LL_DECLARE_BASE_UNIT(Percent, "%");
-LL_DECLARE_DERIVED_UNIT(Percent, * 100, Ratio, "x");
-
-LL_DECLARE_BASE_UNIT(Triangles, "tris");
-LL_DECLARE_DERIVED_UNIT(Triangles, * 1000, Kilotriangles, "ktris");
-
-} // namespace LLUnits
-
-// rare units
-LL_DECLARE_UNIT_TYPEDEFS(LLUnits, Hertz);
-LL_DECLARE_UNIT_TYPEDEFS(LLUnits, Kilohertz);
-LL_DECLARE_UNIT_TYPEDEFS(LLUnits, Megahertz);
-LL_DECLARE_UNIT_TYPEDEFS(LLUnits, Gigahertz);
-LL_DECLARE_UNIT_TYPEDEFS(LLUnits, Radians);
-LL_DECLARE_UNIT_TYPEDEFS(LLUnits, Degrees);
-LL_DECLARE_UNIT_TYPEDEFS(LLUnits, Percent);
-LL_DECLARE_UNIT_TYPEDEFS(LLUnits, Ratio);
-LL_DECLARE_UNIT_TYPEDEFS(LLUnits, Triangles);
-LL_DECLARE_UNIT_TYPEDEFS(LLUnits, Kilotriangles);
-
-
-#endif // LL_LLUNIT_H
+#endif //LL_UNITTYPE_H
diff --git a/indra/llcommon/tests/lltrace_test.cpp b/indra/llcommon/tests/lltrace_test.cpp
index 1c2a4528ae..8ce509699d 100644
--- a/indra/llcommon/tests/lltrace_test.cpp
+++ b/indra/llcommon/tests/lltrace_test.cpp
@@ -36,12 +36,12 @@ namespace LLUnits
{
// using powers of 2 to allow strict floating point equality
LL_DECLARE_BASE_UNIT(Ounces, "oz");
- LL_DECLARE_DERIVED_UNIT(Ounces, * 12, TallCup, "");
- LL_DECLARE_DERIVED_UNIT(Ounces, * 16, GrandeCup, "");
- LL_DECLARE_DERIVED_UNIT(Ounces, * 20, VentiCup, "");
+ LL_DECLARE_DERIVED_UNIT(TallCup, "", Ounces, / 12);
+ LL_DECLARE_DERIVED_UNIT(GrandeCup, "", Ounces, / 16);
+ LL_DECLARE_DERIVED_UNIT(VentiCup, "", Ounces, / 20);
LL_DECLARE_BASE_UNIT(Grams, "g");
- LL_DECLARE_DERIVED_UNIT(Grams, / 1000, Milligrams, "mg");
+ LL_DECLARE_DERIVED_UNIT(Milligrams, "mg", Grams, * 1000);
}
LL_DECLARE_UNIT_TYPEDEFS(LLUnits, Ounces);
diff --git a/indra/llcommon/tests/llunits_test.cpp b/indra/llcommon/tests/llunits_test.cpp
index 31d4f86159..5a18603e4e 100644
--- a/indra/llcommon/tests/llunits_test.cpp
+++ b/indra/llcommon/tests/llunits_test.cpp
@@ -27,15 +27,15 @@
#include "linden_common.h"
-#include "llunit.h"
+#include "llunits.h"
#include "../test/lltut.h"
namespace LLUnits
{
// using powers of 2 to allow strict floating point equality
LL_DECLARE_BASE_UNIT(Quatloos, "Quat");
- LL_DECLARE_DERIVED_UNIT(Quatloos, * 4, Latinum, "Lat");
- LL_DECLARE_DERIVED_UNIT(Latinum, / 16, Solari, "Sol");
+ LL_DECLARE_DERIVED_UNIT(Latinum, "Lat", Quatloos, / 4);
+ LL_DECLARE_DERIVED_UNIT(Solari, "Sol", Latinum, * 16);
}
LL_DECLARE_UNIT_TYPEDEFS(LLUnits, Quatloos);
@@ -256,6 +256,12 @@ namespace tut
// conversion of implicits
LLUnitImplicit<F32, Latinum> latinum_implicit(2);
ensure("implicit units of different types are comparable", latinum_implicit * 2 == quatloos_implicit);
+
+ quatloos_implicit += F32Quatloos(10);
+ ensure("can add-assign explicit units", quatloos_implicit == 26);
+
+ quatloos_implicit -= F32Quatloos(10);
+ ensure("can subtract-assign explicit units", quatloos_implicit == 16);
}
// precision tests
@@ -272,4 +278,65 @@ namespace tut
mega_bytes = (U32Megabytes)5 + (S32Megabytes)-1;
ensure("can mix unsigned and signed in units addition", mega_bytes == (S32Megabytes)4);
}
+
+ // default units
+ template<> template<>
+ void units_object_t::test<9>()
+ {
+ U32Gigabytes GB(1);
+ U32Megabytes MB(GB);
+ U32Kilobytes KB(GB);
+ U32Bytes B(GB);
+
+ ensure("GB -> MB conversion", MB.value() == 1024);
+ ensure("GB -> KB conversion", KB.value() == 1024 * 1024);
+ ensure("GB -> B conversion", B.value() == 1024 * 1024 * 1024);
+
+ KB = U32Kilobytes(1);
+ U32Kilobits Kb(KB);
+ U32Bits b(KB);
+ ensure("KB -> Kb conversion", Kb.value() == 8);
+ ensure("KB -> b conversion", b.value() == 8 * 1024);
+
+ U32Days days(1);
+ U32Hours hours(days);
+ U32Minutes minutes(days);
+ U32Seconds seconds(days);
+ U32Milliseconds ms(days);
+
+ ensure("days -> hours conversion", hours.value() == 24);
+ ensure("days -> minutes conversion", minutes.value() == 24 * 60);
+ ensure("days -> seconds conversion", seconds.value() == 24 * 60 * 60);
+ ensure("days -> ms conversion", ms.value() == 24 * 60 * 60 * 1000);
+
+ U32Kilometers km(1);
+ U32Meters m(km);
+ U32Centimeters cm(km);
+ U32Millimeters mm(km);
+
+ ensure("km -> m conversion", m.value() == 1000);
+ ensure("km -> cm conversion", cm.value() == 1000 * 100);
+ ensure("km -> mm conversion", mm.value() == 1000 * 1000);
+
+ U32Gigahertz GHz(1);
+ U32Megahertz MHz(GHz);
+ U32Kilohertz KHz(GHz);
+ U32Hertz Hz(GHz);
+
+ ensure("GHz -> MHz conversion", MHz.value() == 1000);
+ ensure("GHz -> KHz conversion", KHz.value() == 1000 * 1000);
+ ensure("GHz -> Hz conversion", Hz.value() == 1000 * 1000 * 1000);
+
+ F32Radians rad(6.2831853071795f);
+ F32Degrees deg(rad);
+ ensure("radians -> degrees conversion", deg.value() > 359 && deg.value() < 361);
+
+ F32Percent percent(50);
+ F32Ratio ratio(percent);
+ ensure("percent -> ratio conversion", ratio.value() == 0.5f);
+
+ U32Kilotriangles ktris(1);
+ U32Triangles tris(ktris);
+ ensure("kilotriangles -> triangles conversion", tris.value() == 1000);
+ }
}