Syndication

statement.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 "statement.h"
9#include "literal.h"
10#include "model.h"
11#include "model_p.h"
12#include "property.h"
13#include "resource.h"
14
15#include <QString>
16#include <QWeakPointer>
17
18namespace Syndication
19{
20namespace RDF
21{
22class SYNDICATION_NO_EXPORT Statement::StatementPrivate
23{
24public:
25 uint subjectID;
26 uint predicateID;
27 uint objectID;
29
30 bool operator==(const StatementPrivate &other) const
31 {
32 // FIXME: use better check that works also with multiple models
33 return subjectID == other.subjectID && predicateID == other.predicateID && objectID == other.objectID;
34 }
35};
36
38 : d(new StatementPrivate)
39{
40 d->subjectID = 0;
41 d->predicateID = 0;
42 d->objectID = 0;
43}
44
46{
47 d = other.d;
48}
49
50Statement::Statement(ResourcePtr subject, PropertyPtr predicate, NodePtr object)
51 : d(new StatementPrivate)
52{
53 d->model = subject->model().d;
54 d->subjectID = subject->id();
55 d->predicateID = predicate->id();
56 d->objectID = object->id();
57}
58
62
64{
65 d = other.d;
66 return *this;
67}
68
69bool Statement::operator==(const Statement &other) const
70{
71 if (!d || !other.d) {
72 return d == other.d;
73 }
74
75 return *d == *(other.d);
76}
77
79{
80 return d->subjectID == 0;
81}
82
84{
85 const QSharedPointer<Model::ModelPrivate> m = d ? d->model.toStrongRef() : QSharedPointer<Model::ModelPrivate>();
86 return m ? m->resourceByID(d->subjectID) : ResourcePtr(new Resource);
87}
88
90{
91 const QSharedPointer<Model::ModelPrivate> m = d ? d->model.toStrongRef() : QSharedPointer<Model::ModelPrivate>();
92 return m ? m->propertyByID(d->predicateID) : PropertyPtr(new Property());
93}
94
95NodePtr Statement::object() const
96{
97 const QSharedPointer<Model::ModelPrivate> m = d ? d->model.toStrongRef() : QSharedPointer<Model::ModelPrivate>();
98 return m ? m->nodeByID(d->objectID) : NodePtr(LiteralPtr(new Literal()));
99}
100
102{
103 const QSharedPointer<Model::ModelPrivate> m = d ? d->model.toStrongRef() : QSharedPointer<Model::ModelPrivate>();
104
105 if (isNull() || !m || !m->nodeByID(d->objectID)->isResource()) {
106 return ResourcePtr(new Resource);
107 }
108
109 return m->resourceByID(d->objectID);
110}
111
113{
114 if (isNull()) {
115 return QString();
116 }
117
118 const QSharedPointer<Model::ModelPrivate> m = d ? d->model.toStrongRef() : QSharedPointer<Model::ModelPrivate>();
119 return m ? m->nodeByID(d->objectID)->text() : QString();
120}
121
122} // namespace RDF
123} // namespace Syndication
a node type representing simple string values.
Definition literal.h:29
a property is node type that represents properties of things, like "name" is a property of a person,...
Definition property.h:32
Resources are the entities in the RDF graph.
Definition resource.h:37
An RDF statement, consisting of a triple (subject, predicate, object).
Definition statement.h:29
virtual QString asString() const
returns the object of this statement as string, if possible.
virtual ~Statement()
destructor
Definition statement.cpp:59
virtual bool isNull() const
returns whether this statement is a null statement (i.e.
Definition statement.cpp:78
Statement & operator=(const Statement &other)
assigns another statement
Definition statement.cpp:63
virtual ResourcePtr subject() const
the subject of the statement.
Definition statement.cpp:83
virtual NodePtr object() const
the object of the statement
Definition statement.cpp:95
Statement()
creates a null statement
Definition statement.cpp:37
virtual PropertyPtr predicate() const
the predicate of the statement
Definition statement.cpp:89
virtual ResourcePtr asResource() const
returns the object of this statement as resource, if possible.
virtual bool operator==(const Statement &other) const
returns whether two statements are equal.
Definition statement.cpp:69
bool operator==(const StyleDelim &l, const StyleDelim &r)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:03:18 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.