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

syndication/rdf

  • syndication
  • rdf
statement.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 "statement.h"
24#include "literal.h"
25#include "model.h"
26#include "model_p.h"
27#include "property.h"
28#include "resource.h"
29
30#include <QtCore/QString>
31
32#include <boost/weak_ptr.hpp>
33
34using namespace boost;
35
36namespace Syndication {
37namespace RDF {
38
39class Statement::StatementPrivate
40{
41 public:
42
43 uint subjectID;
44 uint predicateID;
45 uint objectID;
46 weak_ptr<Model::ModelPrivate> model;
47
48 bool operator==(const StatementPrivate& other) const
49 {
50 // FIXME: use better check that works also with multiple models
51 return subjectID == other.subjectID &&
52 predicateID == other.predicateID &&
53 objectID == other.objectID;
54 }
55};
56
57Statement::Statement() : d(new StatementPrivate)
58{
59 d->subjectID = 0;
60 d->predicateID = 0;
61 d->objectID = 0;
62}
63
64Statement::Statement(const Statement& other)
65{
66 d = other.d;
67}
68
69Statement::Statement(ResourcePtr subject, PropertyPtr predicate,
70 NodePtr object) : d(new StatementPrivate)
71{
72 d->model = subject->model().d;
73 d->subjectID = subject->id();
74 d->predicateID = predicate->id();
75 d->objectID = object->id();
76}
77
78Statement::~Statement()
79{
80}
81
82Statement& Statement::operator=(const Statement& other)
83{
84 d = other.d;
85 return *this;
86}
87
88bool Statement::operator==(const Statement& other) const
89{
90 if (!d || !other.d)
91 return d == other.d;
92
93 return *d == *(other.d);
94}
95
96bool Statement::isNull() const
97{
98 return d->subjectID == 0;
99}
100
101ResourcePtr Statement::subject() const
102{
103 const shared_ptr<Model::ModelPrivate> m = d ? d->model.lock() : shared_ptr<Model::ModelPrivate>();
104 return m ? m->resourceByID(d->subjectID) : ResourcePtr(new Resource);
105}
106
107PropertyPtr Statement::predicate() const
108{
109 const shared_ptr<Model::ModelPrivate> m = d ? d->model.lock() : shared_ptr<Model::ModelPrivate>();
110 return m ? m->propertyByID(d->predicateID) : PropertyPtr( new Property() );
111}
112
113NodePtr Statement::object() const
114{
115 const shared_ptr<Model::ModelPrivate> m = d ? d->model.lock() : shared_ptr<Model::ModelPrivate>();
116 return m ? m->nodeByID(d->objectID) : NodePtr( LiteralPtr( new Literal() ) );
117}
118
119ResourcePtr Statement::asResource() const
120{
121 const shared_ptr<Model::ModelPrivate> m = d ? d->model.lock() : shared_ptr<Model::ModelPrivate>();
122
123 if (isNull() || !m || !m->nodeByID(d->objectID)->isResource())
124 return ResourcePtr(new Resource);
125
126 return m->resourceByID(d->objectID);
127}
128
129QString Statement::asString() const
130{
131 if (isNull())
132 return QString();
133
134 const shared_ptr<Model::ModelPrivate> m = d ? d->model.lock() : shared_ptr<Model::ModelPrivate>();
135 return m ? m->nodeByID(d->objectID)->text() : QString();
136}
137
138} // namespace RDF
139} // namespace Syndication
Syndication::RDF::Literal
a node type representing simple string values.
Definition literal.h:45
Syndication::RDF::Property
a property is node type that represents properties of things, like "name" is a property of a person,...
Definition property.h:46
Syndication::RDF::Resource
Resources are the entities in the RDF graph.
Definition resource.h:52
Syndication::RDF::Statement
An RDF statement, consisting of a triple (subject, predicate, object).
Definition statement.h:44
Syndication::RDF::Statement::asString
virtual QString asString() const
returns the object of this statement as string, if possible.
Definition statement.cpp:129
Syndication::RDF::Statement::~Statement
virtual ~Statement()
destructor
Definition statement.cpp:78
Syndication::RDF::Statement::isNull
virtual bool isNull() const
returns whether this statement is a null statement (i.e.
Definition statement.cpp:96
Syndication::RDF::Statement::operator=
Statement & operator=(const Statement &other)
assigns another statement
Definition statement.cpp:82
Syndication::RDF::Statement::subject
virtual ResourcePtr subject() const
the subject of the statement.
Definition statement.cpp:101
Syndication::RDF::Statement::object
virtual NodePtr object() const
the object of the statement
Definition statement.cpp:113
Syndication::RDF::Statement::Statement
Statement()
creates a null statement
Definition statement.cpp:57
Syndication::RDF::Statement::predicate
virtual PropertyPtr predicate() const
the predicate of the statement
Definition statement.cpp:107
Syndication::RDF::Statement::asResource
virtual ResourcePtr asResource() const
returns the object of this statement as resource, if possible.
Definition statement.cpp:119
Syndication::RDF::Statement::operator==
virtual bool operator==(const Statement &other) const
returns whether two statements are equal.
Definition statement.cpp:88
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Wed Jan 24 2024 00:00:00 by doxygen 1.10.0 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.14.10 API Reference

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