Minor: overload constructor

This commit is contained in:
Gerhard Hoffmann 2023-11-27 16:14:27 +01:00
parent 684de4acd1
commit 6a3d183129
2 changed files with 39 additions and 18 deletions

View File

@ -21,6 +21,9 @@ public:
using Status = std::tuple<int, char const*, char const*>;
explicit Ticket();
explicit Ticket(QDateTime const &s, QDateTime const &e,
int durationMinutesNetto, int durationMinutesBrutto,
uint32_t price, Status status);
explicit operator bool() { return std::get<CODE>(m_status) == VALID; }
operator QString();
@ -35,6 +38,15 @@ public:
void setValidUntil(QDateTime const &validUnil);
void setPrice(uint32_t price);
bool isValid() { return operator bool(); }
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" }
};
private:
Status m_status;
@ -45,20 +57,8 @@ private:
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;
}
QDebug operator<<(QDebug debug, Ticket::Status const &status);
#endif // TICKET_H_INCLUDED

View File

@ -12,6 +12,18 @@ Ticket::Ticket()
qDebug() << m_status;
}
Ticket::Ticket(QDateTime const &s, QDateTime const &e,
int durationMinutesNetto, int durationMinutesBrutto,
uint32_t price, Ticket::Status status)
: m_status(status)
, m_validFrom(s)
, m_validUntil(e)
, m_durationMinutesNetto(durationMinutesNetto)
, m_durationMinutesBrutto(durationMinutesBrutto)
, m_price(price) {
}
Ticket::Status Ticket::setStatus(Status status) {
Status old = m_status;
m_status = status;
@ -54,14 +66,23 @@ void Ticket::setPrice(uint32_t price) {
Ticket::operator QString() {
QStringList status;
status << QString("Status .............. : %1 (%2)")
status << QString("**********************");
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);
status << QString("Price .............. : %1").arg(m_price);
status << QString("**********************");
return status.join('\n');;
return status.join('\n');
}
QDebug operator<<(QDebug debug, Ticket::Status const &status) {
QDebugStateSaver saver(debug);
debug << "Ticket-Status: " << std::get<1>(status)
<< "(" << std::get<2>(status) << ")";
return debug;
}