File indexing completed on 2024-04-14 03:58:27

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 #include "literal.h"
0009 #include "nodevisitor.h"
0010 
0011 namespace Syndication
0012 {
0013 namespace RDF
0014 {
0015 class SYNDICATION_NO_EXPORT Literal::LiteralPrivate
0016 {
0017 public:
0018     QString text;
0019     unsigned int id;
0020 
0021     bool operator==(const LiteralPrivate &other) const
0022     {
0023         return text == other.text;
0024     }
0025 };
0026 
0027 Literal::Literal()
0028     : d()
0029 {
0030 }
0031 
0032 Literal::Literal(const Literal &other)
0033     : Node(other)
0034 {
0035     d = other.d;
0036 }
0037 
0038 Literal *Literal::clone() const
0039 {
0040     return new Literal(*this);
0041 }
0042 
0043 void Literal::accept(NodeVisitor *visitor, NodePtr ptr)
0044 {
0045     LiteralPtr lptr = ptr.staticCast<Syndication::RDF::Literal>();
0046     if (!visitor->visitLiteral(lptr)) {
0047         Node::accept(visitor, ptr);
0048     }
0049 }
0050 
0051 Literal::Literal(const QString &text)
0052     : d(new LiteralPrivate)
0053 {
0054     d->text = text;
0055     d->id = idCounter++;
0056 }
0057 
0058 Literal::~Literal()
0059 {
0060 }
0061 
0062 Literal &Literal::operator=(const Literal &other)
0063 {
0064     d = other.d;
0065     return *this;
0066 }
0067 
0068 bool Literal::operator==(const Literal &other) const
0069 {
0070     if (!d || !other.d) {
0071         return d == other.d;
0072     }
0073 
0074     return *d == *(other.d);
0075 }
0076 
0077 bool Literal::isNull() const
0078 {
0079     return !d;
0080 }
0081 
0082 unsigned int Literal::id() const
0083 {
0084     return d ? d->id : 0;
0085 }
0086 
0087 bool Literal::isResource() const
0088 {
0089     return false;
0090 }
0091 
0092 bool Literal::isProperty() const
0093 {
0094     return false;
0095 }
0096 
0097 bool Literal::isLiteral() const
0098 {
0099     return true;
0100 }
0101 
0102 bool Literal::isAnon() const
0103 {
0104     return false;
0105 }
0106 
0107 bool Literal::isSequence() const
0108 {
0109     return false;
0110 }
0111 
0112 QString Literal::text() const
0113 {
0114     return d ? d->text : QString();
0115 }
0116 
0117 Literal::operator QString() const
0118 {
0119     return d ? d->text : QString();
0120 }
0121 
0122 void Literal::setModel(const Model & /*model*/)
0123 {
0124 }
0125 
0126 void Literal::setId(unsigned int id)
0127 {
0128     d->id = id;
0129 }
0130 
0131 } // namespace RDF
0132 } // namespace Syndication