MUSX Document Model
Loading...
Searching...
No Matches
DocumentElement.h
1/*
2 * Copyright (C) 2026, Robert Patterson
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 * THE SOFTWARE.
21 */
22#pragma once
23
24#include <cassert>
25#include <memory>
26#include <stdexcept>
27
28#include "musx/dom/Fundamentals.h"
29
30namespace musx {
31namespace dom {
32
33class Document;
35using DocumentPtr = std::shared_ptr<Document>;
37using DocumentWeakPtr = std::weak_ptr<Document>;
38
46{
47public:
51 virtual ~DocumentElement() noexcept(false) = default;
52
59 {
60 auto document = m_document.lock();
61 MUSX_ASSERT_IF(!document) {
62 throw std::logic_error("Document pointer is no longer valid.");
63 }
64 return document;
65 }
66
70 Cmper getPartId() const { return m_partId; }
71
72protected:
79 DocumentElement(const DocumentWeakPtr& document, Cmper partId)
80 : m_document(document), m_partId(partId) {}
81
82 DocumentElement(const DocumentElement&) = default;
83 DocumentElement(DocumentElement&&) noexcept = default;
84
86 DocumentElement& operator=(const DocumentElement&) { return *this; }
87
89 DocumentElement& operator=(DocumentElement&&) noexcept { return *this; }
90
91private:
92 const DocumentWeakPtr m_document{};
93 const Cmper m_partId{};
94};
95
103{
104 Cmper getPartId() const = delete;
105
106public:
114};
115
116} // namespace dom
117} // namespace musx
Base for DOM classes that belong to a Document.
Definition DocumentElement.h:103
DocumentElementNoPart(const DocumentWeakPtr &document)
Constructs the document element (with no meaningful associated part)
Definition DocumentElement.h:112
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
DocumentElement(DocumentElement &&) noexcept=default
explicit default move constructor
DocumentElement(const DocumentWeakPtr &document, Cmper partId)
Constructs the document element.
Definition DocumentElement.h:79
DocumentElement(const DocumentElement &)=default
explicit default copy constructor
Cmper getPartId() const
Gets the part id associated with this instance.
Definition DocumentElement.h:70
virtual ~DocumentElement() noexcept(false)=default
Virtual destructor for polymorphic behavior.
DocumentElement & operator=(DocumentElement &&) noexcept
no-op move assignment operator allows subclasses to move their values.
Definition DocumentElement.h:89
constexpr Cmper SCORE_PARTID
The part id of the score.
Definition Fundamentals.h:79
uint16_t Cmper
Enigma "comperator" key type.
Definition Fundamentals.h:55
std::weak_ptr< Document > DocumentWeakPtr
Shared weak Document pointer.
Definition DocumentElement.h:37
std::shared_ptr< Document > DocumentPtr
Shared Document pointer.
Definition DocumentElement.h:35
object model for musx file (enigmaxml)
Definition BaseClasses.h:38