From 4eadb321aa742abfc31686ea7bc577fb1c25d5dd Mon Sep 17 00:00:00 2001 From: David Crocker Date: Sat, 11 Jan 2020 11:40:42 +0000 Subject: Added Job members to object model Also changed all calls to gmtime to use gmtime_r instead, for thread safety --- src/ObjectModel/ObjectModel.h | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'src/ObjectModel/ObjectModel.h') diff --git a/src/ObjectModel/ObjectModel.h b/src/ObjectModel/ObjectModel.h index 75d3a723..6d860a40 100644 --- a/src/ObjectModel/ObjectModel.h +++ b/src/ObjectModel/ObjectModel.h @@ -25,6 +25,14 @@ class Enum32; class ObjectModel; // forward declaration class ObjectModelArrayDescriptor; // forward declaration +// Encapsulated time_t, used to facilitate overloading the ExpressionValue constructor +struct DateTime +{ + DateTime(time_t t) : tim(t) { } + + time_t tim; +}; + // Function template used to get constexpr type codes // Each type must return a unique type code in the range 1 to 127 (0 is NoType) template constexpr TypeCode TypeOf() noexcept; @@ -40,6 +48,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; } #define TYPE_OF(_t) (TypeOf<_t>()) @@ -58,7 +67,8 @@ class StringParser; 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 + 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 union { bool bVal; @@ -83,6 +93,7 @@ struct ExpressionValue explicit constexpr ExpressionValue(const ObjectModelArrayDescriptor *omad) noexcept : type(TYPE_OF(const ObjectModelArrayDescriptor*)), param(0), omadVal(omad) { } explicit constexpr ExpressionValue(IPAddress ip) noexcept : type(TYPE_OF(IPAddress)), param(0), uVal(ip.GetV4LittleEndian()) { } explicit constexpr ExpressionValue(nullptr_t dummy) noexcept : type(NoType), param(0), uVal(0) { } + explicit ExpressionValue(DateTime t) noexcept : type(TYPE_OF(DateTime)), param(t.tim >> 32), uVal((uint32_t)t.tim) { } void Set(bool b) noexcept { type = TYPE_OF(bool); bVal = b; } void Set(char c) noexcept { type = TYPE_OF(char); cVal = c; } @@ -90,6 +101,9 @@ struct ExpressionValue void Set(int i) noexcept { type = TYPE_OF(int32_t); iVal = i; } 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; } }; enum class ObjectModelReportFlags : uint16_t -- cgit v1.2.3