Syndication

resource.cpp
1 /*
2  This file is part of the syndication library
3  SPDX-FileCopyrightText: 2006 Frank Osterfeld <[email protected]>
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 
20 namespace Syndication
21 {
22 namespace RDF
23 {
24 class SYNDICATION_NO_EXPORT Resource::ResourcePrivate
25 {
26 public:
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 
42 Resource::Resource(const Resource &other)
43  : Node(other)
44 {
45  *this = other;
46 }
47 
48 Resource::Resource()
49  : d()
50 {
51 }
52 
53 Resource::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 
67 Resource::~Resource()
68 {
69 }
70 
71 Resource &Resource::operator=(const Resource &other)
72 {
73  d = other.d;
74  return *this;
75 }
76 
77 bool Resource::operator==(const Node &other) const
78 {
79  const Resource *o2 = dynamic_cast<const Resource *>(&other);
80  if (!o2) {
81  return false;
82  }
83 
84  if (!d || !o2->d) {
85  return d == o2->d;
86  }
87  return *d == *(o2->d);
88 }
89 
90 bool Resource::hasProperty(PropertyPtr property) const
91 {
92  if (!d) {
93  return false;
94  }
95  const QSharedPointer<Model::ModelPrivate> m = d->model.toStrongRef();
96  if (!m) {
97  return false;
98  }
99  return m->resourceHasProperty(this, property);
100 }
101 
102 StatementPtr Resource::property(PropertyPtr property) const
103 {
104  StatementPtr ptr(new Statement());
105  if (!d) {
106  return ptr;
107  }
108  const QSharedPointer<Model::ModelPrivate> m = d->model.toStrongRef();
109  if (!m) {
110  return ptr;
111  }
112  return m->resourceProperty(this, property);
113 }
114 
115 QList<StatementPtr> Resource::properties(PropertyPtr property) const
116 {
117  if (!d) {
118  return QList<StatementPtr>();
119  }
120  const QSharedPointer<Model::ModelPrivate> m = d->model.toStrongRef();
121  if (!m) {
122  return QList<StatementPtr>();
123  }
124 
125  return m->resourceProperties(this, property);
126 }
127 
128 Resource *Resource::clone() const
129 {
130  return new Resource(*this);
131 }
132 
133 void Resource::accept(NodeVisitor *visitor, NodePtr ptr)
134 {
135  ResourcePtr rptr = ptr.staticCast<Resource>();
136  if (!visitor->visitResource(rptr)) {
137  Node::accept(visitor, ptr);
138  }
139 }
140 
141 unsigned int Resource::id() const
142 {
143  return d ? d->id : 0;
144 }
145 
146 bool Resource::isNull() const
147 {
148  return !d;
149 }
150 
151 Model Resource::model() const
152 {
153  if (!d) {
154  return Model();
155  }
156 
157  const QSharedPointer<Model::ModelPrivate> mp = d->model.toStrongRef();
158 
159  Model m;
160 
161  if (mp) {
162  m.d = mp;
163  }
164 
165  return m;
166 }
167 
168 bool Resource::isResource() const
169 {
170  return true;
171 }
172 
173 bool Resource::isProperty() const
174 {
175  return false;
176 }
177 
178 bool Resource::isLiteral() const
179 {
180  return false;
181 }
182 
183 bool Resource::isAnon() const
184 {
185  return d ? d->isAnon : false;
186 }
187 
188 bool Resource::isSequence() const
189 {
190  return false;
191 }
192 
193 void Resource::setModel(const Model &model)
194 {
195  if (d) {
196  d->model = model.d;
197  }
198 }
199 
200 void Resource::setId(unsigned int id)
201 {
202  if (d) {
203  d->id = id;
204  }
205 }
206 
207 QString Resource::text() const
208 {
209  return QString();
210 }
211 
212 QString Resource::uri() const
213 {
214  return d ? d->uri : QString();
215 }
216 
217 } // namespace RDF
218 } // namespace Syndication
bool isNull() const const
virtual void accept(NodeVisitor *visitor, NodePtr ptr)
Used by visitors for double dispatch.
Definition: node.cpp:17
Model
Definition: resource.h:38
bool operator==(const Qt3DRender::QGraphicsApiFilter &reference, const Qt3DRender::QGraphicsApiFilter &sample)
QUuid createUuid()
QString toString() const const
virtual bool hasProperty(ScriptableExtension *callerPrincipal, quint64 objId, const QString &propName)
QSharedPointer< X > staticCast() const const
QVariant property(const char *name) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Tue Dec 5 2023 03:58:07 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.