| 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 | #include "literal.h" |
| 9 | #include "nodevisitor.h" |
| 10 | |
| 11 | namespace Syndication |
| 12 | { |
| 13 | namespace RDF |
| 14 | { |
| 15 | class SYNDICATION_NO_EXPORT Literal::LiteralPrivate |
| 16 | { |
| 17 | public: |
| 18 | QString text; |
| 19 | unsigned int id; |
| 20 | |
| 21 | bool operator==(const LiteralPrivate &other) const |
| 22 | { |
| 23 | return text == other.text; |
| 24 | } |
| 25 | }; |
| 26 | |
| 27 | Literal::Literal() |
| 28 | : d() |
| 29 | { |
| 30 | } |
| 31 | |
| 32 | Literal::Literal(const Literal &other) |
| 33 | : Node(other) |
| 34 | { |
| 35 | d = other.d; |
| 36 | } |
| 37 | |
| 38 | Literal *Literal::clone() const |
| 39 | { |
| 40 | return new Literal(*this); |
| 41 | } |
| 42 | |
| 43 | void Literal::accept(NodeVisitor *visitor, NodePtr ptr) |
| 44 | { |
| 45 | LiteralPtr lptr = ptr.staticCast<Syndication::RDF::Literal>(); |
| 46 | if (!visitor->visitLiteral(lptr)) { |
| 47 | Node::accept(visitor, ptr); |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | Literal::Literal(const QString &text) |
| 52 | : d(new LiteralPrivate) |
| 53 | { |
| 54 | d->text = text; |
| 55 | d->id = idCounter++; |
| 56 | } |
| 57 | |
| 58 | Literal::~Literal() |
| 59 | { |
| 60 | } |
| 61 | |
| 62 | Literal &Literal::operator=(const Literal &other) |
| 63 | { |
| 64 | d = other.d; |
| 65 | return *this; |
| 66 | } |
| 67 | |
| 68 | bool Literal::operator==(const Literal &other) const |
| 69 | { |
| 70 | if (!d || !other.d) { |
| 71 | return d == other.d; |
| 72 | } |
| 73 | |
| 74 | return *d == *(other.d); |
| 75 | } |
| 76 | |
| 77 | bool Literal::isNull() const |
| 78 | { |
| 79 | return !d; |
| 80 | } |
| 81 | |
| 82 | unsigned int Literal::id() const |
| 83 | { |
| 84 | return d ? d->id : 0; |
| 85 | } |
| 86 | |
| 87 | bool Literal::isResource() const |
| 88 | { |
| 89 | return false; |
| 90 | } |
| 91 | |
| 92 | bool Literal::isProperty() const |
| 93 | { |
| 94 | return false; |
| 95 | } |
| 96 | |
| 97 | bool Literal::isLiteral() const |
| 98 | { |
| 99 | return true; |
| 100 | } |
| 101 | |
| 102 | bool Literal::isAnon() const |
| 103 | { |
| 104 | return false; |
| 105 | } |
| 106 | |
| 107 | bool Literal::isSequence() const |
| 108 | { |
| 109 | return false; |
| 110 | } |
| 111 | |
| 112 | QString Literal::text() const |
| 113 | { |
| 114 | return d ? d->text : QString(); |
| 115 | } |
| 116 | |
| 117 | Literal::operator QString() const |
| 118 | { |
| 119 | return d ? d->text : QString(); |
| 120 | } |
| 121 | |
| 122 | void Literal::setModel(const Model & /*model*/) |
| 123 | { |
| 124 | } |
| 125 | |
| 126 | void Literal::setId(unsigned int id) |
| 127 | { |
| 128 | d->id = id; |
| 129 | } |
| 130 | |
| 131 | } // namespace RDF |
| 132 | } // namespace Syndication |
| 133 |
