commonlib
LibXmlNode Class Reference

LibXmlNode is a class that inherits from Node and SerializableNode. More...

#include <libxml_node.h>

Inheritance diagram for LibXmlNode:
SerializableNode Node

Public Types

using DxNodePtr = Dewesoft::Utils::Serialization::DxNodePtr
 

Public Member Functions

 LibXmlNode ()
 LibXmlNode constructor that initializes a node with a 'RootNode' default name.
 
 LibXmlNode (const std::string &name)
 LibXmlNode constructor that initializes a node with a given name.
 
 LibXmlNode (const std::string &name, const std::string &value)
 LibXmlNode constructor that initializes a node with a given name and value.
 
 LibXmlNode (const std::string &name, const std::string &value, bool write)
 LibXmlNode constructor that initializes a node with a given name, value and update type.
 
 LibXmlNode (const NodePtr &node)
 LibXmlNode constructor that initializes a node with a given NodePtr.
 
 ~LibXmlNode ()
 Destructor.
 
NodePtr updateChild (const std::string &childName) override
 updateChild function creates or finds a node child with a given name based on update type More...
 
NodePtr readChild (const std::string &childName) override
 readChild function finds a node child with a given name More...
 
NodePtr createNode (std::string name, std::string value) override
 createNode function creates a new Node and returns a pointer to it. More...
 
void initializeNode (std::string name, std::string value) override
 initializeNode function initializes a Node with a given name and given value. More...
 
void initializeNode (NodePtr node) override
 initializeNode function initializes an empty Node with a given node. More...
 
void setValue (std::string value) override
 setValue function sets a given value to a node. More...
 
NodePtr addChild (std::string name) override
 addChild function creates and adds a child with a given name to a node and returns a pointer to it. More...
 
NodePtr addChild (const NodePtr &childNode) override
 addChild function creates and adds a given child node to a node and returns a pointer to it. More...
 
NodePtr clone () override
 clone function creates a clone of a node. More...
 
NodePtr addAttributeNode (const NodePtr &attributeNode) override
 addAttributeNode adds a given attribute node to a node and returns a pointer to it. More...
 
void clearChildNodes () override
 clearChildNodes clears all child nodes.
 
void clearAttributeNodes () override
 clearAttributeNodes clears all attribute nodes.
 
NodePtr findChildNode (const std::string &name) override
 findChildNode finds a child node with a given name and returns a pointer to it or nullptr if not found. More...
 
NodePtr findAttributeNode (const std::string &name) override
 findAttributeNode finds an attribute node with a given name and returns a pointer to it or nullptr if not found. More...
 
NodePtr getAttribute (const size_t attributeIndex) override
 getAttribute returns an attribute with a given index or nullptr if index is invalid. More...
 
NodePtr getChild (const size_t childIndex) override
 getChild returns a child with a given index or nullptr if index is invalid. More...
 
size_t getAttributeCount () override
 getAttributeCount returns a number of attributes of a node. More...
 
size_t getChildCount () override
 getChildCount returns a number of children of a node. More...
 
void removeAttribute (const std::string &attributeName) override
 removeAttribute removes all attributes with a given name from a node. More...
 
void removeAttribute (const size_t attributeIndex) override
 removeAttribute removes an attribute with a given index from a node. More...
 
void removeAttribute (NodePtr &attributeNode) override
 removeAttribute removes an attribute that has the same name as given attribute node. More...
 
void removeChild (const std::string &childName) override
 removeChild removes all children with a given name from a node. More...
 
void removeChild (const size_t childIndex) override
 removeChild removes a child with a given index from a node. More...
 
void removeChild (NodePtr &childNode) override
 removeChild removes a child that has the same name as given node. More...
 
std::string getName () override
 getName returns a name of a node. More...
 
std::string getValue () override
 getValue returns a value of a node. More...
 
NodePtr getNextSibling () override
 getNextSibling returns a sibling of a node or nullptr if it does not exist. More...
 
void updateOperation (bool write) override
 updateOperation sets a node update operation (node can be used either for writing or reading). More...
 
bool isWrite () override
 isWrite returns true if node should be used for writing or false otherwise. More...
 
bool isInitialized () override
 isInitialized returns true if node is initialized or false otherwise. More...
 
bool isEmpty () override
 isEmpty returns true if node does not have any children, attributes and if it does not have any value More...
 
void destroy () override
 destroy function releases internal node and sets it value to nullptr.
 
void saveToFile (const std::string &fileName) override
 saveToFile saves an internal node to a given file. More...
 
void readFromFile (const std::string &fileName) override
 readFromFile reads and builds an internal node from a given file. More...
 
void saveToStream (std::ostream &outStream) override
 saveToStream saves an internal node to a given ostream. More...
 
void readFromStream (std::istream &inStream) override
 readFromStream reads and builds an internal node from a given istream. More...
 
- Public Member Functions inherited from Node
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...
 
NodePtr clone (const NodePtr &nodeToClone)
 clone function creates a clone of a given node and returns a pointer to it. More...
 
bool isDummy () const
 isDummy returns true if node was created as a dummy node in updateChild function More...
 

Protected Member Functions

 LibXmlNode (const DxNodePtr &node, bool xmlUpdateType)
 
 LibXmlNode (const DxNodePtr &node, bool xmlUpdateType, bool isDummyNode)
 

Additional Inherited Members

- Protected Attributes inherited from Node
bool isDummyNode = false
 

Detailed Description

LibXmlNode is a class that inherits from Node and SerializableNode.

It uses libxml2 library for parsing and creating xml files. It implements functions from Node and SerializableNode abstract classes.

Member Function Documentation

◆ addAttributeNode()

NodePtr LibXmlNode::addAttributeNode ( const NodePtr &  attributeNode)
overridevirtual

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

Implements Node.

◆ addChild() [1/2]

NodePtr LibXmlNode::addChild ( std::string  name)
overridevirtual

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

Implements Node.

◆ addChild() [2/2]

NodePtr LibXmlNode::addChild ( const NodePtr &  childNode)
overridevirtual

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

Implements Node.

◆ clone()

NodePtr LibXmlNode::clone ( )
overridevirtual

clone function creates a clone of a node.

Returns
Returns a shared pointer to a clone of a node

Implements Node.

◆ createNode()

NodePtr LibXmlNode::createNode ( std::string  name,
std::string  value 
)
overridevirtual

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

Implements Node.

◆ findAttributeNode()

NodePtr LibXmlNode::findAttributeNode ( const std::string &  name)
overridevirtual

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

Implements Node.

◆ findChildNode()

NodePtr LibXmlNode::findChildNode ( const std::string &  name)
overridevirtual

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

Implements Node.

◆ getAttribute()

NodePtr LibXmlNode::getAttribute ( const size_t  attributeIndex)
overridevirtual

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

Implements Node.

◆ getAttributeCount()

size_t LibXmlNode::getAttributeCount ( )
overridevirtual

getAttributeCount returns a number of attributes of a node.

Returns
Returns a number of attributes of a node

Implements Node.

◆ getChild()

NodePtr LibXmlNode::getChild ( const size_t  childIndex)
overridevirtual

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

Implements Node.

◆ getChildCount()

size_t LibXmlNode::getChildCount ( )
overridevirtual

getChildCount returns a number of children of a node.

Returns
Returns a number of children of a node

Implements Node.

◆ getName()

std::string LibXmlNode::getName ( )
overridevirtual

getName returns a name of a node.

Returns
Returns a name of a node

Implements Node.

◆ getNextSibling()

NodePtr LibXmlNode::getNextSibling ( )
overridevirtual

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

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

Implements Node.

◆ getValue()

std::string LibXmlNode::getValue ( )
overridevirtual

getValue returns a value of a node.

Returns
Returns a value of a node

Implements Node.

◆ initializeNode() [1/2]

void LibXmlNode::initializeNode ( std::string  name,
std::string  value 
)
overridevirtual

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

Parameters
nameName of a node
valueValue of a node

Implements Node.

◆ initializeNode() [2/2]

void LibXmlNode::initializeNode ( NodePtr  node)
overridevirtual

initializeNode function initializes an empty Node with a given node.

Parameters
nodeShared pointer to a node

Implements Node.

◆ isEmpty()

bool LibXmlNode::isEmpty ( )
overridevirtual

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

Implements Node.

◆ isInitialized()

bool LibXmlNode::isInitialized ( )
overridevirtual

isInitialized returns true if node is initialized or false otherwise.

Returns
It returns true if node is initialized or false otherwise.

Implements Node.

◆ isWrite()

bool LibXmlNode::isWrite ( )
overridevirtual

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

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

Implements Node.

◆ readChild()

NodePtr LibXmlNode::readChild ( const std::string &  childName)
overridevirtual

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

Implements Node.

◆ readFromFile()

void LibXmlNode::readFromFile ( const std::string &  fileName)
overridevirtual

readFromFile reads and builds an internal node from a given file.

Parameters
fileNameFilename

Implements SerializableNode.

◆ readFromStream()

void LibXmlNode::readFromStream ( std::istream &  inStream)
overridevirtual

readFromStream reads and builds an internal node from a given istream.

Parameters
inStreamInput stream

Implements SerializableNode.

◆ removeAttribute() [1/3]

void LibXmlNode::removeAttribute ( const std::string &  attributeName)
overridevirtual

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

Parameters
attributeNameName of attributes to remove).

Implements Node.

◆ removeAttribute() [2/3]

void LibXmlNode::removeAttribute ( const size_t  attributeIndex)
overridevirtual

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

Parameters
attributeIndexIndex of attribute to remove

Implements Node.

◆ removeAttribute() [3/3]

void LibXmlNode::removeAttribute ( NodePtr &  attributeNode)
overridevirtual

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

Parameters
attributeNodeShared pointer to an attribute node to remove.

Implements Node.

◆ removeChild() [1/3]

void LibXmlNode::removeChild ( const std::string &  childName)
overridevirtual

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

Parameters
childNameName of children to remove

Implements Node.

◆ removeChild() [2/3]

void LibXmlNode::removeChild ( const size_t  childIndex)
overridevirtual

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

Parameters
childIndexIndex of a child to remove

Implements Node.

◆ removeChild() [3/3]

void LibXmlNode::removeChild ( NodePtr &  childNode)
overridevirtual

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

Parameters
childNodeShared pointer to a child node to remove

Implements Node.

◆ saveToFile()

void LibXmlNode::saveToFile ( const std::string &  fileName)
overridevirtual

saveToFile saves an internal node to a given file.

Parameters
fileNameFilename

Implements SerializableNode.

◆ saveToStream()

void LibXmlNode::saveToStream ( std::ostream &  outStream)
overridevirtual

saveToStream saves an internal node to a given ostream.

Parameters
outStreamOutput stream

Implements SerializableNode.

◆ setValue()

void LibXmlNode::setValue ( std::string  value)
overridevirtual

setValue function sets a given value to a node.

Parameters
valueValue of a node

Implements Node.

◆ updateChild()

NodePtr LibXmlNode::updateChild ( const std::string &  childName)
overridevirtual

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

Implements Node.

◆ updateOperation()

void LibXmlNode::updateOperation ( bool  write)
overridevirtual

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

Setting updateOperation is optional.

Parameters
writecan be wither true for writing or false for reading

Implements Node.


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