Skip to content

Commit 6ebb0bd

Browse files
committed
refactor the refactor
1 parent 7147c78 commit 6ebb0bd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1644
-1666
lines changed

CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ set(ODR_SOURCE_FILES
8787
"src/odr/odr.cpp"
8888
"src/odr/quantity.cpp"
8989
"src/odr/style.cpp"
90+
"src/odr/table_dimension.cpp"
91+
"src/odr/table_position.cpp"
9092

9193
"${CMAKE_CURRENT_BINARY_DIR}/src/odr/internal/git_info.cpp"
9294
"src/odr/internal/magic.cpp"
@@ -106,7 +108,7 @@ set(ODR_SOURCE_FILES
106108
"src/odr/internal/common/random.cpp"
107109
"src/odr/internal/common/style.cpp"
108110
"src/odr/internal/common/table_cursor.cpp"
109-
"src/odr/internal/common/table_position.cpp"
111+
"src/odr/table_position.cpp"
110112
"src/odr/internal/common/table_range.cpp"
111113
"src/odr/internal/common/temporary_file.cpp"
112114

src/odr/definitions.hpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#pragma once
2+
3+
#include <cstdint>
4+
5+
namespace odr {
6+
7+
using ElementIdentifier = std::uint64_t;
8+
9+
static constexpr ElementIdentifier null_element_id{0};
10+
11+
} // namespace odr

src/odr/document_element.cpp

Lines changed: 28 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
#include <odr/file.hpp>
44
#include <odr/style.hpp>
5+
#include <odr/table_dimension.hpp>
6+
#include <odr/table_position.hpp>
57

68
#include <odr/internal/abstract/document_element.hpp>
79

@@ -10,13 +12,13 @@ namespace odr {
1012
Element::Element() = default;
1113

1214
Element::Element(const internal::abstract::ElementAdapter *adapter,
13-
const ExtendedElementIdentifier identifier)
15+
const ElementIdentifier identifier)
1416
: m_adapter{adapter}, m_identifier{identifier} {}
1517

1618
Element::operator bool() const { return exists_(); }
1719

1820
bool Element::exists_() const {
19-
return m_adapter != nullptr && !m_identifier.is_null();
21+
return m_adapter != nullptr && m_identifier != null_element_id;
2022
}
2123

2224
ElementType Element::type() const {
@@ -66,6 +68,10 @@ Page Element::as_page() const {
6668
return {m_adapter, m_identifier, m_adapter->page_adapter(m_identifier)};
6769
}
6870

71+
SheetCell Element::as_sheet_cell() const {
72+
return {m_adapter, m_identifier, m_adapter->sheet_cell_adapter(m_identifier)};
73+
}
74+
6975
MasterPage Element::as_master_page() const {
7076
return {m_adapter, m_identifier,
7177
m_adapter->master_page_adapter(m_identifier)};
@@ -152,7 +158,7 @@ ElementIterator::ElementIterator() = default;
152158

153159
ElementIterator::ElementIterator(
154160
const internal::abstract::ElementAdapter *adapter,
155-
const ExtendedElementIdentifier identifier)
161+
const ElementIdentifier identifier)
156162
: m_adapter{adapter}, m_identifier{identifier} {}
157163

158164
ElementIterator::reference ElementIterator::operator*() const {
@@ -174,7 +180,7 @@ ElementIterator ElementIterator::operator++(int) {
174180
}
175181

176182
bool ElementIterator::exists_() const {
177-
return m_adapter != nullptr && !m_identifier.is_null();
183+
return m_adapter != nullptr && m_identifier != null_element_id;
178184
}
179185

180186
ElementRange::ElementRange() = default;
@@ -198,7 +204,7 @@ MasterPage TextRoot::first_master_page() const {
198204
if (!exists_()) {
199205
return {};
200206
}
201-
const ExtendedElementIdentifier master_page_id =
207+
const ElementIdentifier master_page_id =
202208
m_adapter2->text_root_first_master_page(m_identifier);
203209
return {m_adapter, master_page_id,
204210
m_adapter->master_page_adapter(master_page_id)};
@@ -216,7 +222,7 @@ MasterPage Slide::master_page() const {
216222
if (!exists_()) {
217223
return {};
218224
}
219-
const ExtendedElementIdentifier master_page_id =
225+
const ElementIdentifier master_page_id =
220226
m_adapter2->slide_master_page(m_identifier);
221227
return {m_adapter, master_page_id,
222228
m_adapter->master_page_adapter(master_page_id)};
@@ -237,30 +243,12 @@ Sheet::content(const std::optional<TableDimensions> range) const {
237243
: TableDimensions();
238244
}
239245

240-
SheetColumn Sheet::column(const std::uint32_t column) const {
241-
if (!exists_()) {
242-
return {};
243-
}
244-
const ExtendedElementIdentifier column_id =
245-
m_adapter2->sheet_column(m_identifier, column);
246-
return {m_adapter, column_id, m_adapter->sheet_column_adapter(column_id)};
247-
}
248-
249-
SheetRow Sheet::row(const std::uint32_t row) const {
250-
if (!exists_()) {
251-
return {};
252-
}
253-
const ExtendedElementIdentifier row_id =
254-
m_adapter2->sheet_row(m_identifier, row);
255-
return {m_adapter, row_id, m_adapter->sheet_row_adapter(row_id)};
256-
}
257-
258246
SheetCell Sheet::cell(const std::uint32_t column,
259247
const std::uint32_t row) const {
260248
if (!exists_()) {
261249
return {};
262250
}
263-
const ExtendedElementIdentifier cell_id =
251+
const ElementIdentifier cell_id =
264252
m_adapter2->sheet_cell(m_identifier, column, row);
265253
return {m_adapter, cell_id, m_adapter->sheet_cell_adapter(cell_id)};
266254
}
@@ -269,27 +257,28 @@ ElementRange Sheet::shapes() const {
269257
if (!exists_()) {
270258
return {};
271259
}
272-
const ExtendedElementIdentifier first_shape_id =
260+
const ElementIdentifier first_shape_id =
273261
m_adapter2->sheet_first_shape(m_identifier);
274262
return ElementRange(ElementIterator(m_adapter, first_shape_id));
275263
}
276264

277-
TableColumnStyle SheetColumn::style() const {
278-
return exists_() ? m_adapter2->sheet_column_style(m_identifier)
279-
: TableColumnStyle();
265+
TableStyle Sheet::style() const {
266+
return exists_() ? m_adapter2->sheet_style(m_identifier) : TableStyle();
280267
}
281268

282-
TableRowStyle SheetRow::style() const {
283-
return exists_() ? m_adapter2->sheet_row_style(m_identifier)
284-
: TableRowStyle();
269+
TableColumnStyle Sheet::column_style(const std::uint32_t column) const {
270+
return exists_() ? m_adapter2->sheet_column_style(m_identifier, column)
271+
: TableColumnStyle();
285272
}
286273

287-
std::uint32_t SheetCell::column() const {
288-
return exists_() ? m_adapter2->sheet_cell_column(m_identifier) : 0;
274+
TableRowStyle Sheet::row_style(const std::uint32_t row) const {
275+
return exists_() ? m_adapter2->sheet_row_style(m_identifier, row)
276+
: TableRowStyle();
289277
}
290278

291-
std::uint32_t SheetCell::row() const {
292-
return exists_() ? m_adapter2->sheet_cell_row(m_identifier) : 0;
279+
TablePosition SheetCell::position() const {
280+
return exists_() ? m_adapter2->sheet_cell_position(m_identifier)
281+
: TablePosition(0, 0);
293282
}
294283

295284
bool SheetCell::is_covered() const {
@@ -323,7 +312,7 @@ MasterPage Page::master_page() const {
323312
if (!exists_()) {
324313
return {};
325314
}
326-
const ExtendedElementIdentifier master_page_id =
315+
const ElementIdentifier master_page_id =
327316
m_adapter2->page_master_page(m_identifier);
328317
return {m_adapter, master_page_id,
329318
m_adapter->master_page_adapter(master_page_id)};
@@ -383,16 +372,15 @@ TableRow Table::first_row() const {
383372
if (!exists_()) {
384373
return {};
385374
}
386-
const ExtendedElementIdentifier row_id =
387-
m_adapter2->table_first_row(m_identifier);
375+
const ElementIdentifier row_id = m_adapter2->table_first_row(m_identifier);
388376
return {m_adapter, row_id, m_adapter->table_row_adapter(row_id)};
389377
}
390378

391379
TableColumn Table::first_column() const {
392380
if (!exists_()) {
393381
return {};
394382
}
395-
const ExtendedElementIdentifier column_id =
383+
const ElementIdentifier column_id =
396384
m_adapter2->table_first_column(m_identifier);
397385
return {m_adapter, column_id, m_adapter->table_column_adapter(column_id)};
398386
}

src/odr/document_element.hpp

Lines changed: 25 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,21 @@
44
#include <optional>
55
#include <string>
66

7-
#include <odr/document_element_identifier.hpp>
7+
#include <odr/definitions.hpp>
8+
9+
namespace odr {
10+
class TablePosition;
11+
struct TableDimensions;
12+
class File;
13+
struct TextStyle;
14+
struct ParagraphStyle;
15+
struct TableStyle;
16+
struct TableColumnStyle;
17+
struct TableRowStyle;
18+
struct TableCellStyle;
19+
struct GraphicStyle;
20+
struct PageLayout;
21+
} // namespace odr
822

923
namespace odr::internal::abstract {
1024
class Document;
@@ -39,17 +53,6 @@ class ImageAdapter;
3953

4054
namespace odr {
4155

42-
class File;
43-
struct TextStyle;
44-
struct ParagraphStyle;
45-
struct TableStyle;
46-
struct TableColumnStyle;
47-
struct TableRowStyle;
48-
struct TableCellStyle;
49-
struct GraphicStyle;
50-
struct PageLayout;
51-
struct TableDimensions;
52-
5356
class Element;
5457
class ElementIterator;
5558
class ElementRange;
@@ -90,8 +93,6 @@ enum class ElementType {
9093

9194
master_page,
9295

93-
sheet_column,
94-
sheet_row,
9596
sheet_cell,
9697

9798
text,
@@ -141,7 +142,7 @@ class Element {
141142
public:
142143
Element();
143144
Element(const internal::abstract::ElementAdapter *adapter,
144-
ExtendedElementIdentifier identifier);
145+
ElementIdentifier identifier);
145146

146147
explicit operator bool() const;
147148

@@ -160,6 +161,7 @@ class Element {
160161
[[nodiscard]] Slide as_slide() const;
161162
[[nodiscard]] Sheet as_sheet() const;
162163
[[nodiscard]] Page as_page() const;
164+
[[nodiscard]] SheetCell as_sheet_cell() const;
163165
[[nodiscard]] MasterPage as_master_page() const;
164166
[[nodiscard]] LineBreak as_line_break() const;
165167
[[nodiscard]] Paragraph as_paragraph() const;
@@ -181,7 +183,7 @@ class Element {
181183

182184
protected:
183185
const internal::abstract::ElementAdapter *m_adapter{nullptr};
184-
ExtendedElementIdentifier m_identifier;
186+
ElementIdentifier m_identifier;
185187

186188
friend bool operator==(const Element &lhs, const Element &rhs) {
187189
return lhs.m_identifier == rhs.m_identifier;
@@ -201,7 +203,7 @@ class ElementIterator {
201203

202204
ElementIterator();
203205
ElementIterator(const internal::abstract::ElementAdapter *adapter,
204-
ExtendedElementIdentifier identifier);
206+
ElementIdentifier identifier);
205207

206208
reference operator*() const;
207209

@@ -210,7 +212,7 @@ class ElementIterator {
210212

211213
private:
212214
const internal::abstract::ElementAdapter *m_adapter{nullptr};
213-
ExtendedElementIdentifier m_identifier;
215+
ElementIdentifier m_identifier{null_element_id};
214216

215217
friend bool operator==(const ElementIterator &lhs,
216218
const ElementIterator &rhs) {
@@ -240,7 +242,7 @@ template <typename T> class ElementBase : public Element {
240242
public:
241243
ElementBase() = default;
242244
ElementBase(const internal::abstract::ElementAdapter *adapter,
243-
const ExtendedElementIdentifier identifier, const T *adapter2)
245+
const ElementIdentifier identifier, const T *adapter2)
244246
: Element(adapter, identifier), m_adapter2{adapter2} {}
245247

246248
explicit operator bool() const { return exists_(); }
@@ -286,28 +288,12 @@ class Sheet final : public ElementBase<internal::abstract::SheetAdapter> {
286288
[[nodiscard]] TableDimensions
287289
content(std::optional<TableDimensions> range) const;
288290

289-
[[nodiscard]] SheetColumn column(std::uint32_t column) const;
290-
[[nodiscard]] SheetRow row(std::uint32_t row) const;
291291
[[nodiscard]] SheetCell cell(std::uint32_t column, std::uint32_t row) const;
292-
293292
[[nodiscard]] ElementRange shapes() const;
294-
};
295-
296-
/// @brief Represents a sheet column element in a document.
297-
class SheetColumn final
298-
: public ElementBase<internal::abstract::SheetColumnAdapter> {
299-
public:
300-
using ElementBase::ElementBase;
301293

302-
[[nodiscard]] TableColumnStyle style() const;
303-
};
304-
305-
/// @brief Represents a sheet row element in a document.
306-
class SheetRow final : public ElementBase<internal::abstract::SheetRowAdapter> {
307-
public:
308-
using ElementBase::ElementBase;
309-
310-
[[nodiscard]] TableRowStyle style() const;
294+
[[nodiscard]] TableStyle style() const;
295+
[[nodiscard]] TableColumnStyle column_style(std::uint32_t column) const;
296+
[[nodiscard]] TableRowStyle row_style(std::uint32_t row) const;
311297
};
312298

313299
/// @brief Represents a sheet cell element in a document.
@@ -316,8 +302,7 @@ class SheetCell final
316302
public:
317303
using ElementBase::ElementBase;
318304

319-
[[nodiscard]] std::uint32_t column() const;
320-
[[nodiscard]] std::uint32_t row() const;
305+
[[nodiscard]] TablePosition position() const;
321306
[[nodiscard]] bool is_covered() const;
322307
[[nodiscard]] TableDimensions span() const;
323308
[[nodiscard]] ValueType value_type() const;

0 commit comments

Comments
 (0)