Syndication

resource.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 "resource.h"
9#include "model.h"
10#include "model_p.h"
11#include "nodevisitor.h"
12#include "property.h"
13#include "statement.h"
14
15#include <QList>
16#include <QString>
17#include <QUuid>
18#include <QWeakPointer>
19
20namespace Syndication
21{
22namespace RDF
23{
24class SYNDICATION_NO_EXPORT Resource::ResourcePrivate
25{
26public:
27 QString uri;
29 bool isAnon;
30 unsigned int id;
31
32 bool operator==(const ResourcePrivate &other) const
33 {
34 if (!isAnon && !other.isAnon) {
35 return uri == other.uri;
36 } else {
37 return id == other.id;
38 }
39 }
40};
41
42Resource::Resource(const Resource &other)
43 : Node(other)
44{
45 *this = other;
46}
47
48Resource::Resource()
49 : d()
50{
51}
52
53Resource::Resource(const QString &uri)
54 : d(new ResourcePrivate)
55{
56 if (uri.isNull()) {
57 d->uri = QUuid().createUuid().toString();
58 d->isAnon = true;
59 } else {
60 d->uri = uri;
61 d->isAnon = false;
62 }
63
64 d->id = idCounter++;
65}
66
67Resource::~Resource()
68{
69}
70
71Resource &Resource::operator=(const Resource &other)
72{
73 d = other.d;
74 return *this;
75}
76
77bool Resource::operator==(const Resource &other) const
78{
79 if (!d || !other.d) {
80 return d == other.d;
81 }
82 return *d == *(other.d);
83}
84
85bool Resource::hasProperty(PropertyPtr property) const
86{
87 if (!d) {
88 return false;
89 }
90 const QSharedPointer<Model::ModelPrivate> m = d->model.toStrongRef();
91 if (!m) {
92 return false;
93 }
94 return m->resourceHasProperty(this, property);
95}
96
97StatementPtr Resource::property(PropertyPtr property) const
98{
99 StatementPtr ptr(new Statement());
100 if (!d) {
101 return ptr;
102 }
103 const QSharedPointer<Model::ModelPrivate> m = d->model.toStrongRef();
104 if (!m) {
105 return ptr;
106 }
107 return m->resourceProperty(this, property);
108}
109
110QList<StatementPtr> Resource::properties(PropertyPtr property) const
111{
112 if (!d) {
113 return QList<StatementPtr>();
114 }
115 const QSharedPointer<Model::ModelPrivate> m = d->model.toStrongRef();
116 if (!m) {
117 return QList<StatementPtr>();
118 }
119
120 return m->resourceProperties(this, property);
121}
122
123Resource *Resource::clone() const
124{
125 return new Resource(*this);
126}
127
128void Resource::accept(NodeVisitor *visitor, NodePtr ptr)
129{
130 ResourcePtr rptr = ptr.staticCast<Resource>();
131 if (!visitor->visitResource(rptr)) {
132 Node::accept(visitor, ptr);
133 }
134}
135
136unsigned int Resource::id() const
137{
138 return d ? d->id : 0;
139}
140
141bool Resource::isNull() const
142{
143 return !d;
144}
145
146Model Resource::model() const
147{
148 if (!d) {
149 return Model();
150 }
151
152 const QSharedPointer<Model::ModelPrivate> mp = d->model.toStrongRef();
153
154 Model m;
155
156 if (mp) {
157 m.d = mp;
158 }
159
160 return m;
161}
162
163bool Resource::isResource() const
164{
165 return true;
166}
167
168bool Resource::isProperty() const
169{
170 return false;
171}
172
173bool Resource::isLiteral() const
174{
175 return false;
176}
177
178bool Resource::isAnon() const
179{
180 return d ? d->isAnon : false;
181}
182
183bool Resource::isSequence() const
184{
185 return false;
186}
187
188void Resource::setModel(const Model &model)
189{
190 if (d) {
191 d->model = model.d;
192 }
193}
194
195void Resource::setId(unsigned int id)
196{
197 if (d) {
198 d->id = id;
199 }
200}
201
202QString Resource::text() const
203{
204 return QString();
205}
206
207QString Resource::uri() const
208{
209 return d ? d->uri : QString();
210}
211
212} // namespace RDF
213} // namespace Syndication
QVariant property(const char *name) const const
QSharedPointer< X > staticCast() const const
bool isNull() const const
bool operator==(const QGraphicsApiFilter &reference, const QGraphicsApiFilter &sample)
QUuid createUuid()
QString toString(StringFormat mode) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:14:15 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.