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

syndication/rdf

  • 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
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Sat Jul 13 2013 01:26:28 by doxygen 1.8.3.1 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-4.10.5 API Reference

Skip menu "kdepimlibs-4.10.5 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
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