syndication/rdf
statement.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "statement.h"
00024 #include "literal.h"
00025 #include "model.h"
00026 #include "property.h"
00027 #include "resource.h"
00028
00029 #include <QtCore/QString>
00030
00031 namespace Syndication {
00032 namespace RDF {
00033
00034 class Statement::StatementPrivate
00035 {
00036 public:
00037
00038 uint subjectID;
00039 uint predicateID;
00040 uint objectID;
00041 Model model;
00042
00043 bool operator==(const StatementPrivate& other) const
00044 {
00045
00046 return subjectID == other.subjectID &&
00047 predicateID == other.predicateID &&
00048 objectID == other.objectID;
00049 }
00050 };
00051
00052 Statement::Statement() : d(new StatementPrivate)
00053 {
00054 d->subjectID = 0;
00055 d->predicateID = 0;
00056 d->objectID = 0;
00057 }
00058
00059 Statement::Statement(const Statement& other)
00060 {
00061 d = other.d;
00062 }
00063
00064 Statement::Statement(ResourcePtr subject, PropertyPtr predicate,
00065 NodePtr object) : d(new StatementPrivate)
00066 {
00067 d->model = subject->model();
00068 d->subjectID = subject->id();
00069 d->predicateID = predicate->id();
00070 d->objectID = object->id();
00071 }
00072
00073 Statement::~Statement()
00074 {
00075 }
00076
00077 Statement& Statement::operator=(const Statement& other)
00078 {
00079 d = other.d;
00080 return *this;
00081 }
00082
00083 bool Statement::operator==(const Statement& other) const
00084 {
00085 if (!d || !other.d)
00086 return d == other.d;
00087
00088 return *d == *(other.d);
00089 }
00090
00091 bool Statement::isNull() const
00092 {
00093 return d->subjectID == 0;
00094 }
00095
00096 ResourcePtr Statement::subject() const
00097 {
00098 return d->model.resourceByID(d->subjectID);
00099 }
00100
00101 PropertyPtr Statement::predicate() const
00102 {
00103 return d->model.propertyByID(d->predicateID);
00104 }
00105
00106 NodePtr Statement::object() const
00107 {
00108 return d->model.nodeByID(d->objectID);
00109 }
00110
00111 ResourcePtr Statement::asResource() const
00112 {
00113 if (isNull() || !d->model.nodeByID(d->objectID)->isResource())
00114 return ResourcePtr(new Resource);
00115
00116 return d->model.resourceByID(d->objectID);
00117 }
00118
00119 QString Statement::asString() const
00120 {
00121 if (isNull())
00122 return QString();
00123
00124 return d->model.nodeByID(d->objectID)->text();
00125 }
00126
00127 }
00128 }