6 #ifndef ACE_TIME_ZONE_SORTER_BY_OFFSET_AND_NAME_H
7 #define ACE_TIME_ZONE_SORTER_BY_OFFSET_AND_NAME_H
9 #include <AceSorting.h>
10 #include "ZoneManager.h"
21 template <
typename ZM>
29 mZoneManager(zoneManager)
37 for (uint16_t i = 0; i < size; i++) {
44 ace_sorting::shellSortKnuth(indexes, size,
45 [
this](uint16_t indexA, uint16_t indexB) ->
bool {
46 auto za = this->mZoneManager.getZoneForIndex(indexA);
47 auto zb = this->mZoneManager.getZoneForIndex(indexB);
54 void sortIds(uint32_t ids[], uint16_t size)
const {
55 ace_sorting::shellSortKnuth(ids, size,
56 [
this](uint32_t a, uint32_t b) ->
bool {
57 uint16_t indexA = this->mZoneManager.indexForZoneId(a);
58 uint16_t indexB = this->mZoneManager.indexForZoneId(b);
59 auto za = this->mZoneManager.getZoneForIndex(indexA);
60 auto zb = this->mZoneManager.getZoneForIndex(indexB);
67 void sortNames(
const char* names[], uint16_t size)
const {
68 ace_sorting::shellSortKnuth(names, size,
69 [
this](
const char* a,
const char* b) ->
bool {
70 uint16_t indexA = this->mZoneManager.indexForZoneName(a);
71 uint16_t indexB = this->mZoneManager.indexForZoneName(b);
72 auto za = this->mZoneManager.getZoneForIndex(indexA);
73 auto zb = this->mZoneManager.getZoneForIndex(indexB);
98 if (b.isNull())
return 1;
104 return a.kname().compareTo(b.kname());
114 const ZM& mZoneManager;
A thin wrapper that represents a time offset from a reference point, usually 00:00 at UTC,...
int32_t toSeconds() const
Return the time offset as seconds.
ZoneSorterByOffsetAndName, templatized on a ZoneManager (BasicZoneManager, ExtendedZoneManager,...
void sortIndexes(uint16_t indexes[], uint16_t size) const
Sort the given array of indexes by UTC offset, then by name.
static int compareZone(const Z &a, const Z &b)
Return <0, 0, or >0 depending on whether Zone a is <, ==, or > than Zone b.
void fillIndexes(uint16_t indexes[], uint16_t size) const
Fill the given array of indexes with index from [0, size).
void sortIds(uint32_t ids[], uint16_t size) const
Sort the given array of zone ids by UTC offset, then by name.
ZoneSorterByOffsetAndName(const ZM &zoneManager)
Constructor.
void sortNames(const char *names[], uint16_t size) const
Sort the given array of zone names by UTC offset, then by name.