24#include "FactoryBase.h"
25#include "TypeRegistry.h"
26#include "musx/xml/XmlInterface.h"
27#include "musx/dom/BaseClasses.h"
28#include "musx/dom/ObjectPool.h"
29#include "musx/dom/Document.h"
31#ifdef MUSX_DISPLAY_NODE_NAMES
49template<
typename DerivedType,
typename ObjectBase,
typename PoolType>
70 auto pool = std::make_shared<PoolType>();
72#ifdef MUSX_DISPLAY_NODE_NAMES
73 std::set<std::string> alreadyDisplayed;
79 for (
auto childElement = element->getFirstChildElement(); childElement; childElement = childElement->getNextSibling()) {
80 auto basePtr = DerivedType::extractFromXml(childElement, document, elementLinker, pool);
82#ifdef MUSX_DISPLAY_NODE_NAMES
83 auto it = alreadyDisplayed.find(childElement->getTagName());
84 if (it == alreadyDisplayed.end()) {
86 alreadyDisplayed.emplace(childElement->getTagName());
89 auto typedPtr = std::dynamic_pointer_cast<ObjectBase>(basePtr);
91 if constexpr (std::is_same_v<PoolType, EntryPool>) {
92 pool->add(typedPtr->getEntryNumber(), typedPtr);
94 pool->add(childElement->getTagName(), typedPtr);
160 auto cmperAttribute = element->findAttribute(
"cmper");
161 if (!cmperAttribute) {
162 throw std::invalid_argument(
"missing cmper for others element " + element->getTagName());
164 auto inciAttribute = element->findAttribute(
"inci");
167 document, cmperAttribute->getValueAs<
dom::Cmper>(), inciAttribute->getValueAs<
dom::Inci>());
171 document, cmperAttribute->getValueAs<
dom::Cmper>());
203 std::optional<dom::Inci> inci;
204 if (
auto inciAttribute = element->findAttribute(
"inci")) {
205 inci = inciAttribute->getValueAs<
dom::Inci>();
207 if (
auto entnumAttribute = element->findAttribute(
"entnum")) {
208 if (inci.has_value()) {
216 auto cmper1Attribute = element->findAttribute(
"cmper1");
217 if (!cmper1Attribute) {
218 throw std::invalid_argument(
"missing cmper1 for details element " + element->getTagName());
220 auto cmper2Attribute = element->findAttribute(
"cmper2");
221 if (!cmper2Attribute) {
222 throw std::invalid_argument(
"missing cmper2 for details element " + element->getTagName());
224 if (inci.has_value()) {
226 document, cmper1Attribute->getValueAs<
dom::Cmper>(), cmper2Attribute->getValueAs<
dom::Cmper>(), inci.value());
229 document, cmper1Attribute->getValueAs<
dom::Cmper>(), cmper2Attribute->getValueAs<
dom::Cmper>());
259 auto entnumAttr = element->findAttribute(
"entnum");
261 throw std::invalid_argument(
"missing entum attribute for entry");
263 auto prevAttr = element->findAttribute(
"prev");
265 throw std::invalid_argument(
"missing prev attribute for entry");
267 auto nextAttr = element->findAttribute(
"next");
269 throw std::invalid_argument(
"missing next attribute for entry");
305 auto textAttributeName = [element]() -> std::string {
311 auto textAttribute = element->findAttribute(textAttributeName);
312 if (!textAttribute) {
313 throw std::invalid_argument(
"Element <" + element->getTagName() +
"> does not have attribute " + textAttributeName);
315 auto textNumber = [textAttribute]() ->
Cmper {
316 if (textAttribute->getName() ==
"type") {
317 return toCmper(textAttribute->getValue());
319 return textAttribute->getValueAs<
Cmper>();
325 static Cmper toCmper(
const std::string& type) {
328 if (type ==
"title") {
329 return Cmper(TextType::Title);
330 }
else if (type ==
"composer") {
331 return Cmper(TextType::Composer);
332 }
else if (type ==
"copyright") {
333 return Cmper(TextType::Copyright);
334 }
else if (type ==
"description") {
335 return Cmper(TextType::Description);
336 }
else if (type ==
"lyricist") {
337 return Cmper(TextType::Lyricist);
338 }
else if (type ==
"arranger") {
339 return Cmper(TextType::Arranger);
340 }
else if (type ==
"subtitle") {
341 return Cmper(TextType::Subtitle);
343 throw std::invalid_argument(
"Unknown type attribute value for <fileInfo> node: " + type);
static constexpr std::string_view XmlNodeName
The XML node name for this type.
Definition Texts.h:110
TextType
Represents various text types for the file header.
Definition Texts.h:87
Factory class for creating Details objects from XML.
Definition PoolFactory.h:184
static auto extractFromXml(const XmlElementPtr &element, const dom::DocumentPtr &document, ElementLinker &elementLinker, const DetailsPoolPtr &pool)
Extracts an OthersBase object from an XML element.
Definition PoolFactory.h:201
A utility class for managing deferred relationships between elements during document construction.
Definition FactoryBase.h:70
Factory class for creating Entry objects from XML.
Definition PoolFactory.h:241
static auto extractFromXml(const XmlElementPtr &element, const dom::DocumentPtr &document, ElementLinker &elementLinker, const EntryPoolPtr &pool)
Extracts an Entry object from an XML element.
Definition PoolFactory.h:257
Factory base class.
Definition FactoryBase.h:132
Factory class for creating Options objects from XML.
Definition PoolFactory.h:111
static auto extractFromXml(const XmlElementPtr &element, const dom::DocumentPtr &document, ElementLinker &elementLinker, const OptionsPoolPtr &pool)
Extracts an OptionsBase object from an XML element.
Definition PoolFactory.h:127
Factory class for creating Others objects from XML.
Definition PoolFactory.h:141
static auto extractFromXml(const XmlElementPtr &element, const dom::DocumentPtr &document, ElementLinker &elementLinker, const OthersPoolPtr &pool)
Extracts an OthersBase object from an XML element.
Definition PoolFactory.h:158
Factory class for creating a dom::ObjectPool from XML.
Definition PoolFactory.h:51
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 Texts objects from XML.
Definition PoolFactory.h:286
static auto extractFromXml(const XmlElementPtr &element, const dom::DocumentPtr &document, ElementLinker &elementLinker, const TextsPoolPtr &pool)
Extracts a TextsBase object from an XML element.
Definition PoolFactory.h:303
static std::shared_ptr< Base > createInstance(const PoolPtr &pool, const XmlElementPtr &node, ElementLinker &elementLinker, const DocumentPtr &document, Args &&... args)
Creates an instance of the registered type corresponding to the provided node name.
Definition TypeRegistry.h:106
@ 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
std::shared_ptr< OthersPool > OthersPoolPtr
Shared OthersPool pointer.
Definition ObjectPool.h:327
std::shared_ptr< DetailsPool > DetailsPoolPtr
Shared DetailsPool pointer.
Definition ObjectPool.h:378
int16_t Inci
Enigma "incident" key type.
Definition Fundamentals.h:56
uint16_t Cmper
Enigma "comperator" key type.
Definition Fundamentals.h:55
std::shared_ptr< TextsPool > TextsPoolPtr
Shared OthersPool pointer.
Definition ObjectPool.h:420
std::shared_ptr< OptionsPool > OptionsPoolPtr
Shared OptionsPool pointer.
Definition ObjectPool.h:303
int32_t EntryNumber
Entry identifier.
Definition Fundamentals.h:68
std::shared_ptr< Document > DocumentPtr
Shared Document pointer.
Definition BaseClasses.h:55
std::shared_ptr< EntryPool > EntryPoolPtr
Shared EntryPool pointer.
Definition ObjectPool.h:394
std::shared_ptr< IXmlElement > XmlElementPtr
shared pointer to IXmlElement
Definition XmlInterface.h:121
object model for musx file (enigmaxml)
Definition BaseClasses.h:32