broke out llunit.h into llunittype.h and llunits.h for unit declarations
changed unit declarations macros to make a lot more sensemaster
parent
7ab616c187
commit
a7aed07a5b
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@
|
|||
#include <vector>
|
||||
|
||||
#include "llframetimer.h"
|
||||
#include "llunit.h"
|
||||
#include "llunits.h"
|
||||
|
||||
class LL_COMMON_API LLSmoothInterpolation
|
||||
{
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@
|
|||
#include <string>
|
||||
|
||||
#include "stdtypes.h"
|
||||
#include "llunit.h"
|
||||
#include "llunits.h"
|
||||
|
||||
/**
|
||||
* @class LLDate
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@
|
|||
#define LLMEMORY_H
|
||||
|
||||
#include "linden_common.h"
|
||||
#include "llunit.h"
|
||||
#include "llunits.h"
|
||||
#if !LL_WINDOWS
|
||||
#include <stdint.h>
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@
|
|||
|
||||
#ifndef LLPROCESSOR_H
|
||||
#define LLPROCESSOR_H
|
||||
#include "llunit.h"
|
||||
#include "llunits.h"
|
||||
|
||||
class LLProcessorInfoImpl;
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@
|
|||
#define LL_LLPACKETACK_H
|
||||
|
||||
#include "llhost.h"
|
||||
#include "llunit.h"
|
||||
#include "llunits.h"
|
||||
|
||||
class LLReliablePacketParams
|
||||
{
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@
|
|||
#include "llpointer.h"
|
||||
#include "llrefcount.h"
|
||||
#include "v2math.h"
|
||||
#include "llunit.h"
|
||||
#include "llunits.h"
|
||||
|
||||
#include "llrender.h"
|
||||
class LLTextureAtlas ;
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@
|
|||
#include "llsys.h" // for LLOSInfo
|
||||
#include "lltimer.h"
|
||||
#include "llappcorehttp.h"
|
||||
#include "llunit.h"
|
||||
#include "llunits.h"
|
||||
|
||||
class LLCommandLineParser;
|
||||
class LLFrameTimer;
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@
|
|||
|
||||
#include "llfloater.h"
|
||||
#include "llfasttimer.h"
|
||||
#include "llunit.h"
|
||||
#include "llunits.h"
|
||||
#include "lltracerecording.h"
|
||||
#include <deque>
|
||||
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@
|
|||
#define LL_LLTEXTUREINFODETAILS_H
|
||||
|
||||
#include "lluuid.h"
|
||||
#include "llunit.h"
|
||||
#include "llunits.h"
|
||||
|
||||
struct LLTextureInfoDetails
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue