diff --git a/AGENTS.md b/AGENTS.md index 874b3c743..35dadf611 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -239,7 +239,9 @@ Dispatch `release.yml` against main, publish the draft that appears — alias is claimed twice, or if the declared capabilities exceed what the engines actually do. 2. For documents: subclass `internal::Document`; in its constructor build an - `ElementRegistry` and an `ElementAdapter` (pattern above). + `ElementRegistry` and an `ElementAdapter` (pattern above). It defaults to + read-only — override `is_editable`/`is_savable`/`save` only for an engine + that can write. 3. Implement the per-element adapters you can populate; the **generic HTML renderer then works for free**. 4. Register the factory (e.g. `oldms_file.cpp::document()` switches on diff --git a/src/odr/internal/common/document.cpp b/src/odr/internal/common/document.cpp index 5c34af2be..3ee647c15 100644 --- a/src/odr/internal/common/document.cpp +++ b/src/odr/internal/common/document.cpp @@ -1,5 +1,7 @@ #include +#include + #include namespace odr::internal { @@ -11,6 +13,20 @@ Document::Document(const FileType file_type, const DocumentType document_type, Document::~Document() = default; +bool Document::is_editable() const noexcept { return false; } + +bool Document::is_savable(const bool /*encrypted*/) const noexcept { + return false; +} + +void Document::save(std::ostream & /*out*/) const { + throw UnsupportedOperation(); +} + +void Document::save(std::ostream & /*out*/, const char * /*password*/) const { + throw UnsupportedOperation(); +} + FileType Document::file_type() const noexcept { return m_file_type; } DocumentType Document::document_type() const noexcept { diff --git a/src/odr/internal/common/document.hpp b/src/odr/internal/common/document.hpp index 78b9465ce..6af8d3ca0 100644 --- a/src/odr/internal/common/document.hpp +++ b/src/odr/internal/common/document.hpp @@ -19,6 +19,12 @@ class Document : public abstract::Document { std::shared_ptr files); ~Document() override; + /// Read-only, which every engine but odf and ooxml text is. + [[nodiscard]] bool is_editable() const noexcept override; + [[nodiscard]] bool is_savable(bool encrypted) const noexcept override; + void save(std::ostream &out) const override; + void save(std::ostream &out, const char *password) const override; + [[nodiscard]] FileType file_type() const noexcept final; [[nodiscard]] DocumentType document_type() const noexcept final; diff --git a/src/odr/internal/csv/csv_document.cpp b/src/odr/internal/csv/csv_document.cpp index fc4f86d07..fc0d30406 100644 --- a/src/odr/internal/csv/csv_document.cpp +++ b/src/odr/internal/csv/csv_document.cpp @@ -306,22 +306,6 @@ CsvDocument::CsvDocument(const abstract::File &file, m_element_adapter = std::make_unique(*this); } -bool CsvDocument::is_editable() const noexcept { return false; } - -bool CsvDocument::is_savable( - [[maybe_unused]] const bool encrypted) const noexcept { - return false; -} - -void CsvDocument::save(std::ostream & /*out*/) const { - throw UnsupportedOperation(); -} - -void CsvDocument::save(std::ostream & /*out*/, - const char * /*password*/) const { - throw UnsupportedOperation(); -} - std::string_view CsvDocument::cell(const std::uint32_t column, const std::uint32_t row) const { if (row >= m_rows.size()) { diff --git a/src/odr/internal/csv/csv_document.hpp b/src/odr/internal/csv/csv_document.hpp index 26bc142fe..d24bc5e13 100644 --- a/src/odr/internal/csv/csv_document.hpp +++ b/src/odr/internal/csv/csv_document.hpp @@ -28,12 +28,6 @@ class CsvDocument final : public internal::Document { CsvDocument(const abstract::File &file, TextEncoding encoding, Dialect dialect, bool skip_first_line); - [[nodiscard]] bool is_editable() const noexcept override; - [[nodiscard]] bool is_savable(bool encrypted) const noexcept override; - - void save(std::ostream &out) const override; - void save(std::ostream &out, const char *password) const override; - /// The cell's text, empty where a row stops short. [[nodiscard]] std::string_view cell(std::uint32_t column, std::uint32_t row) const; diff --git a/src/odr/internal/iwork/iwork_document.cpp b/src/odr/internal/iwork/iwork_document.cpp index 245ab3055..9a59ef14e 100644 --- a/src/odr/internal/iwork/iwork_document.cpp +++ b/src/odr/internal/iwork/iwork_document.cpp @@ -53,21 +53,6 @@ const ElementRegistry &Document::element_registry() const { return m_element_registry; } -bool Document::is_editable() const noexcept { return false; } - -bool Document::is_savable(const bool encrypted) const noexcept { - (void)encrypted; - return false; -} - -void Document::save(std::ostream & /*out*/) const { - throw UnsupportedOperation(); -} - -void Document::save(std::ostream & /*out*/, const char * /*password*/) const { - throw UnsupportedOperation(); -} - namespace { class ElementAdapter final : public abstract::ElementAdapter, diff --git a/src/odr/internal/iwork/iwork_document.hpp b/src/odr/internal/iwork/iwork_document.hpp index 75da7f178..3204a7999 100644 --- a/src/odr/internal/iwork/iwork_document.hpp +++ b/src/odr/internal/iwork/iwork_document.hpp @@ -19,12 +19,6 @@ class Document final : public internal::Document { [[nodiscard]] const ElementRegistry &element_registry() const; - [[nodiscard]] bool is_editable() const noexcept override; - [[nodiscard]] bool is_savable(bool encrypted) const noexcept override; - - void save(std::ostream &out) const override; - void save(std::ostream &out, const char *password) const override; - private: ElementRegistry m_element_registry; }; diff --git a/src/odr/internal/markdown/markdown_document.cpp b/src/odr/internal/markdown/markdown_document.cpp index 6e3d32587..d4daa6a93 100644 --- a/src/odr/internal/markdown/markdown_document.cpp +++ b/src/odr/internal/markdown/markdown_document.cpp @@ -34,21 +34,6 @@ const StyleRegistry &Document::style_registry() const { return m_style_registry; } -bool Document::is_editable() const noexcept { return false; } - -bool Document::is_savable(const bool encrypted) const noexcept { - (void)encrypted; - return false; -} - -void Document::save(std::ostream & /*out*/) const { - throw UnsupportedOperation(); -} - -void Document::save(std::ostream & /*out*/, const char * /*password*/) const { - throw UnsupportedOperation(); -} - namespace { class ElementAdapter final : public abstract::ElementAdapter, diff --git a/src/odr/internal/markdown/markdown_document.hpp b/src/odr/internal/markdown/markdown_document.hpp index a92401fd8..b3c1bec32 100644 --- a/src/odr/internal/markdown/markdown_document.hpp +++ b/src/odr/internal/markdown/markdown_document.hpp @@ -18,12 +18,6 @@ class Document final : public internal::Document { [[nodiscard]] const StyleRegistry &style_registry() const; - [[nodiscard]] bool is_editable() const noexcept override; - [[nodiscard]] bool is_savable(bool encrypted) const noexcept override; - - void save(std::ostream &out) const override; - void save(std::ostream &out, const char *password) const override; - private: ElementRegistry m_element_registry; StyleRegistry m_style_registry; diff --git a/src/odr/internal/oldms/presentation/ppt_document.cpp b/src/odr/internal/oldms/presentation/ppt_document.cpp index 475079959..9fa28936c 100644 --- a/src/odr/internal/oldms/presentation/ppt_document.cpp +++ b/src/odr/internal/oldms/presentation/ppt_document.cpp @@ -41,21 +41,6 @@ const StyleRegistry &Document::style_registry() const { return m_style_registry; } -bool Document::is_editable() const noexcept { return false; } - -bool Document::is_savable(const bool encrypted) const noexcept { - (void)encrypted; - return false; -} - -void Document::save(std::ostream & /*out*/) const { - throw UnsupportedOperation(); -} - -void Document::save(std::ostream & /*out*/, const char * /*password*/) const { - throw UnsupportedOperation(); -} - namespace { class ElementAdapter final : public abstract::ElementAdapter, diff --git a/src/odr/internal/oldms/presentation/ppt_document.hpp b/src/odr/internal/oldms/presentation/ppt_document.hpp index 6e2ed6395..267ff333b 100644 --- a/src/odr/internal/oldms/presentation/ppt_document.hpp +++ b/src/odr/internal/oldms/presentation/ppt_document.hpp @@ -18,12 +18,6 @@ class Document final : public internal::Document { [[nodiscard]] const StyleRegistry &style_registry() const; - [[nodiscard]] bool is_editable() const noexcept override; - [[nodiscard]] bool is_savable(bool encrypted) const noexcept override; - - void save(std::ostream &out) const override; - void save(std::ostream &out, const char *password) const override; - private: ElementRegistry m_element_registry; StyleRegistry m_style_registry; diff --git a/src/odr/internal/oldms/spreadsheet/xls_document.cpp b/src/odr/internal/oldms/spreadsheet/xls_document.cpp index 6798a9395..986c9abc7 100644 --- a/src/odr/internal/oldms/spreadsheet/xls_document.cpp +++ b/src/odr/internal/oldms/spreadsheet/xls_document.cpp @@ -37,21 +37,6 @@ const StyleRegistry &Document::style_registry() const { return m_style_registry; } -bool Document::is_editable() const noexcept { return false; } - -bool Document::is_savable(const bool encrypted) const noexcept { - (void)encrypted; - return false; -} - -void Document::save(std::ostream & /*out*/) const { - throw UnsupportedOperation(); -} - -void Document::save(std::ostream & /*out*/, const char * /*password*/) const { - throw UnsupportedOperation(); -} - namespace { class ElementAdapter final : public abstract::ElementAdapter, diff --git a/src/odr/internal/oldms/spreadsheet/xls_document.hpp b/src/odr/internal/oldms/spreadsheet/xls_document.hpp index e14168127..c430d5cf6 100644 --- a/src/odr/internal/oldms/spreadsheet/xls_document.hpp +++ b/src/odr/internal/oldms/spreadsheet/xls_document.hpp @@ -18,12 +18,6 @@ class Document final : public internal::Document { [[nodiscard]] const StyleRegistry &style_registry() const; - [[nodiscard]] bool is_editable() const noexcept override; - [[nodiscard]] bool is_savable(bool encrypted) const noexcept override; - - void save(std::ostream &out) const override; - void save(std::ostream &out, const char *password) const override; - private: ElementRegistry m_element_registry; StyleRegistry m_style_registry; diff --git a/src/odr/internal/oldms/text/doc_document.cpp b/src/odr/internal/oldms/text/doc_document.cpp index 31dec33ee..bb57bcf06 100644 --- a/src/odr/internal/oldms/text/doc_document.cpp +++ b/src/odr/internal/oldms/text/doc_document.cpp @@ -36,21 +36,6 @@ const StyleRegistry &Document::style_registry() const { return m_style_registry; } -bool Document::is_editable() const noexcept { return false; } - -bool Document::is_savable(const bool encrypted) const noexcept { - (void)encrypted; - return false; -} - -void Document::save(std::ostream & /*out*/) const { - throw UnsupportedOperation(); -} - -void Document::save(std::ostream & /*out*/, const char * /*password*/) const { - throw UnsupportedOperation(); -} - namespace { class ElementAdapter final : public abstract::ElementAdapter, diff --git a/src/odr/internal/oldms/text/doc_document.hpp b/src/odr/internal/oldms/text/doc_document.hpp index 19f9943ac..0227972fa 100644 --- a/src/odr/internal/oldms/text/doc_document.hpp +++ b/src/odr/internal/oldms/text/doc_document.hpp @@ -18,12 +18,6 @@ class Document final : public internal::Document { [[nodiscard]] const StyleRegistry &style_registry() const; - [[nodiscard]] bool is_editable() const noexcept override; - [[nodiscard]] bool is_savable(bool encrypted) const noexcept override; - - void save(std::ostream &out) const override; - void save(std::ostream &out, const char *password) const override; - private: ElementRegistry m_element_registry; StyleRegistry m_style_registry; diff --git a/src/odr/internal/ooxml/presentation/ooxml_presentation_document.cpp b/src/odr/internal/ooxml/presentation/ooxml_presentation_document.cpp index 078a21903..2eae7c387 100644 --- a/src/odr/internal/ooxml/presentation/ooxml_presentation_document.cpp +++ b/src/odr/internal/ooxml/presentation/ooxml_presentation_document.cpp @@ -1,7 +1,6 @@ #include #include -#include #include #include @@ -138,20 +137,6 @@ const ElementRegistry &Document::element_registry() const { return m_element_registry; } -bool Document::is_editable() const noexcept { return false; } - -bool Document::is_savable(const bool /*encrypted*/) const noexcept { - return false; -} - -void Document::save(std::ostream & /*out*/) const { - throw UnsupportedOperation(); -} - -void Document::save(std::ostream & /*out*/, const char * /*password*/) const { - throw UnsupportedOperation(); -} - namespace { class ElementAdapter final : public abstract::ElementAdapter, diff --git a/src/odr/internal/ooxml/presentation/ooxml_presentation_document.hpp b/src/odr/internal/ooxml/presentation/ooxml_presentation_document.hpp index e25f04bc6..3b99ef3ee 100644 --- a/src/odr/internal/ooxml/presentation/ooxml_presentation_document.hpp +++ b/src/odr/internal/ooxml/presentation/ooxml_presentation_document.hpp @@ -28,12 +28,6 @@ class Document final : public internal::Document { [[nodiscard]] PageLayout slide_page_layout(ElementIdentifier element_id) const; - [[nodiscard]] bool is_editable() const noexcept override; - [[nodiscard]] bool is_savable(bool encrypted) const noexcept override; - - void save(std::ostream &out) const override; - void save(std::ostream &out, const char *password) const override; - private: pugi::xml_document m_document_xml; std::unordered_map m_slides_xml; diff --git a/src/odr/internal/ooxml/spreadsheet/ooxml_spreadsheet_document.cpp b/src/odr/internal/ooxml/spreadsheet/ooxml_spreadsheet_document.cpp index 7cc761986..b18cc88a9 100644 --- a/src/odr/internal/ooxml/spreadsheet/ooxml_spreadsheet_document.cpp +++ b/src/odr/internal/ooxml/spreadsheet/ooxml_spreadsheet_document.cpp @@ -1,7 +1,6 @@ #include #include -#include #include #include @@ -69,20 +68,6 @@ const StyleRegistry &Document::style_registry() const { return m_style_registry; } -bool Document::is_editable() const noexcept { return false; } - -bool Document::is_savable(const bool /*encrypted*/) const noexcept { - return false; -} - -void Document::save(std::ostream & /*out*/) const { - throw UnsupportedOperation(); -} - -void Document::save(std::ostream & /*out*/, const char * /*password*/) const { - throw UnsupportedOperation(); -} - std::pair Document::parse_xml_(const AbsPath &path) { pugi::xml_document document = xml::parse(*m_files, path); diff --git a/src/odr/internal/ooxml/spreadsheet/ooxml_spreadsheet_document.hpp b/src/odr/internal/ooxml/spreadsheet/ooxml_spreadsheet_document.hpp index d8f6bda81..21e3d8ad2 100644 --- a/src/odr/internal/ooxml/spreadsheet/ooxml_spreadsheet_document.hpp +++ b/src/odr/internal/ooxml/spreadsheet/ooxml_spreadsheet_document.hpp @@ -21,12 +21,6 @@ class Document final : public internal::Document { [[nodiscard]] const ElementRegistry &element_registry() const; [[nodiscard]] const StyleRegistry &style_registry() const; - [[nodiscard]] bool is_editable() const noexcept override; - [[nodiscard]] bool is_savable(bool encrypted) const noexcept override; - - void save(std::ostream &out) const override; - void save(std::ostream &out, const char *password) const override; - private: XmlDocumentsAndRelations m_xml_documents_and_relations; SharedStrings m_shared_strings; diff --git a/src/odr/internal/rtf/rtf_document.cpp b/src/odr/internal/rtf/rtf_document.cpp index 595a4103a..260d715b2 100644 --- a/src/odr/internal/rtf/rtf_document.cpp +++ b/src/odr/internal/rtf/rtf_document.cpp @@ -33,21 +33,6 @@ const ElementRegistry &Document::element_registry() const { return m_element_registry; } -bool Document::is_editable() const noexcept { return false; } - -bool Document::is_savable(const bool encrypted) const noexcept { - (void)encrypted; - return false; -} - -void Document::save(std::ostream & /*out*/) const { - throw UnsupportedOperation(); -} - -void Document::save(std::ostream & /*out*/, const char * /*password*/) const { - throw UnsupportedOperation(); -} - namespace { class ElementAdapter final : public abstract::ElementAdapter, diff --git a/src/odr/internal/rtf/rtf_document.hpp b/src/odr/internal/rtf/rtf_document.hpp index 163f8e7dc..ffae470eb 100644 --- a/src/odr/internal/rtf/rtf_document.hpp +++ b/src/odr/internal/rtf/rtf_document.hpp @@ -17,12 +17,6 @@ class Document final : public internal::Document { [[nodiscard]] const ElementRegistry &element_registry() const; - [[nodiscard]] bool is_editable() const noexcept override; - [[nodiscard]] bool is_savable(bool encrypted) const noexcept override; - - void save(std::ostream &out) const override; - void save(std::ostream &out, const char *password) const override; - private: ElementRegistry m_element_registry; };