From afb0e20dd2e64477201a0036960ea625a8ca1b5e Mon Sep 17 00:00:00 2001 From: Gerhard Hoffmann Date: Thu, 22 Feb 2024 16:33:19 +0100 Subject: [PATCH] Implement parsing of "Product" and adding into TariffProduct. --- library/src/configuration.cpp | 51 +++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/library/src/configuration.cpp b/library/src/configuration.cpp index d301cd3..d5e2cec 100644 --- a/library/src/configuration.cpp +++ b/library/src/configuration.cpp @@ -2,6 +2,7 @@ #include "tariff_timebase.h" #include "time_range_header.h" #include "tariff_timestep_config.h" +#include "tariff_permit_type.h" #include #include @@ -24,6 +25,7 @@ MemberType Configuration::IdentifyJsonMember(const char* member_name) if (strcmp(member_name, "Customer") == 0) return MemberType::CustomerType; if (strcmp(member_name, "TimeRange") == 0) return MemberType::TimeRangeType; if (strcmp(member_name, "TimeStepConfig") == 0) return MemberType::TimeStepConfigType; + if (strcmp(member_name, "Product") == 0) return MemberType::ProductType; else return MemberType::UnknownType; } @@ -93,6 +95,7 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json) ATBCustomer Customer; ATBTimeRange TimeRange; ATBTimeStepConfig TimeStepConfig; + ATBTariffProduct TariffProduct; MemberType mb_type = MemberType::UnknownType; this->currentPaymentOptions.clear(); @@ -157,6 +160,50 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json) { case MemberType::UnknownType: break; + case MemberType::ProductType: { + if (QString(inner_obj_name) == QString("tariff_product_id")) { + if (k->value.IsInt()) { + int const x = k->value.GetInt(); + TariffProduct.m_tariff_product_id = PermitType(x); + } + } else + if (QString(inner_obj_name) == QString("tariff_product_price")) { + if (k->value.IsInt()) { + int const x = k->value.GetInt(); + TariffProduct.m_tariff_product_price = x; + } + } else + if (QString(inner_obj_name) == QString("tariff_product_name")) { + if (k->value.IsString()) { + std::string const &s = k->value.GetString(); + TariffProduct.m_tariff_product_name = QString::fromStdString(s); + } + } else + if (QString(inner_obj_name) == QString("tariff_product_start")) { + if (k->value.IsString()) { + std::string const &s = k->value.GetString(); + TariffProduct.m_tariff_product_start = QTime::fromString(QString::fromStdString(s), Qt::ISODate); + } + } else + if (QString(inner_obj_name) == QString("tariff_product_end")) { + if (k->value.IsString()) { + std::string const &s = k->value.GetString(); + TariffProduct.m_tariff_product_end = QTime::fromString(QString::fromStdString(s), Qt::ISODate); + } + } else + if (QString(inner_obj_name) == QString("tariff_product_from_in_minutes_from_start")) { + if (k->value.IsInt()) { + int const x = k->value.GetInt(); + TariffProduct.m_tariff_product_from_in_minutes_from_start = x; + } + } else + if (QString(inner_obj_name) == QString("tariff_product_to_in_minutes_from_start")) { + if (k->value.IsInt()) { + int const x = k->value.GetInt(); + TariffProduct.m_tariff_product_to_in_minutes_from_start = x; + } + } + } break; case MemberType::TimeRangeType: if (QString(inner_obj_name) == QString("time_range_id")) { if (k->value.IsInt()) { @@ -479,6 +526,9 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json) cfg->TimeStepConfig.insert(pair(TimeStepConfig.tsconfig_id, TimeStepConfig)); // qCritical() << TimeStepConfig; break; + case MemberType::ProductType: + cfg->TariffProduct.insert(pair(TariffProduct.m_tariff_product_id, TariffProduct)); + qCritical() << TariffProduct; default: break; } @@ -492,6 +542,7 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json) } } + ATBPaymentOption const &Configuration::getPaymentOptions() const { Q_ASSERT(!this->currentPaymentOptions.isEmpty()); return this->currentPaymentOptions.at(0);