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

syndication/rdf

model_p.h
00001 /*
00002  * This file is part of the syndication library
00003  *
00004  * Copyright (C) 2006 Frank Osterfeld <osterfeld@kde.org>
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Library General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2 of the License, or (at your option) any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Library General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Library General Public License
00017  * along with this library; see the file COPYING.LIB.  If not, write to
00018  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00019  * Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 #ifndef SYNDICATION_RDF_MODEL_P_H
00023 #define SYNDICATION_RDF_MODEL_P_H
00024 
00025 #include "model.h"
00026 #include "literal.h"
00027 #include "nodevisitor.h"
00028 #include "property.h"
00029 #include "rdfvocab.h"
00030 #include "resource.h"
00031 #include "sequence.h"
00032 #include "statement.h"
00033 
00034 #include <QtCore/QHash>
00035 #include <QtCore/QList>
00036 #include <QtCore/QString>
00037 
00038 #include <boost/enable_shared_from_this.hpp>
00039 
00040 namespace Syndication {
00041 namespace RDF {
00042 
00043 class Model::ModelPrivate : public boost::enable_shared_from_this<Model::ModelPrivate>
00044 {
00045 public:
00046     long id;
00047     static long idCounter;
00048     LiteralPtr nullLiteral;
00049     PropertyPtr nullProperty;
00050     ResourcePtr nullResource;
00051     StatementPtr nullStatement;
00052     QHash<QString, StatementPtr> statements;
00053     QHash<QString, QList<StatementPtr> > stmtsBySubject;
00054 
00055     QHash<int, NodePtr> nodes;
00056     QHash<QString, ResourcePtr> resources;
00057     QHash<QString, PropertyPtr> properties;
00058     QHash<QString, SequencePtr> sequences;
00059     bool initialized;
00060 
00061     class AddToHashesVisitor;
00062 
00063 
00064     ModelPrivate() : id(idCounter++)
00065     {
00066         addToHashesVisitor = new AddToHashesVisitor(this);
00067         initialized = false;
00068     }
00069 
00070     ~ModelPrivate()
00071     {
00072         delete addToHashesVisitor;
00073     }
00074 
00075     bool operator==(const ModelPrivate& other) const
00076     {
00077         return id == other.id;
00078     }
00079 
00080     class AddToHashesVisitor : public NodeVisitor
00081     {
00082         public:
00083 
00084         AddToHashesVisitor(ModelPrivate* parent) : p(parent)
00085         {}
00086 
00087         bool visitResource(ResourcePtr res)
00088         {
00089             visitNode(res);
00090             p->resources[res->uri()] = res;
00091             return true;
00092         }
00093 
00094         bool visitSequence(SequencePtr seq)
00095         {
00096             visitResource(seq);
00097             p->sequences[seq->uri()] = seq;
00098             return true;
00099         }
00100 
00101         bool visitProperty(PropertyPtr prop)
00102         {
00103             visitResource(prop);
00104             p->properties[prop->uri()] = prop;
00105             return true;
00106         }
00107 
00108         bool visitNode(NodePtr node)
00109         {
00110             p->nodes[node->id()] = node;
00111             return true;
00112         }
00113 
00114         ModelPrivate* p;
00115     };
00116 
00117     AddToHashesVisitor* addToHashesVisitor;
00118 
00119     bool resourceHasProperty(const Resource* resource,
00120                              PropertyPtr property) const;
00121 
00122     StatementPtr resourceProperty(const Resource* resource,
00123                                   PropertyPtr property) const;
00124 
00125     QList<StatementPtr> resourceProperties(const Resource* resource,
00126                                            PropertyPtr property) const;
00127 
00128     NodePtr nodeByID(uint id) const;
00129 
00130     ResourcePtr resourceByID(uint id) const;
00131 
00132     PropertyPtr propertyByID(uint id) const;
00133 
00134     LiteralPtr literalByID(uint id) const;
00135 
00136     void addToHashes(NodePtr node)
00137     {
00138         addToHashesVisitor->visit(node);
00139     }
00140 
00141     void addToHashes(StatementPtr stmt, const QString& key)
00142     {
00143         statements[key] = stmt;
00144         stmtsBySubject[stmt->subject()->uri()].append(stmt);
00145     }
00146 
00147     void removeFromHashes(const QString& key)
00148     {
00149         StatementPtr stmt = statements[key];
00150         if (stmt)
00151             stmtsBySubject[stmt->subject()->uri()].removeAll(stmt);
00152         statements.remove(key);
00153 
00154     }
00155 
00156     void init()
00157     {
00158         if (!initialized)
00159         {
00160             Model m;
00161             m.d = shared_from_this();
00162             nullLiteral = LiteralPtr( new Literal() );
00163             nullLiteral->setModel(m);
00164             nullProperty = PropertyPtr( new Property() );
00165             nullProperty->setModel(m);
00166             nullResource = ResourcePtr( new Resource() );
00167             nullResource->setModel(m);
00168             nullStatement = StatementPtr( new Statement() );
00169             initialized = true;
00170         }
00171     }
00172 };
00173 
00174 } // namespace RDF
00175 } // namespace Syndication
00176 
00177 #endif // SYNDICATION_RDF_MODEL_P_H
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Thu Aug 2 2012 15:24:53 by doxygen 1.7.5 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.8.5 API Reference

Skip menu "kdepimlibs-4.8.5 API Reference"
  • akonadi
  •   contact
  •   kmime
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  •   richtextbuilders
  • 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