commonlib
Node Class Referenceabstract

Node is an abstract class that represents a node in an xml tree and defines functions for writing and reading values/std containers from a node and for building an xml node tree. More...

#include <node.h>

Inheritance diagram for Node:
SerializableNode LibXmlNode

Public Member Functions

virtual void destroy ()=0
 destroy function releases internal node and sets it value to nullptr.
 
template<typename T >
void addAttribute (const std::string &name, const T &value)
 addAttribute function adds an attribute with a given name and given value to a node. More...
 
template<typename T >
void write (const std::string &name, const T &value)
 write function creates a new child with a given name and adds a given value to it. More...
 
template<typename T , typename U >
void write (const std::string &name, const T &value, const U &defaultValue)
 write function creates a new child with a given name and adds a given value to it. More...
 
template<typename T >
void read (const std::string &name, T &value)
 read function reads a value from a nodes child with a given name. More...
 
template<typename T , typename U >
void read (const std::string &name, T &value, const U &defaultValue)
 read function reads a value from a nodes child with a given name. More...
 
template<typename T >
void update (const std::string &name, T &value)
 update function writes or reads a value to/from a node, depends on nodes isWriteUpdateType More...
 
template<typename T , typename U >
void update (const std::string &name, T &value, const U &defaultValue)
 update function writes or reads a value to/from a node, depends on nodes isWriteUpdateType More...
 
virtual NodePtr updateChild (const std::string &childName)=0
 updateChild function creates or finds a node child with a given name based on update type More...
 
virtual NodePtr readChild (const std::string &childName)=0
 readChild function finds a node child with a given name More...
 
virtual NodePtr createNode (std::string name, std::string value)=0
 createNode function creates a new Node and returns a pointer to it. More...
 
virtual void initializeNode (std::string name, std::string value)=0
 initializeNode function initializes an empty Node with a given name and given value. More...
 
virtual void initializeNode (NodePtr node)=0
 initializeNode function initializes an empty Node with a given node. More...
 
virtual void setValue (std::string value)=0
 setValue function sets a given value to a node. More...
 
virtual NodePtr addChild (std::string name)=0
 addChild function creates and adds a child with a given name to a node and returns a pointer to it. More...
 
virtual NodePtr addChild (const NodePtr &childNode)=0
 addChild function creates and adds a given child node to a node and returns a pointer to it. More...
 
virtual NodePtr clone ()=0
 clone function creates a clone of a node. More...
 
NodePtr clone (const NodePtr &nodeToClone)
 clone function creates a clone of a given node and returns a pointer to it. More...
 
virtual NodePtr addAttributeNode (const NodePtr &attributeNode)=0
 addAttributeNode adds a given attribute node to a node and returns a pointer to it. More...
 
virtual void clearChildNodes ()=0
 clearChildNodes clears all child nodes.
 
virtual void clearAttributeNodes ()=0
 clearAttributeNodes clears all attribute nodes.
 
virtual NodePtr findChildNode (const std::string &name)=0
 findChildNode finds a child node with a given name and returns a pointer to it or nullptr if not found. More...
 
virtual NodePtr findAttributeNode (const std::string &name)=0
 findAttributeNode finds an attribute node with a given name and returns a pointer to it or nullptr if not found. More...
 
virtual NodePtr getAttribute (const size_t attributeIndex)=0
 getAttribute returns an attribute with a given index or nullptr if index is invalid. More...
 
virtual NodePtr getChild (const size_t childIndex)=0
 getChild returns a child with a given index or nullptr if index is invalid. More...
 
virtual size_t getAttributeCount ()=0
 getAttributeCount returns a number of attributes of a node. More...
 
virtual size_t getChildCount ()=0
 getChildCount returns a number of children of a node. More...
 
virtual void removeAttribute (const std::string &attributeName)=0
 removeAttribute removes all attributes with a given name from a node. More...
 
virtual void removeAttribute (const size_t attributeIndex)=0
 removeAttribute removes an attribute with a given index from a node. More...
 
virtual void removeAttribute (NodePtr &attributeNode)=0
 removeAttribute removes an attribute that has the same name as given attribute node. More...
 
virtual void removeChild (const std::string &childName)=0
 removeChild removes all children with a given name from a node. More...
 
virtual void removeChild (const size_t childIndex)=0
 removeChild removes a child with a given index from a node. More...
 
virtual void removeChild (NodePtr &childNode)=0
 removeChild removes a child that has the same name as given node. More...
 
virtual std::string getName ()=0
 getName returns a name of a node. More...
 
virtual std::string getValue ()=0
 getValue returns a value of a node. More...
 
virtual NodePtr getNextSibling ()=0
 getNextSibling returns a sibling of a node or nullptr if it doesnt exist. More...
 
virtual void updateOperation (bool write)=0
 updateOperation sets a node update operation (node can be used either for writting or reading). More...
 
virtual bool isWrite ()=0
 isWrite returns true if node should be used for writting or false otherwise. More...
 
virtual bool isInitialized ()=0
 isInitialized returns true if node is initialized or false otherwise. More...
 
virtual bool isEmpty ()=0
 isEmpty returns true if node does not have any children, attributes and if it does not have any value More...
 
bool isDummy () const
 isDummy returns true if node was created as a dummy node in updateChild function More...
 

Protected Member Functions

virtual void internalWrite (const std::string &name, const std::string &value, const std::string &defaultValue)=0
 
virtual void internalRead (const std::string &name, std::string &value, const std::string &defaultValue)=0
 
virtual void internalAddAttribute (const std::string &name, const std::string &value)=0
 

Protected Attributes

bool isDummyNode = false
 

Detailed Description

Node is an abstract class that represents a node in an xml tree and defines functions for writing and reading values/std containers from a node and for building an xml node tree.

Member Function Documentation

◆ addAttribute()

template<typename T >
void Node::addAttribute ( const std::string &  name,
const T &  value 
)

addAttribute function adds an attribute with a given name and given value to a node.

Parameters
nameName of an attribute
valueValue of an attribute

◆ addAttributeNode()

virtual NodePtr Node::addAttributeNode ( const NodePtr &  attributeNode)
pure virtual

addAttributeNode adds a given attribute node to a node and returns a pointer to it.

Parameters
attributeNodeShared pointer to an attribute node that will be assigned to a node
Returns
Returns a shared pointer to an added attribute

Implemented in LibXmlNode.

◆ addChild() [1/2]

virtual NodePtr Node::addChild ( std::string  name)
pure virtual

addChild function creates and adds a child with a given name to a node and returns a pointer to it.

Parameters
nameName of a child
Returns
Returns a shared pointer to an added child

Implemented in LibXmlNode.

◆ addChild() [2/2]

virtual NodePtr Node::addChild ( const NodePtr &  childNode)
pure virtual

addChild function creates and adds a given child node to a node and returns a pointer to it.

Parameters
childNodeShared pointer to a node that will become a child
Returns
Returns a shared pointer to an added child

Implemented in LibXmlNode.

◆ clone() [1/2]

virtual NodePtr Node::clone ( )
pure virtual

clone function creates a clone of a node.

Returns
Returns a shared pointer to a clone of a node

Implemented in LibXmlNode.

◆ clone() [2/2]

NodePtr Node::clone ( const NodePtr &  nodeToClone)

clone function creates a clone of a given node and returns a pointer to it.

Parameters
nodeToCloneShared pointer to a node that will be cloned
Returns
Returns a shared pointer to a clone of a node).

◆ createNode()

virtual NodePtr Node::createNode ( std::string  name,
std::string  value 
)
pure virtual

createNode function creates a new Node and returns a pointer to it.

Parameters
nameName of a child
valueValue of a child
Returns
Returns a shared pointer to newly created node

Implemented in LibXmlNode.

◆ findAttributeNode()

virtual NodePtr Node::findAttributeNode ( const std::string &  name)
pure virtual

findAttributeNode finds an attribute node with a given name and returns a pointer to it or nullptr if not found.

Parameters
nameName of a attribute node to search for
Returns
Returns a shared pointer to a found attribute node or nullptr if not found

Implemented in LibXmlNode.

◆ findChildNode()

virtual NodePtr Node::findChildNode ( const std::string &  name)
pure virtual

findChildNode finds a child node with a given name and returns a pointer to it or nullptr if not found.

Parameters
nameName of a child node to search for
Returns
Returns a shared pointer to an added attribute or nullptr if not found

Implemented in LibXmlNode.

◆ getAttribute()

virtual NodePtr Node::getAttribute ( const size_t  attributeIndex)
pure virtual

getAttribute returns an attribute with a given index or nullptr if index is invalid.

Parameters
attributeIndexIndex of an attribute
Returns
Returns a shared pointer to a found attribute node or nullptr if index is invalid

Implemented in LibXmlNode.

◆ getAttributeCount()

virtual size_t Node::getAttributeCount ( )
pure virtual

getAttributeCount returns a number of attributes of a node.

Returns
Returns a number of attributes of a node

Implemented in LibXmlNode.

◆ getChild()

virtual NodePtr Node::getChild ( const size_t  childIndex)
pure virtual

getChild returns a child with a given index or nullptr if index is invalid.

Parameters
childIndexIndex of a child
Returns
Returns a shared pointer to a found child node or nullptr if index is invalid

Implemented in LibXmlNode.

◆ getChildCount()

virtual size_t Node::getChildCount ( )
pure virtual

getChildCount returns a number of children of a node.

Returns
Returns a number of children of a node

Implemented in LibXmlNode.

◆ getName()

virtual std::string Node::getName ( )
pure virtual

getName returns a name of a node.

Returns
Returns a name of a node

Implemented in LibXmlNode.

◆ getNextSibling()

virtual NodePtr Node::getNextSibling ( )
pure virtual

getNextSibling returns a sibling of a node or nullptr if it doesnt exist.

Returns
Returns a shared pointer to a found sibling node or nullptr if it does not exist

Implemented in LibXmlNode.

◆ getValue()

virtual std::string Node::getValue ( )
pure virtual

getValue returns a value of a node.

Returns
Returns a value of a node

Implemented in LibXmlNode.

◆ initializeNode() [1/2]

virtual void Node::initializeNode ( std::string  name,
std::string  value 
)
pure virtual

initializeNode function initializes an empty Node with a given name and given value.

Parameters
nameName of a node
valueValue of a node

Implemented in LibXmlNode.

◆ initializeNode() [2/2]

virtual void Node::initializeNode ( NodePtr  node)
pure virtual

initializeNode function initializes an empty Node with a given node.

Parameters
nodeShared pointer to a node

Implemented in LibXmlNode.

◆ isDummy()

bool Node::isDummy ( ) const

isDummy returns true if node was created as a dummy node in updateChild function

Returns
returns true if node was created as a dummy node in updateChild function

◆ isEmpty()

virtual bool Node::isEmpty ( )
pure virtual

isEmpty returns true if node does not have any children, attributes and if it does not have any value

Returns
It returns true if node does not have any children, attributes and if it does not have any value

Implemented in LibXmlNode.

◆ isInitialized()

virtual bool Node::isInitialized ( )
pure virtual

isInitialized returns true if node is initialized or false otherwise.

Returns
It returns true if node is initialized or false otherwise

Implemented in LibXmlNode.

◆ isWrite()

virtual bool Node::isWrite ( )
pure virtual

isWrite returns true if node should be used for writting or false otherwise.

Returns
returns true if node should be used for writting or false otherwise

Implemented in LibXmlNode.

◆ read() [1/2]

template<typename T >
void Node::read ( const std::string &  name,
T &  value 
)

read function reads a value from a nodes child with a given name.

Parameters
nameName of a node
valueValue of a node. It can be of any primitive type or any std container type. Does not support C arrays. If node does not exist than value will be default which is 0 for numbers and empty string for strings.

◆ read() [2/2]

template<typename T , typename U >
void Node::read ( const std::string &  name,
T &  value,
const U &  defaultValue 
)

read function reads a value from a nodes child with a given name.

Parameters
nameName of a node
valueValue of a node. It can be of any primitive type.
defaultValueDefault value of a node which is used for output value if node with a given name is not found.

◆ readChild()

virtual NodePtr Node::readChild ( const std::string &  childName)
pure virtual

readChild function finds a node child with a given name

Parameters
childNameName of a child
Returns
Returns a shared pointer to a found child. If child does not exist a dummy node with given name is returned

Implemented in LibXmlNode.

◆ removeAttribute() [1/3]

virtual void Node::removeAttribute ( const std::string &  attributeName)
pure virtual

removeAttribute removes all attributes with a given name from a node.

Parameters
attributeNameName of attributes to remove

Implemented in LibXmlNode.

◆ removeAttribute() [2/3]

virtual void Node::removeAttribute ( const size_t  attributeIndex)
pure virtual

removeAttribute removes an attribute with a given index from a node.

Parameters
attributeIndexIndex of attribute to remove

Implemented in LibXmlNode.

◆ removeAttribute() [3/3]

virtual void Node::removeAttribute ( NodePtr &  attributeNode)
pure virtual

removeAttribute removes an attribute that has the same name as given attribute node.

Parameters
attributeNodeShared pointer to an attribute node to remove

Implemented in LibXmlNode.

◆ removeChild() [1/3]

virtual void Node::removeChild ( const std::string &  childName)
pure virtual

removeChild removes all children with a given name from a node.

Parameters
childNameName of children to remove

Implemented in LibXmlNode.

◆ removeChild() [2/3]

virtual void Node::removeChild ( const size_t  childIndex)
pure virtual

removeChild removes a child with a given index from a node.

Parameters
childIndexIndex of a child to remove

Implemented in LibXmlNode.

◆ removeChild() [3/3]

virtual void Node::removeChild ( NodePtr &  childNode)
pure virtual

removeChild removes a child that has the same name as given node.

Parameters
childNodeShared pointer to a child node to remove

Implemented in LibXmlNode.

◆ setValue()

virtual void Node::setValue ( std::string  value)
pure virtual

setValue function sets a given value to a node.

Parameters
valueValue of a node

Implemented in LibXmlNode.

◆ update() [1/2]

template<typename T >
void Node::update ( const std::string &  name,
T &  value 
)

update function writes or reads a value to/from a node, depends on nodes isWriteUpdateType

Parameters
nameName of a node
valueValue of a node. It can be of any primitive type or any std container type. Does not support C arrays. If node does not exist than value that is read will be default which is 0 for numbers and empty string for strings.

◆ update() [2/2]

template<typename T , typename U >
void Node::update ( const std::string &  name,
T &  value,
const U &  defaultValue 
)

update function writes or reads a value to/from a node, depends on nodes isWriteUpdateType

Parameters
nameName of a node
valueValue of a node. It can be of any primitive type
defaultValueCustom default value of a node which is used for output value if node with a given name does not exist.

◆ updateChild()

virtual NodePtr Node::updateChild ( const std::string &  childName)
pure virtual

updateChild function creates or finds a node child with a given name based on update type

Parameters
childNameName of a child
Returns
Returns a shared pointer to a created or found child. If child does not exist when update type is read a dummy node with given name is returned

Implemented in LibXmlNode.

◆ updateOperation()

virtual void Node::updateOperation ( bool  write)
pure virtual

updateOperation sets a node update operation (node can be used either for writting or reading).

Setting updateOperation is optional.

Parameters
writecan be wither true for writting or false for reading

Implemented in LibXmlNode.

◆ write() [1/2]

template<typename T >
void Node::write ( const std::string &  name,
const T &  value 
)

write function creates a new child with a given name and adds a given value to it.

Parameters
nameName of a node
valueValue of a node. It can be of any primitive type or any std container type. Does not support C arrays.

◆ write() [2/2]

template<typename T , typename U >
void Node::write ( const std::string &  name,
const T &  value,
const U &  defaultValue 
)

write function creates a new child with a given name and adds a given value to it.

If written value is equal to a given default value than node is not created!

Parameters
nameName of a node
valueValue of a node. It can be of any primitive type.
defaultValueDefault value of a node. If value is equal to node value than node is not created!

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