Dataquay::Node Class Reference

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

#include <dataquay/Node.h>

List of all members.

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 (Type t, QString v)
 Construct a node with the given node type and value, and with no defined datatype.
 Node (Type t, QString v, Uri dt)
 Construct a node with the given node type, 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 62 of file Node.h.


Member Enumeration Documentation

Node type.

Enumerator:
Nothing 
URI 
Literal 
Blank 

Definition at line 68 of file Node.h.


Constructor & Destructor Documentation

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 74 of file Node.h.

Referenced by fromVariant().

Dataquay::Node::Node ( Uri  u  )  [inline]

Construct a node with a URI node type and the given URI.

Note that URIs using namespace prefixes will need to be expanded before they can safely be represented in a Uri. 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.

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

Dataquay::Node::Node ( Type  t,
QString  v 
) [inline]

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

Definition at line 95 of file Node.h.

Dataquay::Node::Node ( Type  t,
QString  v,
Uri  dt 
) [inline]

Construct a node with the given node type, value, and datatype.

Definition at line 100 of file Node.h.

Dataquay::Node::Node ( const Node n  )  [inline]

Definition at line 102 of file Node.h.

Dataquay::Node::~Node (  )  [inline]

Definition at line 111 of file Node.h.


Member Function Documentation

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

Definition at line 106 of file Node.h.

References datatype, type, and value.

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.

Definition at line 262 of file Node.cpp.

References datatype, DEBUG, Dataquay::encodedVariantTypeURI, Dataquay::Node::VariantEncoder::fromVariant(), Dataquay::Uri::isUri(), Literal, Node(), type, URI, and value.

Referenced by Dataquay::PropertyObject::setProperty(), and Dataquay::PropertyObject::setPropertyList().

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

Definition at line 310 of file Node.cpp.

References Blank, datatype, Dataquay::encodedVariantTypeURI, Nothing, Dataquay::Node::VariantEncoder::toVariant(), type, URI, and value.

Referenced by Dataquay::PropertyObject::getProperty(), and Dataquay::CacheingPropertyObject::getPropertyList().

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.

Definition at line 360 of file Node.cpp.

References Dataquay::Node::VariantEncoder::toVariant(), and value.

bool Dataquay::Node::operator< ( const Node n  )  const [inline]

Definition at line 169 of file Node.h.

References datatype, type, and value.

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.

Definition at line 228 of file Node.cpp.

References type.

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.

Definition at line 243 of file Node.cpp.

References type.

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.

Definition at line 254 of file Node.cpp.


Member Data Documentation

Definition at line 240 of file Node.h.

Referenced by fromVariant(), operator<(), operator=(), qHash(), and toVariant().


The documentation for this class was generated from the following files:
Generated on Thu May 17 22:54:21 2012 for Dataquay by  doxygen 1.6.3