syndication/rdf
statement.cpp
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 00023 #include "statement.h" 00024 #include "literal.h" 00025 #include "model.h" 00026 #include "model_p.h" 00027 #include "property.h" 00028 #include "resource.h" 00029 00030 #include <QtCore/QString> 00031 00032 #include <boost/weak_ptr.hpp> 00033 00034 using namespace boost; 00035 00036 namespace Syndication { 00037 namespace RDF { 00038 00039 class Statement::StatementPrivate 00040 { 00041 public: 00042 00043 uint subjectID; 00044 uint predicateID; 00045 uint objectID; 00046 weak_ptr<Model::ModelPrivate> model; 00047 00048 bool operator==(const StatementPrivate& other) const 00049 { 00050 // FIXME: use better check that works also with multiple models 00051 return subjectID == other.subjectID && 00052 predicateID == other.predicateID && 00053 objectID == other.objectID; 00054 } 00055 }; 00056 00057 Statement::Statement() : d(new StatementPrivate) 00058 { 00059 d->subjectID = 0; 00060 d->predicateID = 0; 00061 d->objectID = 0; 00062 } 00063 00064 Statement::Statement(const Statement& other) 00065 { 00066 d = other.d; 00067 } 00068 00069 Statement::Statement(ResourcePtr subject, PropertyPtr predicate, 00070 NodePtr object) : d(new StatementPrivate) 00071 { 00072 d->model = subject->model().d; 00073 d->subjectID = subject->id(); 00074 d->predicateID = predicate->id(); 00075 d->objectID = object->id(); 00076 } 00077 00078 Statement::~Statement() 00079 { 00080 } 00081 00082 Statement& Statement::operator=(const Statement& other) 00083 { 00084 d = other.d; 00085 return *this; 00086 } 00087 00088 bool Statement::operator==(const Statement& other) const 00089 { 00090 if (!d || !other.d) 00091 return d == other.d; 00092 00093 return *d == *(other.d); 00094 } 00095 00096 bool Statement::isNull() const 00097 { 00098 return d->subjectID == 0; 00099 } 00100 00101 ResourcePtr Statement::subject() const 00102 { 00103 const shared_ptr<Model::ModelPrivate> m = d ? d->model.lock() : shared_ptr<Model::ModelPrivate>(); 00104 return m ? m->resourceByID(d->subjectID) : ResourcePtr(new Resource); 00105 } 00106 00107 PropertyPtr Statement::predicate() const 00108 { 00109 const shared_ptr<Model::ModelPrivate> m = d ? d->model.lock() : shared_ptr<Model::ModelPrivate>(); 00110 return m ? m->propertyByID(d->predicateID) : PropertyPtr( new Property() ); 00111 } 00112 00113 NodePtr Statement::object() const 00114 { 00115 const shared_ptr<Model::ModelPrivate> m = d ? d->model.lock() : shared_ptr<Model::ModelPrivate>(); 00116 return m ? m->nodeByID(d->objectID) : NodePtr( LiteralPtr( new Literal() ) ); 00117 } 00118 00119 ResourcePtr Statement::asResource() const 00120 { 00121 const shared_ptr<Model::ModelPrivate> m = d ? d->model.lock() : shared_ptr<Model::ModelPrivate>(); 00122 00123 if (isNull() || !m || !m->nodeByID(d->objectID)->isResource()) 00124 return ResourcePtr(new Resource); 00125 00126 return m->resourceByID(d->objectID); 00127 } 00128 00129 QString Statement::asString() const 00130 { 00131 if (isNull()) 00132 return QString(); 00133 00134 const shared_ptr<Model::ModelPrivate> m = d ? d->model.lock() : shared_ptr<Model::ModelPrivate>(); 00135 return m ? m->nodeByID(d->objectID)->text() : QString(); 00136 } 00137 00138 } // namespace RDF 00139 } // namespace Syndication
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Mon Aug 27 2012 22:08:52 by doxygen 1.7.5 written by Dimitri van Heesch, © 1997-2006
Documentation copyright © 1996-2012 The KDE developers.
Generated on Mon Aug 27 2012 22:08:52 by doxygen 1.7.5 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.