Added parsing of version, tariff_features, waiting_period, parking_time_min and parking_time_max.

This commit is contained in:
Gerhard Hoffmann 2023-01-24 10:06:15 +01:00
parent 9a32a765cd
commit 8fb5699e63

View File

@ -2,6 +2,7 @@
#include <cstdio>
#include <string>
#include <algorithm>
#include <QDebug>
#include <QDateTime>
@ -23,6 +24,11 @@ using namespace rapidjson;
#define MAX_PARKING_PRICE "max_parking_price"
#define MAX_PRICE_FOR_24_HOURS "max_price_for_24_hours"
#define MAX_PARKING_TIME "max_parking_time"
#define TARIFF_VERSION "version"
#define TARIFF_FEATURES "tariff_features"
#define WAITING_PERIOD "waiting_period"
#define PARKING_TIME_MIN "parking_time_min"
#define PARKING_TIME_MAX "parking_time_max"
static const char *weekStr[] {
"week1", "week2", "week3"
@ -59,6 +65,37 @@ parking_tariff_t *parking_tariff_t::parseTariff(const char *confFile) {
tariff = new parking_tariff_t();
if (d.HasMember(TARIFF_VERSION)) {
Value::MemberIterator o = d.FindMember(TARIFF_VERSION);
assert(o != d.MemberEnd());
assert(o->value.IsString());
std::string version = o->value.GetString();
strncpy(tariff->tariff_version, version.c_str(),
std::min((int)version.size(),
(int)sizeof(tariff->tariff_version)-1));
tariff->tariff_version[sizeof(tariff->tariff_version)-1] = '\0';
}
if (d.HasMember(TARIFF_FEATURES)) {
Value::MemberIterator o = d.FindMember(TARIFF_FEATURES);
assert(o != d.MemberEnd());
assert(o->value.IsArray());
int const s = o->value.Size();
if (s > 0) {
// TODO
} else {
tariff->tariff_features = 0;
memset(tariff->_tariff_features, 0x00,
sizeof(tariff->_tariff_features));
}
}
if (d.HasMember(WAITING_PERIOD)) {
Value::MemberIterator o = d.FindMember(WAITING_PERIOD);
assert(o != d.MemberEnd());
assert(o->value.IsString());
std::string wp = o->value.GetString();
tariff->waiting_period = std::stoi(wp);
}
if (d.HasMember(FREE_OF_CHARGE)) {
Value::MemberIterator o = d.FindMember(FREE_OF_CHARGE);
assert(o != d.MemberEnd());
@ -98,6 +135,24 @@ parking_tariff_t *parking_tariff_t::parseTariff(const char *confFile) {
tariff->max_parking_price_units = (uint32_t)std::stoul(mp);
}
}
if (d.HasMember(PARKING_TIME_MIN)) {
Value::MemberIterator o = d.FindMember(PARKING_TIME_MIN);
assert(o != d.MemberEnd());
assert(o->value.IsString());
std::string mp = o->value.GetString();
tariff->parking_time_min = (uint32_t)std::stoul(mp);
}
if (d.HasMember(PARKING_TIME_MAX)) {
Value::MemberIterator o = d.FindMember(PARKING_TIME_MAX);
assert(o != d.MemberEnd());
assert(o->value.IsString());
std::string mp = o->value.GetString();
if (mp == "unlimited") {
tariff->parking_time_max = ~0;
} else {
tariff->parking_time_max = (uint32_t)std::stoul(mp);
}
}
if (d.HasMember(MAX_PRICE_FOR_24_HOURS)) {
Value::MemberIterator o = d.FindMember(MAX_PRICE_FOR_24_HOURS);
assert(o != d.MemberEnd());
@ -109,17 +164,6 @@ parking_tariff_t *parking_tariff_t::parseTariff(const char *confFile) {
tariff->max_price_for_24_hours = (uint32_t)std::stoul(mp);
}
}
if (d.HasMember(MAX_PARKING_TIME)) {
Value::MemberIterator o = d.FindMember(MAX_PARKING_TIME);
assert(o != d.MemberEnd());
assert(o->value.IsString());
std::string mp = o->value.GetString();
if (mp == "unlimited") {
tariff->max_parking_time = ~0;
} else {
tariff->max_parking_time = (uint32_t)std::stoul(mp);
}
}
QDate today = QDate::currentDate();