6 #ifndef ACE_TIME_ZONE_REGISTRAR_H
7 #define ACE_TIME_ZONE_REGISTRAR_H
10 #include <AceCommon.h>
11 #include "../zoneinfo/infos.h"
12 #include "../zoneinfo/brokers.h"
15 void runBasicRegistrarFindIndexForName();
16 void runBasicRegistrarFindIndexForIdBinary();
17 void runBasicRegistrarFindIndexForIdLinear();
18 void runExtendedRegistrarFindIndexForName();
19 void runExtendedRegistrarFindIndexForIdBinary();
20 void runExtendedRegistrarFindIndexForIdLinear();
21 void runCompleteRegistrarFindIndexForName();
22 void runCompleteRegistrarFindIndexForIdBinary();
23 void runCompleteRegistrarFindIndexForIdLinear();
26 class ZoneRegistrarTest_Sorted_isSorted;
27 class ZoneRegistrarTest_Unsorted_isSorted;
28 class ZoneRegistrarTest_Sorted_linearSearchById;
29 class ZoneRegistrarTest_Sorted_linearSearchById_not_found;
30 class ZoneRegistrarTest_Sorted_binarySearchById_zeroEntries;
31 class ZoneRegistrarTest_Sorted_binarySearchById;
32 class ZoneRegistrarTest_Sorted_binarySearchById_not_found;
33 class ZoneRegistrarTest_Unsorted_linearSearchById;
34 class ZoneRegistrarTest_Unsorted_linearSearchById_not_found;
48 template<
typename ZI,
typename ZIB,
typename ZRGB>
57 const ZI*
const* zoneRegistry
61 mZoneRegistry(zoneRegistry)
69 return (i < mZoneRegistrySize)
70 ? ZRGB(mZoneRegistry).zoneInfo(i)
81 return ZRGB(mZoneRegistry).zoneInfo(index);
88 return ZRGB(mZoneRegistry).zoneInfo(index);
93 uint32_t zoneId = ace_common::hashDjb2(name);
98 ZIB zoneInfoBroker(ZRGB(mZoneRegistry).zoneInfo(index));
99 ace_common::KString kname(
100 zoneInfoBroker.name(),
101 zoneInfoBroker.zoneContext().fragments(),
102 zoneInfoBroker.zoneContext().numFragments()
117 friend void ::runBasicRegistrarFindIndexForName();
118 friend void ::runBasicRegistrarFindIndexForIdBinary();
119 friend void ::runBasicRegistrarFindIndexForIdLinear();
120 friend void ::runExtendedRegistrarFindIndexForName();
121 friend void ::runExtendedRegistrarFindIndexForIdBinary();
122 friend void ::runExtendedRegistrarFindIndexForIdLinear();
123 friend void ::runCompleteRegistrarFindIndexForName();
124 friend void ::runCompleteRegistrarFindIndexForIdBinary();
125 friend void ::runCompleteRegistrarFindIndexForIdLinear();
126 friend class ::ZoneRegistrarTest_Sorted_isSorted;
127 friend class ::ZoneRegistrarTest_Unsorted_isSorted;
128 friend class ::ZoneRegistrarTest_Sorted_linearSearchById;
129 friend class ::ZoneRegistrarTest_Sorted_linearSearchById_not_found;
130 friend class ::ZoneRegistrarTest_Sorted_binarySearchById_zeroEntries;
131 friend class ::ZoneRegistrarTest_Sorted_binarySearchById;
132 friend class ::ZoneRegistrarTest_Sorted_binarySearchById_not_found;
133 friend class ::ZoneRegistrarTest_Unsorted_linearSearchById;
134 friend class ::ZoneRegistrarTest_Unsorted_linearSearchById_not_found;
140 static bool isSorted(
const ZI*
const* registry, uint16_t registrySize) {
141 const ZRGB zoneRegistry(registry);
142 return ace_common::isSortedByKey(
143 (
size_t) registrySize,
144 [&zoneRegistry](
size_t i) {
145 const ZI* zoneInfo = zoneRegistry.zoneInfo(i);
146 return ZIB(zoneInfo).zoneId();
156 uint16_t registrySize, uint32_t zoneId) {
157 const ZRGB zoneRegistry(registry);
158 for (uint16_t i = 0; i < registrySize; ++i) {
159 const ZI* zoneInfo = zoneRegistry.zoneInfo(i);
160 if (zoneId == ZIB(zoneInfo).zoneId()) {
189 uint16_t registrySize, uint32_t zoneId) {
190 const ZRGB zoneRegistry(registry);
191 return (uint16_t) ace_common::binarySearchByKey(
192 (
size_t) registrySize,
194 [&zoneRegistry](
size_t i) -> uint32_t {
195 const ZI* zoneInfo = zoneRegistry.zoneInfo(i);
196 return ZIB(zoneInfo).zoneId();
213 uint16_t
const mZoneRegistrySize;
214 bool const mIsSorted;
215 const ZI*
const*
const mZoneRegistry;
226 using ZoneRegistrar = internal::ZoneRegistrarTemplate<
228 basic::ZoneInfoBroker,
229 basic::ZoneRegistryBroker
240 using ZoneRegistrar = internal::ZoneRegistrarTemplate<
242 extended::ZoneInfoBroker,
243 extended::ZoneRegistryBroker
254 using ZoneRegistrar = internal::ZoneRegistrarTemplate<
256 complete::ZoneInfoBroker,
257 complete::ZoneRegistryBroker
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.