6 #ifndef ACE_TIME_ZONE_REGISTRAR_H
7 #define ACE_TIME_ZONE_REGISTRAR_H
10 #include <AceCommon.h>
11 #include "../zoneinfo/infos.h"
14 void runBasicRegistrarFindIndexForName();
15 void runBasicRegistrarFindIndexForIdBinary();
16 void runBasicRegistrarFindIndexForIdLinear();
17 void runExtendedRegistrarFindIndexForName();
18 void runExtendedRegistrarFindIndexForIdBinary();
19 void runExtendedRegistrarFindIndexForIdLinear();
20 void runCompleteRegistrarFindIndexForName();
21 void runCompleteRegistrarFindIndexForIdBinary();
22 void runCompleteRegistrarFindIndexForIdLinear();
25 class ZoneRegistrarTest_Sorted_isSorted;
26 class ZoneRegistrarTest_Unsorted_isSorted;
27 class ZoneRegistrarTest_Sorted_linearSearchById;
28 class ZoneRegistrarTest_Sorted_linearSearchById_not_found;
29 class ZoneRegistrarTest_Sorted_binarySearchById_zeroEntries;
30 class ZoneRegistrarTest_Sorted_binarySearchById;
31 class ZoneRegistrarTest_Sorted_binarySearchById_not_found;
32 class ZoneRegistrarTest_Unsorted_linearSearchById;
33 class ZoneRegistrarTest_Unsorted_linearSearchById_not_found;
54 const typename D::ZoneInfo*
const* zoneRegistry
58 mZoneRegistry(zoneRegistry)
66 return (i < mZoneRegistrySize)
67 ?
typename D::ZoneRegistryBroker(mZoneRegistry).zoneInfo(i)
78 return typename D::ZoneRegistryBroker(mZoneRegistry).zoneInfo(index);
85 return typename D::ZoneRegistryBroker(mZoneRegistry).zoneInfo(index);
90 uint32_t zoneId = ace_common::hashDjb2(name);
95 typename D::ZoneInfoBroker zoneInfoBroker(
96 typename D::ZoneRegistryBroker(mZoneRegistry).zoneInfo(index));
97 ace_common::KString kname(
98 zoneInfoBroker.name(),
99 zoneInfoBroker.zoneContext().fragments(),
100 zoneInfoBroker.zoneContext().numFragments()
115 friend void ::runBasicRegistrarFindIndexForName();
116 friend void ::runBasicRegistrarFindIndexForIdBinary();
117 friend void ::runBasicRegistrarFindIndexForIdLinear();
118 friend void ::runExtendedRegistrarFindIndexForName();
119 friend void ::runExtendedRegistrarFindIndexForIdBinary();
120 friend void ::runExtendedRegistrarFindIndexForIdLinear();
121 friend void ::runCompleteRegistrarFindIndexForName();
122 friend void ::runCompleteRegistrarFindIndexForIdBinary();
123 friend void ::runCompleteRegistrarFindIndexForIdLinear();
124 friend class ::ZoneRegistrarTest_Sorted_isSorted;
125 friend class ::ZoneRegistrarTest_Unsorted_isSorted;
126 friend class ::ZoneRegistrarTest_Sorted_linearSearchById;
127 friend class ::ZoneRegistrarTest_Sorted_linearSearchById_not_found;
128 friend class ::ZoneRegistrarTest_Sorted_binarySearchById_zeroEntries;
129 friend class ::ZoneRegistrarTest_Sorted_binarySearchById;
130 friend class ::ZoneRegistrarTest_Sorted_binarySearchById_not_found;
131 friend class ::ZoneRegistrarTest_Unsorted_linearSearchById;
132 friend class ::ZoneRegistrarTest_Unsorted_linearSearchById_not_found;
139 const typename D::ZoneInfo*
const* registry,
140 uint16_t registrySize) {
142 const typename D::ZoneRegistryBroker zoneRegistry(registry);
143 return ace_common::isSortedByKey(
144 (
size_t) registrySize,
145 [&zoneRegistry](
size_t i) {
146 const typename D::ZoneInfo* zoneInfo = zoneRegistry.zoneInfo(i);
147 return typename D::ZoneInfoBroker(zoneInfo).zoneId();
157 const typename D::ZoneInfo*
const* registry,
158 uint16_t registrySize,
160 const typename D::ZoneRegistryBroker zoneRegistry(registry);
161 for (uint16_t i = 0; i < registrySize; ++i) {
162 const typename D::ZoneInfo* zoneInfo = zoneRegistry.zoneInfo(i);
163 if (zoneId ==
typename D::ZoneInfoBroker(zoneInfo).zoneId()) {
192 const typename D::ZoneInfo*
const* registry,
193 uint16_t registrySize,
195 const typename D::ZoneRegistryBroker zoneRegistry(registry);
196 return (uint16_t) ace_common::binarySearchByKey(
197 (
size_t) registrySize,
199 [&zoneRegistry](
size_t i) -> uint32_t {
200 const typename D::ZoneInfo* zoneInfo = zoneRegistry.zoneInfo(i);
201 return typename D::ZoneInfoBroker(zoneInfo).zoneId();
218 uint16_t
const mZoneRegistrySize;
219 bool const mIsSorted;
220 const typename D::ZoneInfo*
const*
const mZoneRegistry;
224 using ZoneRegistrar = ZoneRegistrarTemplate<basic::Info>;
228 using ZoneRegistrar = ZoneRegistrarTemplate<extended::Info>;
232 using ZoneRegistrar = ZoneRegistrarTemplate<complete::Info>;
Class that allows looking up the ZoneInfo from its TZDB identifier (e.g.
static uint16_t linearSearchById(const typename D::ZoneInfo *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 findIndexForId(uint32_t zoneId) const
Find the index for zone id.
const D::ZoneInfo * getZoneInfoForName(const char *name) const
Return the ZoneInfo corresponding to the given zone name.
static const uint16_t kInvalidIndex
Invalid index to indicate error or not found.
uint16_t findIndexForName(const char *name) const
Find the index for zone name.
uint16_t zoneRegistrySize() const
Return the number of zones and (fat) links.
const D::ZoneInfo * getZoneInfoForId(uint32_t zoneId) const
Return the ZoneInfo using the zoneId.
ZoneRegistrarTemplate(uint16_t zoneRegistrySize, const typename D::ZoneInfo *const *zoneRegistry)
Constructor.
uint16_t findIndexForIdLinear(uint32_t zoneId) const
Exposed only for benchmarking purposes.
const D::ZoneInfo * getZoneInfoForIndex(uint16_t i) const
Return the ZoneInfo at index i.
static uint16_t binarySearchById(const typename D::ZoneInfo *const *registry, uint16_t registrySize, uint32_t zoneId)
Find the registry index corresponding to zoneId using a binary search.
static const uint8_t kBinarySearchThreshold
Use binarySearchById() if zoneRegistrySize >= threshold.
static bool isSorted(const typename D::ZoneInfo *const *registry, uint16_t registrySize)
Determine if the given zone registry is sorted by id.