File indexing completed on 2024-04-28 15:34:24

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 Node &other) const
0069 {
0070     const Literal *o2 = dynamic_cast<const Literal *>(&other);
0071     if (!o2) {
0072         return false;
0073     }
0074 
0075     if (!d || !o2->d) {
0076         return d == o2->d;
0077     }
0078 
0079     return *d == *(o2->d);
0080 }
0081 
0082 bool Literal::isNull() const
0083 {
0084     return !d;
0085 }
0086 
0087 unsigned int Literal::id() const
0088 {
0089     return d ? d->id : 0;
0090 }
0091 
0092 bool Literal::isResource() const
0093 {
0094     return false;
0095 }
0096 
0097 bool Literal::isProperty() const
0098 {
0099     return false;
0100 }
0101 
0102 bool Literal::isLiteral() const
0103 {
0104     return true;
0105 }
0106 
0107 bool Literal::isAnon() const
0108 {
0109     return false;
0110 }
0111 
0112 bool Literal::isSequence() const
0113 {
0114     return false;
0115 }
0116 
0117 QString Literal::text() const
0118 {
0119     return d ? d->text : QString();
0120 }
0121 
0122 Literal::operator QString() const
0123 {
0124     return d ? d->text : QString();
0125 }
0126 
0127 void Literal::setModel(const Model & /*model*/)
0128 {
0129 }
0130 
0131 void Literal::setId(unsigned int id)
0132 {
0133     d->id = id;
0134 }
0135 
0136 } // namespace RDF
0137 } // namespace Syndication