ChimeraTK-ControlSystemAdapter-OPCUAAdapter  04.00.01
xml_file_handler.h
Go to the documentation of this file.
1 /*
2  * This file is part of ChimeraTKs ControlSystem-OPC-UA-Adapter.
3  *
4  * ChimeraTKs ControlSystem-OPC-UA-Adapter is free software: you can
5  * redistribute it and/or modify it under the terms of the Lesser GNU
6  * General Public License as published by the Free Software Foundation,
7  * either version 3 of the License, or (at your option) any later version.
8  *
9  * ChimeraTKs ControlSystem-OPC-UA-Adapter is distributed in the hope
10  * that it will be useful, but WITHOUT ANY WARRANTY; without even the
11  * implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12  * See the Lesser GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with Foobar. If not, see https://www.gnu.org/licenses/lgpl.html
16  *
17  * Copyright (c) 2016 Chris Iatrou <Chris_Paul.Iatrou@tu-dresden.de>
18  * Copyright (c) 2016 Julian Rahm <Julian.Rahm@tu-dresden.de>
19  */
20 
21 #pragma once
22 
23 #include <libxml2/libxml/tree.h>
24 #include <libxml2/libxml/xpath.h>
25 #include <libxml2/libxml/xpathInternals.h>
26 
27 #include <boost/tokenizer.hpp>
28 
29 #include <iostream>
30 #include <vector>
31 
32 namespace ChimeraTK {
45  public:
50  xml_file_handler(const std::string& filePath);
51 
58  bool createDoc(const std::string& filePath);
59 
64  bool isDocSetted();
65 
72  xmlXPathObjectPtr getNodeSet(const std::string& xPathString);
73 
81  static std::vector<xmlNodePtr> getNodesByName(xmlNodePtr startNode, const std::string& nodeName);
90  static std::vector<std::string> parseVariablePath(
91  const std::string& variablePath, const std::string& seperator = "/");
92 
100  static std::string getAttributeValueFromNode(xmlNode* node, const std::string& attributeName);
101 
109  static std::string getContentFromNode(xmlNode* node);
110 
115 
116  private:
117  xmlDocPtr doc{};
118  xmlNodePtr cur{};
119  };
120 } // namespace ChimeraTK
ChimeraTK::xml_file_handler::getNodeSet
xmlXPathObjectPtr getNodeSet(const std::string &xPathString)
This methode return a pointer of a xPath element depending of the given xPathString.
Definition: xml_file_handler.cpp:56
ChimeraTK::xml_file_handler::~xml_file_handler
~xml_file_handler()
Destructor of the class, frees the document and clean the parser.
Definition: xml_file_handler.cpp:144
ChimeraTK::xml_file_handler
This class support any file interaction with a xml file.
Definition: xml_file_handler.h:44
ChimeraTK::xml_file_handler::parseVariablePath
static std::vector< std::string > parseVariablePath(const std::string &variablePath, const std::string &seperator="/")
This methode splitt a given string bey the given seperators.
Definition: xml_file_handler.cpp:110
ChimeraTK::xml_file_handler::getNodesByName
static std::vector< xmlNodePtr > getNodesByName(xmlNodePtr startNode, const std::string &nodeName)
This methode return a list of all nodes with the given name nodeName starting by the given startNode.
Definition: xml_file_handler.cpp:44
ChimeraTK::xml_file_handler::getContentFromNode
static std::string getContentFromNode(xmlNode *node)
This methode returns the value between a xml tag.
Definition: xml_file_handler.cpp:131
ChimeraTK::xml_file_handler::xml_file_handler
xml_file_handler(const std::string &filePath)
The constructor of the class creates a doc pointer depending on the file path.
Definition: xml_file_handler.cpp:37
ChimeraTK
Definition: csa_additionalvariable.h:28
ChimeraTK::xml_file_handler::getAttributeValueFromNode
static std::string getAttributeValueFromNode(xmlNode *node, const std::string &attributeName)
This methode returns a value of the given attribute from the given node you want to know.
Definition: xml_file_handler.cpp:122
ChimeraTK::xml_file_handler::isDocSetted
bool isDocSetted()
This Methode check if a document is currently setted.
Definition: xml_file_handler.cpp:87
ChimeraTK::xml_file_handler::createDoc
bool createDoc(const std::string &filePath)
This methode set a document pointer to the file it ist given by the file path.
Definition: xml_file_handler.cpp:94