File indexing completed on 2024-09-08 03:43:39
0001 /* 0002 This file is part of the syndication library 0003 SPDX-FileCopyrightText: 2006 Frank Osterfeld <osterfeld@kde.org> 0004 0005 SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 #ifndef SYNDICATION_RDF_MODEL_H 0009 #define SYNDICATION_RDF_MODEL_H 0010 0011 #include "../syndication_export.h" 0012 0013 #include "document.h" 0014 #include "literal.h" 0015 #include "node.h" 0016 #include "property.h" 0017 #include "resource.h" 0018 #include "sequence.h" 0019 #include "statement.h" 0020 0021 #include <QString> 0022 0023 template<class T> 0024 class QList; 0025 0026 namespace Syndication 0027 { 0028 namespace RDF 0029 { 0030 /** 0031 * An RDF model, a set of RDF statements. 0032 * Model objects are implicitly shared. 0033 * 0034 * @author Frank Osterfeld 0035 */ 0036 class Model 0037 { 0038 friend class ::Syndication::RDF::Document; 0039 friend class ::Syndication::RDF::Document::Private; 0040 friend class ::Syndication::RDF::Resource; 0041 friend class ::Syndication::RDF::Resource::ResourcePrivate; 0042 friend class ::Syndication::RDF::Statement; 0043 friend class ::Syndication::RDF::Statement::StatementPrivate; 0044 0045 public: 0046 /** 0047 * default constructor, creates an empty model 0048 * containing no statements 0049 */ 0050 Model(); 0051 0052 /** 0053 * constructs a model from another. 0054 * Both models will share the same set of statements, 0055 * so adding/removing statements from one model also 0056 * modifies the other! 0057 * 0058 * @param other another model 0059 */ 0060 Model(const Model &other); 0061 0062 /** 0063 * destructor 0064 */ 0065 virtual ~Model(); 0066 0067 /** 0068 * assigns another model. Both models will share the same 0069 * set of statements, so adding/removing statements from 0070 * one model also modifies the other! 0071 * 0072 * @param other another model 0073 */ 0074 Model &operator=(const Model &other); 0075 0076 /** 0077 * Returns whether two models objects represent the same model 0078 * (i.e. share the same underlying statement set). Currently this 0079 * method does _not_ compare the statement list. 0080 * Two independently created models containing the same statements 0081 * are not equal! 0082 * 0083 * @param other the model to compare to 0084 */ 0085 bool operator==(const Model &other) const; 0086 0087 /** 0088 * creates a resource and associates it with this model. If the model 0089 * already contains a resource with the given URI, the existing instance 0090 * is returned. 0091 * 0092 * @param uri the URI of the resource. If a null string, a blank node 0093 * is created. 0094 * @return a shared pointer to the requested resource 0095 */ 0096 virtual ResourcePtr createResource(const QString &uri = QString()); 0097 0098 /** 0099 * creates a property and associates it with this model. If the model 0100 * already contains a property with the given URI, the existing instance 0101 * is returned. 0102 * 0103 * @param uri the URI of the property. This must be non-empty, otherwise 0104 * null property is returned 0105 * @return a shared pointer to the requested property 0106 */ 0107 virtual PropertyPtr createProperty(const QString &uri); 0108 0109 /** 0110 * creates a sequence and associates it with this model. If the model 0111 * already contains a sequence with the given URI, the existing 0112 * instance is returned. 0113 * 0114 * @param uri the URI of the sequence, or a null string for an 0115 * anonymous instance 0116 * @return a shared pointer to the requested sequence 0117 */ 0118 virtual SequencePtr createSequence(const QString &uri = QString()); 0119 0120 /** 0121 * creates a literal and associates it with this model. 0122 * 0123 * @param text the literal text 0124 * @return a shared pointer to the requested literal 0125 */ 0126 virtual LiteralPtr createLiteral(const QString &text); 0127 0128 /** 0129 * adds a statement to the model. 0130 * 0131 * @param subject 0132 * @param predicate 0133 * @param object 0134 * @return a shared pointer to a statement associated with this 0135 * model, with the given @c subject, @c predicate and @c object 0136 */ 0137 virtual StatementPtr addStatement(ResourcePtr subject, PropertyPtr predicate, NodePtr object); 0138 0139 /** 0140 * removes a statement from the model. 0141 * 0142 * @param subject subject of the statement 0143 * @param predicate predicate of the statement 0144 * @param object object of the statement 0145 */ 0146 virtual void removeStatement(ResourcePtr subject, PropertyPtr predicate, NodePtr object); 0147 0148 /** 0149 * removes a statement from the model. 0150 * 0151 * @param statement the statement to remove 0152 */ 0153 virtual void removeStatement(StatementPtr statement); 0154 0155 /** 0156 * returns whether this model is empty, i.e. contains no statements. 0157 */ 0158 virtual bool isEmpty() const; 0159 0160 /** 0161 * returns all resources of a given type. 0162 * subClassOf semantics are ignored. 0163 * 0164 * @param type a resource representing an RDFS class 0165 */ 0166 virtual QList<ResourcePtr> resourcesWithType(ResourcePtr type) const; 0167 0168 /** 0169 * returns a list of the statements in this model. 0170 * 0171 */ 0172 virtual QList<StatementPtr> statements() const; 0173 0174 /** 0175 * searches the model for a node by ID. 0176 * 0177 * @param id the ID to search for 0178 * @return the node with the given ID, or a null node (which is of type 0179 * Literal) if the model doesn't contain the node with this ID 0180 */ 0181 virtual NodePtr nodeByID(uint id) const; 0182 0183 /** 0184 * searches the model for a resource by ID. 0185 * 0186 * @param id the ID to search for 0187 * @return the resource with the given ID, or a null resource if the 0188 * model doesn't contain a resource with this ID 0189 */ 0190 virtual ResourcePtr resourceByID(uint id) const; 0191 0192 /** 0193 * searches the model for a property by ID. 0194 * 0195 * @param id the ID to search for 0196 * @return the property with the given ID, or a null property if the 0197 * model doesn't contain a property with this ID 0198 */ 0199 virtual PropertyPtr propertyByID(uint id) const; 0200 0201 /** 0202 * searches the model for a literal by ID. 0203 * 0204 * @param id the ID to search for 0205 * @return the literal with the given ID, or a null literal if the 0206 * model doesn't contain a literal with this ID 0207 */ 0208 virtual LiteralPtr literalByID(uint id) const; 0209 //@cond PRIVATE 0210 /** 0211 * @internal 0212 * used by Resource::hasProperty() 0213 */ 0214 virtual bool resourceHasProperty(const Resource *resource, PropertyPtr property) const; 0215 0216 /** 0217 * @internal 0218 * used by Resource::property() 0219 */ 0220 virtual StatementPtr resourceProperty(const Resource *resource, PropertyPtr property) const; 0221 0222 /** 0223 * @internal 0224 * used by Resource::properties() 0225 */ 0226 virtual QList<StatementPtr> resourceProperties(const Resource *resource, PropertyPtr property) const; 0227 0228 //@endcond 0229 /** 0230 * a debug string listing the contained statements for 0231 * debugging purposes 0232 * 0233 * @return debug string 0234 */ 0235 virtual QString debugInfo() const; 0236 0237 private: 0238 class ModelPrivate; 0239 QSharedPointer<ModelPrivate> d; 0240 }; 0241 0242 } // namespace RDF 0243 } // namespace Syndication 0244 0245 #endif // SYNDICATION_RDF_MODEL_H