KItinerary

uic9183flex.cpp
1/*
2 SPDX-FileCopyrightText: 2025 Volker Krause <vkrause@kde.org>
3 SPDX-License-Identifier: LGPL-2.0-or-later
4*/
5
6#include "uic9183flex.h"
7
8#include <optional>
9
10using namespace Qt::Literals;
11using namespace KItinerary;
12
13namespace KItinerary {
14class Uic9183FlexPrivate : public QSharedData
15{
16public:
17 std::optional<std::variant<Fcb::v13::UicRailTicketData, Fcb::v3::UicRailTicketData>> m_data;
18 Uic9183Block m_block;
19};
20}
21
22Uic9183Flex::Uic9183Flex() = default;
23Uic9183Flex::Uic9183Flex(const Uic9183Block &block)
24 : d(new Uic9183FlexPrivate)
25{
26 if (block.version() == 3) {
27 if (auto fcb = Fcb::v3::UicRailTicketData(block); fcb.isValid()) {
28 d->m_data = std::move(fcb);
29 d->m_block = block;
30 return;
31 }
32 }
33 if (auto fcb = Fcb::v13::UicRailTicketData(block); fcb.isValid()) {
34 d->m_data = std::move(fcb);
35 d->m_block = block;
36 }
37}
38
39Uic9183Flex::Uic9183Flex(const Uic9183Flex&) = default;
40Uic9183Flex& Uic9183Flex::operator=(const Uic9183Flex&) = default;
41Uic9183Flex::~Uic9183Flex() = default;
42
44{
45 return d && !d->m_block.isNull() && d->m_data.has_value();
46}
47
49{
50 return isValid() ? std::visit([](auto &&data) { return data.issuingDetail.issueingDateTime(); }, *d->m_data) : QDateTime();
51}
52
54{
55 return isValid() && !std::visit([](auto &&data) { return data.transportDocument.empty(); }, *d->m_data);
56}
57
59{
60 return isValid() ? std::visit([](auto &&data) {
62 l.reserve(data.transportDocument.size());
63 std::transform(data.transportDocument.begin(), data.transportDocument.end(), std::back_inserter(l), [](const auto &doc) { return doc.ticket; });
64 return l;
65 }, *d->m_data) : QList<QVariant>();
66}
67
68const Fcb::UicRailTicketData& Uic9183Flex::fcb() const
69{
70 return *d->m_data;
71}
72
73QVariant Uic9183Flex::fcbVariant() const
74{
75 return isValid() ? std::visit([](auto &&data) { return QVariant::fromValue(data); }, *d->m_data) : QVariant();
76}
77
78#include "moc_uic9183flex.cpp"
Top-level type for the ERA FCB ticket structure.
A data block from a UIC 918.3 ticket.
int version() const
Returns the version number of this block.
Represents a U_FLEX block holding different versions of an FCB payload.
Definition uic9183flex.h:22
QDateTime issuingDateTime() const
Issuing date/time.
bool isValid() const
Returns whether this is a valid U_FLEX layout block.
QList< QVariant > transportDocuments() const
Transport documents of the contained FCB.
bool hasTransportDocument() const
true when this is a valid FCB with at least one transport document.
Classes for reservation/travel data models, data extraction and data augmentation.
Definition berelement.h:17
void reserve(qsizetype size)
QVariant fromValue(T &&value)
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Mar 28 2025 11:59:50 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.