Remove static instance of calculator. Replaced with use of Calculator-singleton-calss.

This commit is contained in:
Gerhard Hoffmann 2024-01-23 10:55:00 +01:00
parent ac45ebb926
commit 1b933c05a6

View File

@ -10,16 +10,15 @@
#include <QDebug>
#include <QList>
static Calculator calculator;
QList<int> CALCULATE_LIBRARY_API get_time_steps(Configuration *cfg) {
return calculator.GetTimeSteps(cfg);
return Calculator::GetInstance().GetTimeSteps(cfg);
}
int CALCULATE_LIBRARY_API get_minimal_parkingtime(Configuration *cfg) {
// get_time_steps() possibly re-computes pop_min_time: see
// calculator.GetTimeSteps()
get_time_steps(cfg);
// for each new sell-procedure, recomute the timesteps. implicitly, set
// the minimal parking time.
Calculator::GetInstance().ResetTimeSteps();
Calculator::GetInstance().GetTimeSteps(cfg);
return qRound(cfg->getPaymentOptions().pop_min_time);
}
@ -109,7 +108,9 @@ void CALCULATE_LIBRARY_API free_tariff(parking_tariff_t *tariff) {
// UpDown 1 -> up; 0 -> down
int CALCULATE_LIBRARY_API compute_next_timestep(parking_tariff_t *tariff, int currentTimeMinutes, int UpDown)
{
qCritical() << " compute_next_timestep() currentTimeMinutes: " << currentTimeMinutes;
qCritical() << " compute_next_timestep() currentTimeMinutes: " << currentTimeMinutes;
qCritical() << " compute_next_timestep() up/down (1=up, 0=down): " << UpDown;
Configuration const *cfg = tariff;
// compute payment method id (e.g. Linear=3, Steps=4)
@ -136,7 +137,8 @@ int CALCULATE_LIBRARY_API compute_next_timestep(parking_tariff_t *tariff, int cu
// without given YearPeriod, SpecialDays and SpecialDaysWorktime
if (paymentMethodId == PaymentMethod::Steps)
{
static const QList<int> stepList = calculator.GetTimeSteps(tariff);
const QList<int> stepList = Calculator::GetInstance().GetTimeSteps(tariff);
qCritical() << " compute_next_timestep() timeSteps:" << stepList;
int currentStepIndex = stepList.indexOf(currentTimeMinutes);
@ -237,7 +239,7 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
start = start.toLocalTime().addSecs(start_parking_time * 60);
QDateTime end(start);
if (start.isValid()) {
double cost = calculator.GetCostFromDuration(
double cost = Calculator::GetInstance().GetCostFromDuration(
tariff,
tariff->getPaymentOptions().pop_payment_method_id,
start,
@ -296,7 +298,7 @@ CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
}
if (start_parking_time.isValid()) {
double cost = calculator.GetCostFromDuration(
double cost = Calculator::GetInstance().GetCostFromDuration(
tariff,
tariff->getPaymentOptions().pop_payment_method_id,
start_parking_time, // starting time
@ -339,7 +341,7 @@ CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket(
qCritical() << " start (cs): " << cs;
qCritical() << " price: " << price;
duration = calculator.GetDurationFromCost(tariff,
duration = Calculator::GetInstance().GetDurationFromCost(tariff,
tariff->getPaymentOptions().pop_payment_method_id,
cs.toLocal8Bit().constData(),
price, false, true).c_str();
@ -364,7 +366,7 @@ CalcState CALCULATE_LIBRARY_API compute_duration_for_parking_ticket(
CalcState calcState;
if (start_parking_time.isValid()) {
QString cs = start_parking_time.toString(Qt::ISODate);
QString endTime = calculator.GetDurationFromCost(
QString endTime = Calculator::GetInstance().GetDurationFromCost(
tariff,
tariff->getPaymentOptions().pop_payment_method_id,
cs.toLocal8Bit().constData(),
@ -392,7 +394,7 @@ CalcState CALCULATE_LIBRARY_API compute_duration_for_daily_ticket(parking_tariff
CalcState calcState;
if (start_parking_time.isValid()) {
ticketEndTime = calculator.GetDailyTicketDuration(tariff,
ticketEndTime = Calculator::GetInstance().GetDailyTicketDuration(tariff,
start_parking_time,
tariff->getPaymentOptions().pop_payment_method_id,
false); // carry over