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