From 41a09d882d696768a2fd8c7828c673ac3013e03e Mon Sep 17 00:00:00 2001 From: Gerhard Hoffmann Date: Mon, 21 Oct 2024 14:31:08 +0200 Subject: [PATCH] brainstorming ... --- library/include/mobilisis/tariff_comp_state.h | 20 +++++++++++++ library/include/mobilisis/tariff_comp_step.h | 29 +++++++++++++++++++ library/src/tariff_comp_step.cpp | 17 +++++++++++ 3 files changed, 66 insertions(+) create mode 100644 library/include/mobilisis/tariff_comp_state.h create mode 100644 library/include/mobilisis/tariff_comp_step.h create mode 100644 library/src/tariff_comp_step.cpp diff --git a/library/include/mobilisis/tariff_comp_state.h b/library/include/mobilisis/tariff_comp_state.h new file mode 100644 index 0000000..cd09d39 --- /dev/null +++ b/library/include/mobilisis/tariff_comp_state.h @@ -0,0 +1,20 @@ +#ifndef TARIFF_COMP_STATE_H_INCLUDED +#define TARIFF_COMP_STATE_H_INCLUDED + +#include + +struct TariffCompState { + QDateTime const m_start; + int m_nettoParkingTimeTotal = 0; + int m_bruttoParkingTimeTotal = 0; + int m_priceTotal = 0; + + explicit TariffCompState(QDateTime start) + : m_start(std::move(start)) + , m_nettoParkingTimeTotal(0) + , m_bruttoParkingTimeTotal(0) + , m_priceTotal(0) { + } +}; + +#endif // TARIFF_COMP_STATE_H_INCLUDED diff --git a/library/include/mobilisis/tariff_comp_step.h b/library/include/mobilisis/tariff_comp_step.h new file mode 100644 index 0000000..ee2f46a --- /dev/null +++ b/library/include/mobilisis/tariff_comp_step.h @@ -0,0 +1,29 @@ +#ifndef TARIFF_COMP_STEP_H_INCLUDED +#define TARIFF_COMP_STEP_H_INCLUDED + +#include +#include "tariff_comp_state.h" + +class TariffCompStep { + int m_duration; + QDateTime const m_start; + QDateTime const m_end; + uint64_t const m_handle; + TariffCompState m_compState; + + uint64_t hash(); + +public: + explicit TariffCompStep(int duration, QDateTime start, QDateTime end, TariffCompState &compState) + : m_duration(duration) + , m_start(std::move(start)) + , m_end(std::move(end)) + , m_handle(hash()) + , m_compState(compState) { + } + + uint64_t handle() { return m_handle; } + uint64_t handle() const { return m_handle; } +}; + +#endif // TARIFF_COMP_STEP_H_INCLUDED diff --git a/library/src/tariff_comp_step.cpp b/library/src/tariff_comp_step.cpp new file mode 100644 index 0000000..6d5cf3a --- /dev/null +++ b/library/src/tariff_comp_step.cpp @@ -0,0 +1,17 @@ +#include "tariff_comp_step.h" + +#include +#include +#include + +uint64_t TariffCompStep::hash() { + QString const str(QString("%1%2%3").arg(m_duration).arg(m_start.toString(Qt::ISODate)).arg(m_end.toString(Qt::ISODate))); + QByteArray const hash = QCryptographicHash::hash( + QByteArray::fromRawData(reinterpret_cast(str.utf16()), str.length()*2), + QCryptographicHash::Md5 + ); + + uint64_t const &i = hash.left(8).toULongLong(nullptr, 16); + uint64_t const &j = hash.right(8).toULongLong(nullptr, 16); + return i ^ j; +}