Skip to content

Commit

Permalink
add convenience mask for calendar availability
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinkreiser committed Jun 29, 2023
1 parent 6bb0f10 commit 375be1c
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions include/just_gtfs/just_gtfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -1000,6 +1000,7 @@ struct CalendarItem
// Required:
Id service_id;

// TODO: store this as a mask?
CalendarAvailability monday = CalendarAvailability::NotAvailable;
CalendarAvailability tuesday = CalendarAvailability::NotAvailable;
CalendarAvailability wednesday = CalendarAvailability::NotAvailable;
Expand All @@ -1020,6 +1021,24 @@ inline bool operator==(const CalendarItem & lhs, const CalendarItem & rhs)
rhs.friday, rhs.saturday, rhs.sunday, rhs.start_date, rhs.end_date);
}

uint8_t inline availability(const CalendarItem& c) {
return uint8_t(c.monday == gtfs::CalendarAvailability::Available) |
uint8_t(c.tuesday == gtfs::CalendarAvailability::Available) << 1 |
uint8_t(c.wednesday == gtfs::CalendarAvailability::Available) << 2 |
uint8_t(c.thursday == gtfs::CalendarAvailability::Available) << 3 |
uint8_t(c.friday == gtfs::CalendarAvailability::Available) << 4 |
uint8_t(c.saturday == gtfs::CalendarAvailability::Available) << 5 |
uint8_t(c.sunday == gtfs::CalendarAvailability::Available) << 6;
}

constexpr uint8_t Monday = 0b00000001;
constexpr uint8_t Tuesday = 0b00000010;
constexpr uint8_t Wednesday = 0b00000100;
constexpr uint8_t Thursday = 0b00001000;
constexpr uint8_t Friday = 0b00010000;
constexpr uint8_t Saturday = 0b00100000;
constexpr uint8_t Sunday = 0b01000000;

// Conditionally required dataset file
struct CalendarDate
{
Expand Down

0 comments on commit 375be1c

Please sign in to comment.