KItinerary

extractorresult.cpp
1/*
2 SPDX-FileCopyrightText: 2019-2021 Volker Krause <vkrause@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "extractorresult.h"
8
9#include <KItinerary/JsonLdDocument>
10
11using namespace KItinerary;
12
13ExtractorResult::ExtractorResult() = default;
14
15ExtractorResult::ExtractorResult(const QJsonArray &result)
16 : m_jsonLdResult(result)
17{
18}
19
20ExtractorResult::ExtractorResult(const QList<QVariant> &result)
21 : m_result(result) {}
22
23ExtractorResult::~ExtractorResult() = default;
24
26{
27 return m_result.isEmpty() && m_jsonLdResult.isEmpty();
28}
29
31{
32 return std::max(m_result.size(), m_jsonLdResult.size());
33}
34
36{
37 if (m_jsonLdResult.isEmpty()) {
38 m_jsonLdResult = JsonLdDocument::toJson(m_result);
39 }
40 return m_jsonLdResult;
41}
42
44 if (m_result.isEmpty()) {
45 m_result = JsonLdDocument::fromJson(m_jsonLdResult);
46 }
47 return m_result;
48}
49
51{
52 if (other.isEmpty()) {
53 return;
54 }
55
56 if (isEmpty()) {
57 m_result = std::move(other.m_result);
58 m_jsonLdResult = std::move(other.m_jsonLdResult);
59 return;
60 }
61
62 if (!m_result.isEmpty()) {
63 auto r = other.result();
64 m_result.reserve(m_result.size() + r.size());
65 std::copy(r.begin(), r.end(), std::back_inserter(m_result));
66 }
67 if (!m_jsonLdResult.isEmpty()) {
68 auto r = other.jsonLdResult();
69 std::copy(r.begin(), r.end(), std::back_inserter(m_jsonLdResult));
70 }
71}
Generic extraction result.
QJsonArray jsonLdResult() const
JSON-LD data extracted from this document or page.
void append(ExtractorResult &&other)
Append another result to this one.
int size() const
Amount of contained result elements.
QList< QVariant > result() const
Result in decoded form.
bool isEmpty() const
Checks if there is any relevant result set in here.
static QJsonArray toJson(const QList< QVariant > &data)
Serialize instantiated data types to JSON-LD.
static QList< QVariant > fromJson(const QJsonArray &array)
Convert JSON-LD array into instantiated data types.
Classes for reservation/travel data models, data extraction and data augmentation.
Definition berelement.h:17
bool isEmpty() const const
qsizetype size() const const
bool isEmpty() const const
void reserve(qsizetype size)
qsizetype size() const const
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.