Soprano
2.7.2
|
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 #include "languagetag.h" 00033 #include "sopranomacros.h" 00034 00035 namespace Soprano 00036 { 00053 class SOPRANO_EXPORT Node 00054 { 00055 public: 00056 enum Type { 00057 EmptyNode = 0, 00058 ResourceNode = 1, 00059 LiteralNode = 2, 00060 BlankNode = 3 00061 }; 00062 00073 Node(); 00074 00075 // This constructor is non-explicit for a reason: it makes creating 00076 // Statements much much easier and more readable 00085 Node( const QUrl &uri ); 00086 00094 explicit Node( const QString& id ); 00095 00106 Node( const LiteralValue& value ); 00107 00120 SOPRANO_CONSTRUCTOR_DEPRECATED Node( const LiteralValue& value, 00121 const QString& language ); 00122 00126 Node( const Node &other ); 00127 00128 ~Node(); 00130 00135 Node& operator=( const Node& other ); 00136 00140 Node& operator=( const QUrl& resource ); 00141 00145 Node& operator=( const LiteralValue& literal ); 00146 00151 bool operator==( const Node& other ) const; 00152 00157 bool operator!=( const Node& other ) const; 00158 00164 bool operator==( const QUrl& uri ) const; 00165 00171 bool operator==( const LiteralValue& other ) const; 00172 00190 bool matches( const Node& other ) const; 00192 00200 Type type() const; 00201 00205 bool isEmpty() const; 00206 00210 bool isValid() const ; 00211 00215 bool isLiteral() const; 00216 00220 bool isResource() const; 00221 00225 bool isBlank() const; 00227 00236 QUrl uri() const; 00238 00248 QString identifier() const; 00250 00259 LiteralValue literal() const; 00260 00266 QUrl dataType() const; 00267 00279 QString language() const; 00281 00294 QString toString() const; 00295 00314 QString toN3() const; 00316 00324 static Node createEmptyNode(); 00325 00336 static Node createResourceNode( const QUrl& uri ); 00337 00352 static Node createBlankNode( const QString& id ); 00353 00367 static Node createLiteralNode( const LiteralValue& value ); 00368 00384 static SOPRANO_DEPRECATED Node createLiteralNode( const LiteralValue& value, const QString& language ); 00385 00401 static QString resourceToN3( const QUrl& resource ); 00402 00418 static QString blankToN3( const QString& blank ); 00419 00436 static QString literalToN3( const LiteralValue& literal ); 00437 00444 enum N3ParserFlag { 00448 NoFlags = 0x0, 00449 00456 StrictLiteralTypes = 0x1, 00457 00463 StrictUris = 0x2, 00464 00468 IgnorePrefixes = 0x4 00469 }; 00470 Q_DECLARE_FLAGS( N3ParserFlags, N3ParserFlag ) 00471 00472 00484 static Node fromN3( const QString& n3, N3ParserFlags flags = NoFlags ); 00485 00498 static Node fromN3Stream( QTextStream& stream, N3ParserFlags flags = NoFlags ); 00499 00500 private: 00501 class NodeData; 00502 class ResourceNodeData; 00503 class BNodeData; 00504 class LiteralNodeData; 00505 QSharedDataPointer<NodeData> d; 00506 }; 00507 00511 SOPRANO_EXPORT uint qHash( const Node& node ); 00512 } 00513 00517 SOPRANO_EXPORT QDebug operator<<( QDebug s, const Soprano::Node& ); 00518 00527 SOPRANO_EXPORT QTextStream& operator<<( QTextStream& s, const Soprano::Node& ); 00528 00536 SOPRANO_EXPORT QTextStream& operator>>( QTextStream& s, Soprano::Node& ); 00537 00538 #if QT_VERSION < 0x040700 00539 SOPRANO_EXPORT uint qHash( const QUrl& url ); 00540 #endif 00541 00542 Q_DECLARE_OPERATORS_FOR_FLAGS( Soprano::Node::N3ParserFlags ) 00543 00544 #endif // SOPRANO_NODE_H