Add CalcState to be used as return type of tarif_init and compute_price_for_parking_ticket.
This commit is contained in:
parent
b422f82dea
commit
1c03745333
@ -4,6 +4,8 @@
|
|||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
|
|
||||||
|
#include <QString>
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
#ifdef CALCULATE_LIBRARY_EXPORTS
|
#ifdef CALCULATE_LIBRARY_EXPORTS
|
||||||
#define CALCULATE_LIBRARY_API __declspec(dllexport)
|
#define CALCULATE_LIBRARY_API __declspec(dllexport)
|
||||||
@ -30,14 +32,79 @@ struct CALCULATE_LIBRARY_API price_t {
|
|||||||
double vat;
|
double vat;
|
||||||
};
|
};
|
||||||
|
|
||||||
bool CALCULATE_LIBRARY_API init_tariff(parking_tariff_t **tariff, char const *config_file);
|
struct CALCULATE_LIBRARY_API CalcState {
|
||||||
|
enum class State : uint8_t {
|
||||||
|
SUCCESS,
|
||||||
|
ERROR_PARSING_ZONE_NR,
|
||||||
|
ERROR_LOADING_TARIFF,
|
||||||
|
ERROR_PARSING_TARIFF,
|
||||||
|
NEGATIVE_PARING_TIME,
|
||||||
|
WRONG_PARAM_VALUES,
|
||||||
|
ABOVE_MAX_PARKING_TIME,
|
||||||
|
BELOW_MIN_PARKING_TIME,
|
||||||
|
BELOW_MIN_PARKING_PRICE,
|
||||||
|
OVERPAID
|
||||||
|
};
|
||||||
|
|
||||||
|
State m_status;
|
||||||
|
QString m_desc;
|
||||||
|
|
||||||
|
explicit CalcState() : m_status(State::SUCCESS), m_desc("") {}
|
||||||
|
|
||||||
|
explicit operator bool() const noexcept {
|
||||||
|
return (m_status == State::SUCCESS);
|
||||||
|
}
|
||||||
|
|
||||||
|
explicit operator QString () const noexcept {
|
||||||
|
QString s;
|
||||||
|
switch (m_status) {
|
||||||
|
case State::SUCCESS:
|
||||||
|
s = "SUCCESS";
|
||||||
|
break;
|
||||||
|
case State::ERROR_PARSING_ZONE_NR:
|
||||||
|
s = "ERROR_PARSING_ZONE_NR";
|
||||||
|
break;
|
||||||
|
case State::ERROR_LOADING_TARIFF:
|
||||||
|
s = "ERROR_LOADING_TARIFF";
|
||||||
|
break;
|
||||||
|
case State::ERROR_PARSING_TARIFF:
|
||||||
|
s = "ERROR_PARSING_TARIFF";
|
||||||
|
break;
|
||||||
|
case State::NEGATIVE_PARING_TIME:
|
||||||
|
s = "NEGATIVE_PARKING_TIME";
|
||||||
|
break;
|
||||||
|
case State::ABOVE_MAX_PARKING_TIME:
|
||||||
|
s = "ABOVE_MAX_PARKING_TIME";
|
||||||
|
break;
|
||||||
|
case State::WRONG_PARAM_VALUES:
|
||||||
|
s = "WRONG_PARAM_VALUES";
|
||||||
|
break;
|
||||||
|
case State::BELOW_MIN_PARKING_TIME:
|
||||||
|
s = "BELOW_MIN_PARKING_TIME";
|
||||||
|
break;
|
||||||
|
case State::BELOW_MIN_PARKING_PRICE:
|
||||||
|
s = "BELOW_MIN_PARKING_PRICE";
|
||||||
|
break;
|
||||||
|
case State::OVERPAID:
|
||||||
|
s = "OVERPAID";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return s + ":" + m_desc;
|
||||||
|
}
|
||||||
|
|
||||||
|
CalcState &set(State s) { m_status = s; return *this; }
|
||||||
|
CalcState &setDesc(QString s) { m_desc = s; return *this; }
|
||||||
|
};
|
||||||
|
|
||||||
|
CalcState CALCULATE_LIBRARY_API init_tariff(parking_tariff_t **tariff,
|
||||||
|
char const *config_file);
|
||||||
void CALCULATE_LIBRARY_API free_tariff(parking_tariff_t *tariff);
|
void CALCULATE_LIBRARY_API free_tariff(parking_tariff_t *tariff);
|
||||||
int CALCULATE_LIBRARY_API get_zone_nr();
|
int CALCULATE_LIBRARY_API get_zone_nr();
|
||||||
|
|
||||||
bool CALCULATE_LIBRARY_API compute_price_for_parking_ticket(parking_tariff_t *tariff,
|
CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(parking_tariff_t *tariff,
|
||||||
time_t start_parking_time,
|
time_t start_parking_time,
|
||||||
time_t end_parking_time,
|
time_t end_parking_time,
|
||||||
struct price_t *price);
|
struct price_t *price);
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
} // extern "C"
|
} // extern "C"
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user