Dataquay 0.8
PropertyObject.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_PROPERTY_OBJECT_H
35#define DATAQUAY_PROPERTY_OBJECT_H
36
37#include <QString>
38#include <QStringList>
39#include <QHash>
40#include <QVariant>
41#include <QVariantList>
42
43#include "Node.h"
44
45namespace Dataquay
46{
47
48class Transaction;
49class Store;
50
97{
98public:
105
112 PropertyObject(Store *s, QString myUri);
113
122
128 PropertyObject(Store *s, QString propertyPrefix, Uri myUri);
129
135 PropertyObject(Store *s, QString propertyPrefix, QString myUri);
136
143 PropertyObject(Store *s, QString propertyPrefix, Node myNode);
144
146
151 Node getNode() const;
152
158
165
172 bool hasProperty(QString name) const;
173
180 bool hasProperty(Transaction *tx, QString name) const;
181
190 QVariant getProperty(QString name) const;
191
201 QVariant getProperty(Transaction *tx, QString name) const;
202
214 QVariantList getPropertyList(QString name) const;
215
228 QVariantList getPropertyList(Transaction *tx, QString name) const;
229
237 Node getPropertyNode(QString name) const;
238
247 Node getPropertyNode(Transaction *tx, QString name) const;
248
259 Nodes getPropertyNodeList(QString name) const;
260
274 Nodes getPropertyNodeList(Transaction *tx, QString name) const;
275
283 QStringList getPropertyNames() const;
284
293 QStringList getPropertyNames(Transaction *tx) const;
294
303 void setProperty(QString name, QVariant value);
304
311 void setProperty(QString name, Uri uri);
312
319 void setProperty(QString name, Node node);
320
329 void setProperty(Transaction *tx, QString name, QVariant value);
330
338 void setProperty(Transaction *tx, QString name, Uri uri);
339
347 void setProperty(Transaction *tx, QString name, Node node);
348
357 void setPropertyList(QString name, QVariantList values);
358
368 void setPropertyList(Transaction *tx, QString name, QVariantList values);
369
377 void setPropertyList(QString name, Nodes nodes);
378
386 void setPropertyList(Transaction *tx, QString name, Nodes nodes);
387
393 void removeProperty(QString name);
394
400 void removeProperty(Transaction *tx, QString name);
401
410
417 Uri getPropertyUri(QString name) const;
418
424 static void setDefaultPropertyPrefix(QString prefix);
425
426private:
427 Store *m_store;
428 QString m_pfx;
429 Uri m_upfx;
430 Node m_node;
431 static QString m_defaultPrefix;
432};
433
451{
452public:
454 CacheingPropertyObject(Store *s, QString myUri);
455 CacheingPropertyObject(Store *s, QString propertyPrefix, Uri myUri);
456 CacheingPropertyObject(Store *s, QString propertyPrefix, QString myUri);
457 CacheingPropertyObject(Store *s, QString propertyPrefix, Node myUri);
458
460
461 bool hasProperty(QString name) const;
462
463 QVariant getProperty(QString name) const;
464 QVariantList getPropertyList(QString name) const;
465 Node getPropertyNode(QString name) const;
466 Nodes getPropertyNodeList(QString name) const;
467 QStringList getPropertyNames() const;
468
469 void setProperty(QString name, QVariant value);
470 void setProperty(QString name, Uri value);
471 void setProperty(QString name, Node node);
472 void setPropertyList(QString name, QVariantList values);
473 void setPropertyList(QString name, Nodes nodes);
474
475 void removeProperty(QString name);
476
477 Uri getPropertyUri(QString name) const;
478
479private:
480 PropertyObject m_po;
481 typedef QHash<Uri, Nodes> Properties;
482 mutable Properties m_cache; // note: value is never empty
483 mutable bool m_cached;
484 void encache() const;
485};
486
487}
488
489#endif
CacheingPropertyObject is a helper class for managing RDF properties of an object URI – that is,...
Nodes getPropertyNodeList(QString name) const
void setPropertyList(QString name, Nodes nodes)
CacheingPropertyObject(Store *s, QString myUri)
CacheingPropertyObject(Store *s, QString propertyPrefix, Uri myUri)
QVariantList getPropertyList(QString name) const
Node getPropertyNode(QString name) const
void setProperty(QString name, QVariant value)
void setProperty(QString name, Uri value)
bool hasProperty(QString name) const
QStringList getPropertyNames() const
CacheingPropertyObject(Store *s, Uri myUri)
void setProperty(QString name, Node node)
void setPropertyList(QString name, QVariantList values)
void removeProperty(QString name)
CacheingPropertyObject(Store *s, QString propertyPrefix, QString myUri)
QVariant getProperty(QString name) const
Uri getPropertyUri(QString name) const
CacheingPropertyObject(Store *s, QString propertyPrefix, Node myUri)
Node represents a single RDF node, with conversions to and from variant types.
Definition Node.h:65
PropertyObject is a helper class for managing RDF properties of an object URI – that is,...
QVariantList getPropertyList(QString name) const
Get the value of the given property as a list.
Node getNode() const
Return the node passed to the constructor (or derived from the URI passed to the constructor).
bool hasProperty(Transaction *tx, QString name) const
Return true if the property object has the given property, querying through the given transaction.
Store * getStore(Transaction *tx) const
Return the Store object that will be used for modifications in the given transaction.
PropertyObject(Store *s, Node myNode)
Construct a PropertyObject acting on the given Store, with the default prefix for properties taken fr...
void setProperty(QString name, Uri uri)
Set the given property to the given URI.
Node getPropertyNode(QString name) const
Get the node for the given property.
PropertyObject(Store *s, QString myUri)
Construct a PropertyObject acting on the given Store, with the default prefix for properties taken fr...
Uri getObjectType() const
Return the rdf:type of my URI, if any.
Nodes getPropertyNodeList(QString name) const
Get the nodes for the given property.
void setProperty(Transaction *tx, QString name, QVariant value)
Set the given property to the given value through the given transaction.
PropertyObject(Store *s, QString propertyPrefix, QString myUri)
Construct a PropertyObject acting on the given Store, with the given default prefix for properties an...
void setProperty(Transaction *tx, QString name, Uri uri)
Set the given property to the given URI through the given transaction.
void setPropertyList(Transaction *tx, QString name, QVariantList values)
Set the given property to the given values through the given transaction.
void setProperty(Transaction *tx, QString name, Node node)
Set the given property to the given node through the given transaction.
Uri getObjectType(Transaction *tx) const
Return the rdf:type of my URI, if any, querying through the given transaction.
void setPropertyList(Transaction *tx, QString name, Nodes nodes)
Set the given property to the given nodes through the given transaction.
void setPropertyList(QString name, Nodes nodes)
Set the given property to the given nodes.
PropertyObject(Store *s, Uri myUri)
Construct a PropertyObject acting on the given Store, with the default prefix for properties taken fr...
void setProperty(QString name, QVariant value)
Set the given property to the given value.
void removeProperty(QString name)
Remove the given property.
QStringList getPropertyNames() const
Get the names of this object's properties beginning with our property prefix.
QVariantList getPropertyList(Transaction *tx, QString name) const
Get the value of the given property as a list, querying through the given transaction.
PropertyObject(Store *s, QString propertyPrefix, Node myNode)
Construct a PropertyObject acting on the given Store, with the given default prefix for properties an...
void setProperty(QString name, Node node)
Set the given property to the given node.
PropertyObject(Store *s, QString propertyPrefix, Uri myUri)
Construct a PropertyObject acting on the given Store, with the given default prefix (which will itsel...
Nodes getPropertyNodeList(Transaction *tx, QString name) const
Get the nodes for the given property, querying through the given transaction.
QStringList getPropertyNames(Transaction *tx) const
Get the names of this object's properties beginning with our property prefix, querying through the gi...
QVariant getProperty(QString name) const
Get the value of the given property.
bool hasProperty(QString name) const
Return true if the property object has the given property.
void removeProperty(Transaction *tx, QString name)
Remove the given property.
void setPropertyList(QString name, QVariantList values)
Set the given property to the given values.
QVariant getProperty(Transaction *tx, QString name) const
Get the value of the given property, querying through the given transaction.
static void setDefaultPropertyPrefix(QString prefix)
Set the global default property prefix.
Uri getPropertyUri(QString name) const
Return the URI used for the "predicate" part of any triple referring to the given property name.
Node getPropertyNode(Transaction *tx, QString name) const
Get the node for the given property, querying through the given transaction.
Store is an abstract interface for Dataquay RDF data stores.
Definition Store.h:72
Transaction is an abstract interface for classes that read and write an RDF Store within the context ...
Definition Transaction.h:53
Uri represents a single URI.
Definition Uri.h:77
QList< Node > Nodes
A list of node types.
Definition Node.h:246