00001 /* 00002 * This file is part of Soprano Project. 00003 * 00004 * Copyright (C) 2006-2007 Daniele Galdi <daniele.galdi@gmail.com> 00005 * Copyright (C) 2007-2009 Sebastian Trueg <trueg@kde.org> 00006 * 00007 * This library is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU Library General Public 00009 * License as published by the Free Software Foundation; either 00010 * version 2 of the License, or (at your option) any later version. 00011 * 00012 * This library is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 * Library General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Library General Public License 00018 * along with this library; see the file COPYING.LIB. If not, write to 00019 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00020 * Boston, MA 02110-1301, USA. 00021 */ 00022 00023 #ifndef SOPRANO_NODE_H 00024 #define SOPRANO_NODE_H 00025 00026 #include <QtCore/QUrl> 00027 #include <QtCore/QSharedDataPointer> 00028 #include <QtCore/QTextStream> 00029 00030 #include "soprano_export.h" 00031 #include "literalvalue.h" 00032 00033 namespace Soprano 00034 { 00055 class SOPRANO_EXPORT Node 00056 { 00057 public: 00058 enum Type { 00059 EmptyNode = 0, 00060 ResourceNode = 1, 00061 LiteralNode = 2, 00062 BlankNode = 3 00063 }; 00064 00075 Node(); 00076 00077 // This constructor is non-explicit for a reason: it makes creating 00078 // Statements much much easier and more readable 00087 Node( const QUrl &uri ); 00088 00096 explicit Node( const QString& id ); 00097 00107 Node( const LiteralValue& value, 00108 const QString& language = QString() ); 00109 00110 Node( const Node &other ); 00111 00112 ~Node(); 00114 00119 Node& operator=( const Node& other ); 00120 00124 Node& operator=( const QUrl& resource ); 00125 00126 Node& operator=( const LiteralValue& literal ); 00127 00128 bool operator==( const Node& other ) const; 00129 bool operator!=( const Node& other ) const; 00130 00131 bool operator==( const QUrl& other ) const; 00132 bool operator==( const LiteralValue& other ) const; 00133 00141 bool matches( const Node& other ) const; 00143 00151 Type type() const; 00152 00156 bool isEmpty() const; 00157 00161 bool isValid() const ; 00162 00166 bool isLiteral() const; 00167 00171 bool isResource() const; 00172 00176 bool isBlank() const; 00178 00187 QUrl uri() const; 00189 00199 QString identifier() const; 00201 00210 LiteralValue literal() const; 00211 00217 QUrl dataType() const; 00218 00227 QString language() const; 00229 00231 00239 QString toString() const; 00240 00251 QString toN3() const; 00253 00261 static Node createEmptyNode(); 00262 00273 static Node createResourceNode( const QUrl& uri ); 00274 00289 static Node createBlankNode( const QString& id ); 00290 00303 static Node createLiteralNode( const LiteralValue& value, const QString& language ); 00304 00305 private: 00306 class NodeData; 00307 class ResourceNodeData; 00308 class BNodeData; 00309 class LiteralNodeData; 00310 QSharedDataPointer<NodeData> d; 00311 }; 00312 00313 SOPRANO_EXPORT uint qHash( const Node& node ); 00314 } 00315 00316 SOPRANO_EXPORT QDebug operator<<( QDebug s, const Soprano::Node& ); 00317 00324 SOPRANO_EXPORT QTextStream& operator<<( QTextStream& s, const Soprano::Node& ); 00325 00326 SOPRANO_EXPORT uint qHash( const QUrl& url ); 00327 00328 #endif // SOPRANO_NODE_H