Dataquay 0.8
Triple.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_TRIPLE_H
35#define DATAQUAY_TRIPLE_H
36
37#include "Node.h"
38
39namespace Dataquay
40{
41
47class Triple
48{
49public:
53 Triple() { }
54
66 Triple(Node _a, Node _b, Node _c) :
67 a(_a), b(_b), c(_c) { }
68
69 ~Triple() { }
70
75 Node subject() { return a; }
76
81 Node predicate() { return b; }
82
87 Node object() { return c; }
88
89 bool operator<(const Triple &t) const {
90 if (a != t.a) return a < t.a;
91 if (b != t.b) return b < t.b;
92 if (c != t.c) return c < t.c;
93 return false;
94 }
95
99};
100
101bool operator==(const Triple &a, const Triple &b);
102bool operator!=(const Triple &a, const Triple &b);
103
104QDataStream &operator<<(QDataStream &out, const Triple &);
105QDataStream &operator>>(QDataStream &in, Triple &);
106
107std::ostream &operator<<(std::ostream &out, const Triple &);
108QTextStream &operator<<(QTextStream &out, const Triple &);
109
111class Triples : public QList<Triple> {
112public:
121 bool matches(const Triples &other) const {
122 if (this == &other) return true;
123 if (size() != other.size()) return false;
124 if (size() < 2) return QList<Triple>::operator==(other);
125 // Triple has operator< but not qHash, hence use QMap rather than QSet
126 QMap<Triple, int> a, b;
127 foreach (Triple t, *this) ++a[t];
128 foreach (Triple t, other) ++b[t];
129 return a == b;
130 }
131
133 Nodes result;
134 foreach (Triple t, *this) result.push_back(t.a);
135 return result;
136 }
138 Nodes result;
139 foreach (Triple t, *this) result.push_back(t.b);
140 return result;
141 }
143 Nodes result;
144 foreach (Triple t, *this) result.push_back(t.c);
145 return result;
146 }
147};
148
149}
150
151#endif
Node represents a single RDF node, with conversions to and from variant types.
Definition Node.h:65
Triple represents an RDF statement made up of three Node objects.
Definition Triple.h:48
Triple()
Construct a triple of three Nothing nodes.
Definition Triple.h:53
Node predicate()
Return the predicate node.
Definition Triple.h:81
Node subject()
Return the subject node.
Definition Triple.h:75
bool operator<(const Triple &t) const
Definition Triple.h:89
Node object()
Return the object node.
Definition Triple.h:87
Triple(Node _a, Node _b, Node _c)
Construct a triple of the three given nodes.
Definition Triple.h:66
A list of RDF triples.
Definition Triple.h:111
Nodes predicates()
Definition Triple.h:137
Nodes objects()
Definition Triple.h:142
bool matches(const Triples &other) const
Return true if the two Triples lists contain the same elements.
Definition Triple.h:121
Nodes subjects()
Definition Triple.h:132
bool operator!=(const Node &a, const Node &b)
QList< Node > Nodes
A list of node types.
Definition Node.h:246
QDataStream & operator<<(QDataStream &out, const Node &)
bool operator==(const Node &a, const Node &b)
QDataStream & operator>>(QDataStream &in, Node &)