28#include <unordered_set>
31#include "musx/dom/Fundamentals.h"
32#include "musx/xml/XmlInterface.h"
33#include "musx/util/EnigmaString.h"
34#include "musx/util/Logger.h"
35#include "DocumentElement.h"
36#include "MusxInstance.h"
52 using std::runtime_error::runtime_error;
55#ifndef DOXYGEN_SHOULD_IGNORE_THIS
57struct PartContextRebinder
59 static void rebind(
const std::shared_ptr<T>&) {}
62class PartContextCloner {
65 static void setRequestedPartId(
const std::shared_ptr<T>& obj, Cmper partId)
67 obj->setRequestedPartId(partId);
71 static std::shared_ptr<T> copyWithPartId(
const std::shared_ptr<const T>& obj, Cmper partId)
73 auto result = std::make_shared<T>(*obj);
74 setRequestedPartId(result, partId);
75 PartContextRebinder<T>::rebind(result);
89 Cmper getPartId()
const =
delete;
128 m_unlinkedNodes.insert(nodeName);
132 virtual void integrityCheck([[maybe_unused]]
const std::shared_ptr<EnigmaBase>& ptrToThis) { }
169 Cmper getSourcePartId()
const =
delete;
193 Cmper getSourcePartId()
const =
delete;
203 if (
this != &other) {
212 if (
this != &other) {
229 template <
typename ParentClass = EnigmaBase>
232 auto result = m_parent.lock();
233 MUSX_ASSERT_IF (!result) {
234 throw std::logic_error(
"Attempt to get parent of contained class, but the parent is no longer allocated.");
236 if constexpr (std::is_same_v<EnigmaBase, ParentClass>) {
239 return std::dynamic_pointer_cast<const ParentClass>(result);
253 Cmper getSourcePartId()
const =
delete;
276 void setRequestedPartId(
Cmper newValue) { m_requestedPartId = newValue; }
278 friend class PartContextCloner;
291 :
EnigmaBase(document, partId, shareMode), m_requestedPartId(partId), m_cmper(cmper), m_inci(inci) {}
296 if (
this != &other) {
304 if (
this != &other) {
326 std::optional<Inci>
getInci()
const {
return m_inci; }
334 Cmper m_requestedPartId{};
336 std::optional<Inci> m_inci;
342template <
typename ElementType,
size_t REQUIRED_SIZE = 0>
346 virtual std::string_view xmlTag()
const = 0;
351 :
OthersBase(document, partId, shareMode, cmper)
362 const auto& v = this->
values;
363 return std::find(v.begin(), v.end(), value) != v.end();
370 if constexpr (REQUIRED_SIZE > 0) {
371 const size_t originalSize =
values.size();
372 values.resize(REQUIRED_SIZE);
373 if (originalSize < REQUIRED_SIZE) {
374 MUSX_INTEGRITY_ERROR(
"Array with xml tag " + std::string(xmlTag()) +
" and cmper " + std::to_string(
getCmper())
375 +
" has fewer than " + std::to_string(REQUIRED_SIZE) +
" elements.");
390 :
OthersBase(document, partId, shareMode, cmper)
408 void setRequestedPartId(
Cmper newValue) { m_requestedPartId = newValue; }
410 friend class PartContextCloner;
424 :
EnigmaBase(document, partId, shareMode), m_requestedPartId(partId), m_cmper1(cmper1), m_cmper2(cmper2), m_inci(inci) {}
429 if (
this != &other) {
437 if (
this != &other) {
460 std::optional<Inci>
getInci()
const {
return m_inci; }
468 Cmper m_requestedPartId{};
471 std::optional<Inci> m_inci;
510 template <
typename EDUP,
typename EDDOWN,
typename EDBASE>
527template <
typename ElementType,
size_t REQUIRED_SIZE = 0>
531 virtual std::string_view xmlTag()
const = 0;
536 :
DetailsBase(document, partId, shareMode, cmper1, cmper2)
547 if constexpr (REQUIRED_SIZE > 0) {
548 const size_t originalSize =
values.size();
549 values.resize(REQUIRED_SIZE);
550 if (originalSize < REQUIRED_SIZE) {
551 MUSX_INTEGRITY_ERROR(
"Array with xml tag " + std::string(xmlTag()) +
" and cmpers [" + std::to_string(
getCmper1()) +
", " + std::to_string(
getCmper2())
552 +
"] has fewer than " + std::to_string(REQUIRED_SIZE) +
" elements.");
578 Cmper getSourcePartId()
const =
delete;
590 :
EnigmaBase(document, partId, shareMode), m_textNumber(textNumber) {}
EnigmaBase class for classes that are commonly used among others, details, entries,...
Definition BaseClasses.h:168
CommonClassBase(const DocumentWeakPtr &document)
Constructs a CommonClassBase object.
Definition BaseClasses.h:177
EnigmaBase class for classes that are contained by other classes.
Definition BaseClasses.h:192
ContainedClassBase & operator=(ContainedClassBase &&other) noexcept
Move assignment preserves the destination's parent while allowing subclasses to move their values.
Definition BaseClasses.h:210
ContainedClassBase(const MusxInstance< EnigmaBase > &parent)
Constructs a ContainedClassBase object.
Definition BaseClasses.h:224
ContainedClassBase & operator=(const ContainedClassBase &other)
Assignment preserves the destination's parent while allowing subclasses to copy their values.
Definition BaseClasses.h:201
MusxInstance< ParentClass > getParent() const
Get the parent.
Definition BaseClasses.h:230
Template pattern for DetailsBase items consisting of an array of a single item.
Definition BaseClasses.h:529
DetailsArray(const DocumentWeakPtr &document, Cmper partId, ShareMode shareMode, Cmper cmper1, Cmper cmper2)
Constructor function.
Definition BaseClasses.h:535
std::vector< ElementType > values
Definition BaseClasses.h:540
void integrityCheck(const std::shared_ptr< EnigmaBase > &ptrToThis) override
Override of EnigmaBase::integrityCheck.
Definition BaseClasses.h:544
EnigmaBase class for all "details" types.
Definition BaseClasses.h:406
DetailsBase & operator=(const DetailsBase &other)
Assignment operator delegates to base, preserving OthersBase state.
Definition BaseClasses.h:427
DetailsBase(const DocumentWeakPtr &document, Cmper partId, ShareMode shareMode, Cmper cmper1, Cmper cmper2, std::optional< Inci > inci=std::nullopt)
Constructs a DetailsBase object.
Definition BaseClasses.h:423
DetailsBase(DetailsBase &&) noexcept=default
explicit default move constructor
Cmper getCmper1() const
Gets the cmper1 key value.
Definition BaseClasses.h:450
DetailsBase(const DetailsBase &)=default
explicit default copy constructor
DetailsBase & operator=(DetailsBase &&other) noexcept
Assignment operator delegates to base, preserving OthersBase state.
Definition BaseClasses.h:435
Cmper getRequestedPartId() const
If this instance was retrieved from an object pool, it contains the part ID that was used to retrieve...
Definition BaseClasses.h:465
Cmper getCmper2() const
Gets the cmper2 key value.
Definition BaseClasses.h:455
std::optional< Inci > getInci() const
Gets the optional array index (inci).
Definition BaseClasses.h:460
Base for DOM classes that belong to a Document.
Definition DocumentElement.h:46
DocumentPtr getDocument() const
Gets a reference to the Document.
Definition DocumentElement.h:58
Cmper getPartId() const
Gets the part id associated with this instance.
Definition DocumentElement.h:70
Base for DOM classes that are represented in EnigmaData.
Definition BaseClasses.h:88
virtual bool requireAllFields() const
Returns true if all fields are required for valid input.
Definition BaseClasses.h:135
EnigmaBase & operator=(const EnigmaBase &)
no-op copy assignment operator allows subclasses to copy their values.
Definition BaseClasses.h:152
ShareMode getShareMode() const
Gets the sharing mode for this instance.
Definition BaseClasses.h:116
std::set< std::string > SharedNodes
The container type for shared nodes.
Definition BaseClasses.h:93
const SharedNodes & getUnlinkedNodes() const
Gets the unlinked nodes for this instance. (Only populated for ShareMode::Partial)
Definition BaseClasses.h:121
EnigmaBase(const EnigmaBase &)=default
explicit default copy constructor
void addUnlinkedNode(const std::string &nodeName)
Adds a shared node for this instance.
Definition BaseClasses.h:126
EnigmaBase & operator=(EnigmaBase &&) noexcept
no-op move assignment operator allows subclasses to move their values.
Definition BaseClasses.h:155
EnigmaBase(const DocumentWeakPtr &document, Cmper partId, ShareMode shareMode)
Constructs the base class.
Definition BaseClasses.h:145
ShareMode
Describes how this instance is shared between part and score.
Definition BaseClasses.h:98
EnigmaBase(EnigmaBase &&) noexcept=default
explicit default move constructor
Cmper getSourcePartId() const
Gets the source partId for this instance. If an instance is fully shared with the score,...
Definition BaseClasses.h:111
virtual void integrityCheck(const std::shared_ptr< EnigmaBase > &ptrToThis)
Performs a final consistency check after population.
Definition BaseClasses.h:132
EnigmaBase class for all "details" types that use entnum rather than cmper and cmper.
Definition BaseClasses.h:478
EntryDetailsBase(const DocumentWeakPtr &document, Cmper partId, ShareMode shareMode, EntryNumber entnum, std::optional< Inci > inci=std::nullopt)
Constructs a EntryDetailsBase object.
Definition BaseClasses.h:500
EntryNumber getEntryNumber() const
Gets the entnum key value.
Definition BaseClasses.h:517
StemSelection
The options for choosing which version to retrieve for stem-specific details.
Definition BaseClasses.h:483
@ DownStem
retrieve the downstem version
@ MatchEntry
match entry's stem direction
@ UpStem
retrieve the upstem version
@ Any
retrieve the first one encountered (starting with upstem)
static MusxInstance< EDBASE > getStemDependentDetail(const EntryInfoPtr &entryInfo, StemSelection stemSelection)
Implement retrieval of stem-specific details. (Actual functions are defined per stem-specific class)
Definition Details.cpp:48
Wraps a frame of shared_ptr<const EntryInfo> and an index for per entry access. This class manages ow...
Definition Entries.h:534
Represents the default font settings for a particular element type.
Definition CommonClasses.h:104
EnigmaBase class note details. Note details are entry details associated with a note ID.
Definition BaseClasses.h:560
virtual NoteNumber getNoteId() const =0
Required virtual function that returns the note id.
EnigmaBase class for all "options" types.
Definition BaseClasses.h:252
OptionsBase(const DocumentWeakPtr &document, Cmper partId, ShareMode shareMode)
Constructs the OptionsBase and validates XmlNodeName in the derived class.
Definition BaseClasses.h:263
Template pattern for OthersBase items consisting of an array of a single item.
Definition BaseClasses.h:344
void integrityCheck(const std::shared_ptr< EnigmaBase > &ptrToThis) override
Override of EnigmaBase::integrityCheck.
Definition BaseClasses.h:367
std::vector< ElementType > values
Definition BaseClasses.h:355
OthersArray(const DocumentWeakPtr &document, Cmper partId, ShareMode shareMode, Cmper cmper)
Constructor function.
Definition BaseClasses.h:350
bool containsValue(const ElementType &value) const noexcept
Returns true if the array contains the specified value.
Definition BaseClasses.h:360
EnigmaBase class for all "others" types.
Definition BaseClasses.h:274
OthersBase & operator=(OthersBase &&other) noexcept
Assignment operator delegates to base, preserving OthersBase state.
Definition BaseClasses.h:302
OthersBase & operator=(const OthersBase &other)
Assignment operator delegates to base, preserving OthersBase state.
Definition BaseClasses.h:294
Cmper getRequestedPartId() const
If this instance was retrieved from an object pool, it contains the part ID that was used to retrieve...
Definition BaseClasses.h:331
std::optional< Inci > getInci() const
Gets the optional array index (inci).
Definition BaseClasses.h:326
OthersBase(OthersBase &&) noexcept=default
explicit default move constructor
OthersBase(const DocumentWeakPtr &document, Cmper partId, ShareMode shareMode, Cmper cmper, std::optional< Inci > inci=std::nullopt)
Constructs an OthersBase object.
Definition BaseClasses.h:290
Cmper getCmper() const
Gets the cmper key value.
Definition BaseClasses.h:319
OthersBase(const OthersBase &)=default
explicit default copy constructor
Many element names are embedded directly in top-level xml tags. This encapsulates that pattern.
Definition BaseClasses.h:386
static const xml::XmlElementArray< OthersName > & xmlMappingArray()
Required for musx::factory::FieldPopulator.
OthersName(const DocumentWeakPtr &document, Cmper partId, ShareMode shareMode, Cmper cmper)
Constructor function.
Definition BaseClasses.h:389
std::string name
the name
Definition BaseClasses.h:394
EnigmaBase class for all text blocks.
Definition BaseClasses.h:577
Cmper getTextNumber() const
Returns the raw text number.
Definition BaseClasses.h:597
util::EnigmaParsingContext getRawTextCtx(const MusxInstance< TextsBase > &ptrToThis, Cmper forPartId, std::optional< Cmper > forPageId=std::nullopt, util::EnigmaString::TextInsertCallback defaultInsertFunc=util::EnigmaString::defaultInsertsCallback) const
Gets the raw text block.
Definition Texts.cpp:36
std::string text
Raw Enigma string (with Enigma string tags), encoded UTF-8.
Definition BaseClasses.h:592
TextsBase(const DocumentWeakPtr &document, Cmper partId, ShareMode shareMode, Cmper textNumber)
Constructs a TextsBase object.
Definition BaseClasses.h:589
void setTextNumber(Cmper textNumber)
Sets the raw text number.
Definition BaseClasses.h:602
Exception for integrity errors. (Used when MUSX_THROW_ON_INTEGRITY_CHECK_FAIL is defined....
Definition BaseClasses.h:50
Wrapper class for interpreting and rendering Enigma-style strings with insert handling.
Definition EnigmaString.h:430
static TextInsertCallback defaultInsertsCallback
Inserts callback to take all default insert subsitutions determined by parseEnigmaText.
Definition EnigmaString.h:351
std::function< std::optional< std::string >(const std::vector< std::string > &parsedCommand)> TextInsertCallback
Iteration function type that the parser calls back when it encounters an Enigma text insert that requ...
Definition EnigmaString.h:348
std::shared_ptr< const T > MusxInstance
Defines the type of a musx instance stored in a pool.
Definition MusxInstance.h:40
constexpr Cmper SCORE_PARTID
The part id of the score.
Definition Fundamentals.h:81
uint16_t Cmper
Enigma "comperator" key type.
Definition Fundamentals.h:57
std::weak_ptr< Document > DocumentWeakPtr
Shared weak Document pointer.
Definition DocumentElement.h:37
int32_t EntryNumber
Entry identifier.
Definition Fundamentals.h:71
uint16_t NoteNumber
Note identifier.
Definition Fundamentals.h:72
std::weak_ptr< const T > MusxInstanceWeak
Defines a weak ptr to the type of a musx instance stored in a pool.
Definition MusxInstance.h:45
std::vector< XmlElementDescriptor< T > > XmlElementArray
an array type for XmlElementDescriptor instances.
Definition XmlInterface.h:127
object model for musx file (enigmaxml)
Definition BaseClasses.h:38