Syndication

literal.cpp
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
11namespace Syndication
12{
13namespace RDF
14{
15class SYNDICATION_NO_EXPORT Literal::LiteralPrivate
16{
17public:
18 QString text;
19 unsigned int id;
20
21 bool operator==(const LiteralPrivate &other) const
22 {
23 return text == other.text;
24 }
25};
26
28 : d()
29{
30}
31
33 : Node(other)
34{
35 d = other.d;
36}
37
39{
40 return new Literal(*this);
41}
42
43void 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
52 : d(new LiteralPrivate)
53{
54 d->text = text;
55 d->id = idCounter++;
56}
57
61
63{
64 d = other.d;
65 return *this;
66}
67
68bool 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
77bool Literal::isNull() const
78{
79 return !d;
80}
81
82unsigned int Literal::id() const
83{
84 return d ? d->id : 0;
85}
86
88{
89 return false;
90}
91
93{
94 return false;
95}
96
98{
99 return true;
100}
101
102bool Literal::isAnon() const
103{
104 return false;
105}
106
108{
109 return false;
110}
111
113{
114 return d ? d->text : QString();
115}
116
117Literal::operator QString() const
118{
119 return d ? d->text : QString();
120}
121
122void Literal::setModel(const Model & /*model*/)
123{
124}
125
126void Literal::setId(unsigned int id)
127{
128 d->id = id;
129}
130
131} // namespace RDF
132} // namespace Syndication
a node type representing simple string values.
Definition literal.h:29
Literal()
creates a null literal.
Definition literal.cpp:27
virtual Literal & operator=(const Literal &other)
assigns another literal
Definition literal.cpp:62
bool isNull() const override
returns whether this node is a null node
Definition literal.cpp:77
bool isSequence() const override
returns false, literals are not sequences
Definition literal.cpp:107
~Literal() override
destructor
Definition literal.cpp:58
bool isLiteral() const override
returns true for literals
Definition literal.cpp:97
void accept(NodeVisitor *visitor, NodePtr ptr) override
Used by visitors for double dispatch.
Definition literal.cpp:43
bool isAnon() const override
returns false, literals are not anonymous resources
Definition literal.cpp:102
QString text() const override
the string value of the literal
Definition literal.cpp:112
bool isProperty() const override
returns false, as a literal is not a property
Definition literal.cpp:92
void setId(unsigned int id) override
used in Model
Definition literal.cpp:126
bool operator==(const Literal &other) const
two literal nodes are equal iff their text and ID's are equal.
Definition literal.cpp:68
void setModel(const Model &model) override
used in Model
Definition literal.cpp:122
Literal * clone() const override
clones the literal node.
Definition literal.cpp:38
unsigned int id() const override
the identifier of this node.
Definition literal.cpp:82
bool isResource() const override
returns false, as a literal is not a resource
Definition literal.cpp:87
An RDF model, a set of RDF statements.
Definition model.h:37
Visitor interface, following the Visitor design pattern.
Definition nodevisitor.h:42
virtual bool visitLiteral(LiteralPtr)
reimplement this method to handle literals.
an RDF node, abstract baseclass for all RDF node types, like resources and literals
Definition node.h:32
virtual void accept(NodeVisitor *visitor, NodePtr ptr)
Used by visitors for double dispatch.
Definition node.cpp:17
static unsigned int idCounter
used to generate unique IDs for node objects
Definition node.h:113
bool operator==(const StyleDelim &l, const StyleDelim &r)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:09:18 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.