From c799c24658a26ab730f3508e39efb2e029c85783 Mon Sep 17 00:00:00 2001 From: Gerhard Hoffmann Date: Tue, 30 Jan 2024 14:04:58 +0100 Subject: [PATCH] Removed local variable PaymentOption. Replaced by usage of currentPaymentOption-vector. --- library/src/configuration.cpp | 60 +++++++++++++++++++++++------------ 1 file changed, 40 insertions(+), 20 deletions(-) diff --git a/library/src/configuration.cpp b/library/src/configuration.cpp index ec22866..6ded661 100644 --- a/library/src/configuration.cpp +++ b/library/src/configuration.cpp @@ -87,7 +87,6 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json) ATBSpecialDays SpecialDays; ATBWeekDays WeekDays; ATBWeekDaysWorktime WeekDaysWorktime; - ATBPaymentOption PaymentOption; ATBPeriodYear YearPeriod; ATBDailyTicket DailyTicket; ATBTimeBase TimeBase; @@ -96,6 +95,7 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json) ATBTimeStepConfig TimeStepConfig; MemberType mb_type = MemberType::UnknownType; + this->currentPaymentOptions.clear(); // Get all JSON object members // This code should run only once (to load JSON variables into memory) @@ -320,22 +320,37 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json) else if (strcmp(inner_obj_name, "pra_price") == 0) PaymentRate.pra_price = k->value.GetDouble(); break; case MemberType::PaymentOptionType: - if (strcmp(inner_obj_name, "pop_id") == 0) PaymentOption.pop_id = k->value.GetInt(); - else if (strcmp(inner_obj_name, "pop_label") == 0) PaymentOption.pop_label = k->value.GetString(); - else if (strcmp(inner_obj_name, "pop_payment_method_id") == 0) PaymentOption.pop_payment_method_id = k->value.GetInt(); - else if (strcmp(inner_obj_name, "pop_day_end_time") == 0) PaymentOption.pop_day_end_time = k->value.GetString(); - else if (strcmp(inner_obj_name, "pop_day_night_end_time") == 0) PaymentOption.pop_day_night_end_time = k->value.GetString(); - else if (strcmp(inner_obj_name, "pop_price_night") == 0) PaymentOption.pop_price_night = k->value.GetDouble(); - else if (strcmp(inner_obj_name, "pop_min_time") == 0) PaymentOption.pop_min_time = k->value.GetDouble(); - else if (strcmp(inner_obj_name, "pop_max_time") == 0) PaymentOption.pop_max_time = k->value.GetDouble(); - else if (strcmp(inner_obj_name, "pop_min_price") == 0) PaymentOption.pop_min_price = k->value.GetDouble(); - else if (strcmp(inner_obj_name, "pop_carry_over") == 0) PaymentOption.pop_carry_over = k->value.GetInt(); - else if (strcmp(inner_obj_name, "pop_carry_over_time_range_id") == 0) PaymentOption.pop_carry_over_time_range_id = k->value.GetInt(); - else if (strcmp(inner_obj_name, "pop_daily_card_price") == 0) PaymentOption.pop_daily_card_price = k->value.GetInt(); - else if (strcmp(inner_obj_name, "pop_business_hours") == 0) PaymentOption.pop_business_hours = k->value.GetInt(); - else if (strcmp(inner_obj_name, "pop_time_step_config") == 0) PaymentOption.pop_time_step_config = k->value.GetInt(); - this->currentPaymentOptions.append(PaymentOption); - PaymentOption.reset(); + if (strcmp(inner_obj_name, "pop_id") == 0) { + this->currentPaymentOptions.append(ATBPaymentOption()); + this->currentPaymentOptions.last().reset(); + this->currentPaymentOptions.last().pop_id = k->value.GetInt(); + } else if (strcmp(inner_obj_name, "pop_label") == 0) { + this->currentPaymentOptions.last().pop_label = k->value.GetString(); + } else if (strcmp(inner_obj_name, "pop_payment_method_id") == 0) { + this->currentPaymentOptions.last().pop_payment_method_id = k->value.GetInt(); + } else if (strcmp(inner_obj_name, "pop_day_end_time") == 0) { + this->currentPaymentOptions.last().pop_day_end_time = k->value.GetString(); + } else if (strcmp(inner_obj_name, "pop_day_night_end_time") == 0) { + this->currentPaymentOptions.last().pop_day_night_end_time = k->value.GetString(); + } else if (strcmp(inner_obj_name, "pop_price_night") == 0) { + this->currentPaymentOptions.last().pop_price_night = k->value.GetDouble(); + } else if (strcmp(inner_obj_name, "pop_min_time") == 0) { + this->currentPaymentOptions.last().pop_min_time = k->value.GetDouble(); + } else if (strcmp(inner_obj_name, "pop_max_time") == 0) { + this->currentPaymentOptions.last().pop_max_time = k->value.GetDouble(); + } else if (strcmp(inner_obj_name, "pop_min_price") == 0) { + this->currentPaymentOptions.last().pop_min_price = k->value.GetDouble(); + } else if (strcmp(inner_obj_name, "pop_carry_over") == 0) { + this->currentPaymentOptions.last().pop_carry_over = k->value.GetInt(); + } else if (strcmp(inner_obj_name, "pop_carry_over_time_range_id") == 0) { + this->currentPaymentOptions.last().pop_carry_over_time_range_id = k->value.GetInt(); + } else if (strcmp(inner_obj_name, "pop_daily_card_price") == 0) { + this->currentPaymentOptions.last().pop_daily_card_price = k->value.GetInt(); + } else if (strcmp(inner_obj_name, "pop_business_hours") == 0) { + this->currentPaymentOptions.last().pop_business_hours = k->value.GetInt(); + } else if (strcmp(inner_obj_name, "pop_time_step_config") == 0) { + this->currentPaymentOptions.last().pop_time_step_config = k->value.GetInt(); + } break; case MemberType::DurationType: if (strcmp(inner_obj_name, "pun_id") == 0) Duration.pun_id = k->value.GetInt(); @@ -397,9 +412,12 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json) // qCritical() << "PaymentRate" << PaymentRate; cfg->PaymentRate.insert(pair(PaymentRate.pra_payment_option_id, PaymentRate)); break; - case MemberType::PaymentOptionType: - cfg->PaymentOption.insert(pair(PaymentOption.pop_payment_method_id, PaymentOption)); - break; + case MemberType::PaymentOptionType: { + if (!this->currentPaymentOptions.isEmpty()) { + ATBPaymentOption const &PaymentOption = this->currentPaymentOptions.last(); + cfg->PaymentOption.insert(pair(PaymentOption.pop_payment_method_id, PaymentOption)); + } + } break; case MemberType::DurationType: cfg->Duration.insert(pair(Duration.pun_id, Duration)); break; @@ -453,10 +471,12 @@ bool Configuration::ParseJson(Configuration* cfg, const char* json) } ATBPaymentOption const &Configuration::getPaymentOptions() const { + Q_ASSERT(!this->currentPaymentOptions.isEmpty()); return this->currentPaymentOptions.at(0); } ATBPaymentOption &Configuration::getPaymentOptions() { + Q_ASSERT(!this->currentPaymentOptions.isEmpty()); return this->currentPaymentOptions[0]; }