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_RESOURCE_H 0009 #define SYNDICATION_RDF_RESOURCE_H 0010 0011 #include <syndication/rdf/node.h> 0012 0013 class QString; 0014 0015 template<class T> 0016 class QList; 0017 0018 namespace Syndication 0019 { 0020 namespace RDF 0021 { 0022 class Model; 0023 class Property; 0024 typedef QSharedPointer<Property> PropertyPtr; 0025 class Resource; 0026 class Statement; 0027 typedef QSharedPointer<Statement> StatementPtr; 0028 0029 typedef QSharedPointer<Resource> ResourcePtr; 0030 0031 /** 0032 * Resources are the entities in the RDF graph. 0033 * In RSS, e.g. the feed channel itself and the items are 0034 * resources. 0035 */ 0036 class Resource : public Node 0037 { 0038 friend class Model; 0039 0040 public: 0041 /** 0042 * creates a null resource 0043 */ 0044 Resource(); 0045 0046 /** 0047 * copies a resource 0048 * 0049 * @param other the resource to copy 0050 */ 0051 Resource(const Resource &other); 0052 0053 /** 0054 * creates a resource with a given URI. 0055 * Do not use this directly, use Model::createResource() instead. 0056 * 0057 * @param uri the URI of the new resource 0058 */ 0059 explicit Resource(const QString &uri); 0060 0061 /** 0062 * destructor 0063 */ 0064 ~Resource() override; 0065 0066 /** 0067 * assigns a resource 0068 * 0069 * @param other the resource to assign 0070 */ 0071 Resource &operator=(const Resource &other); 0072 0073 /** 0074 * checks two resources for equality. Currently both URI (or anonID) 0075 * _and_ id() must be equal! 0076 * 0077 * @param other the node to compare this node to 0078 */ 0079 bool operator==(const Resource &other) const; 0080 0081 /** 0082 * Used by visitors for double dispatch. See NodeVisitor 0083 * for more information. 0084 * @param visitor the visitor calling the method 0085 * @param ptr a shared pointer object for this node 0086 */ 0087 void accept(NodeVisitor *visitor, NodePtr ptr) override; 0088 0089 /** 0090 * creates a copy of the resource object 0091 */ 0092 Resource *clone() const override; 0093 0094 /** 0095 * the model this resource belongs to 0096 */ 0097 virtual Model model() const; 0098 0099 /** 0100 * returns whether the resource has a property @p property in the 0101 * associated model. 0102 * 0103 * @param property the property to check for 0104 */ 0105 virtual bool hasProperty(PropertyPtr property) const; 0106 0107 /** 0108 * returns a statement from the associated model where this resource is 0109 * the subject and the given property the predicate. 0110 * 0111 * @param property the property to check for 0112 * 0113 * @return the first statement found that satisfies the conditions. 0114 * If there are multiple statements, an arbitrary one is returned. 0115 */ 0116 virtual StatementPtr property(PropertyPtr property) const; 0117 0118 /** 0119 * returns the list of all statements from the associated model where 0120 * this resource is the subject and the given property the predicate. 0121 * 0122 * @param property the property to check for 0123 * 0124 * @return a list of the statements that satisfy the conditions. 0125 */ 0126 virtual QList<StatementPtr> properties(PropertyPtr property) const; 0127 0128 /** 0129 * returns whether the resource is a null resource 0130 */ 0131 bool isNull() const override; 0132 0133 /** 0134 * the identifier of this node. the ID is unique per model 0135 * and set by the associated model at creation time. 0136 */ 0137 unsigned int id() const override; 0138 0139 /** 0140 * returns @p true 0141 */ 0142 bool isResource() const override; 0143 0144 /** 0145 * returns @p false 0146 */ 0147 bool isLiteral() const override; 0148 0149 /** 0150 * returns @p true if this resource is also a property, @p false 0151 * otherwise 0152 */ 0153 bool isProperty() const override; 0154 0155 /** 0156 * returns whether this resource is an anonymous resource 0157 */ 0158 bool isAnon() const override; 0159 0160 /** 0161 * returns @p true if this resource is also a sequence, @p false 0162 * otherwise. 0163 */ 0164 bool isSequence() const override; 0165 0166 /** 0167 * returns a null string 0168 */ 0169 QString text() const override; 0170 0171 /** 0172 * returns the URI of the resource 0173 */ 0174 virtual QString uri() const; 0175 0176 /** 0177 * used in Model 0178 * @internal 0179 */ 0180 void setModel(const Model &model) override; 0181 0182 /** 0183 * used in Model 0184 * @internal 0185 */ 0186 void setId(unsigned int id) override; 0187 0188 private: 0189 class ResourcePrivate; 0190 typedef QSharedPointer<ResourcePrivate> ResourcePrivatePtr; 0191 ResourcePrivatePtr d; 0192 }; 0193 0194 } // namespace RDF 0195 } // namespace Syndication 0196 0197 #endif // SYNDICATION_RDF_RESOURCE_H