File indexing completed on 2024-07-14 03:59:03

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_LITERAL_H
0009 #define SYNDICATION_RDF_LITERAL_H
0010 
0011 #include <QString>
0012 #include <syndication/rdf/node.h>
0013 
0014 namespace Syndication
0015 {
0016 namespace RDF
0017 {
0018 class Literal;
0019 
0020 //@cond PRIVATE
0021 typedef QSharedPointer<Literal> LiteralPtr;
0022 //@endcond
0023 
0024 /**
0025  * a node type representing simple string values. Literals can
0026  * be object of statement, but neither subject nor predicate.
0027  */
0028 class Literal : public Node
0029 {
0030 public:
0031     /**
0032      * creates a null literal. text() will return a null string.
0033      */
0034     Literal();
0035 
0036     /**
0037      * copies a literal node
0038      *
0039      * @param other the literal node to copy
0040      */
0041     Literal(const Literal &other);
0042 
0043     /**
0044      * creates a new literal node with a given text
0045      *
0046      * @param text the literal string
0047      */
0048     explicit Literal(const QString &text);
0049 
0050     /**
0051      * destructor
0052      */
0053     ~Literal() override;
0054 
0055     /**
0056      * assigns another literal
0057      *
0058      * @param other the literal to assign
0059      */
0060     virtual Literal &operator=(const Literal &other);
0061 
0062     /**
0063      * two literal nodes are equal iff their text _and_ ID's
0064      * are equal.
0065      */
0066     bool operator==(const Literal &other) const;
0067 
0068     /**
0069      * clones the literal node.
0070      */
0071     Literal *clone() const override;
0072 
0073     /**
0074      * Used by visitors for double dispatch. See NodeVisitor
0075      * for more information.
0076      * @param visitor the visitor calling the method
0077      * @param ptr a shared pointer object for this node
0078      */
0079     void accept(NodeVisitor *visitor, NodePtr ptr) override;
0080 
0081     /**
0082      * returns whether this node is a null node
0083      */
0084     bool isNull() const override;
0085 
0086     /**
0087      * the identifier of this node. the ID is unique per model
0088      * and set by the associated model at creation time.
0089      */
0090     unsigned int id() const override;
0091 
0092     /**
0093      * returns false, as a literal is not a resource
0094      */
0095     bool isResource() const override;
0096     /**
0097      * returns false, as a literal is not a property
0098      */
0099     bool isProperty() const override;
0100 
0101     /**
0102      * returns true for literals
0103      */
0104     bool isLiteral() const override;
0105 
0106     /**
0107      * returns false, literals are not anonymous resources
0108      */
0109     bool isAnon() const override;
0110 
0111     /**
0112      * returns false, literals are not sequences
0113      */
0114     bool isSequence() const override;
0115 
0116     /**
0117      * implicit conversion to string. returns text()
0118      */
0119     virtual operator QString() const;
0120 
0121     /**
0122      * the string value of the literal
0123      */
0124     QString text() const override;
0125 
0126     /**
0127      * used in Model
0128      * @internal
0129      */
0130     void setModel(const Model &model) override;
0131 
0132     /**
0133      * used in Model
0134      * @internal
0135      */
0136     void setId(unsigned int id) override;
0137 
0138 private:
0139     class LiteralPrivate;
0140     typedef QSharedPointer<LiteralPrivate> LiteralPrivatePtr;
0141     LiteralPrivatePtr d;
0142 };
0143 
0144 } // namespace RDF
0145 } // namespace Syndication
0146 
0147 #endif // SYNDICATION_RDF_LITERAL_H