KItinerary

jsonldfilterengine.h
1/*
2 SPDX-FileCopyrightText: 2021 Volker Krause <vkrause@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#ifndef KITINERARY_JSONLDFILTERENGINE_H
8#define KITINERARY_JSONLDFILTERENGINE_H
9
10#include "kitinerary_export.h"
11
12#include <cstddef>
13
14class QJsonArray;
15class QJsonObject;
16
17namespace KItinerary {
18
19namespace JsonLd {
20 /** Rename a property, if present and the new name isn't in use already. */
21 void renameProperty(QJsonObject &obj, const char *oldName, const char *newName);
22}
23
24/** JSON-LD filtering for input normalization or type transforms.
25 * @internal only exported for unit tests
26 */
27class KITINERARY_EXPORT JsonLdFilterEngine
28{
29public:
30 explicit JsonLdFilterEngine();
32
33 /** Recursively apply filtering rules to @p obj. */
34 void filterRecursive(QJsonObject &obj);
35 void filterRecursive(QJsonArray &array);
36
37 /** Type mappings.
38 * Has to be sorted by @c fromType.
39 */
40 struct TypeMapping {
41 const char *fromType;
42 const char *toType;
43 };
44 void setTypeMappings(const TypeMapping *typeMappings, std::size_t count);
45 template <std::size_t N>
46 inline void setTypeMappings(const TypeMapping (&typeMappings)[N])
47 {
48 setTypeMappings(typeMappings, N);
49 }
50
51 /** Type filter functions.
52 * Has to be sorted by @c type.
53 */
54 struct TypeFilter {
55 const char* type;
56 void(*filterFunc)(QJsonObject&);
57 };
58 void setTypeFilters(const TypeFilter *typeFilters, std::size_t count);
59 template <std::size_t N>
60 inline void setTypeFilters(const TypeFilter (&typeFilters)[N])
61 {
62 setTypeFilters(typeFilters, N);
63 }
64
65 /** Property mappings.
66 * Has to be sorted by @c type.
67 */
69 const char* type;
70 const char* fromName;
71 const char* toName;
72 };
73 void setPropertyMappings(const PropertyMapping *propertyMappings, std::size_t count);
74 template <std::size_t N>
75 inline void setPropertyMappings(const PropertyMapping (&propertyMappings)[N])
76 {
77 setPropertyMappings(propertyMappings, N);
78 }
79
80private:
81 const TypeMapping *m_typeMappings = nullptr;
82 std::size_t m_typeMappingsSize;
83 const TypeFilter *m_typeFilters = nullptr;
84 std::size_t m_typeFiltersSize;
85 const PropertyMapping *m_propertyMappings = nullptr;
86 std::size_t m_propertyMappingsSize;
87};
88
89}
90
91#endif // KITINERARY_JSONLDFILTERENGINE_H
JSON-LD filtering for input normalization or type transforms.
void renameProperty(QJsonObject &obj, const char *oldName, const char *newName)
Rename a property, if present and the new name isn't in use already.
Classes for reservation/travel data models, data extraction and data augmentation.
Definition berelement.h:17
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Oct 4 2024 12:00:25 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.