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
37Statement::Statement()
38 : d(new StatementPrivate)
39{
40 d->subjectID = 0;
41 d->predicateID = 0;
42 d->objectID = 0;
43}
44
45Statement::Statement(const Statement &other)
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
59Statement::~Statement()
60{
61}
62
63Statement &Statement::operator=(const Statement &other)
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
78bool Statement::isNull() const
79{
80 return d->subjectID == 0;
81}
82
83ResourcePtr Statement::subject() const
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
89PropertyPtr Statement::predicate() const
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
101ResourcePtr Statement::asResource() const
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
112QString Statement::asString() const
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
bool operator==(const QGraphicsApiFilter &reference, const QGraphicsApiFilter &sample)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:14:15 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.