Skip to content

Commit

Permalink
zoneinfo: move ZoneInfo structs and Brokers into 'zoneinfo' namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
bxparks committed Jun 4, 2023
1 parent 732a0a9 commit 2ba3adb
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 73 deletions.
43 changes: 0 additions & 43 deletions src/zoneinfo/BrokerCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,49 +18,6 @@ class __FlashStringHelper;

namespace ace_time {
namespace internal {
/**
* Convert the `deltaCode` in the ZoneInfo or the ZoneRule struct to the actual
* deltaMinutes. The lower 4-bits stores minutes in units of 15-minutes, shifted
* by 1h, so can represent the interval [-01:00 to 02:45].
*
* @code
* deltaMinutes = deltaCode * 15m - 1h
* @endcode
*/
inline int16_t toDeltaMinutes(uint8_t deltaCode) {
return ((int16_t)(deltaCode & 0x0f) - 4) * 15;
}

/**
* Convert the `offsetCode` and `deltaCode` into a signed 16-bit integer that
* represents the UTCOFF of the ZoneEra in minutes. The `offsetCode` is rounded
* towards -infinity in 15-minute multiples. The upper 4-bits of `deltaCode`
* holds the (unsigned) remainder in one-minute increments.
*/
inline int16_t toOffsetMinutes(int8_t offsetCode, uint8_t deltaCode) {
return (offsetCode * 15) + (((uint8_t)deltaCode & 0xf0) >> 4);
}


/**
* Convert (code, modifier) fields representing the UNTIL time in ZoneInfo or AT
* time in ZoneRule in one minute resolution. The `code` parameter holds the AT
* or UNTIL time in minutes component in units of 15 minutes. The lower 4-bits
* of `modifier` holds the remainder minutes.
*/
inline uint16_t timeCodeToMinutes(uint8_t code, uint8_t modifier) {
return code * (uint16_t) 15 + (modifier & 0x0f);
}

/**
* Extract the 'w', 's' 'u' suffix from the 'modifier' field, so that they can
* be compared against kSuffixW, kSuffixS and kSuffixU. Used for Zone.UNTIL and
* Rule.AT fields.
*/
inline uint8_t toSuffix(uint8_t modifier) {
return modifier & 0xf0;
}

/**
* Return a pointer to the short name of a full ZoneName. The short name is the
* last component, which usually begins after the last separator '/'. If the
Expand Down
84 changes: 67 additions & 17 deletions src/zoneinfo/Brokers.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,54 @@ class __FlashStringHelper;
class Print;

namespace ace_time {
namespace internal {
namespace zoneinfo {

//-----------------------------------------------------------------------------

/**
* Convert the `deltaCode` in the ZoneInfo or the ZoneRule struct to the actual
* deltaMinutes. The lower 4-bits stores minutes in units of 15-minutes, shifted
* by 1h, so can represent the interval [-01:00 to 02:45].
*
* @code
* deltaMinutes = deltaCode * 15m - 1h
* @endcode
*/
inline int16_t toDeltaMinutes(uint8_t deltaCode) {
return ((int16_t)(deltaCode & 0x0f) - 4) * 15;
}

/**
* Convert the `offsetCode` and `deltaCode` into a signed 16-bit integer that
* represents the UTCOFF of the ZoneEra in minutes. The `offsetCode` is rounded
* towards -infinity in 15-minute multiples. The upper 4-bits of `deltaCode`
* holds the (unsigned) remainder in one-minute increments.
*/
inline int16_t toOffsetMinutes(int8_t offsetCode, uint8_t deltaCode) {
return (offsetCode * 15) + (((uint8_t)deltaCode & 0xf0) >> 4);
}


/**
* Convert (code, modifier) fields representing the UNTIL time in ZoneInfo or AT
* time in ZoneRule in one minute resolution. The `code` parameter holds the AT
* or UNTIL time in minutes component in units of 15 minutes. The lower 4-bits
* of `modifier` holds the remainder minutes.
*/
inline uint16_t timeCodeToMinutes(uint8_t code, uint8_t modifier) {
return code * (uint16_t) 15 + (modifier & 0x0f);
}

/**
* Extract the 'w', 's' 'u' suffix from the 'modifier' field, so that they can
* be compared against kSuffixW, kSuffixS and kSuffixU. Used for Zone.UNTIL and
* Rule.AT fields.
*/
inline uint8_t toSuffix(uint8_t modifier) {
return modifier & 0xf0;
}

//-----------------------------------------------------------------------------

/**
* Data broker for accessing a ZoneContext. Currently, this assumes that the
Expand Down Expand Up @@ -97,6 +144,8 @@ class ZoneContextBroker {
const ZC* mZoneContext;
};

//-----------------------------------------------------------------------------

/**
* Data broker for accessing ZoneRule.
*
Expand Down Expand Up @@ -373,7 +422,8 @@ void ZoneInfoBroker<ZC, ZI, ZE, ZP, ZR>::printNameTo(Print& printer) const {
template <typename ZC, typename ZI, typename ZE, typename ZP, typename ZR>
void ZoneInfoBroker<ZC, ZI, ZE, ZP, ZR>::printShortNameTo(Print& printer)
const {
ace_common::printReplaceCharTo(printer, findShortName(name()), '_', ' ');
ace_common::printReplaceCharTo(
printer, internal::findShortName(name()), '_', ' ');
}

//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -430,38 +480,38 @@ class ZoneInfoStore {
}
};

} // internal
} // zoneinfo

//-----------------------------------------------------------------------------

namespace basic {

/** Data broker for accessing ZoneContext. */
using ZoneContextBroker = internal::ZoneContextBroker<ZoneContext>;
using ZoneContextBroker = zoneinfo::ZoneContextBroker<ZoneContext>;

/** Data broker for accessing ZoneRule. */
using ZoneRuleBroker = internal::ZoneRuleBroker<ZoneContext, ZoneRule>;
using ZoneRuleBroker = zoneinfo::ZoneRuleBroker<ZoneContext, ZoneRule>;

/** Data broker for accessing ZonePolicy. */
using ZonePolicyBroker = internal::ZonePolicyBroker<
using ZonePolicyBroker = zoneinfo::ZonePolicyBroker<
ZoneContext, ZonePolicy, ZoneRule>;

/** Data broker for accessing ZoneEra. */
using ZoneEraBroker = internal::ZoneEraBroker<
using ZoneEraBroker = zoneinfo::ZoneEraBroker<
ZoneContext, ZoneEra, ZonePolicy, ZoneRule>;

/** Data broker for accessing ZoneInfo. */
using ZoneInfoBroker = internal::ZoneInfoBroker<
using ZoneInfoBroker = zoneinfo::ZoneInfoBroker<
ZoneContext, ZoneInfo, ZoneEra, ZonePolicy, ZoneRule>;

/**
* Data broker for accessing the ZoneRegistry. The ZoneRegistry is an
* array of (const ZoneInfo*) in the zone_registry.cpp file.
*/
using ZoneRegistryBroker = internal::ZoneRegistryBroker<ZoneInfo>;
using ZoneRegistryBroker = zoneinfo::ZoneRegistryBroker<ZoneInfo>;

/** Storage object that returns a ZoneInfoBroker from a ZoneInfo pointer. */
using ZoneInfoStore = internal::ZoneInfoStore<
using ZoneInfoStore = zoneinfo::ZoneInfoStore<
ZoneContext, ZoneInfo, ZoneEra, ZonePolicy, ZoneRule>;

} // basic
Expand All @@ -471,31 +521,31 @@ using ZoneInfoStore = internal::ZoneInfoStore<
namespace extended {

/** Data broker for accessing ZoneContext. */
using ZoneContextBroker = internal::ZoneContextBroker<ZoneContext>;
using ZoneContextBroker = zoneinfo::ZoneContextBroker<ZoneContext>;

/** Data broker for accessing ZoneRule. */
using ZoneRuleBroker = internal::ZoneRuleBroker<ZoneContext, ZoneRule>;
using ZoneRuleBroker = zoneinfo::ZoneRuleBroker<ZoneContext, ZoneRule>;

/** Data broker for accessing ZonePolicy. */
using ZonePolicyBroker = internal::ZonePolicyBroker<
using ZonePolicyBroker = zoneinfo::ZonePolicyBroker<
ZoneContext, ZonePolicy, ZoneRule>;

/** Data broker for accessing ZoneEra. */
using ZoneEraBroker = internal::ZoneEraBroker<
using ZoneEraBroker = zoneinfo::ZoneEraBroker<
ZoneContext, ZoneEra, ZonePolicy, ZoneRule>;

/** Data broker for accessing ZoneInfo. */
using ZoneInfoBroker = internal::ZoneInfoBroker<
using ZoneInfoBroker = zoneinfo::ZoneInfoBroker<
ZoneContext, ZoneInfo, ZoneEra, ZonePolicy, ZoneRule>;

/**
* Data broker for accessing the ZoneRegistry. The ZoneRegistry is an
* array of (const ZoneInfo*) in the zone_registry.cpp file.
*/
using ZoneRegistryBroker = internal::ZoneRegistryBroker<ZoneInfo>;
using ZoneRegistryBroker = zoneinfo::ZoneRegistryBroker<ZoneInfo>;

/** Storage object that returns a ZoneInfoBroker from a ZoneInfo pointer. */
using ZoneInfoStore = internal::ZoneInfoStore<
using ZoneInfoStore = zoneinfo::ZoneInfoStore<
ZoneContext, ZoneInfo, ZoneEra, ZonePolicy, ZoneRule>;

} // extended
Expand Down
22 changes: 11 additions & 11 deletions src/zoneinfo/ZoneInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <stdint.h>

namespace ace_time{
namespace internal {
namespace zoneinfo {

/**
* Metadata about the zone database. A ZoneInfo struct will contain a pointer
Expand Down Expand Up @@ -327,23 +327,23 @@ struct ZoneInfo {
namespace basic {

class Basic {};
using ZoneContext = internal::ZoneContext<Basic>;
using ZoneRule = internal::ZoneRule<Basic>;
using ZonePolicy = internal::ZonePolicy<Basic>;
using ZoneEra = internal::ZoneEra<Basic>;
using ZoneInfo = internal::ZoneInfo<Basic, ZoneContext>;
using ZoneContext = zoneinfo::ZoneContext<Basic>;
using ZoneRule = zoneinfo::ZoneRule<Basic>;
using ZonePolicy = zoneinfo::ZonePolicy<Basic>;
using ZoneEra = zoneinfo::ZoneEra<Basic>;
using ZoneInfo = zoneinfo::ZoneInfo<Basic, ZoneContext>;

}

// Data structures for ExtendedZoneProcessor
namespace extended {

class Extended {};
using ZoneContext = internal::ZoneContext<Extended>;
using ZoneRule = internal::ZoneRule<Extended>;
using ZonePolicy = internal::ZonePolicy<Extended>;
using ZoneEra = internal::ZoneEra<Extended>;
using ZoneInfo = internal::ZoneInfo<Extended, ZoneContext>;
using ZoneContext = zoneinfo::ZoneContext<Extended>;
using ZoneRule = zoneinfo::ZoneRule<Extended>;
using ZonePolicy = zoneinfo::ZonePolicy<Extended>;
using ZoneEra = zoneinfo::ZoneEra<Extended>;
using ZoneInfo = zoneinfo::ZoneInfo<Extended, ZoneContext>;

}

Expand Down
2 changes: 1 addition & 1 deletion tests/BrokerCommonTest/BrokerCommonTest.ino
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <AceTime.h>

using ace_time::internal::findShortName;
using ace_time::internal::timeCodeToMinutes;
using ace_time::zoneinfo::timeCodeToMinutes;

test(timeCodeToMinutes) {
uint8_t code = 1;
Expand Down
2 changes: 1 addition & 1 deletion tests/ExtendedBrokerTest/ExtendedBrokerTest.ino
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ test(timeCodeToMinutes) {
uint8_t code = 1;
uint8_t modifier = 0x01;
assertEqual((uint16_t)16,
ace_time::internal::timeCodeToMinutes(code, modifier));
ace_time::zoneinfo::timeCodeToMinutes(code, modifier));
}

//---------------------------------------------------------------------------
Expand Down

0 comments on commit 2ba3adb

Please sign in to comment.