Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions src/odr/internal/common/document.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include <odr/internal/common/document.hpp>

#include <odr/exceptions.hpp>

#include <odr/internal/abstract/filesystem.hpp>

namespace odr::internal {
Expand All @@ -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 {
Expand Down
6 changes: 6 additions & 0 deletions src/odr/internal/common/document.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ class Document : public abstract::Document {
std::shared_ptr<abstract::ReadableFilesystem> 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;

Expand Down
16 changes: 0 additions & 16 deletions src/odr/internal/csv/csv_document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,22 +306,6 @@ CsvDocument::CsvDocument(const abstract::File &file,
m_element_adapter = std::make_unique<ElementAdapter>(*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()) {
Expand Down
6 changes: 0 additions & 6 deletions src/odr/internal/csv/csv_document.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
15 changes: 0 additions & 15 deletions src/odr/internal/iwork/iwork_document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 0 additions & 6 deletions src/odr/internal/iwork/iwork_document.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
15 changes: 0 additions & 15 deletions src/odr/internal/markdown/markdown_document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 0 additions & 6 deletions src/odr/internal/markdown/markdown_document.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
15 changes: 0 additions & 15 deletions src/odr/internal/oldms/presentation/ppt_document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 0 additions & 6 deletions src/odr/internal/oldms/presentation/ppt_document.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
15 changes: 0 additions & 15 deletions src/odr/internal/oldms/spreadsheet/xls_document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 0 additions & 6 deletions src/odr/internal/oldms/spreadsheet/xls_document.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
15 changes: 0 additions & 15 deletions src/odr/internal/oldms/text/doc_document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 0 additions & 6 deletions src/odr/internal/oldms/text/doc_document.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include <odr/internal/ooxml/presentation/ooxml_presentation_document.hpp>

#include <odr/document_path.hpp>
#include <odr/exceptions.hpp>
#include <odr/file.hpp>
#include <odr/table_dimension.hpp>

Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string, pugi::xml_document> m_slides_xml;
Expand Down
15 changes: 0 additions & 15 deletions src/odr/internal/ooxml/spreadsheet/ooxml_spreadsheet_document.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include <odr/internal/ooxml/spreadsheet/ooxml_spreadsheet_document.hpp>

#include <odr/document_path.hpp>
#include <odr/exceptions.hpp>
#include <odr/file.hpp>
#include <odr/table_position.hpp>

Expand Down Expand Up @@ -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<pugi::xml_document &, Relations &>
Document::parse_xml_(const AbsPath &path) {
pugi::xml_document document = xml::parse(*m_files, path);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
15 changes: 0 additions & 15 deletions src/odr/internal/rtf/rtf_document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 0 additions & 6 deletions src/odr/internal/rtf/rtf_document.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
Loading