Soprano  2.7.6
node.h
Go to the documentation of this file.
1 /*
2  * This file is part of Soprano Project.
3  *
4  * Copyright (C) 2006-2007 Daniele Galdi <daniele.galdi@gmail.com>
5  * Copyright (C) 2007-2009 Sebastian Trueg <trueg@kde.org>
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Library General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public License
18  * along with this library; see the file COPYING.LIB. If not, write to
19  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20  * Boston, MA 02110-1301, USA.
21  */
22 
23 #ifndef SOPRANO_NODE_H
24 #define SOPRANO_NODE_H
25 
26 #include <QtCore/QUrl>
27 #include <QtCore/QSharedDataPointer>
28 #include <QtCore/QTextStream>
29 
30 #include "soprano_export.h"
31 #include "literalvalue.h"
32 #include "languagetag.h"
33 #include "sopranomacros.h"
34 
35 namespace Soprano
36 {
54  {
55  public:
56  enum Type {
57  EmptyNode = 0,
58  ResourceNode = 1,
59  LiteralNode = 2,
60  BlankNode = 3
61  };
62 
73  Node();
74 
75  // This constructor is non-explicit for a reason: it makes creating
76  // Statements much much easier and more readable
85  Node( const QUrl &uri );
86 
94  explicit Node( const QString& id );
95 
106  Node( const LiteralValue& value );
107 
121  const QString& language );
122 
126  Node( const Node &other );
127 
128  ~Node();
130 
135  Node& operator=( const Node& other );
136 
140  Node& operator=( const QUrl& resource );
141 
145  Node& operator=( const LiteralValue& literal );
146 
151  bool operator==( const Node& other ) const;
152 
157  bool operator!=( const Node& other ) const;
158 
164  bool operator==( const QUrl& uri ) const;
165 
171  bool operator==( const LiteralValue& other ) const;
172 
190  bool matches( const Node& other ) const;
192 
200  Type type() const;
201 
205  bool isEmpty() const;
206 
210  bool isValid() const ;
211 
215  bool isLiteral() const;
216 
220  bool isResource() const;
221 
225  bool isBlank() const;
227 
236  QUrl uri() const;
238 
248  QString identifier() const;
250 
259  LiteralValue literal() const;
260 
266  QUrl dataType() const;
267 
279  QString language() const;
281 
294  QString toString() const;
295 
314  QString toN3() const;
316 
324  static Node createEmptyNode();
325 
336  static Node createResourceNode( const QUrl& uri );
337 
352  static Node createBlankNode( const QString& id );
353 
367  static Node createLiteralNode( const LiteralValue& value );
368 
384  static SOPRANO_DEPRECATED Node createLiteralNode( const LiteralValue& value, const QString& language );
385 
401  static QString resourceToN3( const QUrl& resource );
402 
418  static QString blankToN3( const QString& blank );
419 
436  static QString literalToN3( const LiteralValue& literal );
437 
448  NoFlags = 0x0,
449 
456  StrictLiteralTypes = 0x1,
457 
463  StrictUris = 0x2,
464 
468  IgnorePrefixes = 0x4
469  };
470  Q_DECLARE_FLAGS( N3ParserFlags, N3ParserFlag )
471 
472 
484  static Node fromN3( const QString& n3, N3ParserFlags flags = NoFlags );
485 
498  static Node fromN3Stream( QTextStream& stream, N3ParserFlags flags = NoFlags );
499 
500  private:
501  class NodeData;
502  class ResourceNodeData;
503  class BNodeData;
504  class LiteralNodeData;
505  QSharedDataPointer<NodeData> d;
506  };
507 
511  SOPRANO_EXPORT uint qHash( const Node& node );
512 }
513 
517 SOPRANO_EXPORT QDebug operator<<( QDebug s, const Soprano::Node& );
518 
527 SOPRANO_EXPORT QTextStream& operator<<( QTextStream& s, const Soprano::Node& );
528 
536 SOPRANO_EXPORT QTextStream& operator>>( QTextStream& s, Soprano::Node& );
537 
538 #if QT_VERSION < 0x040700
539 SOPRANO_EXPORT uint qHash( const QUrl& url );
540 #endif
541 
542 Q_DECLARE_OPERATORS_FOR_FLAGS( Soprano::Node::N3ParserFlags )
543 
544 #endif // SOPRANO_NODE_H