6 #ifndef ACE_TIME_ZONE_REGISTRAR_H 7 #define ACE_TIME_ZONE_REGISTRAR_H 11 #include "common/flash.h" 12 #include "internal/ZoneInfo.h" 15 class BasicZoneRegistrarTest_Sorted_isSorted;
16 class BasicZoneRegistrarTest_Sorted_linearSearch;
17 class BasicZoneRegistrarTest_Sorted_linearSearch_not_found;
18 class BasicZoneRegistrarTest_Sorted_binarySearch;
19 class BasicZoneRegistrarTest_Sorted_binarySearch_not_found;
20 class BasicZoneRegistrarTest_Unsorted_isSorted;
21 class BasicZoneRegistrarTest_Unsorted_linearSearch;
26 typedef int (*strcmp_t)(
const char*,
const char*);
40 template<
typename ZI,
typename ZRB,
typename ZIB, strcmp_t STRCMP_P,
46 mRegistrySize(registrySize),
47 mZoneRegistry(zoneRegistry),
48 mIsSorted(
isSorted(zoneRegistry, registrySize)) {}
60 const ZI* getZoneInfoForIndex(uint16_t i)
const {
61 return (i < mRegistrySize) ? ZRB(mZoneRegistry).zoneInfo(i) :
nullptr;
70 return binarySearch(mZoneRegistry, mRegistrySize, name);
72 return linearSearch(mZoneRegistry, mRegistrySize, name);
77 const ZI* getZoneInfoForId(uint32_t zoneId)
const {
78 return linearSearchUsingId(mZoneRegistry, mRegistrySize, zoneId);
82 friend class ::BasicZoneRegistrarTest_Sorted_isSorted;
83 friend class ::BasicZoneRegistrarTest_Sorted_linearSearch;
84 friend class ::BasicZoneRegistrarTest_Sorted_linearSearch_not_found;
85 friend class ::BasicZoneRegistrarTest_Sorted_binarySearch;
86 friend class ::BasicZoneRegistrarTest_Sorted_binarySearch_not_found;
87 friend class ::BasicZoneRegistrarTest_Unsorted_isSorted;
88 friend class ::BasicZoneRegistrarTest_Unsorted_linearSearch;
94 if (registrySize == 0) {
98 const ZRB zoneRegistry(zr);
99 const char* prevName = ZIB(zoneRegistry.zoneInfo(0)).name();
101 const char* currName = ZIB(zoneRegistry.zoneInfo(i)).name();
102 if (STRCMP_PP(prevName, currName) > 0) {
110 static const ZI* linearSearch(
const ZI*
const* zr,
112 const ZRB zoneRegistry(zr);
114 const ZI* zoneInfo = zoneRegistry.zoneInfo(i);
115 if (STRCMP_P(name, ZIB(zoneInfo).name()) == 0) {
122 static const ZI* binarySearch(
const ZI*
const* zr,
123 uint16_t registrySize,
const char* name) {
125 uint16_t b = registrySize - 1;
126 const ZRB zoneRegistry(zr);
128 uint16_t c = (a + b) / 2;
129 const ZI* zoneInfo = zoneRegistry.zoneInfo(c);
130 int8_t compare = STRCMP_P(name, ZIB(zoneInfo).name());
131 if (compare == 0)
return zoneInfo;
132 if (a == b)
return nullptr;
141 static const ZI* linearSearchUsingId(
const ZI*
const* zr,
142 uint16_t registrySize, uint32_t zoneId) {
143 const ZRB zoneRegistry(zr);
145 const ZI* zoneInfo = zoneRegistry.zoneInfo(i);
146 if (zoneId == ZIB(zoneInfo).zoneId()) {
153 uint16_t
const mRegistrySize;
154 const ZI*
const*
const mZoneRegistry;
155 bool const mIsSorted;
162 #if ACE_TIME_USE_PROGMEM 167 typedef ZoneRegistrar<basic::ZoneInfo, basic::ZoneRegistryBroker,
168 basic::ZoneInfoBroker, strcmp, strcmp> BasicZoneRegistrar;
175 #if ACE_TIME_USE_PROGMEM 180 typedef ZoneRegistrar<extended::ZoneInfo, extended::ZoneRegistryBroker,
181 extended::ZoneInfoBroker, strcmp, strcmp> ExtendedZoneRegistrar;
Data broker for accessing the ZoneRegistry in PROGMEM.
Class that allows looking up the ZoneInfo (ZI) from its TZDB identifier (e.g.
const ZI * getZoneInfoForName(const char *name) const
Return the ZoneInfo corresponding to the given zone name.
Representation of a given time zone, implemented as an array of ZoneEra records.
Representation of a given time zone, implemented as an array of ZoneEra records.
bool isSorted() const
Return true if zoneRegistry is sorted, and eligible to use a binary search.
The classes provide a thin layer of indirection for accessing the zoneinfo files stored in the zonedb...
ZoneRegistrar(uint16_t registrySize, const ZI *const *zoneRegistry)
Constructor.
static const uint8_t kBinarySearchThreshold
Use binarySearch() if registrySize >= threshold.
uint16_t registrySize() const
Return the number of zones.