Skip to content

Commit 8f6ce6f

Browse files
authored
cleanup (#449)
1 parent ee2f9f6 commit 8f6ce6f

File tree

194 files changed

+2330
-2260
lines changed

Some content is hidden

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

194 files changed

+2330
-2260
lines changed

CMakeLists.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,13 +161,10 @@ set(ODR_SOURCE_FILES
161161

162162
"src/odr/internal/pdf/pdf_cmap.cpp"
163163
"src/odr/internal/pdf/pdf_cmap_parser.cpp"
164-
"src/odr/internal/pdf/pdf_document.cpp"
165-
"src/odr/internal/pdf/pdf_document_element.cpp"
166164
"src/odr/internal/pdf/pdf_document_parser.cpp"
167165
"src/odr/internal/pdf/pdf_file.cpp"
168166
"src/odr/internal/pdf/pdf_file_object.cpp"
169167
"src/odr/internal/pdf/pdf_file_parser.cpp"
170-
"src/odr/internal/pdf/pdf_graphics_operator.cpp"
171168
"src/odr/internal/pdf/pdf_graphics_operator_parser.cpp"
172169
"src/odr/internal/pdf/pdf_graphics_state.cpp"
173170
"src/odr/internal/pdf/pdf_object.cpp"

cli/src/back_translate.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ int main(int, char **argv) {
2121
return 1;
2222
}
2323

24-
Document document = document_file.document();
24+
const Document document = document_file.document();
2525

26-
const std::string diff = odr::internal::util::file::read(diff_path);
26+
const std::string diff = internal::util::file::read(diff_path);
2727
html::edit(document, diff.c_str());
2828

2929
document.save(output);

cli/src/meta.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99

1010
using namespace odr;
1111

12-
int main(int argc, char **argv) {
12+
int main(const int argc, char **argv) {
1313
const std::string input{argv[1]};
1414

15-
bool has_password = argc >= 4;
15+
const bool has_password = argc >= 4;
1616
std::string password;
1717
if (has_password) {
1818
password = argv[2];
@@ -30,7 +30,7 @@ int main(int argc, char **argv) {
3030
}
3131

3232
const auto json =
33-
odr::internal::util::meta::meta_to_json(document_file.file_meta());
33+
internal::util::meta::meta_to_json(document_file.file_meta());
3434
std::cout << json.dump(4) << std::endl;
3535

3636
return 0;

cli/src/server.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
using namespace odr;
1010

11-
int main(int argc, char **argv) {
11+
int main(const int argc, char **argv) {
1212
auto logger = Logger::create_stdio("odr-server", LogLevel::verbose);
1313

1414
std::string input{argv[1]};

cli/src/translate.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88

99
using namespace odr;
1010

11-
int main(int argc, char **argv) {
12-
std::string input{argv[1]};
13-
std::string output{argv[2]};
11+
int main(const int argc, char **argv) {
12+
const std::string input{argv[1]};
13+
const std::string output{argv[2]};
1414

1515
std::optional<std::string> password;
1616
if (argc >= 4) {
@@ -35,9 +35,9 @@ int main(int argc, char **argv) {
3535
HtmlConfig config;
3636
config.editable = true;
3737

38-
std::string output_tmp = output + "/tmp";
38+
const std::string output_tmp = output + "/tmp";
3939
std::filesystem::create_directories(output_tmp);
40-
HtmlService service = html::translate(decoded_file, output, config);
40+
const HtmlService service = html::translate(decoded_file, output, config);
4141
Html html = service.bring_offline(output);
4242
std::filesystem::remove_all(output_tmp);
4343

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: 23 additions & 12 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,19 +220,26 @@ 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

237+
Sheet SheetCell::sheet() const { return {m_document, m_sheet}; }
238+
239+
std::uint32_t SheetCell::column() const { return m_column; }
240+
241+
std::uint32_t SheetCell::row() const { return m_row; }
242+
232243
bool SheetCell::is_covered() const {
233244
return exists_() ? m_element->is_covered(m_document) : false;
234245
}

src/odr/document_element.hpp

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

3-
#include <cstdint>
43
#include <memory>
54
#include <optional>
65
#include <string>
@@ -87,6 +86,10 @@ enum class ElementType {
8786

8887
master_page,
8988

89+
sheet_column,
90+
sheet_row,
91+
sheet_cell,
92+
9093
text,
9194
line_break,
9295
page_break,
@@ -321,6 +324,9 @@ class SheetCell final : public TypedElement<internal::abstract::SheetCell> {
321324
internal::abstract::Sheet *sheet, std::uint32_t column,
322325
std::uint32_t row, internal::abstract::SheetCell *element);
323326

327+
[[nodiscard]] Sheet sheet() const;
328+
[[nodiscard]] std::uint32_t column() const;
329+
[[nodiscard]] std::uint32_t row() const;
324330
[[nodiscard]] bool is_covered() const;
325331
[[nodiscard]] TableDimensions span() const;
326332
[[nodiscard]] ValueType value_type() const;
@@ -530,7 +536,7 @@ class Image final : public TypedElement<internal::abstract::Image> {
530536
using TypedElement::TypedElement;
531537

532538
[[nodiscard]] bool is_internal() const;
533-
[[nodiscard]] std::optional<odr::File> file() const;
539+
[[nodiscard]] std::optional<File> file() const;
534540
[[nodiscard]] std::string href() const;
535541
};
536542

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 & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,17 @@ class DocumentPath final {
2828
[[nodiscard]] std::string to_string() const noexcept;
2929
};
3030

31-
struct Child final : public ComponentTemplate<Child> {
31+
struct Child final : ComponentTemplate<Child> {
3232
static constexpr std::string_view prefix = "child";
3333
using ComponentTemplate::ComponentTemplate;
3434
};
3535

36-
struct Column final : public ComponentTemplate<Column> {
36+
struct Column final : ComponentTemplate<Column> {
3737
static constexpr std::string_view prefix = "column";
3838
using ComponentTemplate::ComponentTemplate;
3939
};
4040

41-
struct Row final : public ComponentTemplate<Row> {
41+
struct Row final : ComponentTemplate<Row> {
4242
static constexpr std::string_view prefix = "row";
4343
using ComponentTemplate::ComponentTemplate;
4444
};

0 commit comments

Comments
 (0)