Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/odr/document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace odr {

Document::Document(std::shared_ptr<internal::abstract::Document> impl)
: m_impl{std::move(impl)} {
if (!m_impl) {
if (m_impl == nullptr) {
throw NullPointerError("document is null");
}
}
Expand Down
6 changes: 1 addition & 5 deletions src/odr/document_element.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <odr/definitions.hpp>

namespace odr {
class TablePosition;
struct TablePosition;
struct TableDimensions;
class DocumentPath;
class File;
Expand All @@ -29,8 +29,6 @@ class TextRootAdapter;
class SlideAdapter;
class PageAdapter;
class SheetAdapter;
class SheetColumnAdapter;
class SheetRowAdapter;
class SheetCellAdapter;
class MasterPageAdapter;
class LineBreakAdapter;
Expand Down Expand Up @@ -60,8 +58,6 @@ class ElementRange;
class TextRoot;
class Slide;
class Sheet;
class SheetColumn;
class SheetRow;
class SheetCell;
class Page;
class MasterPage;
Expand Down
25 changes: 15 additions & 10 deletions src/odr/file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,40 +167,45 @@ bool DecodedFile::is_pdf_file() const {
}

TextFile DecodedFile::as_text_file() const {
if (const auto text_file =
std::dynamic_pointer_cast<internal::abstract::TextFile>(m_impl)) {
if (const std::shared_ptr text_file =
std::dynamic_pointer_cast<internal::abstract::TextFile>(m_impl);
text_file != nullptr) {
return TextFile(text_file);
}
throw NoTextFile();
}

ImageFile DecodedFile::as_image_file() const {
if (const auto image_file =
std::dynamic_pointer_cast<internal::abstract::ImageFile>(m_impl)) {
if (const std::shared_ptr image_file =
std::dynamic_pointer_cast<internal::abstract::ImageFile>(m_impl);
image_file != nullptr) {
return ImageFile(image_file);
}
throw NoImageFile();
}

ArchiveFile DecodedFile::as_archive_file() const {
if (const auto archive_file =
std::dynamic_pointer_cast<internal::abstract::ArchiveFile>(m_impl)) {
if (const std::shared_ptr archive_file =
std::dynamic_pointer_cast<internal::abstract::ArchiveFile>(m_impl);
archive_file != nullptr) {
return ArchiveFile(archive_file);
}
throw NoArchiveFile();
}

DocumentFile DecodedFile::as_document_file() const {
if (const auto document_file =
std::dynamic_pointer_cast<internal::abstract::DocumentFile>(m_impl)) {
if (const std::shared_ptr document_file =
std::dynamic_pointer_cast<internal::abstract::DocumentFile>(m_impl);
document_file != nullptr) {
return DocumentFile(document_file);
}
throw NoDocumentFile();
}

PdfFile DecodedFile::as_pdf_file() const {
if (const auto pdf_file =
std::dynamic_pointer_cast<internal::abstract::PdfFile>(m_impl)) {
if (const std::shared_ptr pdf_file =
std::dynamic_pointer_cast<internal::abstract::PdfFile>(m_impl);
pdf_file != nullptr) {
return PdfFile(pdf_file);
}
throw NoPdfFile();
Expand Down
2 changes: 1 addition & 1 deletion src/odr/filesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ FileWalker::FileWalker(FileWalker &&other) noexcept = default;
FileWalker::~FileWalker() = default;

FileWalker &FileWalker::operator=(const FileWalker &other) {
if (this == &other) {
if (&other == this) {
return *this;
}
m_impl = other.m_impl->clone();
Expand Down
6 changes: 4 additions & 2 deletions src/odr/html.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,8 @@ HtmlService html::translate(const DocumentFile &document_file,
#ifdef ODR_WITH_WVWARE
if (const std::shared_ptr wv_document_file =
std::dynamic_pointer_cast<WvWareLegacyMicrosoftFile>(
document_file_impl)) {
document_file_impl);
wv_document_file != nullptr) {
std::filesystem::create_directories(cache_path);
return internal::html::create_wvware_oldms_service(
*wv_document_file, cache_path, config, std::move(logger));
Expand All @@ -315,7 +316,8 @@ HtmlService html::translate(const PdfFile &pdf_file,

#ifdef ODR_WITH_PDF2HTMLEX
if (const std::shared_ptr poppler_pdf_file =
std::dynamic_pointer_cast<PopplerPdfFile>(pdf_file_impl)) {
std::dynamic_pointer_cast<PopplerPdfFile>(pdf_file_impl);
poppler_pdf_file != nullptr) {
std::filesystem::create_directories(cache_path);
return internal::html::create_poppler_pdf_service(
*poppler_pdf_file, cache_path, config, std::move(logger));
Expand Down
14 changes: 6 additions & 8 deletions src/odr/http_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@

#include <odr/exceptions.hpp>
#include <odr/file.hpp>
#include <odr/filesystem.hpp>
#include <odr/html.hpp>
#include <odr/internal/pdf_poppler/poppler_pdf_file.hpp>

#include <httplib/httplib.h>

#include <atomic>
#include <memory>
#include <filesystem>
#include <sstream>

namespace odr {
Expand All @@ -23,9 +21,9 @@ class HttpServer::Impl {
// This prevents crashes when exceptions occur during request processing.
m_server->set_exception_handler([this](const httplib::Request & /*req*/,
httplib::Response &res,
std::exception_ptr ep) {
const std::exception_ptr &ep) {
try {
if (ep) {
if (ep != nullptr) {
std::rethrow_exception(ep);
}
} catch (const std::exception &e) {
Expand Down Expand Up @@ -73,7 +71,7 @@ class HttpServer::Impl {
// here (via unique_ptr::reset), we ensure all threads are joined
// before any other members are destroyed.
m_stopping.store(true, std::memory_order_release);
if (m_server) {
if (m_server != nullptr) {
m_server->stop();
m_server.reset(); // Destroy server, join all thread pool threads
}
Expand Down Expand Up @@ -160,7 +158,7 @@ class HttpServer::Impl {
m_content.emplace(prefix, Content{prefix, std::move(service)});
}

void listen(const std::string &host, const std::uint32_t port) {
void listen(const std::string &host, const std::uint32_t port) const {
ODR_VERBOSE(*m_logger, "Listening on " << host << ":" << port);

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

if (m_server) {
if (m_server != nullptr) {
// Stop the server to prevent new connections.
// Note: httplib::Server::stop() signals shutdown but thread pool
// threads may still be running. They only fully stop when the
Expand Down
2 changes: 1 addition & 1 deletion src/odr/internal/abstract/document.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ enum class ValueType;
enum class AnchorType;
struct PageLayout;
struct TableDimensions;
class TablePosition;
struct TablePosition;
struct TableStyle;
struct TableColumnStyle;
struct TableRowStyle;
Expand Down
12 changes: 6 additions & 6 deletions src/odr/internal/cfb/cfb_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,13 @@ std::optional<Archive::Entry> Archive::Entry::child() const {
}

void Archive::Iterator::dig_left_() {
if (!m_entry) {
if (!m_entry.has_value()) {
return;
}

while (true) {
const std::optional<Entry> left = m_entry->left();
if (!left) {
if (!left.has_value()) {
break;
}
m_ancestors.push_back(*m_entry);
Expand All @@ -148,11 +148,11 @@ void Archive::Iterator::dig_left_() {
}

void Archive::Iterator::next_() {
if (!m_entry) {
if (!m_entry.has_value()) {
return;
}

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

void Archive::Iterator::next_flat_() {
if (!m_entry) {
if (!m_entry.has_value()) {
return;
}

if (const std::optional<Entry> right = m_entry->right()) {
if (const std::optional<Entry> right = m_entry->right(); right.has_value()) {
m_entry = right;
dig_left_();
return;
Expand Down
6 changes: 3 additions & 3 deletions src/odr/internal/common/path.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ class Path {

private:
std::string m_path;
std::uint32_t m_upwards;
std::uint32_t m_downwards;
bool m_absolute;
std::uint32_t m_upwards{0};
std::uint32_t m_downwards{0};
bool m_absolute{false};

friend std::ostream &operator<<(std::ostream &os, const Path &p) {
return os << p.m_path;
Expand Down
5 changes: 2 additions & 3 deletions src/odr/internal/common/table_range.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@ std::string TableRange::to_string() const noexcept {
}

bool TableRange::contains(const TablePosition &position) const noexcept {
return m_from.column() <= position.column() &&
m_to.column() > position.column() && m_from.row() <= position.row() &&
m_to.row() > position.row();
return m_from.column <= position.column && m_to.column > position.column &&
m_from.row <= position.row && m_to.row > position.row;
}

} // namespace odr::internal
3 changes: 2 additions & 1 deletion src/odr/internal/html/document_element.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ void html::translate_sheet(const Sheet &sheet, const WritingState &state) {
state.out().write_element_begin(
"td", HtmlElementOptions().set_inline(true).set_style([&] {
std::string style = "text-align:center;vertical-align:middle;";
if (const std::optional<Measure> height = table_row_style.height) {
if (const std::optional<Measure> height = table_row_style.height;
height.has_value()) {
style += "height:" + height->to_string() + ";";
style += "max-height:" + height->to_string() + ";";
}
Expand Down
Loading