1 | /* |
2 | This file is part of the syndication library |
3 | SPDX-FileCopyrightText: 2006 Frank Osterfeld <osterfeld@kde.org> |
4 | |
5 | SPDX-License-Identifier: LGPL-2.0-or-later |
6 | */ |
7 | |
8 | #ifndef SYNDICATION_RDF_NODE_H |
9 | #define SYNDICATION_RDF_NODE_H |
10 | |
11 | #include "../syndication_export.h" |
12 | |
13 | #include <QSharedPointer> |
14 | #include <QString> |
15 | |
16 | namespace Syndication |
17 | { |
18 | namespace RDF |
19 | { |
20 | class Model; |
21 | class Node; |
22 | class NodeVisitor; |
23 | //@cond PRIVATE |
24 | typedef QSharedPointer<Node> NodePtr; |
25 | //@endcond |
26 | |
27 | /** |
28 | * an RDF node, abstract baseclass for all RDF node types, like resources and |
29 | * literals |
30 | */ |
31 | class Node |
32 | { |
33 | public: |
34 | /** |
35 | * destructor |
36 | */ |
37 | virtual ~Node(); |
38 | |
39 | /** |
40 | * Used by visitors for double dispatch. See NodeVisitor |
41 | * for more information. |
42 | * @param visitor the visitor calling the method |
43 | * @param ptr a shared pointer object for this node |
44 | */ |
45 | virtual void accept(NodeVisitor *visitor, NodePtr ptr); |
46 | |
47 | /** |
48 | * returns a copy of the object. Must be implemented |
49 | * by subclasses to return a copy using the concrete |
50 | * type |
51 | */ |
52 | virtual Node *clone() const = 0; |
53 | |
54 | /** |
55 | * returns whether this node is a null node |
56 | */ |
57 | virtual bool isNull() const = 0; |
58 | |
59 | /** |
60 | * returns whether this node is a resource |
61 | */ |
62 | virtual bool isResource() const = 0; |
63 | |
64 | /** |
65 | * returns whether this node is a property |
66 | */ |
67 | virtual bool isProperty() const = 0; |
68 | |
69 | /** |
70 | * returns whether this node is a literal |
71 | */ |
72 | virtual bool isLiteral() const = 0; |
73 | |
74 | /** |
75 | * returns whether this node is an RDF sequence |
76 | */ |
77 | virtual bool isSequence() const = 0; |
78 | |
79 | /** |
80 | * returns whether this node is an anonymous resource |
81 | */ |
82 | virtual bool isAnon() const = 0; |
83 | |
84 | /** |
85 | * the identifier of this node. the ID is unique per model |
86 | * and set by the associated model at creation time. |
87 | */ |
88 | virtual unsigned int id() const = 0; |
89 | |
90 | /** |
91 | * returns a textual representation of the node. |
92 | * This is the literal string for literals, and a null string for other |
93 | * node types. |
94 | */ |
95 | virtual QString text() const = 0; |
96 | |
97 | /** |
98 | * used in Model |
99 | * @internal |
100 | */ |
101 | virtual void setModel(const Model &model) = 0; |
102 | |
103 | /** |
104 | * used in Model |
105 | * @internal |
106 | */ |
107 | virtual void setId(unsigned int id) = 0; |
108 | |
109 | protected: |
110 | /** |
111 | * used to generate unique IDs for node objects |
112 | */ |
113 | static unsigned int idCounter; |
114 | }; |
115 | |
116 | } // namespace RDF |
117 | } // namespace Syndication |
118 | |
119 | #endif // SYNDICATION_RDF_NODE_H |
120 | |