Dataquay 0.8
|
Node represents a single RDF node, with conversions to and from variant types. More...
#include <dataquay/Node.h>
Classes | |
struct | VariantEncoder |
VariantEncoder is an abstract interface for classes that can convert between QVariant and strings for storage in literal Node objects. More... | |
Public Types | |
enum | Type { Nothing , URI , Literal , Blank } |
Node type. More... | |
Public Member Functions | |
Node () | |
Construct a node with no node type (used for example as an undefined node when pattern matching a triple). | |
Node (Uri u) | |
Construct a node with a URI node type and the given URI. | |
Node (QString v) | |
Construct a literal node with the given value, and with no defined datatype. | |
Node (QString v, Uri dt) | |
Construct a literal node with the given value and datatype. | |
Node (const Node &n) | |
Node & | operator= (const Node &n) |
~Node () | |
QVariant | toVariant () const |
Convert a Node to a QVariant. | |
QVariant | toVariant (int metaTypeId) const |
Convert a Node to a QVariant, with a nudge for the variant type, used to override the default variant type corresponding to the node's datatype. | |
bool | operator< (const Node &n) const |
Static Public Member Functions | |
static Node | fromVariant (const QVariant &v) |
Convert a QVariant to a Node. | |
static void | registerDatatype (Uri datatype, QString variantTypeName, VariantEncoder *encoder=0) |
Register an association between a particular datatype URI and a type which can be stored in a QVariant. | |
static Uri | getDatatype (QString variantTypeName) |
Retrieve the datatype URI that has been associated with the given variant type using registerDatatype. | |
static QString | getVariantTypeName (Uri datatype) |
Retrieve the variant type that has been associated with the given datatype Uri using registerDatatype. | |
Public Attributes | |
Type | type |
QString | value |
Uri | datatype |
Node represents a single RDF node, with conversions to and from variant types.
enum Dataquay::Node::Type |
|
inline |
|
inline |
Construct a node with a URI node type and the given URI.
Note that relative URIs (using namespace prefixes) must be expanded before they be represented in a Uri. Call Store::expand() to achieve this.
(One basic principle of this RDF library is that we use QString to represent URIs that may be local or namespace prefixed, and Uri to represent expanded or canonical URIs.)
|
inline |
|
inline |
|
static |
Convert a QVariant to a Node.
Simple QVariant types (integer, etc) are converted to literal Nodes whose values are encoded as XSD datatypes, with the node's value storing the XSD representation and the node's datatype storing the XSD datatype URI.
QVariants containing Uri are converted to URI nodes. Note that URIs using namespace prefixes will need to be expanded before they can safely be represented in a Uri or Uri QVariant. Call Store::expand() to achieve this. In general you should ensure that URIs are expanded when placed in a Node object rather than being stored in prefixed form.
For QVariants whose types have been registered using registerDatatype, the registered VariantEncoder's fromVariant method will be used to convert the variant to a string which will be stored in a literal node.
Other QVariants, including complex structures, are converted into literals containing an encoded representation which may be converted back again using toVariant but cannot be directly read from or interchanged using the node's value. These types are given a specific fixed datatype URI.
QVariant Dataquay::Node::toVariant | ( | ) | const |
Convert a Node to a QVariant.
See fromVariant for details of the conversion.
Note that URI nodes are returned as variants with user type corresponding to Uri, not as QString variants. This may result in invalid Uris if the URIs were not properly expanded on construction (see the notes about fromVariant).
QVariant Dataquay::Node::toVariant | ( | int | metaTypeId | ) | const |
Convert a Node to a QVariant, with a nudge for the variant type, used to override the default variant type corresponding to the node's datatype.
This is marginally simpler than setting the datatype on the node and then converting, and so may be convenient in situations where the proper RDF datatype is missing.
Meaningful results still depend on having the proper encoder available (i.e. the type name whose QMetaType id is metaTypeId must have been registered using registerDatatype, if it is not one of the types with built-in support). If no encoder is found, a QString variant will be returned instead.
|
inline |
|
static |
Register an association between a particular datatype URI and a type which can be stored in a QVariant.
This can be used to provide meaningful conversions between literal nodes and QVariant objects in addition to the built-in types.
For conversions from variant, once an association has been made via this call, a subsequent call to Node::fromVariant given a variant whose type is that of the given variantTypeName will return a Node of the specified datatype. If an encoder is also given, it will be used for the QVariant-to-string conversion needed to produce a value string in the correct form for the RDF datatype.
For conversions to variant, the encoder is required. If it is provided, then a subsequent call to Node::toVariant on a node of the given datatype will result in a variant of the specified type, produced by calling the encoder's toVariant method with the node's value string as argument.
|
static |
Retrieve the datatype URI that has been associated with the given variant type using registerDatatype.
If no such association has been made or the variant type is unknown, return the empty Uri.
|
static |
Retrieve the variant type that has been associated with the given datatype Uri using registerDatatype.
If no such association has been made, return an empty string.
Type Dataquay::Node::type |
Definition at line 238 of file Node.h.
Referenced by operator<(), and operator=().
QString Dataquay::Node::value |
Definition at line 239 of file Node.h.
Referenced by operator<(), and operator=().
Uri Dataquay::Node::datatype |
Definition at line 240 of file Node.h.
Referenced by operator<(), and operator=().