AceTime  1.3
Date and time classes for Arduino that support timezones from the TZ Database, and a system clock that can synchronize from an NTP server or an RTC chip.
Public Member Functions | Static Public Attributes | Static Protected Member Functions | Protected Attributes | Static Protected Attributes | Friends | List of all members
ace_time::ZoneRegistrar< ZI, ZRB, ZIB, STRCMP_P, STRCMP_PP > Class Template Reference

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

#include <ZoneRegistrar.h>

Public Member Functions

 ZoneRegistrar (uint16_t registrySize, const ZI *const *zoneRegistry)
 Constructor.
 
uint16_t registrySize () const
 Return the number of zones.
 
bool isSorted () const
 Return true if zoneRegistry is sorted, and eligible to use a binary search.
 
const ZI * getZoneInfoForIndex (uint16_t i) const
 Return the ZoneInfo at index i. More...
 
const ZI * getZoneInfoForName (const char *name) const
 Return the ZoneInfo corresponding to the given zone name. More...
 
const ZI * 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.
 

Static Protected Member Functions

static bool isSorted (const ZI *const *registry, uint16_t registrySize)
 Determine if the given zone registry is sorted by name.
 
static uint16_t linearSearchByName (const ZI *const *registry, uint16_t registrySize, const char *name)
 Find the registry index corresponding to name using a linear search. More...
 
static uint16_t binarySearchByName (const ZI *const *registry, uint16_t registrySize, const char *name)
 Find the registry index corresponding to name using a binary search. More...
 
static uint16_t linearSearchById (const ZI *const *registry, uint16_t registrySize, uint32_t zoneId)
 Find the registry index corresponding to id using linear search.
 

Protected Attributes

const uint16_t mRegistrySize
 
const ZI *const *const mZoneRegistry
 
const bool mIsSorted
 

Static Protected Attributes

static const uint8_t kBinarySearchThreshold = 6
 Use binarySearch() if registrySize >= threshold.
 

Friends

class ::BasicZoneRegistrarTest_Sorted_isSorted
 
class ::BasicZoneRegistrarTest_Sorted_linearSearchByName
 
class ::BasicZoneRegistrarTest_Sorted_linearSearchByName_not_found
 
class ::BasicZoneRegistrarTest_Sorted_binarySearchByName
 
class ::BasicZoneRegistrarTest_Sorted_binarySearchByName_not_found
 
class ::BasicZoneRegistrarTest_Sorted_linearSearchById
 
class ::BasicZoneRegistrarTest_Sorted_linearSearchById_not_found
 
class ::BasicZoneRegistrarTest_Unsorted_isSorted
 
class ::BasicZoneRegistrarTest_Unsorted_linearSearchByName
 
class ::BasicZoneRegistrarTest_Unsorted_linearSearchByName_not_found
 
class ::BasicZoneRegistrarTest_Unsorted_binarySearchByName
 
class ::BasicZoneRegistrarTest_Unsorted_binarySearchByName_not_found
 
class ::BasicZoneRegistrarTest_Unsorted_linearSearchById
 
class ::BasicZoneRegistrarTest_Unsorted_linearSearchById_not_found
 

Detailed Description

template<typename ZI, typename ZRB, typename ZIB, strcmp_t STRCMP_P, strcmp_t STRCMP_PP>
class ace_time::ZoneRegistrar< ZI, ZRB, ZIB, STRCMP_P, STRCMP_PP >

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

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

Template Parameters
ZIZoneInfo type (e.g. basic::ZoneInfo)
ZRBZoneRegistryBroker type (e.g. basic::ZoneRegistryBroker)
ZIBZoneInfoBroker type (e.g. basic::ZoneInfoBroker)
STRCMP_Pa function that compares a normal string to flash string (e.g strcmp_P())
STRCMP_PPa function that compares 2 flash strings (must be custom written)

Definition at line 51 of file ZoneRegistrar.h.

Member Function Documentation

◆ binarySearchByName()

template<typename ZI , typename ZRB , typename ZIB , strcmp_t STRCMP_P, strcmp_t STRCMP_PP>
static uint16_t ace_time::ZoneRegistrar< ZI, ZRB, ZIB, STRCMP_P, STRCMP_PP >::binarySearchByName ( const ZI *const *  registry,
uint16_t  registrySize,
const char *  name 
)
inlinestaticprotected

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

Returns kInvalidIndex if not found.

Definition at line 164 of file ZoneRegistrar.h.

◆ findIndexForId()

template<typename ZI , typename ZRB , typename ZIB , strcmp_t STRCMP_P, strcmp_t STRCMP_PP>
uint16_t ace_time::ZoneRegistrar< ZI, ZRB, ZIB, STRCMP_P, STRCMP_PP >::findIndexForId ( uint32_t  zoneId) const
inline

Find the index for zone id.

Return kInvalidIndex if not found.

Definition at line 103 of file ZoneRegistrar.h.

◆ findIndexForName()

template<typename ZI , typename ZRB , typename ZIB , strcmp_t STRCMP_P, strcmp_t STRCMP_PP>
uint16_t ace_time::ZoneRegistrar< ZI, ZRB, ZIB, STRCMP_P, STRCMP_PP >::findIndexForName ( const char *  name) const
inline

Find the index for zone name.

Return kInvalidIndex if not found.

Definition at line 94 of file ZoneRegistrar.h.

◆ getZoneInfoForId()

template<typename ZI , typename ZRB , typename ZIB , strcmp_t STRCMP_P, strcmp_t STRCMP_PP>
const ZI* ace_time::ZoneRegistrar< ZI, ZRB, ZIB, STRCMP_P, STRCMP_PP >::getZoneInfoForId ( uint32_t  zoneId) const
inline

Return the ZoneInfo using the zoneId.

Return nullptr if not found.

Definition at line 87 of file ZoneRegistrar.h.

◆ getZoneInfoForIndex()

template<typename ZI , typename ZRB , typename ZIB , strcmp_t STRCMP_P, strcmp_t STRCMP_PP>
const ZI* ace_time::ZoneRegistrar< ZI, ZRB, ZIB, STRCMP_P, STRCMP_PP >::getZoneInfoForIndex ( uint16_t  i) const
inline

Return the ZoneInfo at index i.

Return nullptr if i is out of range.

Definition at line 72 of file ZoneRegistrar.h.

◆ getZoneInfoForName()

template<typename ZI , typename ZRB , typename ZIB , strcmp_t STRCMP_P, strcmp_t STRCMP_PP>
const ZI* ace_time::ZoneRegistrar< ZI, ZRB, ZIB, STRCMP_P, STRCMP_PP >::getZoneInfoForName ( const char *  name) const
inline

Return the ZoneInfo corresponding to the given zone name.

Return nullptr if not found.

Definition at line 80 of file ZoneRegistrar.h.

◆ linearSearchByName()

template<typename ZI , typename ZRB , typename ZIB , strcmp_t STRCMP_P, strcmp_t STRCMP_PP>
static uint16_t ace_time::ZoneRegistrar< ZI, ZRB, ZIB, STRCMP_P, STRCMP_PP >::linearSearchByName ( const ZI *const *  registry,
uint16_t  registrySize,
const char *  name 
)
inlinestaticprotected

Find the registry index corresponding to name using a linear search.

Returns kInvalidIndex if not found.

Definition at line 148 of file ZoneRegistrar.h.


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