From 8e4f47c7b6b22b923d505c1f4fd17c0574a7dd93 Mon Sep 17 00:00:00 2001 From: Gerhard Hoffmann Date: Fri, 27 Sep 2024 13:39:35 +0200 Subject: [PATCH] Added struct ATBTariffPrepaid --- library/include/mobilisis/tariff_prepaid.h | 78 +++++++++++++++++++++- 1 file changed, 76 insertions(+), 2 deletions(-) diff --git a/library/include/mobilisis/tariff_prepaid.h b/library/include/mobilisis/tariff_prepaid.h index 9381855..db3eaaa 100644 --- a/library/include/mobilisis/tariff_prepaid.h +++ b/library/include/mobilisis/tariff_prepaid.h @@ -1,10 +1,84 @@ #ifndef TARIFF_PREPAID_H_INCLUDED #define TARIFF_PREPAID_H_INCLUDED -#include +#include #include -#include "atb_time.h" +#include "time_range.h" + +enum class ApplyPrepaid { + NEVER = 0, + MATCH_PREV_DAY = 1, + MATCH_NEXT_DAY = 2, + ALWAYS = 3 +}; + +struct ATBTariffPrepaid { + int m_id; + QString m_weekDay; + QDate m_date; + TimeRange m_range; + ApplyPrepaid m_prepaidIf; + + explicit ATBTariffPrepaid() + : m_id(-1) + , m_prepaidIf(ApplyPrepaid::NEVER) { + } + + void setPrepaidIf(QString const &ppif) { + if (ppif == "never") { + m_prepaidIf = ApplyPrepaid::NEVER; + } else + if (ppif == "match_prev_day") { + m_prepaidIf = ApplyPrepaid::MATCH_PREV_DAY; + } else + if (ppif == "match_next_day") { + m_prepaidIf = ApplyPrepaid::MATCH_NEXT_DAY; + } else + if (ppif == "always") { + m_prepaidIf = ApplyPrepaid::ALWAYS; + } else { + qCritical() << "ERROR unknown carry over application" << ppif; + } + } + + ApplyPrepaid prepaidIf() const { + return m_prepaidIf; + } + + QString prepaidIfStr() const { + if (m_prepaidIf == ApplyPrepaid::NEVER) { + return "never"; + } + if (m_prepaidIf == ApplyPrepaid::ALWAYS) { + return "always"; + } + if (m_prepaidIf == ApplyPrepaid::MATCH_PREV_DAY) { + return "match prev day"; + } + if (m_prepaidIf == ApplyPrepaid::MATCH_NEXT_DAY) { + return "match next day"; + } + return QString("ERROR unknown prepaid application: %1").arg(static_cast(m_prepaidIf)); + } + + friend QDebug operator<<(QDebug debug, ATBTariffPrepaid const &pp) { + QDebugStateSaver saver(debug); + + debug.nospace() + << "\nTariffPrepaid:\n" + << " week day: " << pp.m_weekDay << "\n" + << " date: " << pp.m_date.toString(Qt::ISODate) << "\n" + << " id: " << pp.m_id << "\n" + << " start: " << pp.m_range.m_start << "\n" + << " end: " << pp.m_range.m_end << "\n" + << " duration: " << pp.m_range.m_duration << "\n" + << " prepaid if: " << pp.prepaidIfStr() << endl; + return debug; + } +}; + +// deprecated struct ATBPrepaid { int id;