File indexing completed on 2024-11-24 04:45:11

0001 /*
0002     SPDX-FileCopyrightText: 2021 Volker Krause <vkrause@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include "kitinerary_export.h"
0010 
0011 #include <QDateTime>
0012 #include <QMetaType>
0013 
0014 namespace KItinerary {
0015 
0016 /** @internal Base class for IATA BCBP sections. */
0017 class KITINERARY_EXPORT IataBcbpSectionBase
0018 {
0019 protected:
0020     QString readString(int offset, int length) const;
0021     int readNumericValue(int offset, int length, int base) const;
0022 
0023     QStringView m_data;
0024 };
0025 
0026 #define IATA_STR_PROPERTY(Name, Start, Length) \
0027 public: \
0028     inline QString Name() const { return readString(Start, Length); } \
0029     Q_PROPERTY(QString Name READ Name)
0030 #define IATA_NUM_PROPERTY(Name, Start, Length) \
0031 public: \
0032     inline int Name() const { return readNumericValue(Start, Length, 10); } \
0033     Q_PROPERTY(int Name READ Name)
0034 #define IATA_HEX_PROPERTY(Name, Start, Length) \
0035 public: \
0036     inline int Name() const { return readNumericValue(Start, Length, 16); } \
0037     Q_PROPERTY(int Name READ Name)
0038 
0039 
0040 /** Unique mandatory section of an IATA BCBP. */
0041 class KITINERARY_EXPORT IataBcbpUniqueMandatorySection : protected IataBcbpSectionBase
0042 {
0043     Q_GADGET
0044     IATA_STR_PROPERTY(formatCode, 0, 1)
0045     IATA_NUM_PROPERTY(numberOfLegs, 1, 1)
0046     IATA_STR_PROPERTY(passengerName, 2, 20)
0047     IATA_STR_PROPERTY(electronicTicketIndicator, 22, 1)
0048 
0049 public:
0050     IataBcbpUniqueMandatorySection() = default;
0051     explicit IataBcbpUniqueMandatorySection(QStringView data);
0052     bool isValid() const;
0053 };
0054 
0055 /** Unique conditional (optional) section of an IATA BCBP. */
0056 class KITINERARY_EXPORT IataBcbpUniqueConditionalSection : protected IataBcbpSectionBase
0057 {
0058     Q_GADGET
0059     IATA_NUM_PROPERTY(version, 1, 1)
0060     IATA_HEX_PROPERTY(fieldSize, 2, 2)
0061     IATA_STR_PROPERTY(passengerDescription, 4, 1)
0062     IATA_STR_PROPERTY(sourceOfCheckin, 5, 1)
0063     IATA_STR_PROPERTY(sourceOfBoardingPassIssuance, 6, 1)
0064     IATA_NUM_PROPERTY(yearOfIssue, 7, 1)
0065     IATA_NUM_PROPERTY(dayOfIssue, 8, 3)
0066     IATA_STR_PROPERTY(documentType, 11, 1)
0067     IATA_STR_PROPERTY(airlineDesignatorOfBoardingPassIssuer, 12, 3)
0068     IATA_STR_PROPERTY(baggageTagLicensePlateNumber1, 15, 13)
0069     IATA_STR_PROPERTY(baggageTagLicensePlateNumber2, 28, 13)
0070     IATA_STR_PROPERTY(baggageTagLicensePlateNumber3, 41, 13)
0071 
0072 public:
0073     IataBcbpUniqueConditionalSection() = default;
0074     explicit IataBcbpUniqueConditionalSection(QStringView data);
0075     bool isValid() const;
0076 
0077     Q_INVOKABLE QDate dateOfIssue(const QDateTime &contextDate = QDateTime::currentDateTime()) const;
0078 };
0079 
0080 /** Repeated mandatory sections of an IATA BCBP, occurs once per leg. */
0081 class KITINERARY_EXPORT IataBcbpRepeatedMandatorySection : protected IataBcbpSectionBase
0082 {
0083     Q_GADGET
0084     IATA_STR_PROPERTY(operatingCarrierPNRCode, 0, 7)
0085     IATA_STR_PROPERTY(fromCityAirportCode, 7, 3)
0086     IATA_STR_PROPERTY(toCityAirportCode, 10, 3)
0087     IATA_STR_PROPERTY(operatingCarrierDesignator, 13, 3)
0088     IATA_STR_PROPERTY(flightNumber, 16, 5)
0089     IATA_NUM_PROPERTY(dayOfFlight, 21, 3)
0090     IATA_STR_PROPERTY(compartmentCode, 24, 1)
0091     IATA_STR_PROPERTY(seatNumber, 25, 4)
0092     IATA_STR_PROPERTY(checkinSequenceNumber, 29, 5)
0093     IATA_STR_PROPERTY(passengerStatus, 34, 1)
0094     IATA_HEX_PROPERTY(variableFieldSize, 35, 2)
0095 
0096 public:
0097     IataBcbpRepeatedMandatorySection() = default;
0098     explicit IataBcbpRepeatedMandatorySection(QStringView data);
0099     bool isValid() const;
0100 
0101     /** Date of the flight.
0102      *  @param contextDate A date before the flight to determine
0103      *  the full year which is not specified in the pass itself.
0104      */
0105     Q_INVOKABLE QDate dateOfFlight(const QDateTime &contextDate = QDateTime::currentDateTime()) const;
0106 };
0107 
0108 /** Conditional (optional) sections of an IATA BCBP, occurs once per leg. */
0109 class KITINERARY_EXPORT IataBcbpRepeatedConditionalSection : protected IataBcbpSectionBase
0110 {
0111     Q_GADGET
0112     IATA_HEX_PROPERTY(conditionalFieldSize, 0, 2)
0113     IATA_STR_PROPERTY(airlineNumericCode, 2, 3)
0114     IATA_STR_PROPERTY(documentNumber, 5, 10)
0115     IATA_STR_PROPERTY(selecteeIndicator, 15, 1)
0116     IATA_STR_PROPERTY(internationalDocumentVerification, 16, 1)
0117     IATA_STR_PROPERTY(marketingCarrierDesignator, 17, 3)
0118     IATA_STR_PROPERTY(frequentFlyerAirlineDesignator, 20, 3)
0119     IATA_STR_PROPERTY(frequenFlyerNumber, 23, 16)
0120     IATA_STR_PROPERTY(idAdIndicator, 39, 1)
0121     IATA_STR_PROPERTY(freeBaggageAllowance, 40, 3)
0122     IATA_STR_PROPERTY(fastTrack, 43, 1)
0123 
0124 public:
0125     IataBcbpRepeatedConditionalSection() = default;
0126     explicit IataBcbpRepeatedConditionalSection(QStringView data);
0127 };
0128 
0129 /** Security section of an IATA BCBP. */
0130 class KITINERARY_EXPORT IataBcbpSecuritySection : protected IataBcbpSectionBase
0131 {
0132     Q_GADGET
0133     IATA_STR_PROPERTY(type, 1, 1)
0134     IATA_HEX_PROPERTY(size, 2, 2)
0135     IATA_STR_PROPERTY(securityData, 4, size())
0136 
0137 public:
0138     IataBcbpSecuritySection() = default;
0139     explicit IataBcbpSecuritySection(QStringView data);
0140 };
0141 
0142 #undef IATA_STR_PROPERTY
0143 #undef IATA_HEX_PROPERTY
0144 
0145 }
0146