22#ifndef SYNDICATION_RDF_MODEL_P_H
23#define SYNDICATION_RDF_MODEL_P_H
27#include "nodevisitor.h"
34#include <QtCore/QHash>
35#include <QtCore/QList>
36#include <QtCore/QString>
38#include <boost/enable_shared_from_this.hpp>
40namespace Syndication {
43class 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;
52 QHash<QString, StatementPtr> statements;
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;
128 NodePtr nodeByID(uint
id)
const;
130 ResourcePtr resourceByID(uint
id)
const;
132 PropertyPtr propertyByID(uint
id)
const;
134 LiteralPtr literalByID(uint
id)
const;
136 void addToHashes(NodePtr node)
138 addToHashesVisitor->visit(node);
141 void addToHashes(StatementPtr stmt,
const QString& key)
143 statements[key] = stmt;
144 stmtsBySubject[stmt->subject()->uri()].append(stmt);
147 void removeFromHashes(
const QString& key)
149 StatementPtr stmt = statements[key];
151 stmtsBySubject[stmt->subject()->uri()].removeAll(stmt);
152 statements.remove(key);
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() );
Model()
default constructor, creates an empty model containing no statements