• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepimlibs API Reference
  • KDE Home
  • Contact Us
 

syndication/rdf

  • sources
  • kde-4.14
  • kdepimlibs
  • syndication
  • rdf
resource.cpp
1 /*
2  * This file is part of the syndication library
3  *
4  * Copyright (C) 2006 Frank Osterfeld <osterfeld@kde.org>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public License
17  * along with this library; see the file COPYING.LIB. If not, write to
18  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 #include "resource.h"
24 #include "model.h"
25 #include "model_p.h"
26 #include "nodevisitor.h"
27 #include "property.h"
28 #include "statement.h"
29 
30 #include <krandom.h>
31 
32 #include <QtCore/QList>
33 #include <QtCore/QString>
34 
35 #include <boost/weak_ptr.hpp>
36 
37 using namespace boost;
38 
39 namespace Syndication {
40 namespace RDF {
41 
42 class Resource::ResourcePrivate
43 {
44  public:
45 
46  QString uri;
47  weak_ptr<Model::ModelPrivate> model;
48  bool isAnon;
49  unsigned int id;
50 
51  bool operator==(const ResourcePrivate& other) const
52  {
53  if (!isAnon && !other.isAnon)
54  return uri == other.uri;
55  else
56  return id == other.id;
57  }
58 };
59 
60 Resource::Resource(const Resource& other) : Node(other)
61 {
62  *this = other;
63 }
64 
65 Resource::Resource() : d()
66 {
67 }
68 
69 Resource::Resource(const QString& uri) : d(new ResourcePrivate)
70 {
71  if (uri.isNull())
72  {
73  d->uri = KRandom::randomString(10); // TODO: ensure uniqueness
74  d->isAnon = true;
75  }
76  else
77  {
78  d->uri = uri;
79  d->isAnon = false;
80  }
81 
82  d->id = idCounter++;
83 }
84 
85 Resource::~Resource()
86 {
87 }
88 
89 Resource& Resource::operator=(const Resource& other)
90 {
91  d = other.d;
92  return *this;
93 }
94 
95 bool Resource::operator==(const Node& other) const
96 {
97  const Resource* o2 = dynamic_cast<const Resource*>(&other);
98  if (!o2)
99  return false;
100 
101  if (!d || !o2->d)
102  return d == o2->d;
103  return *d == *(o2->d);
104 }
105 
106 bool Resource::hasProperty(PropertyPtr property) const
107 {
108  if (!d)
109  return false;
110  const shared_ptr<Model::ModelPrivate> m = d->model.lock();
111  if (!m)
112  return false;
113  return m->resourceHasProperty(this, property);
114 }
115 
116 StatementPtr Resource::property(PropertyPtr property) const
117 {
118  StatementPtr ptr(new Statement());
119  if (!d)
120  return ptr;
121  const shared_ptr<Model::ModelPrivate> m = d->model.lock();
122  if (!m)
123  return ptr;
124  return m->resourceProperty(this, property);
125 }
126 
127 QList<StatementPtr> Resource::properties(PropertyPtr property) const
128 {
129  if (!d)
130  return QList<StatementPtr>();
131  const shared_ptr<Model::ModelPrivate> m = d->model.lock();
132  if (!m)
133  return QList<StatementPtr>();
134 
135  return m->resourceProperties(this, property);
136 }
137 
138 Resource* Resource::clone() const
139 {
140  return new Resource(*this);
141 }
142 
143 void Resource::accept(NodeVisitor* visitor, NodePtr ptr)
144 {
145  ResourcePtr rptr = boost::static_pointer_cast<Resource>(ptr);
146  if (!visitor->visitResource(rptr))
147  Node::accept(visitor, ptr);
148 }
149 
150 unsigned int Resource::id() const
151 {
152  return d ? d->id : 0;
153 }
154 
155 bool Resource::isNull() const
156 {
157  return !d;
158 }
159 
160 Model Resource::model() const
161 {
162  if (!d)
163  return Model();
164 
165  const shared_ptr<Model::ModelPrivate> mp = d->model.lock();
166 
167  Model m;
168 
169  if (mp)
170  m.d = mp;
171 
172  return m;
173 }
174 
175 bool Resource::isResource() const
176 {
177  return true;
178 }
179 
180 bool Resource::isProperty() const
181 {
182  return false;
183 }
184 
185 bool Resource::isLiteral() const
186 {
187  return false;
188 }
189 
190 bool Resource::isAnon() const
191 {
192  return d ? d->isAnon : false;
193 }
194 
195 bool Resource::isSequence() const
196 {
197  return false;
198 }
199 
200 void Resource::setModel(const Model& model)
201 {
202  if (d)
203  d->model = model.d;
204 }
205 
206 void Resource::setId(unsigned int id)
207 {
208  if (d)
209  d->id = id;
210 }
211 
212 QString Resource::text() const
213 {
214  return QString();
215 }
216 
217 QString Resource::uri() const
218 {
219  return d ? d->uri : QString();
220 }
221 
222 } // namespace RDF
223 } // namespace Syndication
Syndication::RDF::Resource
Resources are the entities in the RDF graph.
Definition: resource.h:51
Syndication::RDF::Resource::isAnon
virtual bool isAnon() const
returns whether this resource is an anonymous resource
Definition: resource.cpp:190
Syndication::RDF::Resource::isNull
virtual bool isNull() const
returns whether the resource is a null resource
Definition: resource.cpp:155
Syndication::RDF::Resource::isLiteral
virtual bool isLiteral() const
returns false
Definition: resource.cpp:185
Syndication::RDF::Resource::isResource
virtual bool isResource() const
returns true
Definition: resource.cpp:175
Syndication::RDF::Statement
An RDF statement, consisting of a triple (subject, predicate, object).
Definition: statement.h:43
Syndication::RDF::Resource::id
virtual unsigned int id() const
the identifier of this node.
Definition: resource.cpp:150
Syndication::RDF::Model
An RDF model, a set of RDF statements.
Definition: model.h:49
Syndication::RDF::Resource::text
virtual QString text() const
returns a null string
Definition: resource.cpp:212
Syndication::RDF::Resource::operator=
Resource & operator=(const Resource &other)
assigns a resource
Definition: resource.cpp:89
Syndication::RDF::Resource::clone
virtual Resource * clone() const
creates a copy of the resource object
Definition: resource.cpp:138
Syndication::RDF::Resource::accept
virtual void accept(NodeVisitor *visitor, NodePtr ptr)
Used by visitors for double dispatch.
Definition: resource.cpp:143
Syndication::RDF::Resource::isSequence
virtual bool isSequence() const
returns true if this resource is also a sequence, false otherwise.
Definition: resource.cpp:195
Syndication::RDF::Resource::uri
virtual QString uri() const
returns the URI of the resource
Definition: resource.cpp:217
QString::isNull
bool isNull() const
Syndication::RDF::Resource::~Resource
virtual ~Resource()
destructor
Definition: resource.cpp:85
Syndication::RDF::NodeVisitor
Visitor interface, following the Visitor design pattern.
Definition: nodevisitor.h:57
Syndication::RDF::Node::idCounter
static unsigned int idCounter
used to generate unique IDs for node objects
Definition: node.h:135
QString
QList
Definition: document.h:30
Syndication::RDF::Resource::Resource
Resource()
creates a null resource
Definition: resource.cpp:65
Syndication::RDF::Resource::properties
virtual QList< StatementPtr > properties(PropertyPtr property) const
returns the list of all statements from the associated model where this resource is the subject and t...
Definition: resource.cpp:127
Syndication::RDF::Node
an RDF node, abstract baseclass for all RDF node types, like resources and literals ...
Definition: node.h:43
Syndication::RDF::Resource::setModel
virtual void setModel(const Model &model)
used in Model
Definition: resource.cpp:200
Syndication::RDF::Resource::setId
virtual void setId(unsigned int id)
used in Model
Definition: resource.cpp:206
Syndication::RDF::NodeVisitor::visitResource
virtual bool visitResource(ResourcePtr resource)
reimplement this method to handle resources.
Definition: nodevisitor.cpp:55
Syndication::RDF::Resource::hasProperty
virtual bool hasProperty(PropertyPtr property) const
returns whether the resource has a property property in the associated model.
Definition: resource.cpp:106
Syndication::RDF::Node::accept
virtual void accept(NodeVisitor *visitor, NodePtr ptr)
Used by visitors for double dispatch.
Definition: node.cpp:31
Syndication::RDF::Resource::isProperty
virtual bool isProperty() const
returns true if this resource is also a property, false otherwise
Definition: resource.cpp:180
Syndication::RDF::Resource::property
virtual StatementPtr property(PropertyPtr property) const
returns a statement from the associated model where this resource is the subject and the given proper...
Definition: resource.cpp:116
Syndication::RDF::Resource::model
virtual Model model() const
the model this resource belongs to
Definition: resource.cpp:160
Syndication::RDF::Resource::operator==
bool operator==(const Node &other) const
checks two resources for equality.
Definition: resource.cpp:95
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:37:38 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

syndication/rdf

Skip menu "syndication/rdf"
  • Main Page
  • Namespace List
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List

kdepimlibs API Reference

Skip menu "kdepimlibs API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal