Struct Node

Inheritance Relationships

Derived Types

Struct Documentation

struct Node

Models a node in RDF Datasets, RDF Graphss or pattern matching tuples like QuadPatterns or TriplePatterns.

Please note: The edges of an RDF Graph, dubbed Predicates, are IRIs. As such the same resource can also be used as a node. For the sake of simplicity, we decided to have no separate class for edges in an RDF graph. You can determine if a Node is an edge by the the fact that it is used as predicate in a Dataset, Graph, Quad, Statement, QuadPattern or TriplePattern.

Warning

This type is a POD.

Subclassed by rdf4cpp::BlankNode, rdf4cpp::IRI, rdf4cpp::Literal, rdf4cpp::query::Variable

Public Functions

explicit Node(storage::identifier::NodeBackendHandle id) noexcept
Node to_node_storage(storage::DynNodeStoragePtr node_storage) const

Registers this node in the given node storage (if it does not already exist)

Parameters:

node_storage – node storage to register this node in

Returns:

this node but in node storage

Node try_get_in_node_storage(storage::DynNodeStoragePtr node_storage) const noexcept

Tries to retrieve this nodes equivalent node in the given node storage

Parameters:

node_storage – node storage to try to retrieve the node from

Returns:

this node but in node storage, or the null node if it does not exist in node_storage

Node() noexcept = default

Default construction produces null() const Node. This node models an unset or invalid Node. null() const Nodes should only be used as temporary placeholders. They cannot be inserted into a Graph or Dataset.

Warning

This type is POD. The constructor needs to be invoked explicitly. Alternatively: call Node::make_null()

bool serialize(writer::BufWriterParts writer, NodeSerializationOpts opts = NodeSerializationOpts::long_form()) const noexcept

Serialize the string representation of the given node in N-format as defined by N-Triples and N-Quads.

For specific usage examples have a look at tests/bench_SerDe.cppserialize.

Parameters:
Returns:

true if serialization was successful, false if a call to flush was not able to make room

explicit operator std::string() const noexcept

Returns a string representation of the given node in N-format as defined by N-Triples and N-Quads.

Returns:

string representation in N-format

TriBool is_literal() const noexcept

Checks whether the node is a Literal

Returns:

err if this is null, otherwise true iff this is a literal

TriBool is_variable() const noexcept

Checks whether the node is a variable

Returns:

err if this is null, otherwise true iff this is a variable

TriBool is_blank_node() const noexcept

Checks whether the node is a blank node

Returns:

err if this is null, otherwise true iff this is a blank node

TriBool is_iri() const noexcept

Checks whether the node is a iri

Returns:

err if this is null, otherwise true iff this is a iri

bool is_inlined() const noexcept
Returns:

if the current value of this node is stored inside the handle instead of the node storage

std::strong_ordering order(Node const &other) const noexcept

Due to the split definition of ==/!= and </<=/>/>= in SPARQL we cannot provide a “compare” function for FILTER semantics. Specifically, in SPARQL IRIs,BlankNodes and Variables are comparable via == and !=, but not via <,<=,>,>=.

https://www.w3.org/TR/sparql11-query/#OperatorMapping The comparison function for SPARQL orderings (ORDER BY).

For FILTER semantics, use eq,ne,lt,le,gt,ge.

The difference between this and FILTER semantics, is that here BlankNode, Variable, IRI are compared based on their string representation, and thus have an ordering. For Literals you can find information about the differences in Literal::order

TriBool eq(Node const &other) const noexcept

The equality function for SPARQL filters (FILTER). Due to the split definition of ==/!= and </<=/>/>= in SPARQL we cannot provide a “compare” function for FILTER semantics.

bool order_eq(Node const &other) const noexcept
TriBool ne(Node const &other) const noexcept
bool order_ne(Node const &other) const noexcept
TriBool lt(Node const &other) const noexcept
bool order_lt(Node const &other) const noexcept
TriBool le(Node const &other) const noexcept
bool order_le(Node const &other) const noexcept
TriBool gt(Node const &other) const noexcept
bool order_gt(Node const &other) const noexcept
TriBool ge(Node const &other) const noexcept
bool order_ge(Node const &other) const noexcept
Literal as_eq(Node const &other, storage::DynNodeStoragePtr node_storage = keep_node_storage) const noexcept
Literal as_order_eq(Node const &other, storage::DynNodeStoragePtr node_storage = keep_node_storage) const noexcept
Literal as_ne(Node const &other, storage::DynNodeStoragePtr node_storage = keep_node_storage) const noexcept
Literal as_order_ne(Node const &other, storage::DynNodeStoragePtr node_storage = keep_node_storage) const noexcept
Literal as_lt(Node const &other, storage::DynNodeStoragePtr node_storage = keep_node_storage) const noexcept
Literal as_order_lt(Node const &other, storage::DynNodeStoragePtr node_storage = keep_node_storage) const noexcept
Literal as_le(Node const &other, storage::DynNodeStoragePtr node_storage = keep_node_storage) const noexcept
Literal as_order_le(Node const &other, storage::DynNodeStoragePtr node_storage = keep_node_storage) const noexcept
Literal as_gt(Node const &other, storage::DynNodeStoragePtr node_storage = keep_node_storage) const noexcept
Literal as_order_gt(Node const &other, storage::DynNodeStoragePtr node_storage = keep_node_storage) const noexcept
Literal as_ge(Node const &other, storage::DynNodeStoragePtr node_storage = keep_node_storage) const noexcept
Literal as_order_ge(Node const &other, storage::DynNodeStoragePtr node_storage = keep_node_storage) const noexcept
bool operator==(const Node &other) const noexcept

Equivalent to this->order_eq(other)

std::partial_ordering operator<=>(Node const &other) const noexcept

Equivalent to this->order(other)

TriBool ebv() const noexcept
Returns:

the effective boolean value of this

Literal as_ebv(storage::DynNodeStoragePtr node_storage = keep_node_storage) const noexcept
Returns:

the effective boolean value of this as xsd:boolean (or null literal in case of Err)

explicit operator bool() const noexcept
BlankNode as_blank_node() const noexcept

Casts this Node into a BlankNode if it is one, otherwise returns the null BlankNode.

Returns:

a copy of this as BlankNode if it is one, else null BlankNode

IRI as_iri() const noexcept

Casts this Node into a IRI if it is one, otherwise returns the null IRI.

Returns:

a copy of this as IRI if it is one, else null IRI

Literal as_literal() const noexcept

Casts this Node into a Literal if it is one, otherwise returns the null Literal.

Returns:

a copy of this as Literal if it is one, else null Literal

query::Variable as_variable() const noexcept

Casts this Node into a Variable if it is one, otherwise returns the null Variable.

Returns:

a copy of this as Variable if it is one, else null Variable

bool null() const noexcept

Check whether the Node has no value or an invalid value.

Returns:

if value is unset or invalid

storage::identifier::NodeBackendHandle const &backend_handle() const noexcept

Exposes the const NodeBackendHandle.

This function is unsafe! Make sure this is not null() const.

Returns:

its NodeBackendHandle.

storage::identifier::NodeBackendHandle &backend_handle() noexcept

Exposes the NodeBackendHandle.

This function is unsafe! Make sure this is not null() const.

Returns:

its NodeBackendHandle.

Public Static Functions

static Node make_null() noexcept

Construct the null-node

Protected Functions

inline storage::DynNodeStoragePtr select_node_storage(storage::DynNodeStoragePtr node_storage) const noexcept
TriBool eq_impl(Node const &other) const noexcept

Implementation for eq() and ne()

std::partial_ordering compare_impl(Node const &other) const noexcept

Implementation for lt(), gt(), le(), ge() Do not use for eq() or ne()

Protected Attributes

storage::identifier::NodeBackendHandle handle_

Friends

friend std::ostream &operator<<(std::ostream &os, const Node &node)

See also

operator std::string() const