Skip to content

Commit 7325d1b

Browse files
authored
cleanup more (#466)
1 parent 61868ad commit 7325d1b

25 files changed

+224
-205
lines changed

src/odr/document.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace odr {
1212

1313
Document::Document(std::shared_ptr<internal::abstract::Document> impl)
1414
: m_impl{std::move(impl)} {
15-
if (!m_impl) {
15+
if (m_impl == nullptr) {
1616
throw NullPointerError("document is null");
1717
}
1818
}

src/odr/document_element.hpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include <odr/definitions.hpp>
88

99
namespace odr {
10-
class TablePosition;
10+
struct TablePosition;
1111
struct TableDimensions;
1212
class DocumentPath;
1313
class File;
@@ -29,8 +29,6 @@ class TextRootAdapter;
2929
class SlideAdapter;
3030
class PageAdapter;
3131
class SheetAdapter;
32-
class SheetColumnAdapter;
33-
class SheetRowAdapter;
3432
class SheetCellAdapter;
3533
class MasterPageAdapter;
3634
class LineBreakAdapter;
@@ -60,8 +58,6 @@ class ElementRange;
6058
class TextRoot;
6159
class Slide;
6260
class Sheet;
63-
class SheetColumn;
64-
class SheetRow;
6561
class SheetCell;
6662
class Page;
6763
class MasterPage;

src/odr/file.cpp

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -167,40 +167,45 @@ bool DecodedFile::is_pdf_file() const {
167167
}
168168

169169
TextFile DecodedFile::as_text_file() const {
170-
if (const auto text_file =
171-
std::dynamic_pointer_cast<internal::abstract::TextFile>(m_impl)) {
170+
if (const std::shared_ptr text_file =
171+
std::dynamic_pointer_cast<internal::abstract::TextFile>(m_impl);
172+
text_file != nullptr) {
172173
return TextFile(text_file);
173174
}
174175
throw NoTextFile();
175176
}
176177

177178
ImageFile DecodedFile::as_image_file() const {
178-
if (const auto image_file =
179-
std::dynamic_pointer_cast<internal::abstract::ImageFile>(m_impl)) {
179+
if (const std::shared_ptr image_file =
180+
std::dynamic_pointer_cast<internal::abstract::ImageFile>(m_impl);
181+
image_file != nullptr) {
180182
return ImageFile(image_file);
181183
}
182184
throw NoImageFile();
183185
}
184186

185187
ArchiveFile DecodedFile::as_archive_file() const {
186-
if (const auto archive_file =
187-
std::dynamic_pointer_cast<internal::abstract::ArchiveFile>(m_impl)) {
188+
if (const std::shared_ptr archive_file =
189+
std::dynamic_pointer_cast<internal::abstract::ArchiveFile>(m_impl);
190+
archive_file != nullptr) {
188191
return ArchiveFile(archive_file);
189192
}
190193
throw NoArchiveFile();
191194
}
192195

193196
DocumentFile DecodedFile::as_document_file() const {
194-
if (const auto document_file =
195-
std::dynamic_pointer_cast<internal::abstract::DocumentFile>(m_impl)) {
197+
if (const std::shared_ptr document_file =
198+
std::dynamic_pointer_cast<internal::abstract::DocumentFile>(m_impl);
199+
document_file != nullptr) {
196200
return DocumentFile(document_file);
197201
}
198202
throw NoDocumentFile();
199203
}
200204

201205
PdfFile DecodedFile::as_pdf_file() const {
202-
if (const auto pdf_file =
203-
std::dynamic_pointer_cast<internal::abstract::PdfFile>(m_impl)) {
206+
if (const std::shared_ptr pdf_file =
207+
std::dynamic_pointer_cast<internal::abstract::PdfFile>(m_impl);
208+
pdf_file != nullptr) {
204209
return PdfFile(pdf_file);
205210
}
206211
throw NoPdfFile();

src/odr/filesystem.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ FileWalker::FileWalker(FileWalker &&other) noexcept = default;
2222
FileWalker::~FileWalker() = default;
2323

2424
FileWalker &FileWalker::operator=(const FileWalker &other) {
25-
if (this == &other) {
25+
if (&other == this) {
2626
return *this;
2727
}
2828
m_impl = other.m_impl->clone();

src/odr/html.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,8 @@ HtmlService html::translate(const DocumentFile &document_file,
296296
#ifdef ODR_WITH_WVWARE
297297
if (const std::shared_ptr wv_document_file =
298298
std::dynamic_pointer_cast<WvWareLegacyMicrosoftFile>(
299-
document_file_impl)) {
299+
document_file_impl);
300+
wv_document_file != nullptr) {
300301
std::filesystem::create_directories(cache_path);
301302
return internal::html::create_wvware_oldms_service(
302303
*wv_document_file, cache_path, config, std::move(logger));
@@ -315,7 +316,8 @@ HtmlService html::translate(const PdfFile &pdf_file,
315316

316317
#ifdef ODR_WITH_PDF2HTMLEX
317318
if (const std::shared_ptr poppler_pdf_file =
318-
std::dynamic_pointer_cast<PopplerPdfFile>(pdf_file_impl)) {
319+
std::dynamic_pointer_cast<PopplerPdfFile>(pdf_file_impl);
320+
poppler_pdf_file != nullptr) {
319321
std::filesystem::create_directories(cache_path);
320322
return internal::html::create_poppler_pdf_service(
321323
*poppler_pdf_file, cache_path, config, std::move(logger));

src/odr/http_server.cpp

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

33
#include <odr/exceptions.hpp>
44
#include <odr/file.hpp>
5-
#include <odr/filesystem.hpp>
65
#include <odr/html.hpp>
7-
#include <odr/internal/pdf_poppler/poppler_pdf_file.hpp>
86

97
#include <httplib/httplib.h>
108

119
#include <atomic>
12-
#include <memory>
10+
#include <filesystem>
1311
#include <sstream>
1412

1513
namespace odr {
@@ -23,9 +21,9 @@ class HttpServer::Impl {
2321
// This prevents crashes when exceptions occur during request processing.
2422
m_server->set_exception_handler([this](const httplib::Request & /*req*/,
2523
httplib::Response &res,
26-
std::exception_ptr ep) {
24+
const std::exception_ptr &ep) {
2725
try {
28-
if (ep) {
26+
if (ep != nullptr) {
2927
std::rethrow_exception(ep);
3028
}
3129
} catch (const std::exception &e) {
@@ -73,7 +71,7 @@ class HttpServer::Impl {
7371
// here (via unique_ptr::reset), we ensure all threads are joined
7472
// before any other members are destroyed.
7573
m_stopping.store(true, std::memory_order_release);
76-
if (m_server) {
74+
if (m_server != nullptr) {
7775
m_server->stop();
7876
m_server.reset(); // Destroy server, join all thread pool threads
7977
}
@@ -160,7 +158,7 @@ class HttpServer::Impl {
160158
m_content.emplace(prefix, Content{prefix, std::move(service)});
161159
}
162160

163-
void listen(const std::string &host, const std::uint32_t port) {
161+
void listen(const std::string &host, const std::uint32_t port) const {
164162
ODR_VERBOSE(*m_logger, "Listening on " << host << ":" << port);
165163

166164
m_server->listen(host, static_cast<int>(port));
@@ -186,7 +184,7 @@ class HttpServer::Impl {
186184
// This prevents new requests from starting while we're shutting down.
187185
m_stopping.store(true, std::memory_order_release);
188186

189-
if (m_server) {
187+
if (m_server != nullptr) {
190188
// Stop the server to prevent new connections.
191189
// Note: httplib::Server::stop() signals shutdown but thread pool
192190
// threads may still be running. They only fully stop when the

src/odr/internal/abstract/document.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ enum class ValueType;
1313
enum class AnchorType;
1414
struct PageLayout;
1515
struct TableDimensions;
16-
class TablePosition;
16+
struct TablePosition;
1717
struct TableStyle;
1818
struct TableColumnStyle;
1919
struct TableRowStyle;

src/odr/internal/cfb/cfb_util.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,13 @@ std::optional<Archive::Entry> Archive::Entry::child() const {
133133
}
134134

135135
void Archive::Iterator::dig_left_() {
136-
if (!m_entry) {
136+
if (!m_entry.has_value()) {
137137
return;
138138
}
139139

140140
while (true) {
141141
const std::optional<Entry> left = m_entry->left();
142-
if (!left) {
142+
if (!left.has_value()) {
143143
break;
144144
}
145145
m_ancestors.push_back(*m_entry);
@@ -148,11 +148,11 @@ void Archive::Iterator::dig_left_() {
148148
}
149149

150150
void Archive::Iterator::next_() {
151-
if (!m_entry) {
151+
if (!m_entry.has_value()) {
152152
return;
153153
}
154154

155-
if (const std::optional<Entry> child = m_entry->child()) {
155+
if (const std::optional<Entry> child = m_entry->child(); child.has_value()) {
156156
m_directories.push_back(*m_entry);
157157
m_entry = child;
158158
dig_left_();
@@ -163,11 +163,11 @@ void Archive::Iterator::next_() {
163163
}
164164

165165
void Archive::Iterator::next_flat_() {
166-
if (!m_entry) {
166+
if (!m_entry.has_value()) {
167167
return;
168168
}
169169

170-
if (const std::optional<Entry> right = m_entry->right()) {
170+
if (const std::optional<Entry> right = m_entry->right(); right.has_value()) {
171171
m_entry = right;
172172
dig_left_();
173173
return;

src/odr/internal/common/path.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,9 @@ class Path {
9494

9595
private:
9696
std::string m_path;
97-
std::uint32_t m_upwards;
98-
std::uint32_t m_downwards;
99-
bool m_absolute;
97+
std::uint32_t m_upwards{0};
98+
std::uint32_t m_downwards{0};
99+
bool m_absolute{false};
100100

101101
friend std::ostream &operator<<(std::ostream &os, const Path &p) {
102102
return os << p.m_path;

src/odr/internal/common/table_range.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,8 @@ std::string TableRange::to_string() const noexcept {
2828
}
2929

3030
bool TableRange::contains(const TablePosition &position) const noexcept {
31-
return m_from.column() <= position.column() &&
32-
m_to.column() > position.column() && m_from.row() <= position.row() &&
33-
m_to.row() > position.row();
31+
return m_from.column <= position.column && m_to.column > position.column &&
32+
m_from.row <= position.row && m_to.row > position.row;
3433
}
3534

3635
} // namespace odr::internal

0 commit comments

Comments
 (0)