KItinerary

elbticket.h
1/*
2 SPDX-FileCopyrightText: 2023 Volker Krause <vkrause@kde.org>
3 SPDX-License-Identifier: LGPL-2.0-or-later
4*/
5
6#ifndef KITINERARY_ELBTICKET_H
7#define KITINERARY_ELBTICKET_H
8
9#include "kitinerary_export.h"
10
11#include <QByteArray>
12#include <QDateTime>
13#include <QMetaType>
14
15#include <optional>
16
17namespace KItinerary {
18
19#define ELB_STR_PROPERTY(Name, Start, Len) \
20public: \
21 inline QString Name() const { return readString(Start, Len); } \
22 Q_PROPERTY(QString Name READ Name)
23#define ELB_NUM_PROPERTY(Name, Start, Len) \
24public: \
25 inline int Name() const { return readNumber(Start, Len); } \
26 Q_PROPERTY(int Name READ Name)
27
28class KITINERARY_EXPORT ELBTicketSegment;
29
30/** ERA (Element List Barcode) ELB ticket barcode.
31 * @see ERA TAP TSI TD B.12 Digital Security Elements For Rail Passenger Ticketing - ยง8 ELB - Element List Barcode
32 */
33class KITINERARY_EXPORT ELBTicket
34{
35 Q_GADGET
36 // decoding info
37 ELB_STR_PROPERTY(idFormat, 0, 1)
38 ELB_STR_PROPERTY(pectabCode, 1, 1)
39 ELB_STR_PROPERTY(ticketCode, 2, 2)
40 ELB_STR_PROPERTY(pnr, 4, 6)
41 ELB_STR_PROPERTY(tcnCode, 10, 9)
42 ELB_NUM_PROPERTY(specimen, 19, 1)
43 ELB_NUM_PROPERTY(barcodeVersion, 20, 1)
44 ELB_NUM_PROPERTY(sequenceNumberCurrent, 21, 1)
45 ELB_NUM_PROPERTY(sequenceNumberTotal, 22, 1)
46 ELB_STR_PROPERTY(futureUse, 23, 10)
47 // ticket info
48 ELB_STR_PROPERTY(travelerType, 33, 2)
49 ELB_NUM_PROPERTY(numberAdults, 35, 2)
50 ELB_NUM_PROPERTY(numberChildren, 37, 2)
51 ELB_NUM_PROPERTY(year, 39, 1)
52 ELB_NUM_PROPERTY(emissionDay, 40, 3)
53 ELB_NUM_PROPERTY(beginValidityDay, 43, 3)
54 ELB_NUM_PROPERTY(endValidityDay, 46, 3)
55 // segments
56 Q_PROPERTY(KItinerary::ELBTicketSegment segment1 READ segment1)
57 Q_PROPERTY(KItinerary::ELBTicketSegment segment2 READ segment2)
58
59 Q_PROPERTY(QString rawData READ rawData STORED false)
60public:
61 ~ELBTicket();
62
63 ELBTicketSegment segment1() const;
64 ELBTicketSegment segment2() const;
65
66 static bool maybeELBTicket(const QByteArray &data);
67 static std::optional<ELBTicket> parse(const QByteArray &data);
68
69 Q_INVOKABLE QDate emissionDate(const QDateTime &contextDate = QDateTime::currentDateTime()) const;
70 Q_INVOKABLE QDate validFromDate(const QDateTime &contextDate = QDateTime::currentDateTime()) const;
71 Q_INVOKABLE QDate validUntilDate(const QDateTime &contextDate = QDateTime::currentDateTime()) const;
72
73 QString rawData() const;
74private:
75 friend class ELBTicketSegment;
76 QString readString(int start, int len) const;
77 int readNumber(int start, int len) const;
78 QByteArray m_data;
79};
80
81/** Segment block of an ERA ELB ticket .*/
82class KITINERARY_EXPORT ELBTicketSegment
83{
84 Q_GADGET
85 ELB_STR_PROPERTY(departureStation, 0, 5)
86 ELB_STR_PROPERTY(arrivalStation, 5, 5)
87 ELB_STR_PROPERTY(trainNumber, 10, 6)
88 ELB_STR_PROPERTY(securityCode, 16, 4)
89 ELB_NUM_PROPERTY(departureDay, 20, 3)
90 ELB_STR_PROPERTY(coachNumber, 23, 3)
91 ELB_STR_PROPERTY(seatNumber, 26, 3)
92 ELB_STR_PROPERTY(classOfTransport, 29, 1)
93 ELB_STR_PROPERTY(tariffCode, 30, 4)
94 ELB_STR_PROPERTY(classOfService, 34, 2)
95
96 Q_PROPERTY(bool isValid READ isValid STORED false)
97public:
99 bool isValid() const;
100
101 Q_INVOKABLE QDate departureDate(const QDateTime &contextDate = QDateTime::currentDateTime()) const;
102
103private:
104 friend class ELBTicket;
105 QString readString(int start, int len) const;
106 int readNumber(int start, int len) const;
107 ELBTicket m_ticket;
108 int m_offset;
109};
110
111#undef ELB_STR_PROPERTY
112
113}
114
115#endif // KITINERARY_ELBTICKET_H
Segment block of an ERA ELB ticket .
Definition elbticket.h:83
ERA (Element List Barcode) ELB ticket barcode.
Definition elbticket.h:34
Q_SCRIPTABLE Q_NOREPLY void start()
Classes for reservation/travel data models, data extraction and data augmentation.
Definition berelement.h:17
QDateTime currentDateTime()
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:09:58 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.