Dataquay 0.8
Uri.h
Go to the documentation of this file.
1/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2
3/*
4 Dataquay
5
6 A C++/Qt library for simple RDF datastore management.
7 Copyright 2009-2012 Chris Cannam.
8
9 Permission is hereby granted, free of charge, to any person
10 obtaining a copy of this software and associated documentation
11 files (the "Software"), to deal in the Software without
12 restriction, including without limitation the rights to use, copy,
13 modify, merge, publish, distribute, sublicense, and/or sell copies
14 of the Software, and to permit persons to whom the Software is
15 furnished to do so, subject to the following conditions:
16
17 The above copyright notice and this permission notice shall be
18 included in all copies or substantial portions of the Software.
19
20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
24 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
25 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27
28 Except as contained in this notice, the name of Chris Cannam
29 shall not be used in advertising or otherwise to promote the sale,
30 use or other dealings in this Software without prior written
31 authorization.
32*/
33
34#ifndef DATAQUAY_URI_H
35#define DATAQUAY_URI_H
36
37namespace Dataquay {
38class Uri;
39}
40
41// Declare this early, to avoid any problems with instantiation order
42// arising from inclusion "races"
43extern unsigned int qHash(const Dataquay::Uri &u);
44
45#include <QString>
46#include <QUrl>
47
48#include <QMetaType>
49
50#include <iostream>
51
52class QDataStream;
53class QTextStream;
54class QVariant;
55
56namespace Dataquay
57{
58
76class Uri
77{
78public:
82 Uri() {
83 }
84
104 explicit Uri(const QString &s) : m_uri(s) {
105 checkComplete();
106 }
107
113 explicit Uri(const QUrl &u) : m_uri(u.toString()) {
114 checkComplete();
115 }
117 }
118
119 inline QString toString() const { return m_uri; }
120 inline QUrl toUrl() const { return QUrl(m_uri); }
121 inline int length() const { return m_uri.length(); }
122
123 QString scheme() const;
124
125 bool operator==(const Uri &u) const;
126 inline bool operator!=(const Uri &u) const { return !operator==(u); }
127 inline bool operator<(const Uri &u) const { return m_uri < u.m_uri; }
128 inline bool operator>(const Uri &u) const { return u < *this; }
129
134 static bool isCompleteUri(QString s);
135
136 static QString metaTypeName();
137 static int metaTypeId();
138
142 static bool hasUriType(const QVariant &);
143
147 static Uri rdfTypeUri();
148
149private:
150 void checkComplete();
151 QString m_uri;
152 static bool canBeComplete(QString &s);
153};
154
155typedef QList<Uri> UriList;
156
157QDataStream &operator<<(QDataStream &out, const Uri &);
158QDataStream &operator>>(QDataStream &in, Uri &);
159
160std::ostream &operator<<(std::ostream &out, const Uri &);
161QTextStream &operator<<(QTextStream &out, const Uri &);
162
163}
164
165Q_DECLARE_METATYPE(Dataquay::Uri)
166
167#endif
unsigned int qHash(const Dataquay::Uri &u)
Uri represents a single URI.
Definition Uri.h:77
bool operator==(const Uri &u) const
QString scheme() const
static bool isCompleteUri(QString s)
Return true if the given string contains a complete URI, i.e.
QString toString() const
Definition Uri.h:119
static int metaTypeId()
Uri(const QString &s)
Construct a URI from the given string, which is expected to contain the text of a complete well-forme...
Definition Uri.h:104
Uri()
Construct an empty (invalid, null) URI.
Definition Uri.h:82
static bool hasUriType(const QVariant &)
Return true if the given variant has metatype metatypeId().
static Uri rdfTypeUri()
Return the rdf:type URI.
bool operator<(const Uri &u) const
Definition Uri.h:127
QUrl toUrl() const
Definition Uri.h:120
int length() const
Definition Uri.h:121
bool operator!=(const Uri &u) const
Definition Uri.h:126
Uri(const QUrl &u)
Construct a URI from the given QUrl, which is expected to contain a complete well-formed URI.
Definition Uri.h:113
static QString metaTypeName()
bool operator>(const Uri &u) const
Definition Uri.h:128
QDataStream & operator<<(QDataStream &out, const Node &)
QDataStream & operator>>(QDataStream &in, Node &)
QList< Uri > UriList
Definition Uri.h:155