Commit f12cc09028e3b0b66251638ce9ad49362ba3a619
1 parent
1c528733
Intermediate Commit
Showing
4 changed files
with
95 additions
and
205 deletions
src/CMakeLists.txt
| ... | ... | @@ -16,8 +16,8 @@ include_directories( |
| 16 | 16 | ) |
| 17 | 17 | |
| 18 | 18 | set(SRC_LIST |
| 19 | - ${CMAKE_CURRENT_SOURCE_DIR}/dcxmlbase.h | |
| 20 | - ${CMAKE_CURRENT_SOURCE_DIR}/dcxmlbase.cpp | |
| 19 | + ${CMAKE_CURRENT_SOURCE_DIR}/xmlbase.h | |
| 20 | + ${CMAKE_CURRENT_SOURCE_DIR}/xmlbase.cpp | |
| 21 | 21 | ) |
| 22 | 22 | |
| 23 | 23 | link_directories( | ... | ... |
src/dcxmlbase.h deleted
| 1 | -/* **************************************************************************** | |
| 2 | - * Copyright 2022 Open Systems Development BV * | |
| 3 | - * * | |
| 4 | - * Permission is hereby granted, free of charge, to any person obtaining a * | |
| 5 | - * copy of this software and associated documentation files (the "Software"), * | |
| 6 | - * to deal in the Software without restriction, including without limitation * | |
| 7 | - * the rights to use, copy, modify, merge, publish, distribute, sublicense, * | |
| 8 | - * and/or sell copies of the Software, and to permit persons to whom the * | |
| 9 | - * Software is furnished to do so, subject to the following conditions: * | |
| 10 | - * * | |
| 11 | - * The above copyright notice and this permission notice shall be included in * | |
| 12 | - * all copies or substantial portions of the Software. * | |
| 13 | - * * | |
| 14 | - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * | |
| 15 | - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * | |
| 16 | - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * | |
| 17 | - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * | |
| 18 | - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * | |
| 19 | - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * | |
| 20 | - * DEALINGS IN THE SOFTWARE. * | |
| 21 | - * ***************************************************************************/ | |
| 22 | - | |
| 23 | -#pragma once | |
| 24 | - | |
| 25 | -#include <pugixml.hpp> | |
| 26 | -#include <string> | |
| 27 | - | |
| 28 | -#include <QtCore> | |
| 29 | - | |
| 30 | -namespace osdev { | |
| 31 | -namespace components { | |
| 32 | -namespace xml { | |
| 33 | - | |
| 34 | -/*! | |
| 35 | - * \brief xml_string_writer | |
| 36 | - * This struct is used to write a pugiXL DOM document to a std::string (QString) | |
| 37 | - * pugiXML is not able to this on its own, but we use the possibility to dump | |
| 38 | - * an XML-document to std::cout | |
| 39 | - */ | |
| 40 | -struct xml_string_writer : pugi::xml_writer | |
| 41 | -{ | |
| 42 | - std::string result = std::string(); | |
| 43 | - virtual void write(const void* data, size_t size) override; | |
| 44 | -}; | |
| 45 | - | |
| 46 | -/*! | |
| 47 | - * \brief The dcXmlBase class describes the base class for all xml related classes | |
| 48 | - * The basic functionality is implemented here. This class is intended to | |
| 49 | - * be inherited and specialized and not to be used directly. ( Nothing bad | |
| 50 | - * will happen, just to make life easier ) | |
| 51 | - */ | |
| 52 | -/* | |
| 53 | - * ________________________________________ | |
| 54 | - * / I'm serious about thinking through all \ | |
| 55 | - * | the possibilities before we settle on | | |
| 56 | - * | anything. All things have the | | |
| 57 | - * | advantages of their disadvantages, and | | |
| 58 | - * | vice versa. | | |
| 59 | - * | | | |
| 60 | - * | -- Larry Wall in | | |
| 61 | - * \ <199709032332.QAA21669@wall.org> / | |
| 62 | - * ---------------------------------------- | |
| 63 | - * \ | |
| 64 | - * \ | |
| 65 | - * .--. | |
| 66 | - * |o_o | | |
| 67 | - * |:_/ | | |
| 68 | - * // \ \ | |
| 69 | - * (| | ) | |
| 70 | - * /'\_ _/`\ | |
| 71 | - * \___)=(___/ | |
| 72 | - */ | |
| 73 | - | |
| 74 | -class DcXmlBase | |
| 75 | -{ | |
| 76 | -public: | |
| 77 | - /*! Default constructor */ | |
| 78 | - explicit DcXmlBase(const QString& xmlFile = QString()); | |
| 79 | - virtual ~DcXmlBase(); | |
| 80 | - | |
| 81 | - /*! | |
| 82 | - * \brief Parses the XML contents of the string. | |
| 83 | - * \param qsXml - String containing the contents of the XML-string | |
| 84 | - * \return true if successfull, false if not... | |
| 85 | - */ | |
| 86 | - bool parseString(const QString& qsXml); | |
| 87 | - | |
| 88 | - /*! | |
| 89 | - * \brief Parses the contents of the given XML-file. | |
| 90 | - * \param qsXml - String with the filepath & -name of the XML file. | |
| 91 | - * \return true if successfull, false if not... | |
| 92 | - */ | |
| 93 | - bool parseFile(const QString& qsXml); | |
| 94 | - | |
| 95 | - /*! | |
| 96 | - * \brief Adds an XPath expression to the internal structure. | |
| 97 | - * \param qsName - Name of the XPath expression. This should be descriptive to make life easier | |
| 98 | - * \param qsXPath - The XPath expression to the specific data we're interested in. | |
| 99 | - */ | |
| 100 | - void addXPath(const QString& qsName, const QString& qsXPath); | |
| 101 | - | |
| 102 | - /*! | |
| 103 | - * \brief Retrieves an XPath expression from the internal structure | |
| 104 | - * \param qsXPathSelect - The name of the XPath expression. | |
| 105 | - * \return The XPath expression as stored in the internal Hash | |
| 106 | - */ | |
| 107 | - QString getXPath(const QString& qsXPathSelect) const; | |
| 108 | - | |
| 109 | - /*! | |
| 110 | - * \brief Interprets the XPath expression and adds values to the variables. | |
| 111 | - * \param qsXPathSelect - The XPath expression as given by getXPath. | |
| 112 | - * \param arguments - The list of variables to be added to the XPath expression. | |
| 113 | - * \return The interpreted XPath expression. | |
| 114 | - */ | |
| 115 | - QString evaluateXPath(const QString& qsXPathSelect, const QList<QVariant>& arguments) const; | |
| 116 | - | |
| 117 | - /*! | |
| 118 | - * \brief Set a simple node in the xml-doc. | |
| 119 | - * \param qsXPathSelect - The XPath expression of the node we want to set. | |
| 120 | - * \param arguments - the list of arguments in the node | |
| 121 | - * \param data - The nodetext. | |
| 122 | - */ | |
| 123 | - void setSimpleData(const QString& qsXPathSelect, const QList<QVariant>& arguments, const QVariant& data); | |
| 124 | - | |
| 125 | - /*! | |
| 126 | - * \brief Set a simple node in the xml-doc. | |
| 127 | - * \param qsXPathSelect - The XPath expression of the node we want to set. | |
| 128 | - * \param data - The nodetext. | |
| 129 | - */ | |
| 130 | - void setSimpleData(const QString& qsXPathSelect, const QVariant& data); | |
| 131 | - | |
| 132 | - QVariant getSimpleData(const QString& qsXPathSelect, const QList<QVariant>& arguments) const; | |
| 133 | - | |
| 134 | - /*! | |
| 135 | - * \brief Retreive a single node based on the XPath expression | |
| 136 | - * \param qsXPath - The XPath expression | |
| 137 | - * \return - a single xpath-node | |
| 138 | - */ | |
| 139 | - pugi::xpath_node selectNode(const QString& qsXPath) const; | |
| 140 | - | |
| 141 | - /*! | |
| 142 | - * \brief Retreives a list of nodes based on the given XPath expression | |
| 143 | - * \param qsXPath - The XPath expression | |
| 144 | - * \return - The list of nodes | |
| 145 | - */ | |
| 146 | - QList<pugi::xpath_node> selectNodes(const QString& qsXPath) const; | |
| 147 | - | |
| 148 | - /*! Added for convenience. The DOMTree is exported as QString */ | |
| 149 | - QString asString() const; | |
| 150 | - | |
| 151 | - /*! Helper method for the setSimpleData */ | |
| 152 | - void setNodeData(const QString& qsXPath, const QVariant& qsData); | |
| 153 | - | |
| 154 | - //! Helper method for the getSimpleData. Get data from the node that | |
| 155 | - //! is selected with the XPath expression. | |
| 156 | - virtual QVariant getNodeData(const QString& qsXPath) const; | |
| 157 | - | |
| 158 | - /** | |
| 159 | - * @brief Turns a value into a boolean. | |
| 160 | - * @param value Value to be interpreted. | |
| 161 | - * @return boolean representation of value | |
| 162 | - * | |
| 163 | - * The following (capitalised) items convert to "true" : | |
| 164 | - * - Y | |
| 165 | - * - YES | |
| 166 | - * - TRUE | |
| 167 | - * - ON | |
| 168 | - * - 1 | |
| 169 | - * | |
| 170 | - * Everything else converts to false. | |
| 171 | - */ | |
| 172 | - static bool getBoolean(const QVariant& value); | |
| 173 | - | |
| 174 | - /** | |
| 175 | - * @param xmlNode The node to query for an attribute value. | |
| 176 | - * @param attributeName The name of the attribute to query. | |
| 177 | - * @return an attribute value. | |
| 178 | - * @retval value as QString | |
| 179 | - * @retval null QString when the attribute is not found. | |
| 180 | - */ | |
| 181 | - static QString getAttributeValue(const pugi::xml_node& xmlNode, const char* attributeName); | |
| 182 | - | |
| 183 | -private: | |
| 184 | - /*! | |
| 185 | - * \brief Translates the pugiXML status into Human Readable messages | |
| 186 | - * \param parseStatus - The pugi::XML status enum from the parser. | |
| 187 | - * \return True if there was no error whatsoever. False if not.. 8-| | |
| 188 | - */ | |
| 189 | - bool checkError(pugi::xml_parse_status parseStatus); | |
| 190 | - | |
| 191 | - /*! | |
| 192 | - * \brief The internal representation of the XML document. | |
| 193 | - */ | |
| 194 | - pugi::xml_document m_xmldoc; | |
| 195 | - | |
| 196 | - //! Storage for the XPath expressions | |
| 197 | - QHash<QString, QString> m_xPathHash; | |
| 198 | -}; | |
| 199 | - | |
| 200 | -} // End namespace xml | |
| 201 | -} // End namespace osdev | |
| 202 | -} // End namespace components | |
| 203 | - |
src/dcxmlbase.cpp renamed to src/xmlbase.cpp
src/xmlbase.h
0 → 100644
| 1 | +/* **************************************************************************** | |
| 2 | + * Copyright 2022 Open Systems Development BV * | |
| 3 | + * * | |
| 4 | + * Permission is hereby granted, free of charge, to any person obtaining a * | |
| 5 | + * copy of this software and associated documentation files (the "Software"), * | |
| 6 | + * to deal in the Software without restriction, including without limitation * | |
| 7 | + * the rights to use, copy, modify, merge, publish, distribute, sublicense, * | |
| 8 | + * and/or sell copies of the Software, and to permit persons to whom the * | |
| 9 | + * Software is furnished to do so, subject to the following conditions: * | |
| 10 | + * * | |
| 11 | + * The above copyright notice and this permission notice shall be included in * | |
| 12 | + * all copies or substantial portions of the Software. * | |
| 13 | + * * | |
| 14 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * | |
| 15 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * | |
| 16 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * | |
| 17 | + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * | |
| 18 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * | |
| 19 | + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * | |
| 20 | + * DEALINGS IN THE SOFTWARE. * | |
| 21 | + * ***************************************************************************/ | |
| 22 | + | |
| 23 | +#pragma once | |
| 24 | + | |
| 25 | +#include <pugixml.hpp> | |
| 26 | +#include <string> | |
| 27 | +#include <vector> | |
| 28 | +#include <variant> | |
| 29 | + | |
| 30 | +namespace osdev { | |
| 31 | +namespace components { | |
| 32 | +namespace xml { | |
| 33 | + | |
| 34 | +/*! | |
| 35 | + * \brief xml_string_writer | |
| 36 | + * This struct is used to write a pugixml DOM document to a std::string. | |
| 37 | + * pugiXML is not able to do this on its own, but we use the possibility | |
| 38 | + * to dump an xml-document to std::cout. | |
| 39 | + */ | |
| 40 | +struct xml_string_writer : pugi::xml_writer | |
| 41 | +{ | |
| 42 | + std::string result = std::string(); | |
| 43 | + virtual void write(const void* data, size_t size) override; | |
| 44 | +}; | |
| 45 | + | |
| 46 | +/*! | |
| 47 | + * \brief The XmlBase class describes the base class for all xml related classes. | |
| 48 | + * The basic functionality is implemented here. This class is intrended to | |
| 49 | + * be inherited an d specialized and not to be used directly. ( Nothing bad | |
| 50 | + * will happen, just to make life easier. ) | |
| 51 | + */ | |
| 52 | +class XmlBase | |
| 53 | +{ | |
| 54 | +public: | |
| 55 | + /*! Default constructor */ | |
| 56 | + explicit XmlBase(const std::string xmlFile = std::string() ); | |
| 57 | + virtual ~XmlBase(); | |
| 58 | + | |
| 59 | + /*! | |
| 60 | + * \brief Parses the xml contents of the string. | |
| 61 | + * \param sxml - String containing the xml-string | |
| 62 | + * \return true if succesful, false if not... | |
| 63 | + */ | |
| 64 | + bool parseString(const std::string &sxml); | |
| 65 | + | |
| 66 | + /*! | |
| 67 | + * \brief Parses the contents of the givenm XML-file. | |
| 68 | + * \param sxml - String with the filepath & -name of the xml file. | |
| 69 | + * \return true if succesfull, false if not. | |
| 70 | + */ | |
| 71 | + bool parseFile(const std::string sxml); | |
| 72 | + | |
| 73 | + /*! | |
| 74 | + * \brief Adds and XPath expression to the internal structure. | |
| 75 | + * \param sName - Name of the XPath expression. This should be descriptive to make life easier. | |
| 76 | + * \param sXPath - The XPath expression to the specific data we're interested in. | |
| 77 | + */ | |
| 78 | + void addXPath(const std::string &sName, const std::string &sXPath); | |
| 79 | + | |
| 80 | + /*! | |
| 81 | + * \brief Retrieves an XPatrh expression from the internal structure | |
| 82 | + * \param sXpathSelect - The name of the XPath expression | |
| 83 | + * \return The XPath expression as stored in the internal Hash. | |
| 84 | + */ | |
| 85 | + std::string getXPath(const std::string &sXpathSelect); | |
| 86 | + | |
| 87 | + | |
| 88 | +}; | |
| 89 | + | |
| 90 | + | |
| 91 | +} // End namespace xml | |
| 92 | +} // End namespace components | |
| 93 | +} // End namespace osdev | ... | ... |