@@ -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+
95161void 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 {
131197void 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
137203void 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
143209void 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
151221pugi::xml_node
152222ElementRegistry::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
160230pugi::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 {};
0 commit comments