6 #ifndef ACE_TIME_ZONE_REGISTRAR_H
7 #define ACE_TIME_ZONE_REGISTRAR_H
10 #include <AceCommon.h>
16 void runIndexForZoneIdBinary();
17 void runIndexForZoneIdLinear();
20 class ZoneRegistrarTest_Sorted_isSorted;
21 class ZoneRegistrarTest_Unsorted_isSorted;
22 class ZoneRegistrarTest_Sorted_linearSearchById;
23 class ZoneRegistrarTest_Sorted_linearSearchById_not_found;
24 class ZoneRegistrarTest_Sorted_binarySearchById_zeroEntries;
25 class ZoneRegistrarTest_Sorted_binarySearchById;
26 class ZoneRegistrarTest_Sorted_binarySearchById_not_found;
27 class ZoneRegistrarTest_Unsorted_linearSearchById;
28 class ZoneRegistrarTest_Unsorted_linearSearchById_not_found;
42 template<
typename ZI,
typename ZIB,
typename ZRGB>
51 const ZI*
const* zoneRegistry
55 mZoneRegistry(zoneRegistry)
63 return (i < mZoneRegistrySize)
64 ? ZRGB(mZoneRegistry).zoneInfo(i)
75 return ZRGB(mZoneRegistry).zoneInfo(index);
82 return ZRGB(mZoneRegistry).zoneInfo(index);
87 uint32_t zoneId = ace_common::hashDjb2(name);
92 ZIB zoneInfoBroker(ZRGB(mZoneRegistry).zoneInfo(index));
93 ace_common::KString kname(
94 zoneInfoBroker.name(),
95 zoneInfoBroker.zoneContext()->fragments,
96 zoneInfoBroker.zoneContext()->numFragments
111 friend void ::runIndexForZoneIdBinary();
112 friend void ::runIndexForZoneIdLinear();
113 friend class ::ZoneRegistrarTest_Sorted_isSorted;
114 friend class ::ZoneRegistrarTest_Unsorted_isSorted;
115 friend class ::ZoneRegistrarTest_Sorted_linearSearchById;
116 friend class ::ZoneRegistrarTest_Sorted_linearSearchById_not_found;
117 friend class ::ZoneRegistrarTest_Sorted_binarySearchById_zeroEntries;
118 friend class ::ZoneRegistrarTest_Sorted_binarySearchById;
119 friend class ::ZoneRegistrarTest_Sorted_binarySearchById_not_found;
120 friend class ::ZoneRegistrarTest_Unsorted_linearSearchById;
121 friend class ::ZoneRegistrarTest_Unsorted_linearSearchById_not_found;
127 static bool isSorted(
const ZI*
const* registry, uint16_t registrySize) {
128 const ZRGB zoneRegistry(registry);
129 return ace_common::isSortedByKey(
130 (
size_t) registrySize,
131 [&zoneRegistry](
size_t i) {
132 const ZI* zoneInfo = zoneRegistry.zoneInfo(i);
133 return ZIB(zoneInfo).zoneId();
143 uint16_t registrySize, uint32_t zoneId) {
144 const ZRGB zoneRegistry(registry);
145 for (uint16_t i = 0; i < registrySize; ++i) {
146 const ZI* zoneInfo = zoneRegistry.zoneInfo(i);
147 if (zoneId == ZIB(zoneInfo).zoneId()) {
176 uint16_t registrySize, uint32_t zoneId) {
177 const ZRGB zoneRegistry(registry);
178 return (uint16_t) ace_common::binarySearchByKey(
179 (
size_t) registrySize,
181 [&zoneRegistry](
size_t i) -> uint32_t {
182 const ZI* zoneInfo = zoneRegistry.zoneInfo(i);
183 return ZIB(zoneInfo).zoneId();
200 uint16_t
const mZoneRegistrySize;
201 bool const mIsSorted;
202 const ZI*
const*
const mZoneRegistry;
217 basic::ZoneInfoBroker,
218 basic::ZoneRegistryBroker
223 const basic::ZoneInfo*
const* zoneRegistry
261 extended::ZoneInfoBroker,
262 extended::ZoneRegistryBroker
266 uint16_t zoneRegistrySize,
267 const extended::ZoneInfo*
const* zoneRegistry
273 >(zoneRegistrySize, zoneRegistry)
These classes provide a thin layer of indirection for accessing the zoneinfo files stored in the zone...
Concrete template instantiation of ZoneRegistrarTemplate for basic::ZoneInfo, which can be used with ...
Concrete template instantiation of ZoneRegistrarTemplate for extended::ZoneInfo, which can be used wi...
Class that allows looking up the ZoneInfo (ZI) from its TZDB identifier (e.g.
const ZI * getZoneInfoForId(uint32_t zoneId) const
Return the ZoneInfo using the zoneId.
uint16_t findIndexForIdLinear(uint32_t zoneId) const
Exposed only for benchmarking purposes.
const ZI * getZoneInfoForIndex(uint16_t i) const
Return the ZoneInfo at index i.
static const uint16_t kInvalidIndex
Invalid index to indicate error or not found.
uint16_t zoneRegistrySize() const
Return the number of zones and (fat) links.
static uint16_t linearSearchById(const ZI *const *registry, uint16_t registrySize, uint32_t zoneId)
Find the registry index corresponding to zoneId using linear search.
uint16_t findIndexForIdBinary(uint32_t zoneId) const
Exposed only for benchmarking purposes.
uint16_t findIndexForName(const char *name) const
Find the index for zone name.
static const uint8_t kBinarySearchThreshold
Use binarySearchById() if zoneRegistrySize >= threshold.
const ZI * getZoneInfoForName(const char *name) const
Return the ZoneInfo corresponding to the given zone name.
static uint16_t binarySearchById(const ZI *const *registry, uint16_t registrySize, uint32_t zoneId)
Find the registry index corresponding to zoneId using a binary search.
uint16_t findIndexForId(uint32_t zoneId) const
Find the index for zone id.
ZoneRegistrarTemplate(uint16_t zoneRegistrySize, const ZI *const *zoneRegistry)
Constructor.
static bool isSorted(const ZI *const *registry, uint16_t registrySize)
Determine if the given zone registry is sorted by id.
Data broker for accessing the ZoneRegistry.
Macros and definitions that provide a consistency layer among the various Arduino boards for compatib...