Skip to content

Commit

Permalink
wire element id
Browse files Browse the repository at this point in the history
  • Loading branch information
andiwand committed Nov 29, 2023
1 parent 4812d0e commit ee95e28
Show file tree
Hide file tree
Showing 20 changed files with 234 additions and 149 deletions.
108 changes: 74 additions & 34 deletions src/odr/document_element.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,15 @@ namespace odr {
Element::Element() = default;

Element::Element(const internal::abstract::Document *document,
internal::abstract::Element *element)
: m_document{document}, m_element{element} {}
internal::abstract::Element *element,
ElementIdentifier elementId)
: m_document{document}, m_element{element}, m_elementId{elementId} {}

Element::Element(
const internal::abstract::Document *document,
std::pair<internal::abstract::Element *, ElementIdentifier> element)
: m_document{document}, m_element{element.first}, m_elementId{
element.second} {}

bool Element::operator==(const Element &rhs) const {
return m_element == rhs.m_element;
Expand Down Expand Up @@ -53,49 +60,69 @@ Element Element::next_sibling() const {
: Element();
}

TextRoot Element::text_root() const { return {m_document, m_element}; }
TextRoot Element::text_root() const {
return {m_document, m_element, m_elementId};
}

Slide Element::slide() const { return {m_document, m_element}; }
Slide Element::slide() const { return {m_document, m_element, m_elementId}; }

Sheet Element::sheet() const { return {m_document, m_element}; }
Sheet Element::sheet() const { return {m_document, m_element, m_elementId}; }

Page Element::page() const { return {m_document, m_element}; }
Page Element::page() const { return {m_document, m_element, m_elementId}; }

MasterPage Element::master_page() const { return {m_document, m_element}; }
MasterPage Element::master_page() const {
return {m_document, m_element, m_elementId};
}

LineBreak Element::line_break() const { return {m_document, m_element}; }
LineBreak Element::line_break() const {
return {m_document, m_element, m_elementId};
}

Paragraph Element::paragraph() const { return {m_document, m_element}; }
Paragraph Element::paragraph() const {
return {m_document, m_element, m_elementId};
}

Span Element::span() const { return {m_document, m_element}; }
Span Element::span() const { return {m_document, m_element, m_elementId}; }

Text Element::text() const { return {m_document, m_element}; }
Text Element::text() const { return {m_document, m_element, m_elementId}; }

Link Element::link() const { return {m_document, m_element}; }
Link Element::link() const { return {m_document, m_element, m_elementId}; }

Bookmark Element::bookmark() const { return {m_document, m_element}; }
Bookmark Element::bookmark() const {
return {m_document, m_element, m_elementId};
}

ListItem Element::list_item() const { return {m_document, m_element}; }
ListItem Element::list_item() const {
return {m_document, m_element, m_elementId};
}

Table Element::table() const { return {m_document, m_element}; }
Table Element::table() const { return {m_document, m_element, m_elementId}; }

TableColumn Element::table_column() const { return {m_document, m_element}; }
TableColumn Element::table_column() const {
return {m_document, m_element, m_elementId};
}

TableRow Element::table_row() const { return {m_document, m_element}; }
TableRow Element::table_row() const {
return {m_document, m_element, m_elementId};
}

TableCell Element::table_cell() const { return {m_document, m_element}; }
TableCell Element::table_cell() const {
return {m_document, m_element, m_elementId};
}

Frame Element::frame() const { return {m_document, m_element}; }
Frame Element::frame() const { return {m_document, m_element, m_elementId}; }

Rect Element::rect() const { return {m_document, m_element}; }
Rect Element::rect() const { return {m_document, m_element, m_elementId}; }

Line Element::line() const { return {m_document, m_element}; }
Line Element::line() const { return {m_document, m_element, m_elementId}; }

Circle Element::circle() const { return {m_document, m_element}; }
Circle Element::circle() const { return {m_document, m_element, m_elementId}; }

CustomShape Element::custom_shape() const { return {m_document, m_element}; }
CustomShape Element::custom_shape() const {
return {m_document, m_element, m_elementId};
}

Image Element::image() const { return {m_document, m_element}; }
Image Element::image() const { return {m_document, m_element, m_elementId}; }

ElementIterator Element::begin() const {
return m_element
Expand All @@ -109,8 +136,15 @@ ElementIterator Element::end() const { return {}; }
ElementIterator::ElementIterator() = default;

ElementIterator::ElementIterator(const internal::abstract::Document *document,
internal::abstract::Element *element)
: m_document{document}, m_element{element} {}
internal::abstract::Element *element,
ElementIdentifier elementId)
: m_document{document}, m_element{element}, m_elementId{elementId} {}

ElementIterator::ElementIterator(
const internal::abstract::Document *document,
std::pair<internal::abstract::Element *, ElementIdentifier> element)
: m_document{document}, m_element{element.first}, m_elementId{
element.second} {}

bool ElementIterator::operator==(const ElementIterator &rhs) const {
return m_elementId == rhs.m_elementId;
Expand All @@ -121,12 +155,14 @@ bool ElementIterator::operator!=(const ElementIterator &rhs) const {
}

ElementIterator::reference ElementIterator::operator*() const {
return Element(m_document, m_element);
return Element(m_document, m_element, m_elementId);
}

ElementIterator &ElementIterator::operator++() {
if (m_element != nullptr) {
m_element = m_element->next_sibling(m_document, m_elementId);
auto element = m_element->next_sibling(m_document, m_elementId);
m_element = element.first;
m_elementId = element.second;
}
return *this;
}
Expand Down Expand Up @@ -193,27 +229,31 @@ TableDimensions Sheet::content(std::optional<TableDimensions> range) const {
TableColumn Sheet::column(std::uint32_t column) const {
return m_element
? TableColumn(m_document,
m_element->column(m_document, m_elementId, column))
m_element->column(m_document, m_elementId, column),
0) // TODO
: TableColumn();
}

TableRow Sheet::row(std::uint32_t row) const {
return m_element ? TableRow(m_document,
m_element->row(m_document, m_elementId, row))
: TableRow();
return m_element
? TableRow(m_document,
m_element->row(m_document, m_elementId, row), 0) // TODO
: TableRow();
}

TableCell Sheet::cell(std::uint32_t column, std::uint32_t row) const {
return m_element
? TableCell(m_document,
m_element->cell(m_document, m_elementId, column, row))
m_element->cell(m_document, m_elementId, column, row),
0) // TODO
: TableCell();
}

ElementRange Sheet::shapes() const {
return m_element
? ElementRange(ElementIterator(
m_document, m_element->first_shape(m_document, m_elementId)))
m_document, m_element->first_shape(m_document, m_elementId),
0)) // TODO
: ElementRange();
}

Expand Down
30 changes: 23 additions & 7 deletions src/odr/document_element.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,10 @@ enum class ValueType {
class Element {
public:
Element();
Element(const internal::abstract::Document *document,
internal::abstract::Element *element);
Element(const internal::abstract::Document *, internal::abstract::Element *,
ElementIdentifier);
Element(const internal::abstract::Document *,
std::pair<internal::abstract::Element *, ElementIdentifier>);

bool operator==(const Element &rhs) const;
bool operator!=(const Element &rhs) const;
Expand Down Expand Up @@ -184,8 +186,10 @@ class ElementIterator {
using iterator_category = std::forward_iterator_tag;

ElementIterator();
ElementIterator(const internal::abstract::Document *document,
internal::abstract::Element *element);
ElementIterator(const internal::abstract::Document *,
internal::abstract::Element *, ElementIdentifier);
ElementIterator(const internal::abstract::Document *,
std::pair<internal::abstract::Element *, ElementIdentifier>);

bool operator==(const ElementIterator &rhs) const;
bool operator!=(const ElementIterator &rhs) const;
Expand All @@ -204,11 +208,23 @@ class ElementIterator {
template <typename T> class TypedElement : public Element {
public:
TypedElement() = default;
TypedElement(const internal::abstract::Document *document, T *element)

TypedElement(const internal::abstract::Document *document, T *element,
ElementIdentifier elementId)
: Element(document, element, elementId), m_element{element} {}
TypedElement(const internal::abstract::Document *document,
std::pair<T *, ElementIdentifier> element)
: Element(document, element), m_element{element} {}

TypedElement(const internal::abstract::Document *document,
internal::abstract::Element *element)
: TypedElement(document, dynamic_cast<T *>(element)) {}
internal::abstract::Element *element,
ElementIdentifier elementId)
: TypedElement(document, dynamic_cast<T *>(element), elementId) {}
TypedElement(
const internal::abstract::Document *document,
std::pair<internal::abstract::Element *, ElementIdentifier> element)
: TypedElement(document, dynamic_cast<T *>(element.first),
element.second) {}

protected:
T *m_element{nullptr};
Expand Down
5 changes: 4 additions & 1 deletion src/odr/internal/abstract/document.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef ODR_INTERNAL_ABSTRACT_DOCUMENT_H
#define ODR_INTERNAL_ABSTRACT_DOCUMENT_H

#include <odr/document_element.hpp>

#include <memory>

namespace odr {
Expand Down Expand Up @@ -46,7 +48,8 @@ class Document {
files() const noexcept = 0;

/// \return cursor to the root element of the document.
[[nodiscard]] virtual Element *root_element() const = 0;
[[nodiscard]] virtual std::pair<Element *, ElementIdentifier>
root_element() const = 0;
};

} // namespace odr::internal::abstract
Expand Down
59 changes: 29 additions & 30 deletions src/odr/internal/abstract/document_element.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@ class Element {
[[nodiscard]] virtual ElementType type(const Document *,
ElementIdentifier) const = 0;

[[nodiscard]] virtual Element *parent(const Document *,
ElementIdentifier) const = 0;
[[nodiscard]] virtual Element *first_child(const Document *,
ElementIdentifier) const = 0;
[[nodiscard]] virtual Element *last_child(const Document *,
ElementIdentifier) const = 0;
[[nodiscard]] virtual Element *previous_sibling(const Document *,
ElementIdentifier) const = 0;
[[nodiscard]] virtual Element *next_sibling(const Document *,
ElementIdentifier) const = 0;
[[nodiscard]] virtual std::pair<Element *, ElementIdentifier>
parent(const Document *, ElementIdentifier) const = 0;
[[nodiscard]] virtual std::pair<Element *, ElementIdentifier>
first_child(const Document *, ElementIdentifier) const = 0;
[[nodiscard]] virtual std::pair<Element *, ElementIdentifier>
last_child(const Document *, ElementIdentifier) const = 0;
[[nodiscard]] virtual std::pair<Element *, ElementIdentifier>
previous_sibling(const Document *, ElementIdentifier) const = 0;
[[nodiscard]] virtual std::pair<Element *, ElementIdentifier>
next_sibling(const Document *, ElementIdentifier) const = 0;
};

class TextRoot : public virtual Element {
Expand All @@ -55,7 +55,7 @@ class TextRoot : public virtual Element {
[[nodiscard]] virtual PageLayout page_layout(const Document *,
ElementIdentifier) const = 0;

[[nodiscard]] virtual MasterPage *
[[nodiscard]] virtual std::pair<abstract::Element *, ElementIdentifier>
first_master_page(const Document *, ElementIdentifier) const = 0;
};

Expand All @@ -69,8 +69,8 @@ class Slide : public virtual Element {
[[nodiscard]] virtual PageLayout page_layout(const Document *,
ElementIdentifier) const = 0;

[[nodiscard]] virtual MasterPage *master_page(const Document *,
ElementIdentifier) const = 0;
[[nodiscard]] virtual std::pair<abstract::Element *, ElementIdentifier>
master_page(const Document *, ElementIdentifier) const = 0;

[[nodiscard]] virtual std::string name(const Document *,
ElementIdentifier) const = 0;
Expand Down Expand Up @@ -117,8 +117,8 @@ class Page : public virtual Element {
[[nodiscard]] virtual PageLayout page_layout(const Document *,
ElementIdentifier) const = 0;

[[nodiscard]] virtual MasterPage *master_page(const Document *,
ElementIdentifier) const = 0;
[[nodiscard]] virtual std::pair<abstract::Element *, ElementIdentifier>
master_page(const Document *, ElementIdentifier) const = 0;

[[nodiscard]] virtual std::string name(const Document *,
ElementIdentifier) const = 0;
Expand Down Expand Up @@ -229,10 +229,10 @@ class Table : public virtual Element {
[[nodiscard]] virtual TableDimensions dimensions(const Document *,
ElementIdentifier) const = 0;

[[nodiscard]] virtual Element *first_column(const Document *,
ElementIdentifier) const = 0;
[[nodiscard]] virtual Element *first_row(const Document *,
ElementIdentifier) const = 0;
[[nodiscard]] virtual std::pair<abstract::Element *, ElementIdentifier>
first_column(const Document *, ElementIdentifier) const = 0;
[[nodiscard]] virtual std::pair<abstract::Element *, ElementIdentifier>
first_row(const Document *, ElementIdentifier) const = 0;

[[nodiscard]] virtual TableStyle style(const Document *,
ElementIdentifier) const = 0;
Expand Down Expand Up @@ -404,8 +404,8 @@ class SheetColumn : public virtual Element {
return ElementType::table_column;
}

[[nodiscard]] virtual TableColumnStyle
style(const Document *, ElementIdentifier, ColumnIndex) const = 0;
[[nodiscard]] virtual TableColumnStyle style(const Document *,
ColumnIndex) const = 0;
};

class SheetRow : public virtual Element {
Expand All @@ -415,7 +415,7 @@ class SheetRow : public virtual Element {
return ElementType::table_row;
}

[[nodiscard]] virtual TableRowStyle style(const Document *, ElementIdentifier,
[[nodiscard]] virtual TableRowStyle style(const Document *,
RowIndex) const = 0;
};

Expand All @@ -426,16 +426,15 @@ class SheetCell : public virtual Element {
return ElementType::table_cell;
}

[[nodiscard]] virtual bool covered(const Document *, ElementIdentifier,
ColumnIndex, RowIndex) const = 0;
[[nodiscard]] virtual TableDimensions
span(const Document *, ElementIdentifier, ColumnIndex, RowIndex) const = 0;
[[nodiscard]] virtual ValueType value_type(const Document *,
ElementIdentifier, ColumnIndex,
[[nodiscard]] virtual bool covered(const Document *, ColumnIndex,
RowIndex) const = 0;
[[nodiscard]] virtual TableDimensions span(const Document *, ColumnIndex,
RowIndex) const = 0;
[[nodiscard]] virtual ValueType value_type(const Document *, ColumnIndex,
RowIndex) const = 0;

[[nodiscard]] virtual TableCellStyle
style(const Document *, ElementIdentifier, ColumnIndex, RowIndex) const = 0;
[[nodiscard]] virtual TableCellStyle style(const Document *, ColumnIndex,
RowIndex) const = 0;
};

} // namespace odr::internal::abstract
Expand Down
Loading

0 comments on commit ee95e28

Please sign in to comment.