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

syndication/rdf

  • syndication
  • rdf
model_p.h
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#ifndef SYNDICATION_RDF_MODEL_P_H
23#define SYNDICATION_RDF_MODEL_P_H
24
25#include "model.h"
26#include "literal.h"
27#include "nodevisitor.h"
28#include "property.h"
29#include "rdfvocab.h"
30#include "resource.h"
31#include "sequence.h"
32#include "statement.h"
33
34#include <QtCore/QHash>
35#include <QtCore/QList>
36#include <QtCore/QString>
37
38#include <boost/enable_shared_from_this.hpp>
39
40namespace Syndication {
41namespace RDF {
42
43class Model::ModelPrivate : public boost::enable_shared_from_this<Model::ModelPrivate>
44{
45public:
46 long id;
47 static long idCounter;
48 LiteralPtr nullLiteral;
49 PropertyPtr nullProperty;
50 ResourcePtr nullResource;
51 StatementPtr nullStatement;
52 QHash<QString, StatementPtr> statements;
53 QHash<QString, QList<StatementPtr> > stmtsBySubject;
54
55 QHash<int, NodePtr> nodes;
56 QHash<QString, ResourcePtr> resources;
57 QHash<QString, PropertyPtr> properties;
58 QHash<QString, SequencePtr> sequences;
59 bool initialized;
60
61 class AddToHashesVisitor;
62
63
64 ModelPrivate() : id(idCounter++)
65 {
66 addToHashesVisitor = new AddToHashesVisitor(this);
67 initialized = false;
68 }
69
70 ~ModelPrivate()
71 {
72 delete addToHashesVisitor;
73 }
74
75 bool operator==(const ModelPrivate& other) const
76 {
77 return id == other.id;
78 }
79
80 class AddToHashesVisitor : public NodeVisitor
81 {
82 public:
83
84 AddToHashesVisitor(ModelPrivate* parent) : p(parent)
85 {}
86
87 bool visitResource(ResourcePtr res)
88 {
89 visitNode(res);
90 p->resources[res->uri()] = res;
91 return true;
92 }
93
94 bool visitSequence(SequencePtr seq)
95 {
96 visitResource(seq);
97 p->sequences[seq->uri()] = seq;
98 return true;
99 }
100
101 bool visitProperty(PropertyPtr prop)
102 {
103 visitResource(prop);
104 p->properties[prop->uri()] = prop;
105 return true;
106 }
107
108 bool visitNode(NodePtr node)
109 {
110 p->nodes[node->id()] = node;
111 return true;
112 }
113
114 ModelPrivate* p;
115 };
116
117 AddToHashesVisitor* addToHashesVisitor;
118
119 bool resourceHasProperty(const Resource* resource,
120 PropertyPtr property) const;
121
122 StatementPtr resourceProperty(const Resource* resource,
123 PropertyPtr property) const;
124
125 QList<StatementPtr> resourceProperties(const Resource* resource,
126 PropertyPtr property) const;
127
128 NodePtr nodeByID(uint id) const;
129
130 ResourcePtr resourceByID(uint id) const;
131
132 PropertyPtr propertyByID(uint id) const;
133
134 LiteralPtr literalByID(uint id) const;
135
136 void addToHashes(NodePtr node)
137 {
138 addToHashesVisitor->visit(node);
139 }
140
141 void addToHashes(StatementPtr stmt, const QString& key)
142 {
143 statements[key] = stmt;
144 stmtsBySubject[stmt->subject()->uri()].append(stmt);
145 }
146
147 void removeFromHashes(const QString& key)
148 {
149 StatementPtr stmt = statements[key];
150 if (stmt)
151 stmtsBySubject[stmt->subject()->uri()].removeAll(stmt);
152 statements.remove(key);
153
154 }
155
156 void init()
157 {
158 if (!initialized)
159 {
160 Model m;
161 m.d = shared_from_this();
162 nullLiteral = LiteralPtr( new Literal() );
163 nullLiteral->setModel(m);
164 nullProperty = PropertyPtr( new Property() );
165 nullProperty->setModel(m);
166 nullResource = ResourcePtr( new Resource() );
167 nullResource->setModel(m);
168 nullStatement = StatementPtr( new Statement() );
169 initialized = true;
170 }
171 }
172};
173
174} // namespace RDF
175} // namespace Syndication
176
177#endif // SYNDICATION_RDF_MODEL_P_H
Syndication::RDF::Model::Model
Model()
default constructor, creates an empty model containing no statements
Definition model.cpp:31
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