Skip to content

Commit 084731f

Browse files
authored
Write more properties to meta.json and rework some public interfaces (#430)
1 parent 6d0e3cf commit 084731f

43 files changed

Lines changed: 278 additions & 222 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/archive.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include <odr/archive.hpp>
22

3+
#include <odr/exceptions.hpp>
34
#include <odr/filesystem.hpp>
45

56
#include <odr/internal/abstract/archive.hpp>
@@ -9,14 +10,16 @@
910
namespace odr {
1011

1112
Archive::Archive(std::shared_ptr<internal::abstract::Archive> impl)
12-
: m_impl{std::move(impl)} {}
13-
14-
Archive::operator bool() const { return m_impl.operator bool(); }
13+
: m_impl{std::move(impl)} {
14+
if (m_impl == nullptr) {
15+
throw NullPointerError("Archive implementation is null");
16+
}
17+
}
1518

16-
Filesystem Archive::filesystem() const {
19+
Filesystem Archive::as_filesystem() const {
1720
return Filesystem(
1821
std::dynamic_pointer_cast<internal::abstract::ReadableFilesystem>(
19-
m_impl->filesystem()));
22+
m_impl->as_filesystem()));
2023
}
2124

2225
void Archive::save(std::ostream &out) const { m_impl->save(out); }

src/odr/archive.hpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ class Archive {
1515
public:
1616
explicit Archive(std::shared_ptr<internal::abstract::Archive>);
1717

18-
[[nodiscard]] explicit operator bool() const;
19-
20-
[[nodiscard]] Filesystem filesystem() const;
18+
[[nodiscard]] Filesystem as_filesystem() const;
2119

2220
void save(std::ostream &out) const;
2321

src/odr/document.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <odr/document.hpp>
22

33
#include <odr/document_element.hpp>
4+
#include <odr/exceptions.hpp>
45
#include <odr/file.hpp>
56
#include <odr/filesystem.hpp>
67

@@ -14,13 +15,13 @@ namespace odr {
1415
Document::Document(std::shared_ptr<internal::abstract::Document> impl)
1516
: m_impl{std::move(impl)} {
1617
if (!m_impl) {
17-
throw std::runtime_error("document is null");
18+
throw NullPointerError("document is null");
1819
}
1920
}
2021

21-
bool Document::editable() const noexcept { return m_impl->is_editable(); }
22+
bool Document::is_editable() const noexcept { return m_impl->is_editable(); }
2223

23-
bool Document::savable(const bool encrypted) const noexcept {
24+
bool Document::is_savable(const bool encrypted) const noexcept {
2425
return m_impl->is_savable(encrypted);
2526
}
2627

@@ -43,6 +44,8 @@ Element Document::root_element() const {
4344
return {m_impl.get(), m_impl->root_element()};
4445
}
4546

46-
Filesystem Document::files() const { return Filesystem(m_impl->files()); }
47+
Filesystem Document::as_filesystem() const {
48+
return Filesystem(m_impl->as_filesystem());
49+
}
4750

4851
} // namespace odr

src/odr/document.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ class Document final {
1919
public:
2020
explicit Document(std::shared_ptr<internal::abstract::Document>);
2121

22-
[[nodiscard]] bool editable() const noexcept;
23-
[[nodiscard]] bool savable(bool encrypted = false) const noexcept;
22+
[[nodiscard]] bool is_editable() const noexcept;
23+
[[nodiscard]] bool is_savable(bool encrypted = false) const noexcept;
2424

2525
void save(const std::string &path) const;
2626
void save(const std::string &path, const std::string &password) const;
@@ -30,7 +30,7 @@ class Document final {
3030

3131
[[nodiscard]] Element root_element() const;
3232

33-
[[nodiscard]] Filesystem files() const;
33+
[[nodiscard]] Filesystem as_filesystem() const;
3434

3535
private:
3636
std::shared_ptr<internal::abstract::Document> m_impl;

src/odr/document_element.cpp

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -55,49 +55,49 @@ bool Element::is_editable() const {
5555
return exists_() ? m_element->is_editable(m_document) : false;
5656
}
5757

58-
TextRoot Element::text_root() const { return {m_document, m_element}; }
58+
TextRoot Element::as_text_root() const { return {m_document, m_element}; }
5959

60-
Slide Element::slide() const { return {m_document, m_element}; }
60+
Slide Element::as_slide() const { return {m_document, m_element}; }
6161

62-
Sheet Element::sheet() const { return {m_document, m_element}; }
62+
Sheet Element::as_sheet() const { return {m_document, m_element}; }
6363

64-
Page Element::page() const { return {m_document, m_element}; }
64+
Page Element::as_page() const { return {m_document, m_element}; }
6565

66-
MasterPage Element::master_page() const { return {m_document, m_element}; }
66+
MasterPage Element::as_master_page() const { return {m_document, m_element}; }
6767

68-
LineBreak Element::line_break() const { return {m_document, m_element}; }
68+
LineBreak Element::as_line_break() const { return {m_document, m_element}; }
6969

70-
Paragraph Element::paragraph() const { return {m_document, m_element}; }
70+
Paragraph Element::as_paragraph() const { return {m_document, m_element}; }
7171

72-
Span Element::span() const { return {m_document, m_element}; }
72+
Span Element::as_span() const { return {m_document, m_element}; }
7373

74-
Text Element::text() const { return {m_document, m_element}; }
74+
Text Element::as_text() const { return {m_document, m_element}; }
7575

76-
Link Element::link() const { return {m_document, m_element}; }
76+
Link Element::as_link() const { return {m_document, m_element}; }
7777

78-
Bookmark Element::bookmark() const { return {m_document, m_element}; }
78+
Bookmark Element::as_bookmark() const { return {m_document, m_element}; }
7979

80-
ListItem Element::list_item() const { return {m_document, m_element}; }
80+
ListItem Element::as_list_item() const { return {m_document, m_element}; }
8181

82-
Table Element::table() const { return {m_document, m_element}; }
82+
Table Element::as_table() const { return {m_document, m_element}; }
8383

84-
TableColumn Element::table_column() const { return {m_document, m_element}; }
84+
TableColumn Element::as_table_column() const { return {m_document, m_element}; }
8585

86-
TableRow Element::table_row() const { return {m_document, m_element}; }
86+
TableRow Element::as_table_row() const { return {m_document, m_element}; }
8787

88-
TableCell Element::table_cell() const { return {m_document, m_element}; }
88+
TableCell Element::as_table_cell() const { return {m_document, m_element}; }
8989

90-
Frame Element::frame() const { return {m_document, m_element}; }
90+
Frame Element::as_frame() const { return {m_document, m_element}; }
9191

92-
Rect Element::rect() const { return {m_document, m_element}; }
92+
Rect Element::as_rect() const { return {m_document, m_element}; }
9393

94-
Line Element::line() const { return {m_document, m_element}; }
94+
Line Element::as_line() const { return {m_document, m_element}; }
9595

96-
Circle Element::circle() const { return {m_document, m_element}; }
96+
Circle Element::as_circle() const { return {m_document, m_element}; }
9797

98-
CustomShape Element::custom_shape() const { return {m_document, m_element}; }
98+
CustomShape Element::as_custom_shape() const { return {m_document, m_element}; }
9999

100-
Image Element::image() const { return {m_document, m_element}; }
100+
Image Element::as_image() const { return {m_document, m_element}; }
101101

102102
ElementRange Element::children() const {
103103
return {exists_()

src/odr/document_element.hpp

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -151,28 +151,28 @@ class Element {
151151

152152
[[nodiscard]] ElementRange children() const;
153153

154-
[[nodiscard]] TextRoot text_root() const;
155-
[[nodiscard]] Slide slide() const;
156-
[[nodiscard]] Sheet sheet() const;
157-
[[nodiscard]] Page page() const;
158-
[[nodiscard]] MasterPage master_page() const;
159-
[[nodiscard]] LineBreak line_break() const;
160-
[[nodiscard]] Paragraph paragraph() const;
161-
[[nodiscard]] Span span() const;
162-
[[nodiscard]] Text text() const;
163-
[[nodiscard]] Link link() const;
164-
[[nodiscard]] Bookmark bookmark() const;
165-
[[nodiscard]] ListItem list_item() const;
166-
[[nodiscard]] Table table() const;
167-
[[nodiscard]] TableColumn table_column() const;
168-
[[nodiscard]] TableRow table_row() const;
169-
[[nodiscard]] TableCell table_cell() const;
170-
[[nodiscard]] Frame frame() const;
171-
[[nodiscard]] Rect rect() const;
172-
[[nodiscard]] Line line() const;
173-
[[nodiscard]] Circle circle() const;
174-
[[nodiscard]] CustomShape custom_shape() const;
175-
[[nodiscard]] Image image() const;
154+
[[nodiscard]] TextRoot as_text_root() const;
155+
[[nodiscard]] Slide as_slide() const;
156+
[[nodiscard]] Sheet as_sheet() const;
157+
[[nodiscard]] Page as_page() const;
158+
[[nodiscard]] MasterPage as_master_page() const;
159+
[[nodiscard]] LineBreak as_line_break() const;
160+
[[nodiscard]] Paragraph as_paragraph() const;
161+
[[nodiscard]] Span as_span() const;
162+
[[nodiscard]] Text as_text() const;
163+
[[nodiscard]] Link as_link() const;
164+
[[nodiscard]] Bookmark as_bookmark() const;
165+
[[nodiscard]] ListItem as_list_item() const;
166+
[[nodiscard]] Table as_table() const;
167+
[[nodiscard]] TableColumn as_table_column() const;
168+
[[nodiscard]] TableRow as_table_row() const;
169+
[[nodiscard]] TableCell as_table_cell() const;
170+
[[nodiscard]] Frame as_frame() const;
171+
[[nodiscard]] Rect as_rect() const;
172+
[[nodiscard]] Line as_line() const;
173+
[[nodiscard]] Circle as_circle() const;
174+
[[nodiscard]] CustomShape as_custom_shape() const;
175+
[[nodiscard]] Image as_image() const;
176176

177177
protected:
178178
const internal::abstract::Document *m_document{nullptr};

src/odr/document_path.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ DocumentPath DocumentPath::extract(Element element, Element root) {
8787
++distance;
8888
}
8989

90-
if (current.table_column() || current.table_cell()) {
90+
if (current.as_table_column() || current.as_table_cell()) {
9191
reverse.emplace_back(Column(distance));
92-
} else if (current.table_row()) {
92+
} else if (current.as_table_row()) {
9393
reverse.emplace_back(Row(distance));
9494
} else {
9595
reverse.emplace_back(Child(distance));

src/odr/file.cpp

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -60,25 +60,17 @@ void File::copy(const std::string &path) const {
6060

6161
std::shared_ptr<internal::abstract::File> File::impl() const { return m_impl; }
6262

63-
std::vector<FileType> DecodedFile::types(const std::string &path) {
64-
return internal::open_strategy::types(
63+
std::vector<FileType> DecodedFile::list_file_types(const std::string &path) {
64+
return internal::open_strategy::list_file_types(
6565
std::make_shared<internal::common::DiskFile>(path));
6666
}
6767

68-
std::vector<DecoderEngine> DecodedFile::engines(const std::string &path,
69-
FileType as) {
70-
return internal::open_strategy::engines(
68+
std::vector<DecoderEngine>
69+
DecodedFile::list_decoder_engines(const std::string &path, FileType as) {
70+
return internal::open_strategy::list_decoder_engines(
7171
std::make_shared<internal::common::DiskFile>(path), as);
7272
}
7373

74-
FileType DecodedFile::type(const std::string &path) {
75-
return DecodedFile(path).file_type();
76-
}
77-
78-
FileMeta DecodedFile::meta(const std::string &path) {
79-
return DecodedFile(path).file_meta();
80-
}
81-
8274
DecodedFile::DecodedFile(std::shared_ptr<internal::abstract::DecodedFile> impl)
8375
: m_impl{std::move(impl)} {
8476
if (m_impl == nullptr) {
@@ -156,39 +148,39 @@ bool DecodedFile::is_pdf_file() const {
156148
nullptr;
157149
}
158150

159-
TextFile DecodedFile::text_file() const {
151+
TextFile DecodedFile::as_text_file() const {
160152
if (auto text_file =
161153
std::dynamic_pointer_cast<internal::abstract::TextFile>(m_impl)) {
162154
return TextFile(text_file);
163155
}
164156
throw NoTextFile();
165157
}
166158

167-
ImageFile DecodedFile::image_file() const {
159+
ImageFile DecodedFile::as_image_file() const {
168160
if (auto image_file =
169161
std::dynamic_pointer_cast<internal::abstract::ImageFile>(m_impl)) {
170162
return ImageFile(image_file);
171163
}
172164
throw NoImageFile();
173165
}
174166

175-
ArchiveFile DecodedFile::archive_file() const {
167+
ArchiveFile DecodedFile::as_archive_file() const {
176168
if (auto archive_file =
177169
std::dynamic_pointer_cast<internal::abstract::ArchiveFile>(m_impl)) {
178170
return ArchiveFile(archive_file);
179171
}
180172
throw NoArchiveFile();
181173
}
182174

183-
DocumentFile DecodedFile::document_file() const {
175+
DocumentFile DecodedFile::as_document_file() const {
184176
if (auto document_file =
185177
std::dynamic_pointer_cast<internal::abstract::DocumentFile>(m_impl)) {
186178
return DocumentFile(document_file);
187179
}
188180
throw NoDocumentFile();
189181
}
190182

191-
PdfFile DecodedFile::pdf_file() const {
183+
PdfFile DecodedFile::as_pdf_file() const {
192184
if (auto pdf_file =
193185
std::dynamic_pointer_cast<internal::abstract::PdfFile>(m_impl)) {
194186
return PdfFile(pdf_file);
@@ -248,7 +240,7 @@ DocumentMeta DocumentFile::document_meta() const {
248240
}
249241

250242
DocumentFile DocumentFile::decrypt(const std::string &password) const {
251-
return DecodedFile::decrypt(password).document_file();
243+
return DecodedFile::decrypt(password).as_document_file();
252244
}
253245

254246
Document DocumentFile::document() const { return Document(m_impl->document()); }
@@ -261,7 +253,7 @@ PdfFile::PdfFile(std::shared_ptr<internal::abstract::PdfFile> impl)
261253
: DecodedFile(impl), m_impl{std::move(impl)} {}
262254

263255
PdfFile PdfFile::decrypt(const std::string &password) const {
264-
return DecodedFile::decrypt(password).pdf_file();
256+
return DecodedFile::decrypt(password).as_pdf_file();
265257
}
266258

267259
std::shared_ptr<internal::abstract::PdfFile> PdfFile::impl() const {

src/odr/file.hpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,9 @@ class File final {
174174
/// @brief Represents a decoded file.
175175
class DecodedFile {
176176
public:
177-
static std::vector<FileType> types(const std::string &path);
178-
static std::vector<DecoderEngine> engines(const std::string &path,
179-
FileType as);
180-
static FileType type(const std::string &path);
181-
static FileMeta meta(const std::string &path);
177+
static std::vector<FileType> list_file_types(const std::string &path);
178+
static std::vector<DecoderEngine>
179+
list_decoder_engines(const std::string &path, FileType as);
182180

183181
explicit DecodedFile(std::shared_ptr<internal::abstract::DecodedFile> impl);
184182
explicit DecodedFile(const File &file);
@@ -204,11 +202,11 @@ class DecodedFile {
204202
[[nodiscard]] bool is_document_file() const;
205203
[[nodiscard]] bool is_pdf_file() const;
206204

207-
[[nodiscard]] TextFile text_file() const;
208-
[[nodiscard]] ImageFile image_file() const;
209-
[[nodiscard]] ArchiveFile archive_file() const;
210-
[[nodiscard]] DocumentFile document_file() const;
211-
[[nodiscard]] PdfFile pdf_file() const;
205+
[[nodiscard]] TextFile as_text_file() const;
206+
[[nodiscard]] ImageFile as_image_file() const;
207+
[[nodiscard]] ArchiveFile as_archive_file() const;
208+
[[nodiscard]] DocumentFile as_document_file() const;
209+
[[nodiscard]] PdfFile as_pdf_file() const;
212210

213211
protected:
214212
std::shared_ptr<internal::abstract::DecodedFile> m_impl;

src/odr/global_params.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,11 @@ void GlobalParams::set_pdf2htmlex_data_path(const std::string &path) {
6363
}
6464

6565
GlobalParams::GlobalParams()
66-
: m_odr_core_data_path{internal::project_info::odr_data_path()},
67-
m_fontconfig_data_path{internal::project_info::fontconfig_data_path()},
68-
m_poppler_data_path{internal::project_info::poppler_data_path()},
69-
m_pdf2htmlex_data_path{internal::project_info::pdf2htmlex_data_path()} {}
66+
: m_odr_core_data_path{internal::project_info::get_odr_data_path()},
67+
m_fontconfig_data_path{
68+
internal::project_info::get_fontconfig_data_path()},
69+
m_poppler_data_path{internal::project_info::get_poppler_data_path()},
70+
m_pdf2htmlex_data_path{
71+
internal::project_info::get_pdf2htmlex_data_path()} {}
7072

7173
} // namespace odr

0 commit comments

Comments
 (0)