Dataquay 0.8
Dataquay::Node Class Reference

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)
 
Nodeoperator= (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
 

Detailed Description

Node represents a single RDF node, with conversions to and from variant types.

Definition at line 64 of file Node.h.

Member Enumeration Documentation

◆ Type

Node type.

Enumerator
Nothing 
URI 
Literal 
Blank 

Definition at line 70 of file Node.h.

Constructor & Destructor Documentation

◆ Node() [1/5]

Dataquay::Node::Node ( )
inline

Construct a node with no node type (used for example as an undefined node when pattern matching a triple).

Definition at line 76 of file Node.h.

◆ Node() [2/5]

Dataquay::Node::Node ( Uri u)
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.)

Definition at line 89 of file Node.h.

◆ Node() [3/5]

Dataquay::Node::Node ( QString v)
inline

Construct a literal node with the given value, and with no defined datatype.

Definition at line 95 of file Node.h.

◆ Node() [4/5]

Dataquay::Node::Node ( QString v,
Uri dt )
inline

Construct a literal node with the given value and datatype.

Definition at line 100 of file Node.h.

◆ Node() [5/5]

Dataquay::Node::Node ( const Node & n)
inline

Definition at line 102 of file Node.h.

◆ ~Node()

Dataquay::Node::~Node ( )
inline

Definition at line 111 of file Node.h.

Member Function Documentation

◆ operator=()

Node & Dataquay::Node::operator= ( const Node & n)
inline

Definition at line 106 of file Node.h.

References datatype, type, and value.

◆ fromVariant()

static Node Dataquay::Node::fromVariant ( const QVariant & v)
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.

◆ toVariant() [1/2]

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).

◆ toVariant() [2/2]

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.

◆ operator<()

bool Dataquay::Node::operator< ( const Node & n) const
inline

Definition at line 169 of file Node.h.

References datatype, type, and value.

◆ registerDatatype()

static void Dataquay::Node::registerDatatype ( Uri datatype,
QString variantTypeName,
VariantEncoder * encoder = 0 )
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.

◆ getDatatype()

static Uri Dataquay::Node::getDatatype ( QString variantTypeName)
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.

◆ getVariantTypeName()

static QString Dataquay::Node::getVariantTypeName ( Uri datatype)
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.

Member Data Documentation

◆ type

Type Dataquay::Node::type

Definition at line 238 of file Node.h.

Referenced by operator<(), and operator=().

◆ value

QString Dataquay::Node::value

Definition at line 239 of file Node.h.

Referenced by operator<(), and operator=().

◆ datatype

Uri Dataquay::Node::datatype

Definition at line 240 of file Node.h.

Referenced by operator<(), and operator=().


The documentation for this class was generated from the following file: