6 #ifndef ACE_TIME_ZONE_REGISTRAR_H
7 #define ACE_TIME_ZONE_REGISTRAR_H
11 #include <AceCommon.h>
13 #include "internal/ZoneInfo.h"
16 class BasicZoneRegistrarTest_Sorted_isSorted;
17 class BasicZoneRegistrarTest_Sorted_linearSearch;
18 class BasicZoneRegistrarTest_Sorted_linearSearch_not_found;
19 class BasicZoneRegistrarTest_Sorted_binarySearch;
20 class BasicZoneRegistrarTest_Sorted_binarySearch_not_found;
21 class BasicZoneRegistrarTest_Unsorted_isSorted;
22 class BasicZoneRegistrarTest_Unsorted_linearSearch;
27 typedef int (*strcmp_t)(
const char*,
const char*);
41 template<
typename ZI,
typename ZRB,
typename ZIB, strcmp_t STRCMP_P,
48 mZoneRegistry(zoneRegistry),
61 const ZI* getZoneInfoForIndex(uint16_t i)
const {
62 return (i < mRegistrySize) ? ZRB(mZoneRegistry).zoneInfo(i) :
nullptr;
71 return binarySearch(mZoneRegistry, mRegistrySize, name);
73 return linearSearch(mZoneRegistry, mRegistrySize, name);
78 const ZI* getZoneInfoForId(uint32_t zoneId)
const {
79 return linearSearchUsingId(mZoneRegistry, mRegistrySize, zoneId);
83 friend class ::BasicZoneRegistrarTest_Sorted_isSorted;
84 friend class ::BasicZoneRegistrarTest_Sorted_linearSearch;
85 friend class ::BasicZoneRegistrarTest_Sorted_linearSearch_not_found;
86 friend class ::BasicZoneRegistrarTest_Sorted_binarySearch;
87 friend class ::BasicZoneRegistrarTest_Sorted_binarySearch_not_found;
88 friend class ::BasicZoneRegistrarTest_Unsorted_isSorted;
89 friend class ::BasicZoneRegistrarTest_Unsorted_linearSearch;
99 const ZRB zoneRegistry(zr);
100 const char* prevName = ZIB(zoneRegistry.zoneInfo(0)).name();
102 const char* currName = ZIB(zoneRegistry.zoneInfo(i)).name();
103 if (STRCMP_PP(prevName, currName) > 0) {
111 static const ZI* linearSearch(
const ZI*
const* zr,
113 const ZRB zoneRegistry(zr);
115 const ZI* zoneInfo = zoneRegistry.zoneInfo(i);
116 if (STRCMP_P(name, ZIB(zoneInfo).name()) == 0) {
123 static const ZI* binarySearch(
const ZI*
const* zr,
127 const ZRB zoneRegistry(zr);
129 uint16_t c = (a + b) / 2;
130 const ZI* zoneInfo = zoneRegistry.zoneInfo(c);
131 int8_t compare = STRCMP_P(name, ZIB(zoneInfo).name());
132 if (compare == 0)
return zoneInfo;
133 if (a == b)
return nullptr;
142 static const ZI* linearSearchUsingId(
const ZI*
const* zr,
144 const ZRB zoneRegistry(zr);
146 const ZI* zoneInfo = zoneRegistry.zoneInfo(i);
147 if (zoneId == ZIB(zoneInfo).zoneId()) {
154 uint16_t
const mRegistrySize;
155 const ZI*
const*
const mZoneRegistry;
156 bool const mIsSorted;
163 #if ACE_TIME_USE_PROGMEM
164 typedef ZoneRegistrar<basic::ZoneInfo, basic::ZoneRegistryBroker,
165 basic::ZoneInfoBroker, acetime_strcmp_P, ace_common::strcmp_PP>
168 typedef ZoneRegistrar<basic::ZoneInfo, basic::ZoneRegistryBroker,
169 basic::ZoneInfoBroker, strcmp, strcmp> BasicZoneRegistrar;
176 #if ACE_TIME_USE_PROGMEM
177 typedef ZoneRegistrar<extended::ZoneInfo, extended::ZoneRegistryBroker,
178 extended::ZoneInfoBroker, acetime_strcmp_P, ace_common::strcmp_PP>
179 ExtendedZoneRegistrar;
181 typedef ZoneRegistrar<extended::ZoneInfo, extended::ZoneRegistryBroker,
182 extended::ZoneInfoBroker, strcmp, strcmp> ExtendedZoneRegistrar;