Accelerated Computation Engine
Public Member Functions | List of all members
Ace::MetadataModel::Node Class Reference

#include <ace_metadatamodel_node.h>

Inheritance diagram for Ace::MetadataModel::Node:

Public Member Functions

 Node (EMetadata::Type type=EMetadata::Null, QObject *parent=nullptr)
 
 Node (const EMetadata &meta, QObject *parent=nullptr)
 
 Node (const Node &object)
 
bool isBytes () const
 
bool isEditable () const
 
bool isContainer () const
 
bool isArray () const
 
bool isObject () const
 
int size () const
 
MetadataModel::Nodeparent () const
 
QString key () const
 
bool setKey (const QString &newKey)
 
QString type () const
 
QByteArray bytes () const
 
EMetadata meta () const
 
QVariant value () const
 
bool setValue (const QVariant &value)
 
QList< MetadataModel::Node * >::const_iterator arrayBegin () const
 
QList< MetadataModel::Node * >::const_iterator arrayEnd () const
 
QMap< QString, MetadataModel::Node * >::const_iterator objectBegin () const
 
QMap< QString, MetadataModel::Node * >::const_iterator objectEnd () const
 
MetadataModel::Nodeget (int index) const
 
int indexOf (const Node *pointer) const
 
bool contains (const QString &key) const
 
int getFutureIndex (const QString &key) const
 
std::unique_ptr< MetadataModel::Nodecopy (int index)
 
std::unique_ptr< MetadataModel::Nodecut (int index)
 
void insertArray (int index, std::unique_ptr< Node > &&node)
 
void insertObject (const QString &key, std::unique_ptr< Node > &&node)
 
void remove (int index)
 

Detailed Description

This class represents a single metadata node within the metadata model. The reason this class must exist as a wrapper around the metadata class is because the model must work with pointers for arrays and objects while the metadata classes do not use pointers. The node can be any possible metadata class. If it is an array or object it uses its own custom qt containers that hold pointers instead of metadata arrays or objects. The nodes are also Qt Objects to allow for easy memory cleanup.

Constructor & Destructor Documentation

◆ Node() [1/3]

MetadataModel::Node::Node ( EMetadata::Type  type = EMetadata::Null,
QObject *  parent = nullptr 
)
explicit

Constructs a new node object with the given qt object as its parent, if any.

Parameters
typeThe metadata type of this new node.
parentThe parent of this new node, if any.

◆ Node() [2/3]

MetadataModel::Node::Node ( const EMetadata meta,
QObject *  parent = nullptr 
)
explicit

Constructs a new node object with the given metadata value and the given qt object as its parent, if any. If the metadata given is an array or object then the metadata values contained within are not copied. This is because nodes store their values in an entirely different manner than the metadata class.

Parameters
metaThe metadata value of this new node.
parentThe parent of this new node, if any.

◆ Node() [3/3]

MetadataModel::Node::Node ( const Node object)

Constructs a new node object as a copy of the given object.

Parameters
objectThe other node object that is copied to this one.

Member Function Documentation

◆ arrayBegin()

QList< MetadataModel::Node * >::const_iterator MetadataModel::Node::arrayBegin ( ) const

Returns first constant iterator to node pointer in this node's internal array of pointers. If this node is not an array type this list will always be empty.

Returns
First node pointer constant iterator in array.

◆ arrayEnd()

QList< MetadataModel::Node * >::const_iterator MetadataModel::Node::arrayEnd ( ) const

Returns end of list constant iterator in this node's internal array of pointers. If this node is not an array type this list will always be empty.

Returns
End of list constant iterator of array.

◆ bytes()

QByteArray MetadataModel::Node::bytes ( ) const

Returns the byte array of this node. If this node is not a bytes type then an empty byte array is returned.

Returns
Byte array of this node, if any.

◆ contains()

bool MetadataModel::Node::contains ( const QString &  key) const

Tests whether this node's internal mapping of node pointers already contains the given key. If this node is not an object type false is always returned.

Parameters
keyThe given key to be tested if it already exists within this node's mapping.
Returns
Returns true if the given key already exists, else returns false.

◆ copy()

std::unique_ptr< MetadataModel::Node > MetadataModel::Node::copy ( int  index)

Creates a copy of this node's child at the given index. If the given index does not exist or this node is not a container type then a null pointer is returned.

Parameters
indexIndex of child node that is copied.
Returns
Pointer to copy of child node or null pointer if no such child exists.

◆ cut()

std::unique_ptr< MetadataModel::Node > MetadataModel::Node::cut ( int  index)

Cuts this node's child at the given index, returning its pointer and removing it form this node's list of children. If the given index does not exist or this node is not a container type then a null pointer is returned.

Parameters
indexIndex of child node that is cut.
Returns
Pointer to child node removed or null pointer if no such child exists.

◆ get()

MetadataModel::Node * MetadataModel::Node::get ( int  index) const

Returns the node pointer contains in this node's internal container, map or array, with the given index. If this node is not a container type or the index is out of range then null is returned.

Parameters
indexThe index of the requested node pointer.
Returns
Node pointer with given index, if any.

◆ getFutureIndex()

int MetadataModel::Node::getFutureIndex ( const QString &  key) const

This will return the index a new node would be inserted into this node's internal map with the given key if this is an object type. If this node is not an object then -1 is returned.

Parameters
keyThe given key to test for indexing position within the map.
Returns
Index where the given key would be inserted.

◆ indexOf()

int MetadataModel::Node::indexOf ( const Node pointer) const

Finds what index the given node pointer exists within this node if at all. If this node is not a container or the pointer is not matched to any of its children then -1 is returned.

Parameters
pointerThe node pointer that will be matched against any children this node contains.
Returns
Index where match to node pointer is found or -1 if no match is found.

◆ insertArray()

void MetadataModel::Node::insertArray ( int  index,
std::unique_ptr< Node > &&  node 
)

Inserts a new node with the given pointer into this node's internal array at the given index if this node is an array type. If this node is not an array type this does nothing but free then given node pointer. If the index is less than 0 the new node is prepended to the array. If the index is greater than or equal to its size it is appended to the array.

Parameters
indexIndex where the new node is inserted.
nodePointer to the new node that is inserted.

◆ insertObject()

void MetadataModel::Node::insertObject ( const QString &  key,
std::unique_ptr< Node > &&  node 
)

Inserts a new node with the given pointer into this node's internal mapping with the given key. If the key already exists the node pointer is overwritten with the new node pointer, freeing the old node's memory. If this node is not an object type this does nothing but free the given node pointer.

Parameters
keyThe key where the new node that is inserted to in the map.
nodeThe pointer to the new node that is inserted into the map.

◆ isArray()

bool MetadataModel::Node::isArray ( ) const

Tests if this node is an array.

Returns
Returns true of this is an array, else returns false.

◆ isBytes()

bool MetadataModel::Node::isBytes ( ) const

Tests if this node is a bytes type.

Returns
Returns true of this node is a bytes type else returns false.

◆ isContainer()

bool MetadataModel::Node::isContainer ( ) const

Tests if this node is either an array or an object.

Returns
Returns true if this is an array or object, else returns false.

◆ isEditable()

bool MetadataModel::Node::isEditable ( ) const

Tests if this node's metadata is editable as a string.

Returns
Returns true if this node is editable else returns false.

◆ isObject()

bool MetadataModel::Node::isObject ( ) const

Tests of this node is an object.

Returns
Returns true of this is an object, else returns false.

◆ key()

QString MetadataModel::Node::key ( ) const

Returns the key or name for this node in relation to its parent. If its parent is an array the index is returned as a string.

Returns
The key or index number of this node.

◆ meta()

EMetadata MetadataModel::Node::meta ( ) const

This returns the metadata value for this node.

Returns
This node's metadata value.

◆ objectBegin()

QMap< QString, MetadataModel::Node * >::const_iterator MetadataModel::Node::objectBegin ( ) const

Returns first constant iterator to node pointer in this node's internal map of pointers. If this node is not an object type this list will always be empty.

Returns
First node pointer constant iterator in map.

◆ objectEnd()

QMap< QString, MetadataModel::Node * >::const_iterator MetadataModel::Node::objectEnd ( ) const

Returns end of list constant iterator in this node's internal mapping of pointers. If this node is not an object type this list will always be empty.

Returns
End of list constant iterator of map.

◆ parent()

MetadataModel::Node * MetadataModel::Node::parent ( ) const

Returns this node's parent. If this is the root node then null is returned.

Returns
Pointer to this node's parent unless this node is root.

◆ remove()

void MetadataModel::Node::remove ( int  index)

Removes and deletes this node's child with the given index. This will work if the node is an array or an object type. If this node is not a container type or the index is out of range this does nothing.

Parameters
indexIndex of the child node to be removed and deleted.

◆ setKey()

bool MetadataModel::Node::setKey ( const QString &  newKey)

This sets the key of this node to a new value. If this node's parent is not an object type or the key already exists then false is returned.

Parameters
newKeyThe new key for this node.
Returns
Returns true on success or false on failure.

◆ setValue()

bool MetadataModel::Node::setValue ( const QVariant &  value)

Sets the metadata value of this node if it is not a container type. If it is a container or null type then this will do nothing and return immediately.

Parameters
valueNew value this node's metadata will be set to if it is not a container type.
Returns
Returns true if value was successfully set else returns false if no value was set.

◆ size()

int MetadataModel::Node::size ( ) const

Returns the number of children this node contains. This works for any metadata type. If this node is not a container type then 0 is always returned.

Returns
Number of children, if any, this node contains.

◆ type()

QString MetadataModel::Node::type ( ) const

Returns the metadata type for this node as a string.

Returns
Metadata type of this node.

◆ value()

QVariant MetadataModel::Node::value ( ) const

Returns the metadata value of this node if it is not a container or bytes type. If this node is a container type then a string reporting the number of nodes it holds is returned. If this node is a bytes type then a string informing the user this is an image is returned.

Returns
Value of this node's metadata, or information about what it contains, or a plain string stating it is a bytes(image) type.

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