From c812ce5e14cf476526d955edbce2effa9d922902 Mon Sep 17 00:00:00 2001 From: David Crocker Date: Sat, 18 Jan 2020 23:03:39 +0000 Subject: Major refactoring, bug fixes in function evaluation Changed all bitmaps to use the bitmap class from RRFLibraries Fixed bugs in functoin evaluation --- src/ObjectModel/ObjectModel.h | 50 ++++++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 20 deletions(-) (limited to 'src/ObjectModel/ObjectModel.h') diff --git a/src/ObjectModel/ObjectModel.h b/src/ObjectModel/ObjectModel.h index f6514d8d..eac396fc 100644 --- a/src/ObjectModel/ObjectModel.h +++ b/src/ObjectModel/ObjectModel.h @@ -14,6 +14,7 @@ #if SUPPORT_OBJECT_MODEL #include +#include #include typedef uint8_t TypeCode; @@ -21,6 +22,7 @@ constexpr TypeCode NoType = 0; // code for an invalid or unknown type // Dummy types, used to define type codes class Bitmap32; +class Bitmap64; class Enum32; class ObjectModel; // forward declaration class ObjectModelArrayDescriptor; // forward declaration @@ -37,19 +39,21 @@ struct DateTime // Each type must return a unique type code in the range 1 to 127 (0 is NoType) template constexpr TypeCode TypeOf() noexcept; -template<> constexpr TypeCode TypeOf() noexcept { return 1; } -template<> constexpr TypeCode TypeOf() noexcept { return 2; } -template<> constexpr TypeCode TypeOf() noexcept { return 3; } -template<> constexpr TypeCode TypeOf() noexcept { return 4; } -template<> constexpr TypeCode TypeOf() noexcept { return 5; } -template<> constexpr TypeCode TypeOf() noexcept { return 6; } -template<> constexpr TypeCode TypeOf() noexcept { return 7; } -template<> constexpr TypeCode TypeOf() noexcept { return 8; } -template<> constexpr TypeCode TypeOf() noexcept { return 9; } -template<> constexpr TypeCode TypeOf() noexcept { return 10; } -template<> constexpr TypeCode TypeOf() noexcept { return 11; } -template<> constexpr TypeCode TypeOf() noexcept { return 12; } -template<> constexpr TypeCode TypeOf() noexcept { return 13; } +template<> constexpr TypeCode TypeOf () noexcept { return 1; } +template<> constexpr TypeCode TypeOf () noexcept { return 2; } +template<> constexpr TypeCode TypeOf () noexcept { return 3; } +template<> constexpr TypeCode TypeOf () noexcept { return 4; } +template<> constexpr TypeCode TypeOf () noexcept { return 5; } +template<> constexpr TypeCode TypeOf> () noexcept { return 6; } +template<> constexpr TypeCode TypeOf> () noexcept { return 7; } +template<> constexpr TypeCode TypeOf> () noexcept { return 8; } +template<> constexpr TypeCode TypeOf () noexcept { return 9; } +template<> constexpr TypeCode TypeOf () noexcept { return 10; } +template<> constexpr TypeCode TypeOf () noexcept { return 11; } +template<> constexpr TypeCode TypeOf () noexcept { return 12; } +template<> constexpr TypeCode TypeOf () noexcept { return 13; } +template<> constexpr TypeCode TypeOf () noexcept { return 14; } +template<> constexpr TypeCode TypeOf () noexcept { return 15; } #define TYPE_OF(_t) (TypeOf<_t>()) @@ -61,9 +65,9 @@ class StringParser; // Struct used to hold the expressions with polymorphic types struct ExpressionValue { - TypeCode type; // what type is stored in the union - uint8_t param; // additional parameter, e.g. number of usual displayed decimal places for a float, - // or table # for an ObjectModel, or 8 extra bits for a date/time + uint32_t type : 8, // what type is stored in the union + param : 24; // additional parameter, e.g. number of usual displayed decimal places for a float, + // or table # for an ObjectModel, or 24 extra bits for a date/time or a long bitmap union { bool bVal; @@ -72,14 +76,14 @@ struct ExpressionValue int32_t iVal; uint32_t uVal; // used for enumerations, bitmaps and IP addresses (not for integers, we always use int32_t for those) const char *sVal; - const ObjectModel *omVal; // object of some class derived form ObkectModel + const ObjectModel *omVal; // object of some class derived form ObjectModel const ObjectModelArrayDescriptor *omadVal; }; ExpressionValue() noexcept : type(NoType) { } explicit constexpr ExpressionValue(bool b) noexcept : type(TYPE_OF(bool)), param(0), bVal(b) { } explicit constexpr ExpressionValue(char c) noexcept : type(TYPE_OF(char)), param(0), cVal(c) { } - explicit constexpr ExpressionValue(float f) noexcept : type(TYPE_OF(float)), param(1), fVal(f) { } + explicit constexpr ExpressionValue(float f) noexcept : type(TYPE_OF(float)), param(MaxFloatDigitsDisplayedAfterPoint), fVal(f) { } constexpr ExpressionValue(float f, uint8_t numDecimalPlaces) noexcept : type(TYPE_OF(float)), param(numDecimalPlaces), fVal(f) { } explicit constexpr ExpressionValue(int32_t i) noexcept : type(TYPE_OF(int32_t)), param(0), iVal(i) { } explicit constexpr ExpressionValue(const ObjectModel *om) noexcept : type(TYPE_OF(const ObjectModel*)), param(0), omVal(om) { } @@ -90,6 +94,9 @@ struct ExpressionValue explicit constexpr ExpressionValue(nullptr_t dummy) noexcept : type(NoType), param(0), uVal(0) { } explicit ExpressionValue(DateTime t) noexcept : type((t.tim == 0) ? NoType : TYPE_OF(DateTime)), param(t.tim >> 32), uVal((uint32_t)t.tim) { } explicit ExpressionValue(DriverId id) noexcept : type(TYPE_OF(DriverId)), param(0), uVal(id.AsU32()) { } + explicit ExpressionValue(Bitmap bm) noexcept : type(TYPE_OF(Bitmap)), param(0), uVal(bm.GetRaw()) { } + explicit ExpressionValue(Bitmap bm) noexcept : type(TYPE_OF(Bitmap)), param(0), uVal(bm.GetRaw()) { } + explicit ExpressionValue(Bitmap bm) noexcept : type(TYPE_OF(Bitmap)), param(bm.GetRaw() >> 32), uVal((uint32_t)bm.GetRaw()) { } void Set(bool b) noexcept { type = TYPE_OF(bool); bVal = b; } void Set(char c) noexcept { type = TYPE_OF(char); cVal = c; } @@ -98,8 +105,11 @@ struct ExpressionValue void Set(float f) noexcept { type = TYPE_OF(float); fVal = f; param = 1; } void Set(const char *s) noexcept { type = TYPE_OF(const char*); sVal = s; } - // Extract a 40-bit value that we have stored. Used to retrieve date/times. - uint64_t Get40BitValue() const noexcept { return ((uint64_t)param << 32) | uVal; } + // Extract a 56-bit value that we have stored. Used to retrieve date/times and large bitmaps. + uint64_t Get56BitValue() const noexcept { return ((uint64_t)param << 32) | uVal; } + + // Get the format string to use assuming this is a floating point number + const char *GetFloatFormatString() const noexcept; }; // Flags field of a table entry -- cgit v1.2.3