Added CalcState &setStatus(QString const &desc);

This commit is contained in:
Gerhard Hoffmann 2024-06-05 16:58:12 +02:00
parent 2dc93271fd
commit 6fb4d245cb
2 changed files with 115 additions and 30 deletions

View File

@ -42,18 +42,34 @@ struct CALCULATE_LIBRARY_API price_t {
};
struct CALCULATE_LIBRARY_API CalcState {
static QString const SUCCESS;
static QString const ERROR_PARSING_ZONE_NR;
static QString const ERROR_LOADING_TARIFF;
static QString const ERROR_PARSING_TARIFF;
static QString const NEGATIVE_PARKING_TIME;
static QString const INVALID_START_DATE;
static QString const WRONG_PARAM_VALUES;
static QString const WRONG_ISO_TIME_FORMAT;
static QString const ABOVE_MAX_PARKING_TIME;
static QString const BELOW_MIN_PARKING_TIME;
static QString const BELOW_MIN_PARKING_PRICE;
static QString const ABOVE_MAX_PARKING_PRICE;
static QString const OVERPAID;
static QString const OUTSIDE_ALLOWED_PARKING_TIME;
enum class State : uint8_t {
SUCCESS,
ERROR_PARSING_ZONE_NR,
ERROR_LOADING_TARIFF,
ERROR_PARSING_TARIFF,
NEGATIVE_PARING_TIME,
NEGATIVE_PARKING_TIME,
INVALID_START_DATE,
WRONG_PARAM_VALUES,
WRONG_ISO_TIME_FORMAT,
ABOVE_MAX_PARKING_TIME,
BELOW_MIN_PARKING_TIME,
BELOW_MIN_PARKING_PRICE,
ABOVE_MAX_PARKING_PRICE,
OVERPAID,
OUTSIDE_ALLOWED_PARKING_TIME
};
@ -88,43 +104,47 @@ struct CALCULATE_LIBRARY_API CalcState {
QString s;
switch (m_status) {
case State::SUCCESS:
s = "SUCCESS";
s = CalcState::SUCCESS;
break;
case State::ERROR_PARSING_ZONE_NR:
s = "ERROR_PARSING_ZONE_NR";
s = CalcState::ERROR_PARSING_ZONE_NR;
break;
case State::ERROR_LOADING_TARIFF:
s = "ERROR_LOADING_TARIFF";
s = CalcState::ERROR_LOADING_TARIFF;
break;
case State::ERROR_PARSING_TARIFF:
s = "ERROR_PARSING_TARIFF";
s = CalcState::ERROR_PARSING_TARIFF;
break;
case State::NEGATIVE_PARING_TIME:
s = "NEGATIVE_PARKING_TIME";
case State::NEGATIVE_PARKING_TIME:
s = CalcState::NEGATIVE_PARKING_TIME;
break;
case State::ABOVE_MAX_PARKING_TIME:
s = "ABOVE_MAX_PARKING_TIME";
s = CalcState::ABOVE_MAX_PARKING_TIME;
break;
case State::WRONG_PARAM_VALUES:
s = "WRONG_PARAM_VALUES";
s = CalcState::WRONG_PARAM_VALUES;
break;
case State::BELOW_MIN_PARKING_TIME:
s = "BELOW_MIN_PARKING_TIME";
s = CalcState::BELOW_MIN_PARKING_TIME;
break;
case State::BELOW_MIN_PARKING_PRICE:
s = "BELOW_MIN_PARKING_PRICE";
s = CalcState::BELOW_MIN_PARKING_PRICE;
break;
case State::OVERPAID:
s = "OVERPAID";
s = CalcState::OVERPAID;
break;
case State::INVALID_START_DATE:
s = "INVALID_START_DATE";
s = CalcState::INVALID_START_DATE;
break;
case State::WRONG_ISO_TIME_FORMAT:
s = "WRONG_ISO_TIME_FORMAT";
s = CalcState::WRONG_ISO_TIME_FORMAT;
break;
case State::OUTSIDE_ALLOWED_PARKING_TIME:
s = "OUTSIDE_ALLOWED_PARKING_TIME";
s = CalcState::OUTSIDE_ALLOWED_PARKING_TIME;
break;
case State::ABOVE_MAX_PARKING_PRICE:
s = CalcState::ABOVE_MAX_PARKING_TIME;
break;
}
return s + ":" + m_desc;
}
@ -133,51 +153,101 @@ struct CALCULATE_LIBRARY_API CalcState {
QString s;
switch (m_status) {
case State::SUCCESS:
s = "SUCCESS";
s = CalcState::SUCCESS;
break;
case State::ERROR_PARSING_ZONE_NR:
s = "ERROR_PARSING_ZONE_NR";
s = CalcState::ERROR_PARSING_ZONE_NR;
break;
case State::ERROR_LOADING_TARIFF:
s = "ERROR_LOADING_TARIFF";
s = CalcState::ERROR_LOADING_TARIFF;
break;
case State::ERROR_PARSING_TARIFF:
s = "ERROR_PARSING_TARIFF";
s = CalcState::ERROR_PARSING_TARIFF;
break;
case State::NEGATIVE_PARING_TIME:
s = "NEGATIVE_PARKING_TIME";
case State::NEGATIVE_PARKING_TIME:
s = CalcState::NEGATIVE_PARKING_TIME;
break;
case State::ABOVE_MAX_PARKING_TIME:
s = "ABOVE_MAX_PARKING_TIME";
s = CalcState::ABOVE_MAX_PARKING_TIME;
break;
case State::WRONG_PARAM_VALUES:
s = "WRONG_PARAM_VALUES";
s = CalcState::WRONG_PARAM_VALUES;
break;
case State::BELOW_MIN_PARKING_TIME:
s = "BELOW_MIN_PARKING_TIME";
s = CalcState::BELOW_MIN_PARKING_TIME;
break;
case State::BELOW_MIN_PARKING_PRICE:
s = "BELOW_MIN_PARKING_PRICE";
s = CalcState::BELOW_MIN_PARKING_PRICE;
break;
case State::OVERPAID:
s = "OVERPAID";
s = CalcState::OVERPAID;
break;
case State::INVALID_START_DATE:
s = "INVALID_START_DATE";
s = CalcState::INVALID_START_DATE;
break;
case State::WRONG_ISO_TIME_FORMAT:
s = "WRONG_ISO_TIME_FORMAT";
s = CalcState::WRONG_ISO_TIME_FORMAT;
break;
case State::OUTSIDE_ALLOWED_PARKING_TIME:
s = "OUTSIDE_ALLOWED_PARKING_TIME";
s = CalcState::OUTSIDE_ALLOWED_PARKING_TIME;
break;
case State::ABOVE_MAX_PARKING_PRICE:
s = CalcState::ABOVE_MAX_PARKING_TIME;
break;
}
return s + ":" + m_desc;
}
CalcState &set(State s) { m_status = s; return *this; }
CalcState &setStatus(State s) { return set(s); }
CalcState &setStatus(QString const &desc) {
if (desc == SUCCESS) {
m_status = State::SUCCESS;
} else
if (desc == ERROR_PARSING_ZONE_NR) {
m_status = State::ERROR_PARSING_ZONE_NR;
} else
if (desc == ERROR_LOADING_TARIFF) {
m_status = State::SUCCESS;
} else
if (desc == ERROR_PARSING_TARIFF) {
m_status = State::ERROR_LOADING_TARIFF;
} else
if (desc == NEGATIVE_PARKING_TIME) {
m_status = State::NEGATIVE_PARKING_TIME;
} else
if (desc == INVALID_START_DATE) {
m_status = State::INVALID_START_DATE;
} else
if (desc == WRONG_PARAM_VALUES) {
m_status = State::WRONG_PARAM_VALUES;
} else
if (desc == WRONG_ISO_TIME_FORMAT) {
m_status = State::WRONG_ISO_TIME_FORMAT;
} else
if (desc == ABOVE_MAX_PARKING_TIME) {
m_status = State::ABOVE_MAX_PARKING_TIME;
} else
if (desc == BELOW_MIN_PARKING_TIME) {
m_status = State::BELOW_MIN_PARKING_TIME;
} else
if (desc == BELOW_MIN_PARKING_PRICE) {
m_status = State::BELOW_MIN_PARKING_PRICE;
} else
if (desc == OVERPAID) {
m_status = State::OVERPAID;
} else
if (desc == OUTSIDE_ALLOWED_PARKING_TIME) {
m_status = State::OUTSIDE_ALLOWED_PARKING_TIME;
} else
if (desc == ABOVE_MAX_PARKING_PRICE) {
m_status = State::ABOVE_MAX_PARKING_PRICE;
}
return *this;
}
State getStatus() const { return m_status; }
CalcState &setDesc(QString s) { m_desc = s; return *this; }
CalcState &setDesc(QString const &s) { m_desc = s; return *this; }
void setAllowedTimeRange(QTime const &from, QTime const &until) {
m_allowedTimeRange.setTimeRange(from, until);

View File

@ -10,6 +10,21 @@
#include <QDebug>
#include <QList>
QString const CalcState::SUCCESS = "SUCCESS";
QString const CalcState::ERROR_PARSING_ZONE_NR = "ERROR_PARSING_ZONE_NR";
QString const CalcState::ERROR_LOADING_TARIFF = "ERROR_LOADING_TARIFF";
QString const CalcState::ERROR_PARSING_TARIFF = "ERROR_PARSING_TARIFF";
QString const CalcState::NEGATIVE_PARKING_TIME = "NEGATIVE_PARKING_TIME";
QString const CalcState::INVALID_START_DATE = "INVALID_START_DATE";
QString const CalcState::WRONG_PARAM_VALUES = "WRONG_PARAM_VALUES";
QString const CalcState::WRONG_ISO_TIME_FORMAT = "WRONG_ISO_TIME_FORMAT";
QString const CalcState::ABOVE_MAX_PARKING_TIME = "ABOVE_MAX_PARKING_TIME";
QString const CalcState::BELOW_MIN_PARKING_TIME = "BELOW_MIN_PARKING_TIME";
QString const CalcState::BELOW_MIN_PARKING_PRICE = "BELOW_MIN_PARKING_PRICE";
QString const CalcState::ABOVE_MAX_PARKING_PRICE = "ABOVE_MAX_PARKING_PRICE";
QString const CalcState::OVERPAID = "OVERPAID";
QString const CalcState::OUTSIDE_ALLOWED_PARKING_TIME = "OUTSIDE_ALLOWED_PARKING_TIME";
QList<int> CALCULATE_LIBRARY_API get_time_steps(Configuration *cfg) {
return Calculator::GetInstance().GetTimeSteps(cfg);
}