KItinerary

extractordocumentprocessor.h
1/*
2 SPDX-FileCopyrightText: 2021 Volker Krause <vkrause@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#pragma once
8
9#include "extractordocumentnode.h"
10
11class QByteArray;
12class QJSEngine;
13class QJSValue;
14class QStringView;
15class QVariant;
16
17namespace KItinerary {
18
19class ExtractorEngine;
20class ExtractorFilter;
21
22/** Abstract base class of a document type processor. */
24{
25public:
27
28 /** Fast check whether the given encoded data can possibly be processed by this instance.
29 * The default implementation returns false, relying on QMimeDatabase for detection.
30 */
31 virtual bool canHandleData(const QByteArray &encodedData, QStringView fileName) const;
32
33 /** Create a document node from raw data.
34 * The default implementation produces in invalid node.
35 */
36 virtual ExtractorDocumentNode createNodeFromData(const QByteArray &encodedData) const;
37 /** Create a document node from an already decoded data type.
38 * The default implementation just sets @p decodedData on the resulting node.
39 */
40 virtual ExtractorDocumentNode createNodeFromContent(const QVariant &decodedData) const;
41
42 /** Create child nodes for @p node, as far as that's necessary for this document type. */
43 virtual void expandNode(ExtractorDocumentNode &node, const ExtractorEngine *engine) const;
44
45 /** Propagate results from child nodes up to @p node.
46 * The default implementation just appends results.
47 */
48 virtual void reduceNode(ExtractorDocumentNode &node) const;
49
50 /** Called before extractors are applied to @p node.
51 * This can be used for performing document type specific extraction steps.
52 * The default implementation does nothing.
53 */
54 virtual void preExtract(ExtractorDocumentNode &node, const ExtractorEngine *engine) const;
55
56 /** Checks whether the given @p filter matches @p node.
57 * The default implementation can handle QObject and Q_GADGET types via Qt's property system.
58 */
59 virtual bool matches(const ExtractorFilter &filter, const ExtractorDocumentNode &node) const;
60
61 /** Called after extractors have been applied to @p node.
62 * This can be used for applying document type specific data to the extracted result.
63 * The default implementation does nothing.
64 */
65 virtual void postExtract(ExtractorDocumentNode &node, const ExtractorEngine *engine) const;
66
67 /** Create a QJSValue for the node content.
68 * The default implementation is sufficient if the content is a QObject pointer, QGadget value,
69 * or any built-in type.
70 */
71 virtual QJSValue contentToScriptValue(const ExtractorDocumentNode &node, QJSEngine *engine) const;
72
73 /** Destroys type-specific data in @p node.
74 * The default implementation does nothing.
75 */
76 virtual void destroyNode(ExtractorDocumentNode &node) const;
77
78protected:
79 template <typename T>
80 inline void destroyIfOwned(ExtractorDocumentNode &node) const
81 {
82 delete static_cast<T*>(node.content<Internal::OwnedPtr<T>>());
83 }
84
85 static bool matchesGadget(const ExtractorFilter &filter, const QMetaObject *mo, const void *obj);
86 template <typename T>
87 static inline bool matchesGadget(const ExtractorFilter &filter, const T *obj)
88 {
89 return matchesGadget(filter, &T::staticMetaObject, obj);
90 }
91};
92
93}
94
A node in the extracted document object tree.
QJSValue content
The decoded content of this node.
Abstract base class of a document type processor.
virtual bool matches(const ExtractorFilter &filter, const ExtractorDocumentNode &node) const
Checks whether the given filter matches node.
virtual bool canHandleData(const QByteArray &encodedData, QStringView fileName) const
Fast check whether the given encoded data can possibly be processed by this instance.
virtual void preExtract(ExtractorDocumentNode &node, const ExtractorEngine *engine) const
Called before extractors are applied to node.
virtual void postExtract(ExtractorDocumentNode &node, const ExtractorEngine *engine) const
Called after extractors have been applied to node.
virtual void expandNode(ExtractorDocumentNode &node, const ExtractorEngine *engine) const
Create child nodes for node, as far as that's necessary for this document type.
virtual QJSValue contentToScriptValue(const ExtractorDocumentNode &node, QJSEngine *engine) const
Create a QJSValue for the node content.
virtual void reduceNode(ExtractorDocumentNode &node) const
Propagate results from child nodes up to node.
virtual ExtractorDocumentNode createNodeFromData(const QByteArray &encodedData) const
Create a document node from raw data.
virtual void destroyNode(ExtractorDocumentNode &node) const
Destroys type-specific data in node.
virtual ExtractorDocumentNode createNodeFromContent(const QVariant &decodedData) const
Create a document node from an already decoded data type.
Semantic data extraction engine.
Determines whether an extractor is applicable to a given email.
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 Nov 22 2024 12:00:33 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.