From e980d8c451eb1b9baad400c7650bc255a28478fd Mon Sep 17 00:00:00 2001 From: Gerhard Hoffmann Date: Thu, 22 Feb 2024 16:34:57 +0100 Subject: [PATCH] Implement std::optional> getTariffProductForAllKeys() const; std::optional> getTariffProductForProductId(int id) const; std::optional> getTariffProductForProductId(PermitType permitType) const; --- library/src/configuration.cpp | 42 +++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/library/src/configuration.cpp b/library/src/configuration.cpp index d5e2cec..812425f 100644 --- a/library/src/configuration.cpp +++ b/library/src/configuration.cpp @@ -561,6 +561,48 @@ QVector &Configuration::getAllPaymentOptions() { return this->currentPaymentOptions; } +std::optional> +Configuration::getTariffProductForAllKeys() const { + QVector products; + std::optional> value; + + products.clear(); + + for (std::multimap::const_iterator it = this->TariffProduct.cbegin(); + it != this->TariffProduct.cend(); ++it) { + products.append(it->second); + } + + if (products.size() > 0) { + value = value.value_or(products); + } + + return value; +} + +std::optional> +Configuration::getTariffProductForProductId(PermitType permitType) const { + QVector products; + std::optional> value; + + products.clear(); + + for (auto[it, rangeEnd] = this->TariffProduct.equal_range(permitType); it != rangeEnd; ++it) { + products.append(it->second); + } + + if (products.size() > 0) { + value = value.value_or(products); + } + + return value; +} + +std::optional> +Configuration::getTariffProductForProductId(int id) const { + return getTariffProductForProductId(PermitType(id)); +} + std::optional> Configuration::getDailyTicketsForAllKeys() const { QVector tickets;