opentripplannerparser.h 2.46 KB
Newer Older
1
/*
2
    SPDX-FileCopyrightText: 2020 Volker Krause <vkrause@kde.org>
3

4
    SPDX-License-Identifier: LGPL-2.0-or-later
5
6
7
8
9
*/

#ifndef KPUBLICTRANSPORT_OPENTRIPPLANNERPARSER_H
#define KPUBLICTRANSPORT_OPENTRIPPLANNERPARSER_H

10
11
#include "kpublictransport_export.h"

12
#include <KPublicTransport/Location>
13
#include <KPublicTransport/RentalVehicle>
14

15
#include <QHash>
16
#include <QString>
17
#include <QStringList>
18

19
#include <vector>
20

21
class QJsonArray;
22
23
24
25
class QJsonObject;

namespace KPublicTransport {

26
class Journey;
27
class JourneySection;
28
29
class Line;
class Route;
Volker Krause's avatar
Volker Krause committed
30
class Stopover;
31

32
33
34
/** Parser for OTP responses as defined by the GraphQL files in the otp/ subdir.
 *  @internal only exported for unit tests
 */
35
class KPUBLICTRANSPORT_EXPORT OpenTripPlannerParser
36
{
37
38
39
public:
    explicit OpenTripPlannerParser(const QString &identifierType);
    ~OpenTripPlannerParser();
40
    void setKnownRentalVehicleNetworks(const QHash<QString, RentalVehicleNetwork> &networks);
41
42
43

    std::vector<Location> parseLocationsByCoordinate(const QJsonObject &obj) const;
    std::vector<Location> parseLocationsByName(const QJsonObject &obj) const;
44
    std::vector<Location> parseLocationsArray(const QJsonArray &array) const;
45
    std::vector<Location> parseGeocodeResult(const QJsonArray &array) const;
Volker Krause's avatar
Volker Krause committed
46
47
    std::vector<Stopover> parseDepartures(const QJsonObject &obj) const;
    std::vector<Stopover> parseDeparturesArray(const QJsonArray &array) const;
48
49
50
    std::vector<Journey> parseJourneys(const QJsonObject &obj) const;

private:
51
    QVariant parseRentalVehicleData(const QJsonObject &obj) const;
52
53
    /// @return @c false for Location objects that should be discarded entirely
    bool parseLocationFragment(const QJsonObject &obj, Location &loc) const;
54
    Location parseLocation(const QJsonObject &obj) const;
55
56
57
    void parseAlerts(const QJsonArray &alertsArray) const;
    Line parseLine(const QJsonObject &obj) const;
    Route parseRoute(const QJsonObject &obj) const;
58
    Route parseInlineRoute(const QJsonObject &obj) const;
59
    Route detectAndParseRoute(const QJsonObject &obj) const;
Volker Krause's avatar
Volker Krause committed
60
61
    Stopover parseDeparture(const QJsonObject &obj) const;
    void parseDeparturesForStop(const QJsonObject &obj, std::vector<Stopover> &deps) const;
62
63
64
65
    JourneySection parseJourneySection(const QJsonObject &obj) const;
    Journey parseJourney(const QJsonObject &obj) const;

    QString m_identifierType;
66
    QHash<QString, RentalVehicleNetwork> m_rentalVehicleNetworks;
67
    mutable QStringList m_alerts;
68
};
69
70
71
72

}

#endif // KPUBLICTRANSPORT_OPENTRIPPLANNERPARSER_H