Skip to content

Commit df75338

Browse files
committed
more cleanup
1 parent 47e59e6 commit df75338

80 files changed

Lines changed: 979 additions & 946 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/internal/abstract/document_element.hpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
#include <odr/document_element.hpp>
44

5-
#include <memory>
65
#include <optional>
76
#include <string>
87

@@ -41,8 +40,7 @@ class Element {
4140
[[nodiscard]] virtual Element *previous_sibling(const Document *) const = 0;
4241
[[nodiscard]] virtual Element *next_sibling(const Document *) const = 0;
4342

44-
[[nodiscard]] virtual bool
45-
is_editable(const abstract::Document *document) const = 0;
43+
[[nodiscard]] virtual bool is_editable(const Document *document) const = 0;
4644
};
4745

4846
class TextRoot : public virtual Element {
@@ -53,8 +51,7 @@ class TextRoot : public virtual Element {
5351

5452
[[nodiscard]] virtual PageLayout page_layout(const Document *) const = 0;
5553

56-
[[nodiscard]] virtual abstract::Element *
57-
first_master_page(const Document *) const = 0;
54+
[[nodiscard]] virtual Element *first_master_page(const Document *) const = 0;
5855
};
5956

6057
class Slide : public virtual Element {
@@ -290,8 +287,7 @@ class Image : public virtual Element {
290287
}
291288

292289
[[nodiscard]] virtual bool is_internal(const Document *) const = 0;
293-
[[nodiscard]] virtual std::optional<odr::File>
294-
file(const Document *) const = 0;
290+
[[nodiscard]] virtual std::optional<File> file(const Document *) const = 0;
295291
[[nodiscard]] virtual std::string href(const Document *) const = 0;
296292
};
297293

src/odr/internal/abstract/filesystem.hpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class ReadableFilesystem {
4040
[[nodiscard]] virtual std::unique_ptr<FileWalker>
4141
file_walker(const AbsPath &path) const = 0;
4242

43-
[[nodiscard]] virtual std::shared_ptr<abstract::File>
43+
[[nodiscard]] virtual std::shared_ptr<File>
4444
open(const AbsPath &path) const = 0;
4545
};
4646

@@ -53,10 +53,9 @@ class WriteableFilesystem {
5353

5454
virtual bool remove(const AbsPath &path) = 0;
5555
virtual bool copy(const AbsPath &from, const AbsPath &to) = 0;
56-
virtual std::shared_ptr<abstract::File> copy(const abstract::File &from,
57-
const AbsPath &to) = 0;
58-
virtual std::shared_ptr<abstract::File>
59-
copy(std::shared_ptr<abstract::File> from, const AbsPath &to) = 0;
56+
virtual std::shared_ptr<File> copy(const File &from, const AbsPath &to) = 0;
57+
virtual std::shared_ptr<File> copy(std::shared_ptr<File> from,
58+
const AbsPath &to) = 0;
6059
virtual bool move(const AbsPath &from, const AbsPath &to) = 0;
6160
};
6261

src/odr/internal/abstract/html_service.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#include <odr/html.hpp>
44

55
#include <iosfwd>
6-
#include <memory>
76
#include <optional>
87

98
namespace odr {

src/odr/internal/cfb/cfb_archive.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#include <odr/exceptions.hpp>
44
#include <odr/internal/cfb/cfb_util.hpp>
55
#include <odr/internal/common/filesystem.hpp>
6-
#include <odr/internal/util/string_util.hpp>
76

87
namespace odr::internal::abstract {
98
class File;

src/odr/internal/cfb/cfb_archive.hpp

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

33
#include <odr/internal/abstract/archive.hpp>
4-
#include <odr/internal/common/file.hpp>
5-
#include <odr/internal/common/path.hpp>
64

7-
#include <iterator>
85
#include <memory>
9-
#include <optional>
10-
#include <string>
116
#include <vector>
127

138
namespace odr {
@@ -34,9 +29,9 @@ class CfbArchive final : public abstract::Archive {
3429
explicit CfbArchive(std::shared_ptr<util::Archive> archive);
3530

3631
[[nodiscard]] std::shared_ptr<abstract::Filesystem>
37-
as_filesystem() const final;
32+
as_filesystem() const override;
3833

39-
void save(std::ostream &out) const final;
34+
void save(std::ostream &out) const override;
4035

4136
private:
4237
std::shared_ptr<util::Archive> m_cfb;

src/odr/internal/cfb/cfb_file.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ class CfbFile final : public abstract::ArchiveFile {
2121
public:
2222
explicit CfbFile(const std::shared_ptr<MemoryFile> &file);
2323

24-
[[nodiscard]] std::shared_ptr<abstract::File> file() const noexcept final;
24+
[[nodiscard]] std::shared_ptr<abstract::File> file() const noexcept override;
2525

26-
[[nodiscard]] FileType file_type() const noexcept final;
27-
[[nodiscard]] FileMeta file_meta() const noexcept final;
28-
[[nodiscard]] DecoderEngine decoder_engine() const noexcept final;
26+
[[nodiscard]] FileType file_type() const noexcept override;
27+
[[nodiscard]] FileMeta file_meta() const noexcept override;
28+
[[nodiscard]] DecoderEngine decoder_engine() const noexcept override;
2929

30-
[[nodiscard]] std::shared_ptr<abstract::Archive> archive() const final;
30+
[[nodiscard]] std::shared_ptr<abstract::Archive> archive() const override;
3131

3232
private:
3333
std::shared_ptr<util::Archive> m_cfb;

src/odr/internal/cfb/cfb_impl.cpp

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ CompoundFileReader::CompoundFileReader(const void *buffer,
4141

4242
m_sector_size = m_hdr->major_version == 3 ? 512 : 4096;
4343

44-
// The file must contains at least 3 sectors
44+
// The file must contain at least 3 sectors
4545
if (m_buffer_len < m_sector_size * 3) {
4646
throw CfbFileCorrupted();
4747
}
@@ -54,7 +54,8 @@ CompoundFileReader::CompoundFileReader(const void *buffer,
5454
m_mini_stream_start_sector = root->start_sector_location;
5555
}
5656

57-
const CompoundFileEntry *CompoundFileReader::get_entry(size_t entry_id) const {
57+
const CompoundFileEntry *
58+
CompoundFileReader::get_entry(const std::size_t entry_id) const {
5859
if (entry_id == 0xFFFFFFFF) {
5960
return nullptr;
6061
}
@@ -94,9 +95,9 @@ void CompoundFileReader::read_file(const CompoundFileEntry *entry,
9495
}
9596

9697
void CompoundFileReader::enum_files(const CompoundFileEntry *entry,
97-
int max_level,
98+
const int max_level,
9899
const EnumFilesCallback &callback) const {
99-
std::u16string dir;
100+
const std::u16string dir;
100101
enum_nodes(get_entry(entry->child_id), 0, max_level, dir, callback);
101102
}
102103

@@ -114,10 +115,10 @@ void CompoundFileReader::enum_nodes(const CompoundFileEntry *entry,
114115

115116
callback(entry, dir, current_level + 1);
116117

117-
const CompoundFileEntry *child = get_entry(entry->child_id);
118-
if (child != nullptr) {
118+
if (const CompoundFileEntry *child = get_entry(entry->child_id);
119+
child != nullptr) {
119120
std::u16string new_dir = dir;
120-
if (dir.length() != 0) {
121+
if (!dir.empty()) {
121122
new_dir.push_back('/');
122123
}
123124
new_dir.append(reinterpret_cast<const char16_t *>(entry->name),
@@ -141,7 +142,7 @@ void CompoundFileReader::read_stream(std::size_t sector, std::size_t offset,
141142
// --> m_sectorSize --> ... --> remaining
142143
while (len > 0) {
143144
const std::uint8_t *src = sector_offset_to_address(sector, offset);
144-
std::size_t copylen = std::min(len, m_sector_size - offset);
145+
const std::size_t copylen = std::min(len, m_sector_size - offset);
145146
if (m_buffer + m_buffer_len < src + copylen) {
146147
throw CfbFileCorrupted();
147148
}
@@ -164,7 +165,7 @@ void CompoundFileReader::read_mini_stream(std::size_t sector,
164165
// --> m_sectorSize --> ... --> remaining
165166
while (len > 0) {
166167
const std::uint8_t *src = mini_sector_offset_to_address(sector, offset);
167-
std::size_t copylen = std::min(len, m_mini_sector_size - offset);
168+
const std::size_t copylen = std::min(len, m_mini_sector_size - offset);
168169
if (m_buffer + m_buffer_len < src + copylen) {
169170
throw CfbFileCorrupted();
170171
}
@@ -177,25 +178,28 @@ void CompoundFileReader::read_mini_stream(std::size_t sector,
177178
}
178179
}
179180

180-
std::size_t CompoundFileReader::get_next_sector(size_t sector) const {
181+
std::size_t
182+
CompoundFileReader::get_next_sector(const std::size_t sector) const {
181183
// lookup FAT
182-
std::size_t entriesPerSector = m_sector_size / 4;
183-
std::size_t fatSectorNumber = sector / entriesPerSector;
184-
std::size_t fatSectorLocation = get_fat_sector_location(fatSectorNumber);
184+
const std::size_t entriesPerSector = m_sector_size / 4;
185+
const std::size_t fatSectorNumber = sector / entriesPerSector;
186+
const std::size_t fatSectorLocation =
187+
get_fat_sector_location(fatSectorNumber);
185188
return parse_uint32(sector_offset_to_address(fatSectorLocation,
186189
sector % entriesPerSector * 4));
187190
}
188191

189-
std::size_t CompoundFileReader::get_next_mini_sector(size_t mini_sector) const {
192+
std::size_t
193+
CompoundFileReader::get_next_mini_sector(const std::size_t mini_sector) const {
190194
std::size_t sector, offset;
191195
locate_final_sector(m_hdr->first_mini_fat_sector_location, mini_sector * 4,
192196
&sector, &offset);
193197
return parse_uint32(sector_offset_to_address(sector, offset));
194198
}
195199

196200
const std::uint8_t *
197-
CompoundFileReader::sector_offset_to_address(size_t sector,
198-
size_t offset) const {
201+
CompoundFileReader::sector_offset_to_address(const std::size_t sector,
202+
const std::size_t offset) const {
199203
if (sector >= MAX_REG_SECT || offset >= m_sector_size ||
200204
m_buffer_len <= static_cast<std::uint64_t>(m_sector_size) * sector +
201205
m_sector_size + offset) {
@@ -249,7 +253,7 @@ std::size_t CompoundFileReader::get_fat_sector_location(
249253
}
250254

251255
fat_sector_number -= 109;
252-
std::size_t entriesPerSector = m_sector_size / 4 - 1;
256+
const std::size_t entriesPerSector = m_sector_size / 4 - 1;
253257
std::size_t difatSectorLocation = m_hdr->first_difat_sector_location;
254258
while (fat_sector_number >= entriesPerSector) {
255259
fat_sector_number -= entriesPerSector;
@@ -273,15 +277,18 @@ PropertySet::PropertySet(const void *buffer, const std::size_t len,
273277
}
274278
}
275279

276-
const std::uint16_t *PropertySet::get_string_property(uint32_t property_id) {
280+
const std::uint16_t *
281+
PropertySet::get_string_property(const std::uint32_t property_id) {
277282
for (std::uint32_t i = 0; i < m_hdr->num_properties; i++) {
278283
if (m_hdr->property_identifier_and_offset[i].id == property_id) {
279-
std::uint32_t offset = m_hdr->property_identifier_and_offset[i].offset;
284+
const std::uint32_t offset =
285+
m_hdr->property_identifier_and_offset[i].offset;
280286
if (m_buffer_len < offset + 8) {
281287
throw CfbFileCorrupted();
282288
}
283-
std::uint32_t stringLengthInChar = parse_uint32(m_buffer + offset + 4);
284-
if (m_buffer_len < offset + 8 + stringLengthInChar * 2) {
289+
if (const std::uint32_t stringLengthInChar =
290+
parse_uint32(m_buffer + offset + 4);
291+
m_buffer_len < offset + 8 + stringLengthInChar * 2) {
285292
throw CfbFileCorrupted();
286293
}
287294
return reinterpret_cast<const std::uint16_t *>(m_buffer + offset + 8);
@@ -307,15 +314,15 @@ std::size_t PropertySetStream::get_property_set_count() {
307314
return m_hdr->num_property_sets;
308315
}
309316

310-
PropertySet PropertySetStream::get_property_set(size_t index) {
317+
PropertySet PropertySetStream::get_property_set(const std::size_t index) {
311318
if (index >= get_property_set_count()) {
312319
throw CfbFileCorrupted();
313320
}
314-
std::uint32_t offset = m_hdr->property_set_info[index].offset;
321+
const std::uint32_t offset = m_hdr->property_set_info[index].offset;
315322
if (m_buffer_len < offset + 4) {
316323
throw CfbFileCorrupted();
317324
}
318-
std::uint32_t size = parse_uint32(m_buffer + offset);
325+
const std::uint32_t size = parse_uint32(m_buffer + offset);
319326
if (m_buffer_len < offset + size) {
320327
throw CfbFileCorrupted();
321328
}

src/odr/internal/cfb/cfb_impl.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,6 @@ class CompoundFileReader final {
135135
[[nodiscard]] std::size_t
136136
get_fat_sector_location(std::size_t fat_sector_number) const;
137137

138-
private:
139138
const std::uint8_t *m_buffer;
140139
std::size_t m_buffer_len;
141140

0 commit comments

Comments
 (0)