KItinerary

mergeutil.h
1/*
2 SPDX-FileCopyrightText: 2018 Volker Krause <vkrause@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#pragma once
8
9#include "kitinerary_export.h"
10
11#include <QVariant>
12
13#include <functional>
14
15namespace KItinerary {
16class Flight;
17class Person;
18
19/** Utilities for merging reservations or elements of them. */
21{
22public:
23 /**
24 * Checks if two Reservation or Trip values refer to the same booking element.
25 *
26 * This does not mean being exactly equal, but having matching identifying properties.
27 * What this means exactly depends on the data type:
28 * - Flights: booking reference, flight number and departure day match
29 * - Train trip: booking reference, train number and departure day match
30 * - Bus trip: booking ref and/or number and departure time match
31 * - Hotel booking: hotel name, booking reference and checkin day match
32 *
33 * For all reservation types, the Reservation::underName property is
34 * checked and either needs to be equal or absent in one of the values.
35 */
36 KITINERARY_EXPORT static bool isSame(const QVariant &lhs, const QVariant &rhs);
37
38 /**
39 * Checks if two Person objects refer to the same person.
40 *
41 * Essentially a case-insensitive comparison of the name components.
42 */
43 KITINERARY_EXPORT static bool isSamePerson(const Person &lhs, const Person &rhs);
44
45 /**
46 * Checks whether to elements refer to the same thing, just for different people.
47 * For example two reservations for the same trip or event, but with separate tickets
48 * for different attendees.
49 * This is useful for batching elements together.
50 * @since 5.23.41
51 */
52 KITINERARY_EXPORT static bool isSameIncidence(const QVariant &lhs, const QVariant &rhs);
53
54 /**
55 * Checks whether two transport reservation elements refer to the same departure.
56 * This considers time, location and mode of transport.
57 */
58 static bool hasSameDeparture(const QVariant &lhs, const QVariant &rhs);
59
60 /**
61 * Checks whether two transport reservation elements refer to the same arrival.
62 * This considers time, location and mode of transport.
63 */
64 static bool hasSameArrival(const QVariant &lhs, const QVariant &rhs);
65
66 /**
67 * Merge the two given objects.
68 * This is the same as JsonLdDocument::apply in most cases, but if one side
69 * can be determined to be "better", that one is preferred.
70 */
71 KITINERARY_EXPORT static QVariant merge(const QVariant &lhs, const QVariant &rhs);
72
73 /** Register a comparator function for a custom type that will be used by isSame. */
74 template <typename T>
75 inline static void registerComparator(bool(*func)(const T&, const T&))
76 {
77 std::function<bool(const QVariant&, const QVariant &)> f([func](const QVariant &lhs, const QVariant &rhs) -> bool {
78 return (*func)(lhs.value<T>(), rhs.value<T>());
79 });
80 registerComparator(qMetaTypeId<T>(), std::move(f));
81 }
82
83private:
84 KITINERARY_EXPORT static void registerComparator(int metaTypeId, std::function<bool(const QVariant&, const QVariant &)> &&func);
85};
86
87}
88
Utilities for merging reservations or elements of them.
Definition mergeutil.h:21
static QVariant merge(const QVariant &lhs, const QVariant &rhs)
Merge the two given objects.
static void registerComparator(bool(*func)(const T &, const T &))
Register a comparator function for a custom type that will be used by isSame.
Definition mergeutil.h:75
static bool isSameIncidence(const QVariant &lhs, const QVariant &rhs)
Checks whether to elements refer to the same thing, just for different people.
static bool isSamePerson(const Person &lhs, const Person &rhs)
Checks if two Person objects refer to the same person.
static bool hasSameArrival(const QVariant &lhs, const QVariant &rhs)
Checks whether two transport reservation elements refer to the same arrival.
static bool isSame(const QVariant &lhs, const QVariant &rhs)
Checks if two Reservation or Trip values refer to the same booking element.
static bool hasSameDeparture(const QVariant &lhs, const QVariant &rhs)
Checks whether two transport reservation elements refer to the same departure.
A person.
Definition person.h:20
Classes for reservation/travel data models, data extraction and data augmentation.
Definition berelement.h:17
T value() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:14:49 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.