26#include "musx/dom/Document.h"
27#include "musx/factory/HeaderFactory.h"
28#include "musx/factory/PoolFactory.h"
29#include "musx/xml/XmlInterface.h"
40 using DocumentPtr = std::shared_ptr<Document>;
52 template <
typename XmlDocumentType>
56 static_assert(std::is_base_of<musx::xml::IXmlDocument, XmlDocumentType>::value,
57 "XmlReaderType must derive from IXmlDocument.");
59 std::unique_ptr<musx::xml::IXmlDocument> xmlDocument = std::make_unique<XmlDocumentType>();
60 xmlDocument->loadFromBuffer(data, size);
62 auto rootElement = xmlDocument->getRootElement();
63 if (!rootElement || rootElement->getTagName() !=
"finale") {
64 throw std::invalid_argument(
"Missing <finale> element.");
68 document->m_self = document;
69 document->m_partVoicingPolicy = partVoicingPolicy;
72 for (
auto element = rootElement->getFirstChildElement(); element; element = element->getNextSibling()) {
73 if (element->getTagName() ==
"header") {
75 }
else if (element->getTagName() ==
"options") {
77 }
else if (element->getTagName() ==
"others") {
79 }
else if (element->getTagName() ==
"details") {
81 }
else if (element->getTagName() ==
"entries") {
83 }
else if (element->getTagName() ==
"texts") {
87 if (!document->getHeader()) document->getHeader() = std::make_shared<musx::dom::Header>();
88 if (!document->getOptions()) document->getOptions() = std::make_shared<musx::dom::OptionsPool>(document);
89 if (!document->getOthers()) document->getOthers() = std::make_shared<musx::dom::OthersPool>(document);
90 if (!document->getDetails()) document->getDetails() = std::make_shared<musx::dom::DetailsPool>(document);
91 if (!document->getEntries()) document->getEntries() = std::make_shared<musx::dom::EntryPool>(document);
92 if (!document->getTexts()) document->getTexts() = std::make_shared<musx::dom::TextsPool>(document);
94#ifdef MUSX_DISPLAY_NODE_NAMES
98 document->m_instruments = document->createInstrumentMap(
SCORE_PARTID);
100 document->m_maxBlankPages = 0;
101 auto linkedParts = document->getOthers()->getArray<PartDefinition>(
SCORE_PARTID);
102 for (
const auto& part : linkedParts) {
103 auto mutablePart =
const_cast<PartDefinition*
>(part.get());
104 mutablePart->numberOfLeadingBlankPages = 0;
105 auto pages = document->getOthers()->getArray<Page>(part->getCmper());
106 mutablePart->numberOfPages = int(pages.size());
107 for (
const auto& page : pages) {
108 if (!page->isBlank()) {
111 mutablePart->numberOfLeadingBlankPages++;
113 if (mutablePart->numberOfLeadingBlankPages > document->m_maxBlankPages) {
114 document->m_maxBlankPages = part->numberOfLeadingBlankPages;
129 template <
typename XmlDocumentType>
133 return create<XmlDocumentType>(xmlBuffer.data(), xmlBuffer.size(), partVoicingPolicy);
Represents a document object that encapsulates the entire EnigmaXML structure.
Definition Document.h:92
static std::shared_ptr< PoolType > create(const XmlElementPtr &element, const dom::DocumentPtr &document, ElementLinker &elementLinker)
Creates a OthersPool object from an XML element.
Definition PoolFactory.h:68
Factory class for creating Document objects from XML.
Definition DocumentFactory.h:38
static DocumentPtr create(const char *data, size_t size, dom::PartVoicingPolicy partVoicingPolicy=dom::PartVoicingPolicy::Ignore)
Creates a Document object from an XML buffer.
Definition DocumentFactory.h:54
static DocumentPtr create(const std::vector< char > &xmlBuffer, dom::PartVoicingPolicy partVoicingPolicy=dom::PartVoicingPolicy::Ignore)
Creates a Document object from an XML buffer.
Definition DocumentFactory.h:131
A utility class for managing deferred relationships between elements during document construction.
Definition FactoryBase.h:72
void resolveAll(const dom::DocumentPtr &document)
Resolves all deferred relationships.
Definition FactoryBase.h:110
static std::shared_ptr< PoolType > create(const XmlElementPtr &element, const dom::DocumentPtr &document, ElementLinker &elementLinker)
Creates a OthersPool object from an XML element.
Definition PoolFactory.h:68
Factory base class.
Definition FactoryBase.h:134
static std::shared_ptr< PoolType > create(const XmlElementPtr &element, const dom::DocumentPtr &document, ElementLinker &elementLinker)
Creates a OthersPool object from an XML element.
Definition PoolFactory.h:68
static std::shared_ptr< PoolType > create(const XmlElementPtr &element, const dom::DocumentPtr &document, ElementLinker &elementLinker)
Creates a OthersPool object from an XML element.
Definition PoolFactory.h:68
static std::shared_ptr< PoolType > create(const XmlElementPtr &element, const dom::DocumentPtr &document, ElementLinker &elementLinker)
Creates a OthersPool object from an XML element.
Definition PoolFactory.h:68
@ Verbose
Informational messages that should only displayed when verbose logging is requested.
static void log(LogLevel level, const std::string &message)
Logs a message with a specific severity level.
Definition Logger.h:87
constexpr Cmper SCORE_PARTID
The part id of the score.
Definition Fundamentals.h:79
PartVoicingPolicy
Controls whether Finale-style part voicing is applied when iterating entries via musx::dom::details::...
Definition Document.h:75
object model for musx file (enigmaxml)
Definition BaseClasses.h:36