22 #ifndef SYNDICATION_RDF_MODEL_P_H
23 #define SYNDICATION_RDF_MODEL_P_H
27 #include "nodevisitor.h"
32 #include "statement.h"
34 #include <QtCore/QHash>
35 #include <QtCore/QList>
36 #include <QtCore/QString>
38 #include <boost/enable_shared_from_this.hpp>
40 namespace Syndication {
43 class Model::ModelPrivate :
public boost::enable_shared_from_this<Model::ModelPrivate>
47 static long idCounter;
48 LiteralPtr nullLiteral;
49 PropertyPtr nullProperty;
50 ResourcePtr nullResource;
51 StatementPtr nullStatement;
53 QHash<QString, QList<StatementPtr> > stmtsBySubject;
55 QHash<int, NodePtr> nodes;
56 QHash<QString, ResourcePtr> resources;
57 QHash<QString, PropertyPtr> properties;
58 QHash<QString, SequencePtr> sequences;
61 class AddToHashesVisitor;
64 ModelPrivate() : id(idCounter++)
66 addToHashesVisitor =
new AddToHashesVisitor(
this);
72 delete addToHashesVisitor;
75 bool operator==(
const ModelPrivate& other)
const
77 return id == other.id;
80 class AddToHashesVisitor :
public NodeVisitor
84 AddToHashesVisitor(ModelPrivate* parent) : p(parent)
87 bool visitResource(ResourcePtr res)
90 p->resources[res->uri()] = res;
94 bool visitSequence(SequencePtr seq)
97 p->sequences[seq->uri()] = seq;
101 bool visitProperty(PropertyPtr prop)
104 p->properties[prop->uri()] = prop;
108 bool visitNode(NodePtr node)
110 p->nodes[node->id()] = node;
117 AddToHashesVisitor* addToHashesVisitor;
119 bool resourceHasProperty(
const Resource* resource,
120 PropertyPtr property)
const;
122 StatementPtr resourceProperty(
const Resource* resource,
123 PropertyPtr property)
const;
125 QList<StatementPtr> resourceProperties(
const Resource* resource,
126 PropertyPtr property)
const;
136 void addToHashes(NodePtr node)
138 addToHashesVisitor->visit(node);
141 void addToHashes(StatementPtr stmt,
const QString& key)
144 stmtsBySubject[stmt->subject()->uri()].append(stmt);
147 void removeFromHashes(
const QString& key)
151 stmtsBySubject[stmt->subject()->uri()].removeAll(stmt);
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() );
177 #endif // SYNDICATION_RDF_MODEL_P_H