Skip to content

Commit 43f2880

Browse files
committed
draft more
1 parent 7e45387 commit 43f2880

6 files changed

Lines changed: 361 additions & 162 deletions

File tree

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,8 @@ set(ODR_SOURCE_FILES
136136
"src/odr/internal/odf/odf_file.cpp"
137137
"src/odr/internal/odf/odf_manifest.cpp"
138138
"src/odr/internal/odf/odf_meta.cpp"
139-
#"src/odr/internal/odf/odf_parser.cpp"
140-
#"src/odr/internal/odf/odf_style.cpp"
139+
"src/odr/internal/odf/odf_parser.cpp"
140+
"src/odr/internal/odf/odf_style.cpp"
141141

142142
"src/odr/internal/oldms/oldms_file.cpp"
143143

src/odr/internal/odf/odf_element_registry.cpp

Lines changed: 76 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,72 @@ ElementRegistry::sheet_element(const ExtendedElementIdentifier id) const {
9292
return m_sheets.at(id.element_id());
9393
}
9494

95+
void ElementRegistry::append_child(const ExtendedElementIdentifier parent_id,
96+
const ExtendedElementIdentifier child_id) {
97+
check_element_id(parent_id);
98+
check_element_id(child_id);
99+
100+
const ExtendedElementIdentifier previous_sibling_id(
101+
element(parent_id).last_child_id);
102+
103+
element(child_id).parent_id = parent_id;
104+
element(child_id).first_child_id = null_element_id;
105+
element(child_id).last_child_id = null_element_id;
106+
element(child_id).previous_sibling_id = previous_sibling_id.element_id();
107+
element(child_id).next_sibling_id = null_element_id;
108+
109+
if (element(parent_id).first_child_id == null_element_id) {
110+
element(parent_id).first_child_id = child_id.element_id();
111+
} else {
112+
element(previous_sibling_id).next_sibling_id = child_id.element_id();
113+
}
114+
element(parent_id).last_child_id = child_id.element_id();
115+
}
116+
117+
void ElementRegistry::append_column(const ExtendedElementIdentifier table_id,
118+
const ExtendedElementIdentifier column_id) {
119+
check_table_id(table_id);
120+
check_element_id(column_id);
121+
122+
const ExtendedElementIdentifier previous_sibling_id(
123+
table_element(table_id).last_column_id);
124+
125+
element(column_id).parent_id = table_id;
126+
element(column_id).first_child_id = null_element_id;
127+
element(column_id).last_child_id = null_element_id;
128+
element(column_id).previous_sibling_id = previous_sibling_id.element_id();
129+
element(column_id).next_sibling_id = null_element_id;
130+
131+
if (table_element(table_id).first_column_id == null_element_id) {
132+
table_element(table_id).first_column_id = column_id.element_id();
133+
} else {
134+
element(previous_sibling_id).next_sibling_id = column_id.element_id();
135+
}
136+
table_element(table_id).last_column_id = column_id.element_id();
137+
}
138+
139+
void ElementRegistry::append_shape(const ExtendedElementIdentifier sheet_id,
140+
const ExtendedElementIdentifier shape_id) {
141+
check_sheet_id(sheet_id);
142+
check_element_id(shape_id);
143+
144+
const ExtendedElementIdentifier previous_sibling_id(
145+
sheet_element(sheet_id).last_shape_id);
146+
147+
element(shape_id).parent_id = sheet_id;
148+
element(shape_id).first_child_id = null_element_id;
149+
element(shape_id).last_child_id = null_element_id;
150+
element(shape_id).previous_sibling_id = previous_sibling_id.element_id();
151+
element(shape_id).next_sibling_id = null_element_id;
152+
153+
if (sheet_element(sheet_id).first_shape_id == null_element_id) {
154+
sheet_element(sheet_id).first_shape_id = shape_id.element_id();
155+
} else {
156+
element(previous_sibling_id).next_sibling_id = shape_id.element_id();
157+
}
158+
sheet_element(sheet_id).last_shape_id = shape_id.element_id();
159+
}
160+
95161
void ElementRegistry::check_element_id(
96162
const ExtendedElementIdentifier id) const {
97163
if (id.is_null()) {
@@ -131,36 +197,40 @@ void ElementRegistry::check_sheet_id(const ExtendedElementIdentifier id) const {
131197
void ElementRegistry::Sheet::create_column(const std::uint32_t column,
132198
const std::uint32_t repeated,
133199
const pugi::xml_node element) {
134-
columns[column + repeated] = element;
200+
columns[column + repeated] = {.node = element};
135201
}
136202

137203
void ElementRegistry::Sheet::create_row(const std::uint32_t row,
138204
const std::uint32_t repeated,
139205
const pugi::xml_node element) {
140-
rows[row + repeated].row = element;
206+
rows[row + repeated].node = element;
141207
}
142208

143209
void ElementRegistry::Sheet::create_cell(const std::uint32_t column,
144210
const std::uint32_t row,
145211
const std::uint32_t columns_repeated,
146212
const std::uint32_t rows_repeated,
147213
const pugi::xml_node element) {
148-
rows[row + rows_repeated].cells[column + columns_repeated] = element;
214+
const bool is_repeated = columns_repeated > 1 || rows_repeated > 1;
215+
216+
Cell &cell = rows[row + rows_repeated].cells[column + columns_repeated];
217+
cell.node = element;
218+
cell.is_repeated = is_repeated;
149219
}
150220

151221
pugi::xml_node
152222
ElementRegistry::Sheet::column(const std::uint32_t column) const {
153223
if (const auto it = util::map::lookup_greater_than(columns, column);
154224
it != std::end(columns)) {
155-
return it->second;
225+
return it->second.node;
156226
}
157227
return {};
158228
}
159229

160230
pugi::xml_node ElementRegistry::Sheet::row(const std::uint32_t row) const {
161231
if (const auto it = util::map::lookup_greater_than(rows, row);
162232
it != std::end(rows)) {
163-
return it->second.row;
233+
return it->second.node;
164234
}
165235
return {};
166236
}
@@ -172,7 +242,7 @@ pugi::xml_node ElementRegistry::Sheet::cell(const std::uint32_t column,
172242
const auto &cells = row_it->second.cells;
173243
if (const auto cell_it = util::map::lookup_greater_than(cells, column);
174244
cell_it != std::end(cells)) {
175-
return cell_it->second;
245+
return cell_it->second.node;
176246
}
177247
}
178248
return {};

src/odr/internal/odf/odf_element_registry.hpp

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,28 @@ class ElementRegistry final {
3535
};
3636

3737
struct Sheet final {
38-
struct Row {
39-
pugi::xml_node row;
40-
std::map<std::uint32_t, pugi::xml_node> cells;
38+
struct Column final {
39+
pugi::xml_node node;
40+
};
41+
42+
struct Cell final {
43+
pugi::xml_node node;
44+
bool is_repeated{false};
45+
};
46+
47+
struct Row final {
48+
pugi::xml_node node;
49+
std::map<std::uint32_t, Cell> cells;
4150
};
4251

4352
TableDimensions dimensions;
4453

45-
std::map<std::uint32_t, pugi::xml_node> columns;
54+
std::map<std::uint32_t, Column> columns;
4655
std::map<std::uint32_t, Row> rows;
4756

57+
ElementIdentifier first_shape_id{null_element_id};
58+
ElementIdentifier last_shape_id{null_element_id};
59+
4860
void create_column(std::uint32_t column, std::uint32_t repeated,
4961
pugi::xml_node element);
5062
void create_row(std::uint32_t row, std::uint32_t repeated,
@@ -80,6 +92,13 @@ class ElementRegistry final {
8092
[[nodiscard]] Sheet &sheet_element(ExtendedElementIdentifier id);
8193
[[nodiscard]] const Sheet &sheet_element(ExtendedElementIdentifier id) const;
8294

95+
void append_child(ExtendedElementIdentifier parent_id,
96+
ExtendedElementIdentifier child_id);
97+
void append_column(ExtendedElementIdentifier table_id,
98+
ExtendedElementIdentifier column_id);
99+
void append_shape(ExtendedElementIdentifier sheet_id,
100+
ExtendedElementIdentifier shape_id);
101+
83102
private:
84103
std::vector<Element> m_elements;
85104
std::unordered_map<ElementIdentifier, Table> m_tables;

0 commit comments

Comments
 (0)