6 #ifndef ACE_TIME_ZONE_REGISTRAR_H
7 #define ACE_TIME_ZONE_REGISTRAR_H
10 #include <AceCommon.h>
11 #include "../common/compat.h"
17 void runIndexForZoneIdBinary();
18 void runIndexForZoneIdLinear();
21 class ZoneRegistrarTest_Sorted_isSorted;
22 class ZoneRegistrarTest_Unsorted_isSorted;
23 class ZoneRegistrarTest_Sorted_linearSearchById;
24 class ZoneRegistrarTest_Sorted_linearSearchById_not_found;
25 class ZoneRegistrarTest_Sorted_binarySearchById_zeroEntries;
26 class ZoneRegistrarTest_Sorted_binarySearchById;
27 class ZoneRegistrarTest_Sorted_binarySearchById_not_found;
28 class ZoneRegistrarTest_Unsorted_linearSearchById;
29 class ZoneRegistrarTest_Unsorted_linearSearchById_not_found;
43 template<
typename ZI,
typename ZIB,
typename ZRGB>
52 const ZI*
const* zoneRegistry
56 mZoneRegistry(zoneRegistry)
64 return (i < mZoneRegistrySize)
65 ? ZRGB(mZoneRegistry).zoneInfo(i)
76 return ZRGB(mZoneRegistry).zoneInfo(index);
83 return ZRGB(mZoneRegistry).zoneInfo(index);
88 uint32_t zoneId = ace_common::hashDjb2(name);
93 ZIB zoneInfoBroker(ZRGB(mZoneRegistry).zoneInfo(index));
94 ace_common::KString kname(
95 zoneInfoBroker.name(),
96 zoneInfoBroker.zoneContext()->fragments,
97 zoneInfoBroker.zoneContext()->numFragments
112 friend void ::runIndexForZoneIdBinary();
113 friend void ::runIndexForZoneIdLinear();
114 friend class ::ZoneRegistrarTest_Sorted_isSorted;
115 friend class ::ZoneRegistrarTest_Unsorted_isSorted;
116 friend class ::ZoneRegistrarTest_Sorted_linearSearchById;
117 friend class ::ZoneRegistrarTest_Sorted_linearSearchById_not_found;
118 friend class ::ZoneRegistrarTest_Sorted_binarySearchById_zeroEntries;
119 friend class ::ZoneRegistrarTest_Sorted_binarySearchById;
120 friend class ::ZoneRegistrarTest_Sorted_binarySearchById_not_found;
121 friend class ::ZoneRegistrarTest_Unsorted_linearSearchById;
122 friend class ::ZoneRegistrarTest_Unsorted_linearSearchById_not_found;
128 static bool isSorted(
const ZI*
const* registry, uint16_t registrySize) {
129 const ZRGB zoneRegistry(registry);
130 return ace_common::isSortedByKey(
131 (
size_t) registrySize,
132 [&zoneRegistry](
size_t i) {
133 const ZI* zoneInfo = zoneRegistry.zoneInfo(i);
134 return ZIB(zoneInfo).zoneId();
144 uint16_t registrySize, uint32_t zoneId) {
145 const ZRGB zoneRegistry(registry);
146 for (uint16_t i = 0; i < registrySize; ++i) {
147 const ZI* zoneInfo = zoneRegistry.zoneInfo(i);
148 if (zoneId == ZIB(zoneInfo).zoneId()) {
177 uint16_t registrySize, uint32_t zoneId) {
178 const ZRGB zoneRegistry(registry);
179 return (uint16_t) ace_common::binarySearchByKey(
180 (
size_t) registrySize,
182 [&zoneRegistry](
size_t i) -> uint32_t {
183 const ZI* zoneInfo = zoneRegistry.zoneInfo(i);
184 return ZIB(zoneInfo).zoneId();
201 uint16_t
const mZoneRegistrySize;
202 bool const mIsSorted;
203 const ZI*
const*
const mZoneRegistry;
218 basic::ZoneInfoBroker,
219 basic::ZoneRegistryBroker
224 const basic::ZoneInfo*
const* zoneRegistry
262 extended::ZoneInfoBroker,
263 extended::ZoneRegistryBroker
267 uint16_t zoneRegistrySize,
268 const extended::ZoneInfo*
const* zoneRegistry
274 >(zoneRegistrySize, zoneRegistry)
The classes provide a thin layer of indirection for accessing the zoneinfo files stored in the zonedb...
The classes provide a thin layer of indirection for accessing the zoneinfo files stored in the zonedb...
Data broker for accessing ZoneInfo.
Concrete template instantiation of ZoneRegistrarTemplate for basic::ZoneInfo, which can be used with ...
Data broker for accessing the ZoneRegistry.
Data broker for accessing ZoneInfo.
Concrete template instantiation of ZoneRegistrarTemplate for extended::ZoneInfo, which can be used wi...
Data broker for accessing the ZoneRegistry.
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.