File indexing completed on 2024-04-21 04:01:02

0001 /*
0002     This file is part of the syndication library
0003     SPDX-FileCopyrightText: 2006 Frank Osterfeld <osterfeld@kde.org>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 
0008 #ifndef SYNDICATION_RDF_NODE_H
0009 #define SYNDICATION_RDF_NODE_H
0010 
0011 #include "../syndication_export.h"
0012 
0013 #include <QSharedPointer>
0014 #include <QString>
0015 
0016 namespace Syndication
0017 {
0018 namespace RDF
0019 {
0020 class Model;
0021 class Node;
0022 class NodeVisitor;
0023 //@cond PRIVATE
0024 typedef QSharedPointer<Node> NodePtr;
0025 //@endcond
0026 
0027 /**
0028  * an RDF node, abstract baseclass for all RDF node types, like resources and
0029  * literals
0030  */
0031 class Node
0032 {
0033 public:
0034     /**
0035      * destructor
0036      */
0037     virtual ~Node();
0038 
0039     /**
0040      * Used by visitors for double dispatch. See NodeVisitor
0041      * for more information.
0042      * @param visitor the visitor calling the method
0043      * @param ptr a shared pointer object for this node
0044      */
0045     virtual void accept(NodeVisitor *visitor, NodePtr ptr);
0046 
0047     /**
0048      * returns a copy of the object. Must be implemented
0049      * by subclasses to return a copy using the concrete
0050      * type
0051      */
0052     virtual Node *clone() const = 0;
0053 
0054     /**
0055      * returns whether this node is a null node
0056      */
0057     virtual bool isNull() const = 0;
0058 
0059     /**
0060      * returns whether this node is a resource
0061      */
0062     virtual bool isResource() const = 0;
0063 
0064     /**
0065      * returns whether this node is a property
0066      */
0067     virtual bool isProperty() const = 0;
0068 
0069     /**
0070      * returns whether this node is a literal
0071      */
0072     virtual bool isLiteral() const = 0;
0073 
0074     /**
0075      * returns whether this node is an RDF sequence
0076      */
0077     virtual bool isSequence() const = 0;
0078 
0079     /**
0080      * returns whether this node is an anonymous resource
0081      */
0082     virtual bool isAnon() const = 0;
0083 
0084     /**
0085      * the identifier of this node. the ID is unique per model
0086      * and set by the associated model at creation time.
0087      */
0088     virtual unsigned int id() const = 0;
0089 
0090     /**
0091      * returns a textual representation of the node.
0092      * This is the literal string for literals, and a null string for other
0093      * node types.
0094      */
0095     virtual QString text() const = 0;
0096 
0097     /**
0098      * used in Model
0099      * @internal
0100      */
0101     virtual void setModel(const Model &model) = 0;
0102 
0103     /**
0104      *  used in Model
0105      * @internal
0106      */
0107     virtual void setId(unsigned int id) = 0;
0108 
0109 protected:
0110     /**
0111      * used to generate unique IDs for node objects
0112      */
0113     static unsigned int idCounter;
0114 };
0115 
0116 } // namespace RDF
0117 } // namespace Syndication
0118 
0119 #endif // SYNDICATION_RDF_NODE_H