Add class Ticket for future use.
This commit is contained in:
parent
7ac033720e
commit
b84970fd12
64
library/include/mobilisis/ticket.h
Normal file
64
library/include/mobilisis/ticket.h
Normal file
@ -0,0 +1,64 @@
|
||||
#ifndef TICKET_H_INCLUDED
|
||||
#define TICKET_H_INCLUDED
|
||||
|
||||
#include <tuple>
|
||||
#include <vector>
|
||||
|
||||
#include <QDebug>
|
||||
#include <QDebugStateSaver>
|
||||
#include <QStringList>
|
||||
#include <QDateTime>
|
||||
|
||||
#define NOT_INITIALIZED (0)
|
||||
#define VALID (1)
|
||||
#define INVALID_FROM_DATETIME (2)
|
||||
#define INVALID_UNTIL_DATETIME (3)
|
||||
#define STATUS_END (4)
|
||||
|
||||
class Ticket {
|
||||
enum {CODE=0, CODE_STR=1, CODE_DESC=3};
|
||||
public:
|
||||
using Status = std::tuple<int, char const*, char const*>;
|
||||
|
||||
explicit Ticket();
|
||||
|
||||
explicit operator bool() { return std::get<CODE>(m_status) == VALID; }
|
||||
operator QString();
|
||||
|
||||
Status getStatus() const;
|
||||
QDateTime getValidFrom() const;
|
||||
QDateTime getValidUntil() const;
|
||||
uint32_t getPrice() const;
|
||||
|
||||
Status setStatus(Status status);
|
||||
void setValidFrom(QDateTime const &validFrom);
|
||||
void setValidUntil(QDateTime const &validUnil);
|
||||
void setPrice(uint32_t price);
|
||||
|
||||
private:
|
||||
Status m_status;
|
||||
|
||||
QDateTime m_validFrom;
|
||||
QDateTime m_validUntil;
|
||||
|
||||
int m_durationMinutesNetto;
|
||||
int m_durationMinutesBrutto;
|
||||
|
||||
uint32_t m_price;
|
||||
|
||||
static constexpr const Status s[STATUS_END] = {
|
||||
{NOT_INITIALIZED , "NOT_INITIALIZED" , "Ticket not initialized" },
|
||||
{VALID , "VALID" , "Ticket is valid" },
|
||||
{INVALID_FROM_DATETIME , "INVALID_FROM_DATETIME" , "Ticket has invalid start datetime"},
|
||||
{INVALID_UNTIL_DATETIME, "INVALID_UNTIL_DATETIME", "Ticket has invalid end datetime" }
|
||||
};
|
||||
};
|
||||
|
||||
QDebug operator<<(QDebug debug, Ticket::Status const &status) {
|
||||
QDebugStateSaver saver(debug);
|
||||
debug << "Ticket-Status: " << std::get<1>(status)
|
||||
<< "(" << std::get<2>(status) << ")";
|
||||
return debug;
|
||||
}
|
||||
|
||||
#endif // TICKET_H_INCLUDED
|
67
library/src/ticket.cpp
Normal file
67
library/src/ticket.cpp
Normal file
@ -0,0 +1,67 @@
|
||||
#include "ticket.h"
|
||||
|
||||
Ticket::Ticket()
|
||||
: m_status(Ticket::s[NOT_INITIALIZED])
|
||||
, m_validFrom()
|
||||
, m_validUntil()
|
||||
, m_durationMinutesNetto(0)
|
||||
, m_durationMinutesBrutto(0)
|
||||
, m_price() {
|
||||
|
||||
qDebug() << *this;
|
||||
qDebug() << m_status;
|
||||
}
|
||||
|
||||
Ticket::Status Ticket::setStatus(Status status) {
|
||||
Status old = m_status;
|
||||
m_status = status;
|
||||
return old;
|
||||
}
|
||||
|
||||
Ticket::Status Ticket::getStatus() const {
|
||||
return m_status;
|
||||
}
|
||||
|
||||
void Ticket::setValidFrom(QDateTime const &validFrom) {
|
||||
m_validFrom = validFrom;
|
||||
}
|
||||
|
||||
void Ticket::setValidUntil(QDateTime const &validUntil) {
|
||||
m_validUntil = validUntil;
|
||||
}
|
||||
|
||||
QDateTime Ticket::getValidFrom() const {
|
||||
if (std::get<CODE>(m_status) == VALID) {
|
||||
return m_validFrom;
|
||||
}
|
||||
return QDateTime();
|
||||
}
|
||||
|
||||
QDateTime Ticket::getValidUntil() const {
|
||||
if (std::get<CODE>(m_status) == VALID) {
|
||||
return m_validFrom;
|
||||
}
|
||||
return QDateTime();
|
||||
}
|
||||
|
||||
uint32_t Ticket::getPrice() const {
|
||||
return m_price;
|
||||
}
|
||||
|
||||
void Ticket::setPrice(uint32_t price) {
|
||||
m_price = price;
|
||||
}
|
||||
|
||||
Ticket::operator QString() {
|
||||
QStringList status;
|
||||
status << QString("Status .............. : %1 (%2)")
|
||||
.arg(std::get<0>(m_status))
|
||||
.arg(std::get<2>(m_status));
|
||||
status << QString("Valid from ......... : %1").arg(m_validFrom.toString(Qt::ISODate));
|
||||
status << QString("Valid until ........ : %1").arg(m_validUntil.toString(Qt::ISODate));
|
||||
status << QString("Duration (netto) ... : %1").arg(m_durationMinutesNetto);
|
||||
status << QString("Duration (brutto)... : %1").arg(m_durationMinutesBrutto);
|
||||
status << QString("Price ......... : %1").arg(m_price);
|
||||
|
||||
return status.join('\n');;
|
||||
}
|
Loading…
Reference in New Issue
Block a user