24#ifdef MUSX_USE_PUGIXML
30#include "XmlInterface.h"
49 const ::pugi::xml_attribute m_attribute;
55 explicit Attribute(::pugi::xml_attribute attr) : m_attribute(attr) {}
57 std::string
getName()
const override {
return m_attribute.name(); }
58 std::string
getValue()
const override {
return m_attribute.value(); }
61 ::pugi::xml_attribute next = m_attribute.next_attribute();
62 return next ? std::make_shared<Attribute>(next) :
nullptr;
70 const ::pugi::xml_node m_element;
72 static const char* tagPtr(
const std::string& tagName) {
73 return tagName.empty() ? nullptr : tagName.c_str();
80 explicit Element(::pugi::xml_node elem) : m_element(elem) {}
82 std::string
getTagName()
const override {
return m_element.name(); }
85 return m_element.child_value();
89 ::pugi::xml_attribute attr = m_element.first_attribute();
90 return attr ? std::make_shared<Attribute>(attr) :
nullptr;
93 std::shared_ptr<IXmlAttribute>
findAttribute(
const std::string& name)
const override {
94 ::pugi::xml_attribute attr = m_element.attribute(name.c_str());
95 return attr ? std::make_shared<Attribute>(attr) :
nullptr;
99 ::pugi::xml_node child = tagPtr(tagName) ? m_element.child(tagPtr(tagName)) : m_element.first_child();
100 return child ? std::make_shared<Element>(child) : nullptr;
103 std::shared_ptr<IXmlElement>
getNextSibling(
const std::string& tagName = {})
const override {
104 ::pugi::xml_node sibling = tagPtr(tagName) ? m_element.next_sibling(tagPtr(tagName)) : m_element.next_sibling();
105 return sibling ? std::make_shared<Element>(sibling) : nullptr;
109 ::pugi::xml_node sibling = tagPtr(tagName) ? m_element.previous_sibling(tagPtr(tagName)) : m_element.previous_sibling();
110 return sibling ? std::make_shared<Element>(sibling) : nullptr;
113 std::shared_ptr<IXmlElement>
getParent()
const override {
114 ::pugi::xml_node parent = m_element.parent();
115 return parent && parent.type() == ::pugi::node_element ? std::make_shared<Element>(parent) :
nullptr;
123 ::pugi::xml_document m_document;
127 ::pugi::xml_parse_result result = m_document.load_string(xmlContent.c_str());
134 ::pugi::xml_parse_result result = m_document.load_buffer(xmlContent.data(), xmlContent.size());
141 ::pugi::xml_node root = m_document.document_element();
142 return root ? std::make_shared<Element>(root) :
nullptr;
Interface for an XML attribute.
Definition XmlInterface.h:65
Interface for an XML document.
Definition XmlInterface.h:230
Interface for an XML element.
Definition XmlInterface.h:133
Exception for load xml error.
Definition XmlInterface.h:46
Implementation of IXmlAttribute using PugiXML.
Definition PugiXmlImpl.h:48
std::string getValue() const override
Gets the value of the attribute.
Definition PugiXmlImpl.h:58
std::shared_ptr< IXmlAttribute > nextAttribute() const override
Advances to the next attribute.
Definition PugiXmlImpl.h:60
std::string getName() const override
Gets the name of the attribute.
Definition PugiXmlImpl.h:57
Attribute(::pugi::xml_attribute attr)
Constructor.
Definition PugiXmlImpl.h:55
Implementation of IXmlDocument using PugiXML.
Definition PugiXmlImpl.h:122
void loadFromString(const std::string &xmlContent) override
Loads XML content from a string.
Definition PugiXmlImpl.h:126
std::shared_ptr< IXmlElement > getRootElement() const override
Gets the root element of the document.
Definition PugiXmlImpl.h:140
void loadFromString(const std::vector< char > &xmlContent) override
Loads XML content from a vector of characters.
Definition PugiXmlImpl.h:133
Implementation of IXmlElement using PugiXML.
Definition PugiXmlImpl.h:69
std::shared_ptr< IXmlElement > getFirstChildElement(const std::string &tagName={}) const override
Finds the first child element.
Definition PugiXmlImpl.h:98
Element(::pugi::xml_node elem)
Constructor.
Definition PugiXmlImpl.h:80
std::string getTagName() const override
Gets the tag name of the element.
Definition PugiXmlImpl.h:82
std::string getText() const override
Gets the text content of the element.
Definition PugiXmlImpl.h:84
std::shared_ptr< IXmlAttribute > getFirstAttribute() const override
Gets the first attribute.
Definition PugiXmlImpl.h:88
std::shared_ptr< IXmlElement > getParent() const override
Gets the parent element.
Definition PugiXmlImpl.h:113
std::shared_ptr< IXmlElement > getPreviousSibling(const std::string &tagName={}) const override
Gets the previous sibling element.
Definition PugiXmlImpl.h:108
std::shared_ptr< IXmlElement > getNextSibling(const std::string &tagName={}) const override
Gets the next sibling element.
Definition PugiXmlImpl.h:103
std::shared_ptr< IXmlAttribute > findAttribute(const std::string &name) const override
Finds the first attribute.
Definition PugiXmlImpl.h:93
object model for musx file (enigmaxml)
Definition BaseClasses.h:32