Skip to content

Commit ceb37a1

Browse files
committed
more cleanup
1 parent 62972c0 commit ceb37a1

48 files changed

Lines changed: 505 additions & 469 deletions

Some content is hidden

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

src/odr/document.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
#include <odr/internal/abstract/document.hpp>
99
#include <odr/internal/common/path.hpp>
1010

11-
#include <stdexcept>
12-
1311
namespace odr {
1412

1513
Document::Document(std::shared_ptr<internal::abstract::Document> impl)

src/odr/document_element.cpp

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ bool ElementIterator::operator!=(const ElementIterator &rhs) const {
121121
}
122122

123123
ElementIterator::reference ElementIterator::operator*() const {
124-
return Element(m_document, m_element);
124+
return {m_document, m_element};
125125
}
126126

127127
ElementIterator &ElementIterator::operator++() {
@@ -142,10 +142,11 @@ bool ElementIterator::exists_() const { return m_element != nullptr; }
142142

143143
ElementRange::ElementRange() = default;
144144

145-
ElementRange::ElementRange(ElementIterator begin) : m_begin{std::move(begin)} {}
145+
ElementRange::ElementRange(const ElementIterator begin) : m_begin{begin} {}
146146

147-
ElementRange::ElementRange(ElementIterator begin, ElementIterator end)
148-
: m_begin{std::move(begin)}, m_end{std::move(end)} {}
147+
ElementRange::ElementRange(const ElementIterator begin,
148+
const ElementIterator end)
149+
: m_begin{begin}, m_end{end} {}
149150

150151
ElementIterator ElementRange::begin() const { return m_begin; }
151152

@@ -182,19 +183,21 @@ TableDimensions Sheet::dimensions() const {
182183
return exists_() ? m_element->dimensions(m_document) : TableDimensions();
183184
}
184185

185-
TableDimensions Sheet::content(std::optional<TableDimensions> range) const {
186+
TableDimensions
187+
Sheet::content(const std::optional<TableDimensions> range) const {
186188
return exists_() ? m_element->content(m_document, range) : TableDimensions();
187189
}
188190

189-
SheetColumn Sheet::column(std::uint32_t column) const {
191+
SheetColumn Sheet::column(const std::uint32_t column) const {
190192
return exists_() ? SheetColumn(m_document, m_element, column) : SheetColumn();
191193
}
192194

193-
SheetRow Sheet::row(std::uint32_t row) const {
195+
SheetRow Sheet::row(const std::uint32_t row) const {
194196
return exists_() ? SheetRow(m_document, m_element, row) : SheetRow();
195197
}
196198

197-
SheetCell Sheet::cell(std::uint32_t column, std::uint32_t row) const {
199+
SheetCell Sheet::cell(const std::uint32_t column,
200+
const std::uint32_t row) const {
198201
return exists_() ? SheetCell(m_document, m_element, column, row,
199202
m_element->cell(m_document, column, row))
200203
: SheetCell();
@@ -207,7 +210,8 @@ ElementRange Sheet::shapes() const {
207210
}
208211

209212
SheetColumn::SheetColumn(const internal::abstract::Document *document,
210-
internal::abstract::Sheet *sheet, std::uint32_t column)
213+
internal::abstract::Sheet *sheet,
214+
const std::uint32_t column)
211215
: TypedElement(document, sheet), m_column{column} {}
212216

213217
TableColumnStyle SheetColumn::style() const {
@@ -216,20 +220,21 @@ TableColumnStyle SheetColumn::style() const {
216220
}
217221

218222
SheetRow::SheetRow(const internal::abstract::Document *document,
219-
internal::abstract::Sheet *sheet, std::uint32_t row)
223+
internal::abstract::Sheet *sheet, const std::uint32_t row)
220224
: TypedElement(document, sheet), m_row{row} {}
221225

222226
TableRowStyle SheetRow::style() const {
223227
return exists_() ? m_element->row_style(m_document, m_row) : TableRowStyle();
224228
}
225229

226230
SheetCell::SheetCell(const internal::abstract::Document *document,
227-
internal::abstract::Sheet *sheet, std::uint32_t column,
228-
std::uint32_t row, internal::abstract::SheetCell *element)
231+
internal::abstract::Sheet *sheet,
232+
const std::uint32_t column, const std::uint32_t row,
233+
internal::abstract::SheetCell *element)
229234
: TypedElement(document, element), m_sheet{sheet}, m_column{column},
230235
m_row{row} {}
231236

232-
Sheet SheetCell::sheet() const { return Sheet(m_document, m_sheet); }
237+
Sheet SheetCell::sheet() const { return {m_document, m_sheet}; }
233238

234239
std::uint32_t SheetCell::column() const { return m_column; }
235240

src/odr/document_path.cpp

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ DocumentPath::ComponentTemplate<Derived>::to_string() const noexcept {
5050

5151
DocumentPath::Component
5252
DocumentPath::component_from_string(const std::string &string) {
53-
auto colon = string.find(':');
53+
const auto colon = string.find(':');
5454
if (colon == std::string::npos) {
5555
throw std::invalid_argument("string");
5656
}
@@ -60,24 +60,26 @@ DocumentPath::component_from_string(const std::string &string) {
6060

6161
if (prefix == Child::prefix_string()) {
6262
return Child(number);
63-
} else if (prefix == Column::prefix_string()) {
63+
}
64+
if (prefix == Column::prefix_string()) {
6465
return Column(number);
65-
} else if (prefix == Row::prefix_string()) {
66+
}
67+
if (prefix == Row::prefix_string()) {
6668
return Row(number);
6769
}
6870

6971
throw std::invalid_argument("string");
7072
}
7173

72-
DocumentPath DocumentPath::extract(Element element) {
74+
DocumentPath DocumentPath::extract(const Element element) {
7375
return extract(element, {});
7476
}
7577

76-
DocumentPath DocumentPath::extract(Element element, Element root) {
78+
DocumentPath DocumentPath::extract(const Element element, const Element root) {
7779
std::vector<Component> reverse;
7880

7981
for (auto current = element; current != root;) {
80-
auto parent = current.parent();
82+
const auto parent = current.parent();
8183
if (!parent) {
8284
break;
8385
}
@@ -98,28 +100,28 @@ DocumentPath DocumentPath::extract(Element element, Element root) {
98100
current = parent;
99101
}
100102

101-
std::reverse(std::begin(reverse), std::end(reverse));
103+
std::ranges::reverse(reverse);
102104
return DocumentPath(reverse);
103105
}
104106

105-
Element DocumentPath::find(Element root, const DocumentPath &path) {
107+
Element DocumentPath::find(const Element root, const DocumentPath &path) {
106108
Element element = root;
107109

108-
for (const DocumentPath::Component &c : path) {
110+
for (const Component &c : path) {
109111
std::uint32_t number = 0;
110-
if (const auto child = std::get_if<DocumentPath::Child>(&c)) {
112+
if (const auto child = std::get_if<Child>(&c)) {
111113
if (!element.first_child()) {
112114
throw std::invalid_argument("child not found");
113115
}
114116
element = element.first_child();
115117
number = child->number;
116-
} else if (const auto column = std::get_if<DocumentPath::Column>(&c)) {
118+
} else if (const auto column = std::get_if<Column>(&c)) {
117119
if (!element.as_table().first_column()) {
118120
throw std::invalid_argument("column not found");
119121
}
120122
element = Element(element.as_table().first_column());
121123
number = column->number;
122-
} else if (const auto row = std::get_if<DocumentPath::Row>(&c)) {
124+
} else if (const auto row = std::get_if<Row>(&c)) {
123125
if (!element.as_table().first_row()) {
124126
throw std::invalid_argument("row not found");
125127
}

src/odr/document_path.hpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#pragma once
22

3-
#include <cstdint>
43
#include <string>
54
#include <variant>
65
#include <vector>
@@ -28,17 +27,17 @@ class DocumentPath final {
2827
[[nodiscard]] std::string to_string() const noexcept;
2928
};
3029

31-
struct Child final : public ComponentTemplate<Child> {
30+
struct Child final : ComponentTemplate<Child> {
3231
static constexpr std::string_view prefix = "child";
3332
using ComponentTemplate::ComponentTemplate;
3433
};
3534

36-
struct Column final : public ComponentTemplate<Column> {
35+
struct Column final : ComponentTemplate<Column> {
3736
static constexpr std::string_view prefix = "column";
3837
using ComponentTemplate::ComponentTemplate;
3938
};
4039

41-
struct Row final : public ComponentTemplate<Row> {
40+
struct Row final : ComponentTemplate<Row> {
4241
static constexpr std::string_view prefix = "row";
4342
using ComponentTemplate::ComponentTemplate;
4443
};

0 commit comments

Comments
 (0)