/* * Author: Patrick-Christopher Mattulat * Company: Lynar Studios * E-Mail: webmaster@lynarstudios.com * Created: 2020-10-08 * Changed: 2020-11-20 * * */ #ifndef LS_STD_XML_READER_HPP #define LS_STD_XML_READER_HPP #include #include "XMLDocument.hpp" #include #include #include "XMLParseMode.hpp" #include "XMLParseData.hpp" #include namespace ls_std { class XMLReader : public Class, IReader { public: explicit XMLReader(const std::shared_ptr& _document, const std::string& _absolutePath); ~XMLReader() = default; // implementation ls_std::byte_field read() override; // additional functionality std::shared_ptr getDocument(); void setFile(const ls_std::File& _xmlFile); protected: static std::pair _readAttribute_(const ls_std::byte_field& _data); static std::list> _readAttributes_(ls_std::byte_field _data); private: uint8_t currentLevel {}; std::shared_ptr document {}; uint8_t maxLevel {}; ls_std::XMLParseMode mode {}; std::list parseData {}; ls_std::File xmlFile; void _analyze(const ls_std::byte_field &_data, std::string::size_type _index); static void _checkDocumentExistence(const std::shared_ptr& _document); static void _checkFileExistence(ls_std::File _xmlFile); static std::shared_ptr _createDeclaration(const std::list>& _attributes); static std::shared_ptr _createNode(const std::list>& _attributes, const std::string& _name); static std::pair _findAttribute(const std::list>& _attributes, const std::string& _name); static size_t _findAttributeEndPosition(const ls_std::byte_field& _data); static ls_std::byte_field _getNextTagString(const ls_std::byte_field& _data, std::string::size_type _index); void _isClosingTag(const ls_std::byte_field& _data, std::string::size_type _index); void _isDeclaration(const ls_std::byte_field& _data, std::string::size_type _index); void _isOpeningTag(const ls_std::byte_field& _data, std::string::size_type _index); void _isValue(const ls_std::byte_field& _data, std::string::size_type _index); void _mergeNodes(); void _mergeChildrenToParentNode(const std::shared_ptr& _parent, std::list::iterator& _iterator, uint8_t _parentLevel); void _mergeNodesOnCurrentLevel(); void _parse(const ls_std::byte_field& _data); static std::pair _parseAttribute(const ls_std::byte_field& _data); static std::list> _parseAttributes(ls_std::byte_field _data); size_t _parseClosingTag(const ls_std::byte_field& _data, std::string::size_type _index); size_t _parseDeclaration(const ls_std::byte_field& _data, std::string::size_type _index); size_t _parseOpeningTag(const ls_std::byte_field& _data, std::string::size_type _index); static ls_std::byte_field _parseTagName(const ls_std::byte_field& _data); size_t _parseValue(const ls_std::byte_field& _data, std::string::size_type _index); void _reset(); void _setMaxLevel(); }; } #endif