zorba::Item

#include <zorba/item.h>

The Zorba Item interface. This class is the Zorba representation of an Item as defined in the XQuery 1.0 and XPath 2.0 Data Model (XDM); see http://www.w3.org/TR/xpath-datamodel/.Instances of the XDM are a sequence, i.e. an ordered collection of zero or more items. In the Zorba API, a sequence is represented by the ItemSequence class.The Item class is the union of all XQuery node and atomic types. The class provides functions to access the information of an Item. Note that not all functions are defined on every Item kind. If a function is called on an Item that does not provide the called function, an ZXQP0024_FUNCTION_NOT_IMPLEMENTED_FOR_ITEMTYPE error is raised.Instances of the Item class are always passed by copy. To check whether a given Item is valid isNull() can be called which returns true if the given Item is not valid and false otherwise. A new atomic Item can be created using the ItemFactory. A new node Item should be created by the result of a query.

Friend Classes

friend class

Unmarshaller

friend void

zorba::serialization::operator&(zorba::serialization::Archiver &ar, Item &obj)

Private Attributes

store::Item *

m_item

Public Functions

void

close()

Free all resources aquired by this Item.

uint64_t

getArraySize() const

Get the size of a JSON Array.

Item

getArrayValue(uint32_t aIndex) const

Returns the item in the JSON array at the specified index.

Iterator_t

getAtomizationValue() const

Get the atomization value of the Item.

Iterator_t

getAttributes() const

Get an iterator for the attributes of this (node) Item.

const char *

getBase64BinaryValue(size_t &s) const

Returns the value and size of the given base64Binary item.

bool

getBooleanValue() const

Get the bool value of the boolean Item.

Iterator_t

getChildren() const

Get an iterator for the children of this (node) Item.

Item

getCollectionName() const

Returns the name of the collection this node is stored in.

double

getDoubleValue() const

Get the int value of the Item.

Item

getEBV() const

Get the effective boolean value of the Item.

const char *

getHexBinaryValue(size_t &s) const

Returns the value and size of the given hexBinary item.

int32_t

getIntValue() const

Get the int value of the Item.

store::StoreConsts::JSONItemKind

getJSONItemKind() const

Get the kind of this (JSON) Item.

String

getLocalName() const

Get the value of a QName's local name.

int64_t

getLongValue() const

Get the long value of the Item.

String

getNamespace() const

Get the (optional) value of a QName's namespace.

void

getNamespaceBindings(NsBindings &aBindings, store::StoreConsts::NsScoping scope=store::StoreConsts::ALL_BINDINGS) const

Get an iterator for the namespace bindings of this (element) Item.

int

getNodeKind() const

Get the type of this (node) Item.

bool

getNodeName(Item &aNodeName) const

Get the name of this (node) Item.

Iterator_t

getObjectKeys() const

Get the keys of a JSON Object.

Item

getObjectValue(String aName) const

Returns the value with the given name from a JSON Object.

Item

getParent() const

Get parent of this (node) Item.

String

getPrefix() const

Get the (optional) value of a QName's prefix.

std::istream &

getStream()

Gets an istream for the item's content.

String

getStringValue() const

Get the string value of the Item.

Item

getType() const

Get the type of the Item.

store::SchemaTypeCode

getTypeCode() const

uint32_t

getUnsignedIntValue() const

Get the unsigned int value of the Item.

bool

isAtomic() const

Check if the Item is an atomic Item.

bool

isEncoded() const

Returns true if the contents of a binary item is already encoded.

bool

isJSONItem() const

Check if the Item is a JSON Item, that is, part of the JSONiq data model.

bool

isNaN() const

Check if the value of the Item is not a number (NaN).

bool

isNode() const

Check if the Item is a node Item.

bool

isNull() const

Check if the Item is null.

bool

isPosOrNegInf() const

Check if the value of the Item is positive or negative infinity.

bool

isSeekable() const

Checks whether the item's streamable content is arbitrarily (forward anb backward) seekable.

bool

isStreamable() const

Checks whether the item's content is streamable.

Item()

Default constructor.

Item(const Item &other)

Copy constructor.

Item(const store::Item *item)

Constructor that is used to construct Items in the Zorba engine itself.

size_t

mem_size() const

Gets the total amount of memory this Item and all its child Items are using.

const Item &

operator=(const Item &rhs)

Assingment operator.

const Item &

operator=(const store::Item *rhs)

Assingment operator that is used in the Zorba engine itself.

bool

operator==(const Item &rhs)

~Item()

Destructor.

Friend Classes

Unmarshaller

friend class Unmarshaller

zorba::serialization::operator&

friend void zorba::serialization::operator&(zorba::serialization::Archiver &ar, Item &obj)

Private Attributes

m_item

store::Item * m_item

Public Functions

close

void close()

Free all resources aquired by this Item.

After calling close() on an Item the Item is invalidated, i.e. a subsequent call to isNull() will return true.Note that calling this function is usually not necessary because close() is implicitly called by the destructor. Calling close() is only necessary if the resources aquired by an Item should be released before the Item goes out of scope, i.e. the destructor is called.Also note that this function is available for all types of Items.

getArraySize

uint64_t getArraySize() const

Get the size of a JSON Array.

Note that this function is only available for JSON Arrays.

Returns

Item the size of the array.

Parameters

if an error occured (e.g. the Item is not of type JSON Array).

getArrayValue

Item getArrayValue(uint32_t aIndex) const

Returns the item in the JSON array at the specified index.

Note that this function is only available for JSON Arrays.

Parameters

aIndex the index in the array.

Returns

Item the indexed Item.

Parameters

if an error occured (e.g. the Item is not of type JSON Array).

getAtomizationValue

Iterator_t getAtomizationValue() const

Get the atomization value of the Item.

The atomization value is the value that is returned by atomization (see http://www.w3.org/TR/xquery/#id-atomization). Note that this function is available for all types of Items.

Returns

Item the atomization value of the Item.

Parameters

if an error occured.

getAttributes

Iterator_t getAttributes() const

Get an iterator for the attributes of this (node) Item.

Note that this function is only available for node Items. The file simple.cpp contains some basic examples that demonstrate the use of this function.

Returns

Iterator over the attributes of this node.

Parameters

if an error occured, e.g. the Item is not of type node.

getBase64BinaryValue

const char * getBase64BinaryValue(size_t &s) const

Returns the value and size of the given base64Binary item.

The value is a string which is base64 encoded if isEncoded() returns true. Otherwise, it is the original unencoded binary data.If the given item is streamable (i.e. isStreamable() returns true), the stream returned by getStream() should to be used to retrieve the value. Otherwise, the contents of the stream will be materialized in main memory.

getBooleanValue

bool getBooleanValue() const

Get the bool value of the boolean Item.

Note that this function is only available for Items of type boolean.

Returns

true if the boolean value is true, false otherwise.

Parameters

if an error occured, e.g. the Item is not of type boolean.

getChildren

Iterator_t getChildren() const

Get an iterator for the children of this (node) Item.

Note that this function is only available for node Items. The file simple.cpp contains some basic examples that demonstrate the use of this function.

Returns

Iterator over the children of this node.

Parameters

if an error occured, e.g. the Item is not of type node.

getCollectionName

Item getCollectionName() const

Returns the name of the collection this node is stored in.

Returns

The name of the collection or 0 if the given item is not a node or not stored in a collection.

getDoubleValue

double getDoubleValue() const

Get the int value of the Item.

Returns

Item the int value of the Item.

Parameters

if an error occured.

getEBV

Item getEBV() const

Get the effective boolean value of the Item.

The effective boolean value is the result of applying the fn:boolean function on the Item (see http://www.w3.org/TR/xpath-functions/#func-boolean). Note that this function is available for all types of Items.

Returns

Item the effective boolean value of the Item

Parameters

if an error occured.

getHexBinaryValue

const char * getHexBinaryValue(size_t &s) const

Returns the value and size of the given hexBinary item.

The value is a string which is hexBinary encoded if isEncoded() returns true. Otherwise, it is the original unencoded binary data.If the given item is streamable (i.e. isStreamable() returns true), the stream returned by getStream() should to be used to retrieve the value. Otherwise, the contents of the stream will be materialized in main memory.

getIntValue

int32_t getIntValue() const

Get the int value of the Item.

Returns

Item the int value of the Item.

Parameters

if an error occured.

getJSONItemKind

store::StoreConsts::JSONItemKind getJSONItemKind() const

Get the kind of this (JSON) Item.

Note that this function is only available for JSON Items, that is, Items which return true from isJSONItem().

Returns

the kind of this JSON item

Parameters

if an error occured (e.g. the Item is not of type JSON).

getLocalName

String getLocalName() const

Get the value of a QName's local name.

Note that this function is only available for Items of type QName.

Returns

String the local name of the QName.

Parameters

if an error occured, e.g. the Item is not a QName.

getLongValue

int64_t getLongValue() const

Get the long value of the Item.

Returns

Item the long value of the Item.

Parameters

if an error occured.

getNamespace

String getNamespace() const

Get the (optional) value of a QName's namespace.

Note that this function is only available for Items of type QName.

Returns

String the namespace URI of the QName.

Parameters

if an error occured, e.g. the Item is not a QName.

getNamespaceBindings

void getNamespaceBindings(NsBindings &aBindings, store::StoreConsts::NsScoping scope=store::StoreConsts::ALL_BINDINGS) const

Get an iterator for the namespace bindings of this (element) Item.

Note that this function is only available for element Items. The file simple.cpp contains some basic examples that demonstrate the use of this function.

Parameters

aBindings An std::vector to receive the namespace bindings of this node (each represented as a std::pair<zorba::String,zorba::String> where the first string is the namespace prefix and the second is the namespace URI).
scope A value to specify which bindings to return: all bindings (the default); only those that are specified by the namespace declaration attributes of the node (if any); or those that are implied by the qnames of the node and its attributes plus those that are specified by the namespace declaration attributes of the node (if any)

Parameters

if an error occured, e.g. the Item is not of type element.

getNodeKind

int getNodeKind() const

Get the type of this (node) Item.

Note that this function is only available for node Items.

Returns

int the kind of this node (the avaialble kinds can be found in the store::StoreConsts class)

Parameters

if an error occured (e.g. the Item is not of type node).

getNodeName

bool getNodeName(Item &aNodeName) const

Get the name of this (node) Item.

Note that this function is only available for node Items. The file simple.cpp contains some basic examples that demonstrate the use of this function.

Returns

bool if the name of the node was retrieved successfully aNodeName the name of the node

Parameters

if an error occured (e.g. the Item is not of type node).

getObjectKeys

Iterator_t getObjectKeys() const

Get the keys of a JSON Object.

Note that this function is only available for JSON Objects.

Returns

Iterator_t an iterator on the keys of the object.

Parameters

if an error occured (e.g. the Item is not of type JSON Object).

getObjectValue

Item getObjectValue(String aName) const

Returns the value with the given name from a JSON Object.

Note that this function is only available for JSON Objects.

Parameters

aName the name of the value in the Object to return.

Returns

Item the named value from the Object.

Parameters

if an error occured (e.g. the Item is not of type JSON Object).

getParent

Item getParent() const

Get parent of this (node) Item.

Note that this function is only available for node Items.

Returns

element or document parent node of this node.

Parameters

if an error occured, e.g. the Item is not of type node.

getPrefix

String getPrefix() const

Get the (optional) value of a QName's prefix.

Note that this function is only available for Items of type QName.

Returns

String the prefix of the QName.

Parameters

if an error occured, e.g. the Item is not a QName.

getStream

std::istream & getStream()

Gets an istream for the item's content.

Returns

the stream.

Parameters

if the item is not streamable.

getStringValue

String getStringValue() const

Get the string value of the Item.

The string value is the string that is extracted by calling the fn:string function on the Item (see http://www.w3.org/TR/xpath-functions/#func-string). Note that this function is available for all types of Items.

Returns

Item the string value of the Item.

Parameters

if an error occured.

getType

Item getType() const

Get the type of the Item.

See http://www.w3.org/TR/xpath-datamodel/#types. Note that this function is available for all types of Items.

Returns

Item the type of the Item as a QName Item

Parameters

if an error occured.

getTypeCode

store::SchemaTypeCode getTypeCode() const

Returns

the type of this item based on the enum values in store_const.h

getUnsignedIntValue

uint32_t getUnsignedIntValue() const

Get the unsigned int value of the Item.

Returns

Item the unsigned int value of the Item.

Parameters

if an error occured.

isAtomic

bool isAtomic() const

Check if the Item is an atomic Item.

Note that this function is available for all types of Items.

Returns

true if the Item is an atomic Item, false otherwise.

isEncoded

bool isEncoded() const

Returns true if the contents of a binary item is already encoded.

Returns

true if the content is already encoded, false otherwise

isJSONItem

bool isJSONItem() const

Check if the Item is a JSON Item, that is, part of the JSONiq data model.

Note that this function is available for all types of Items.

Returns

true if the Item is a JSON Item, false otherwise.

isNaN

bool isNaN() const

Check if the value of the Item is not a number (NaN).

Note that this function is only available for numeric Items (e.g. Double or Float).

Returns

true if the Item is NaN, false otherwise.

Parameters

if an error occured, e.g. the Item is not a numeric type.

isNode

bool isNode() const

Check if the Item is a node Item.

Note that this function is available for all types of Items.

Returns

true if the Item is of type node, false otherwise.

isNull

bool isNull() const

Check if the Item is null.

If this function returns true, the Item is not valid. Note that this function is available for all types of Items.

Returns

true if the Item is null, false otherwise.

isPosOrNegInf

bool isPosOrNegInf() const

Check if the value of the Item is positive or negative infinity.

Note that this function is only available for numeric Items (e.g. Double or Float).

Returns

true if the Item is +/-INF, false otherwise.

Parameters

if an error occured, e.g. the Item is not a numeric type.

isSeekable

bool isSeekable() const

Checks whether the item's streamable content is arbitrarily (forward anb backward) seekable.

Returns

true only if it is.

isStreamable

bool isStreamable() const

Checks whether the item's content is streamable.

Returns

true only if it is.

Item

 Item()

Default constructor.

Item

 Item(const Item &other)

Copy constructor.

Item

 Item(const store::Item *item)

Constructor that is used to construct Items in the Zorba engine itself.

This constructor is for internal use only.

mem_size

size_t mem_size() const

Gets the total amount of memory this Item and all its child Items are using.

Returns

said total amount of memory.

operator=

const Item & operator=(const Item &rhs)

Assingment operator.

operator=

const Item & operator=(const store::Item *rhs)

Assingment operator that is used in the Zorba engine itself.

This operator is for internal use only.

operator==

bool operator==(const Item &rhs)

~Item

 ~Item()

Destructor.