AceTime  3.0.0
Date and time classes for Arduino that support timezones from the TZ Database.
Public Member Functions | Static Public Attributes | Protected Member Functions | Static Protected Member Functions | Static Protected Attributes | Friends | List of all members
ace_time::ZoneRegistrarTemplate< D > Class Template Reference

Class that allows looking up the ZoneInfo from its TZDB identifier (e.g. More...

#include <ZoneRegistrar.h>

Public Member Functions

 ZoneRegistrarTemplate (uint16_t zoneRegistrySize, const typename D::ZoneInfo *const *zoneRegistry)
 Constructor.
 
uint16_t zoneRegistrySize () const
 Return the number of zones and (fat) links.
 
const D::ZoneInfo * getZoneInfoForIndex (uint16_t i) const
 Return the ZoneInfo at index i. More...
 
const D::ZoneInfo * getZoneInfoForName (const char *name) const
 Return the ZoneInfo corresponding to the given zone name. More...
 
const D::ZoneInfo * getZoneInfoForId (uint32_t zoneId) const
 Return the ZoneInfo using the zoneId. More...
 
uint16_t findIndexForName (const char *name) const
 Find the index for zone name. More...
 
uint16_t findIndexForId (uint32_t zoneId) const
 Find the index for zone id. More...
 

Static Public Attributes

static const uint16_t kInvalidIndex = 0xffff
 Invalid index to indicate error or not found.
 

Protected Member Functions

friend void ::runBasicRegistrarFindIndexForName ()
 
friend void ::runBasicRegistrarFindIndexForIdBinary ()
 
friend void ::runBasicRegistrarFindIndexForIdLinear ()
 
friend void ::runExtendedRegistrarFindIndexForName ()
 
friend void ::runExtendedRegistrarFindIndexForIdBinary ()
 
friend void ::runExtendedRegistrarFindIndexForIdLinear ()
 
friend void ::runCompleteRegistrarFindIndexForName ()
 
friend void ::runCompleteRegistrarFindIndexForIdBinary ()
 
friend void ::runCompleteRegistrarFindIndexForIdLinear ()
 
uint16_t findIndexForIdLinear (uint32_t zoneId) const
 Exposed only for benchmarking purposes.
 
uint16_t findIndexForIdBinary (uint32_t zoneId) const
 Exposed only for benchmarking purposes.
 

Static Protected Member Functions

static bool isSorted (const typename D::ZoneInfo *const *registry, uint16_t registrySize)
 Determine if the given zone registry is sorted by id.
 
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. More...
 
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. More...
 

Static Protected Attributes

static const uint8_t kBinarySearchThreshold = 8
 Use binarySearchById() if zoneRegistrySize >= threshold.
 

Friends

class ::ZoneRegistrarTest_Sorted_isSorted
 
class ::ZoneRegistrarTest_Unsorted_isSorted
 
class ::ZoneRegistrarTest_Sorted_linearSearchById
 
class ::ZoneRegistrarTest_Sorted_linearSearchById_not_found
 
class ::ZoneRegistrarTest_Sorted_binarySearchById_zeroEntries
 
class ::ZoneRegistrarTest_Sorted_binarySearchById
 
class ::ZoneRegistrarTest_Sorted_binarySearchById_not_found
 
class ::ZoneRegistrarTest_Unsorted_linearSearchById
 
class ::ZoneRegistrarTest_Unsorted_linearSearchById_not_found
 

Detailed Description

template<typename D>
class ace_time::ZoneRegistrarTemplate< D >

Class that allows looking up the ZoneInfo from its TZDB identifier (e.g.

"America/Los_Angeles"), zoneId (hash from its name), or the index in the zone registry.

Template Parameters
Dcontainer type of ZoneInfo database (e.g. basic::Info, extended::Info, complete::Info)

Definition at line 46 of file ZoneRegistrar.h.

Member Function Documentation

◆ binarySearchById()

template<typename D >
static uint16_t ace_time::ZoneRegistrarTemplate< D >::binarySearchById ( const typename D::ZoneInfo *const *  registry,
uint16_t  registrySize,
uint32_t  zoneId 
)
inlinestaticprotected

Find the registry index corresponding to zoneId using a binary search.

Returns kInvalidIndex if not found.

The largest registrySize is UINT16_MAX so the largest valid index is UINT16_MAX - 1. This allows us to set kInvalidIndex to UINT16_MAX to indicate "Not Found".

Definition at line 191 of file ZoneRegistrar.h.

◆ findIndexForId()

template<typename D >
uint16_t ace_time::ZoneRegistrarTemplate< D >::findIndexForId ( uint32_t  zoneId) const
inline

Find the index for zone id.

Return kInvalidIndex if not found.

Definition at line 106 of file ZoneRegistrar.h.

◆ findIndexForName()

template<typename D >
uint16_t ace_time::ZoneRegistrarTemplate< D >::findIndexForName ( const char *  name) const
inline

Find the index for zone name.

Return kInvalidIndex if not found.

Definition at line 89 of file ZoneRegistrar.h.

◆ getZoneInfoForId()

template<typename D >
const D::ZoneInfo* ace_time::ZoneRegistrarTemplate< D >::getZoneInfoForId ( uint32_t  zoneId) const
inline

Return the ZoneInfo using the zoneId.

Return nullptr if not found.

Definition at line 82 of file ZoneRegistrar.h.

◆ getZoneInfoForIndex()

template<typename D >
const D::ZoneInfo* ace_time::ZoneRegistrarTemplate< D >::getZoneInfoForIndex ( uint16_t  i) const
inline

Return the ZoneInfo at index i.

Return nullptr if i is out of range.

Definition at line 65 of file ZoneRegistrar.h.

◆ getZoneInfoForName()

template<typename D >
const D::ZoneInfo* ace_time::ZoneRegistrarTemplate< D >::getZoneInfoForName ( const char *  name) const
inline

Return the ZoneInfo corresponding to the given zone name.

Return nullptr if not found.

Definition at line 75 of file ZoneRegistrar.h.

◆ linearSearchById()

template<typename D >
static uint16_t ace_time::ZoneRegistrarTemplate< D >::linearSearchById ( const typename D::ZoneInfo *const *  registry,
uint16_t  registrySize,
uint32_t  zoneId 
)
inlinestaticprotected

Find the registry index corresponding to zoneId using linear search.

Returns kInvalidIndex if not found.

Definition at line 156 of file ZoneRegistrar.h.


The documentation for this class was generated from the following file: