KItinerary

extractordocumentprocessor.h
1 /*
2  SPDX-FileCopyrightText: 2021 Volker Krause <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #pragma once
8 
9 #include "extractordocumentnode.h"
10 
11 class QByteArray;
12 class QJSEngine;
13 class QJSValue;
14 class QStringView;
15 class QVariant;
16 
17 namespace KItinerary {
18 
19 class ExtractorEngine;
20 class ExtractorFilter;
21 
22 /** Abstract base class of a document type processor. */
24 {
25 public:
26  virtual ~ExtractorDocumentProcessor();
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;
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 
78 protected:
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 
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 void postExtract(ExtractorDocumentNode &node) const
Called after extractors have been applied to node.
A node in the extracted document object tree.
Determines whether an extractor is applicable to a given email.
virtual void reduceNode(ExtractorDocumentNode &node) const
Propagate results from child nodes up to node.
virtual ExtractorDocumentNode createNodeFromContent(const QVariant &decodedData) const
Create a document node from an already decoded data type.
Abstract base class of a document type processor.
virtual bool canHandleData(const QByteArray &encodedData, QStringView fileName) const
Fast check whether the given encoded data can possibly be processed by this instance.
virtual bool matches(const ExtractorFilter &filter, const ExtractorDocumentNode &node) const
Checks whether the given filter matches node.
virtual void destroyNode(ExtractorDocumentNode &node) const
Destroys type-specific data in node.
virtual QJSValue contentToScriptValue(const ExtractorDocumentNode &node, QJSEngine *engine) const
Create a QJSValue for the node content.
virtual void preExtract(ExtractorDocumentNode &node, const ExtractorEngine *engine) const
Called before extractors are applied to node.
virtual ExtractorDocumentNode createNodeFromData(const QByteArray &encodedData) const
Create a document node from raw data.
Semantic data extraction engine.
QJSValue content
The decoded content of this node.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Thu May 26 2022 03:54:24 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.