diff --git a/src/odr/archive.hpp b/src/odr/archive.hpp index 1cc75a9d..9d3a4485 100644 --- a/src/odr/archive.hpp +++ b/src/odr/archive.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_ARCHIVE_HPP -#define ODR_ARCHIVE_HPP +#pragma once #include #include @@ -27,5 +26,3 @@ class Archive { }; } // namespace odr - -#endif // ODR_ARCHIVE_HPP diff --git a/src/odr/document.cpp b/src/odr/document.cpp index ba58dbba..5ebffc13 100644 --- a/src/odr/document.cpp +++ b/src/odr/document.cpp @@ -8,7 +8,6 @@ #include #include -#include namespace odr { @@ -25,11 +24,13 @@ bool Document::savable(const bool encrypted) const noexcept { return m_impl->is_savable(encrypted); } -void Document::save(const std::string &path) const { m_impl->save(path); } +void Document::save(const std::string &path) const { + m_impl->save(internal::common::Path(path)); +} void Document::save(const std::string &path, const std::string &password) const { - m_impl->save(path, password.c_str()); + m_impl->save(internal::common::Path(path), password.c_str()); } FileType Document::file_type() const noexcept { return m_impl->file_type(); } diff --git a/src/odr/document.hpp b/src/odr/document.hpp index 787966d2..10652b11 100644 --- a/src/odr/document.hpp +++ b/src/odr/document.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_DOCUMENT_HPP -#define ODR_DOCUMENT_HPP +#pragma once #include #include @@ -40,5 +39,3 @@ class Document final { }; } // namespace odr - -#endif // ODR_DOCUMENT_HPP diff --git a/src/odr/document_element.hpp b/src/odr/document_element.hpp index 615b25a7..67247f84 100644 --- a/src/odr/document_element.hpp +++ b/src/odr/document_element.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_DOCUMENT_ELEMENT_HPP -#define ODR_DOCUMENT_ELEMENT_HPP +#pragma once #include #include @@ -533,5 +532,3 @@ class Image final : public TypedElement { }; } // namespace odr - -#endif // ODR_DOCUMENT_ELEMENT_HPP diff --git a/src/odr/document_path.hpp b/src/odr/document_path.hpp index e6812877..4863025c 100644 --- a/src/odr/document_path.hpp +++ b/src/odr/document_path.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_DOCUMENT_PATH_HPP -#define ODR_DOCUMENT_PATH_HPP +#pragma once #include #include @@ -78,5 +77,3 @@ class DocumentPath final { }; } // namespace odr - -#endif // ODR_DOCUMENT_PATH_HPP diff --git a/src/odr/exceptions.hpp b/src/odr/exceptions.hpp index eae36daf..0a4a2dce 100644 --- a/src/odr/exceptions.hpp +++ b/src/odr/exceptions.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_EXCEPTIONS_HPP -#define ODR_EXCEPTIONS_HPP +#pragma once #include @@ -149,5 +148,3 @@ struct UnknownDocumentType final : public std::runtime_error { }; } // namespace odr - -#endif // ODR_EXCEPTIONS_HPP diff --git a/src/odr/file.hpp b/src/odr/file.hpp index 1506fb04..935dea3f 100644 --- a/src/odr/file.hpp +++ b/src/odr/file.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_FILE_HPP -#define ODR_FILE_HPP +#pragma once #include #include @@ -289,5 +288,3 @@ class PdfFile final : public DecodedFile { }; } // namespace odr - -#endif // ODR_FILE_HPP diff --git a/src/odr/filesystem.cpp b/src/odr/filesystem.cpp index 14f4def5..d2819ba1 100644 --- a/src/odr/filesystem.cpp +++ b/src/odr/filesystem.cpp @@ -67,23 +67,24 @@ Filesystem::Filesystem( Filesystem::operator bool() const { return m_impl.operator bool(); } bool Filesystem::exists(const std::string &path) const { - return m_impl ? m_impl->exists(path) : false; + return m_impl ? m_impl->exists(internal::common::Path(path)) : false; } bool Filesystem::is_file(const std::string &path) const { - return m_impl ? m_impl->is_file(path) : false; + return m_impl ? m_impl->is_file(internal::common::Path(path)) : false; } bool Filesystem::is_directory(const std::string &path) const { - return m_impl ? m_impl->is_directory(path) : false; + return m_impl ? m_impl->is_directory(internal::common::Path(path)) : false; } FileWalker Filesystem::file_walker(const std::string &path) const { - return m_impl ? FileWalker(m_impl->file_walker(path)) : FileWalker(); + return m_impl ? FileWalker(m_impl->file_walker(internal::common::Path(path))) + : FileWalker(); } File Filesystem::open(const std::string &path) const { - return m_impl ? File(m_impl->open(path)) : File(); + return m_impl ? File(m_impl->open(internal::common::Path(path))) : File(); } } // namespace odr diff --git a/src/odr/filesystem.hpp b/src/odr/filesystem.hpp index 59c2fb17..ada13250 100644 --- a/src/odr/filesystem.hpp +++ b/src/odr/filesystem.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_FILESYSTEM_HPP -#define ODR_FILESYSTEM_HPP +#pragma once #include #include @@ -60,5 +59,3 @@ class Filesystem { }; } // namespace odr - -#endif // ODR_FILESYSTEM_HPP diff --git a/src/odr/html.hpp b/src/odr/html.hpp index 020bf218..cbbdc53f 100644 --- a/src/odr/html.hpp +++ b/src/odr/html.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_HTML_HPP -#define ODR_HTML_HPP +#pragma once #include #include @@ -202,5 +201,3 @@ void edit(const Document &document, const char *diff); } // namespace html } // namespace odr - -#endif // ODR_HTML_HPP diff --git a/src/odr/html_service.hpp b/src/odr/html_service.hpp index 6d9eeb03..d0b407a6 100644 --- a/src/odr/html_service.hpp +++ b/src/odr/html_service.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_HTML_SERVICE_HPP -#define ODR_HTML_SERVICE_HPP +#pragma once #include #include @@ -61,5 +60,3 @@ class HtmlFragment final { }; } // namespace odr - -#endif // ODR_HTML_SERVICE_HPP diff --git a/src/odr/internal/abstract/archive.hpp b/src/odr/internal/abstract/archive.hpp index b50a9720..908732b1 100644 --- a/src/odr/internal/abstract/archive.hpp +++ b/src/odr/internal/abstract/archive.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_INTERNAL_ABSTRACT_ARCHIVE_HPP -#define ODR_INTERNAL_ABSTRACT_ARCHIVE_HPP +#pragma once #include @@ -20,5 +19,3 @@ class Archive { }; } // namespace odr::internal::abstract - -#endif // ODR_INTERNAL_ABSTRACT_ARCHIVE_HPP diff --git a/src/odr/internal/abstract/document.hpp b/src/odr/internal/abstract/document.hpp index 181d30c3..385b8bd6 100644 --- a/src/odr/internal/abstract/document.hpp +++ b/src/odr/internal/abstract/document.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_INTERNAL_ABSTRACT_DOCUMENT_HPP -#define ODR_INTERNAL_ABSTRACT_DOCUMENT_HPP +#pragma once #include @@ -52,5 +51,3 @@ class Document { }; } // namespace odr::internal::abstract - -#endif // ODR_INTERNAL_ABSTRACT_DOCUMENT_HPP diff --git a/src/odr/internal/abstract/document_element.hpp b/src/odr/internal/abstract/document_element.hpp index 2fc07140..1032267d 100644 --- a/src/odr/internal/abstract/document_element.hpp +++ b/src/odr/internal/abstract/document_element.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_INTERNAL_ABSTRACT_DOCUMENT_ELEMENT_HPP -#define ODR_INTERNAL_ABSTRACT_DOCUMENT_ELEMENT_HPP +#pragma once #include @@ -297,5 +296,3 @@ class Image : public virtual Element { }; } // namespace odr::internal::abstract - -#endif // ODR_INTERNAL_ABSTRACT_DOCUMENT_ELEMENT_HPP diff --git a/src/odr/internal/abstract/file.hpp b/src/odr/internal/abstract/file.hpp index 728e9d30..508f5e74 100644 --- a/src/odr/internal/abstract/file.hpp +++ b/src/odr/internal/abstract/file.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_INTERNAL_ABSTRACT_FILE_HPP -#define ODR_INTERNAL_ABSTRACT_FILE_HPP +#pragma once #include @@ -97,5 +96,3 @@ class PdfFile : public DecodedFile { }; } // namespace odr::internal::abstract - -#endif // ODR_INTERNAL_ABSTRACT_FILE_HPP diff --git a/src/odr/internal/abstract/filesystem.hpp b/src/odr/internal/abstract/filesystem.hpp index 4acfbc5c..6b072515 100644 --- a/src/odr/internal/abstract/filesystem.hpp +++ b/src/odr/internal/abstract/filesystem.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_INTERNAL_ABSTRACT_FILESYSTEM_HPP -#define ODR_INTERNAL_ABSTRACT_FILESYSTEM_HPP +#pragma once #include #include @@ -65,5 +64,3 @@ class WriteableFilesystem { class Filesystem : public ReadableFilesystem, public WriteableFilesystem {}; } // namespace odr::internal::abstract - -#endif // ODR_INTERNAL_ABSTRACT_FILESYSTEM_HPP diff --git a/src/odr/internal/abstract/html_service.hpp b/src/odr/internal/abstract/html_service.hpp index 36168ff6..f8e5520e 100644 --- a/src/odr/internal/abstract/html_service.hpp +++ b/src/odr/internal/abstract/html_service.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_INTERNAL_ABSTRACT_HTML_SERVICE_HPP -#define ODR_INTERNAL_ABSTRACT_HTML_SERVICE_HPP +#pragma once #include @@ -42,5 +41,3 @@ class HtmlFragment { }; } // namespace odr::internal::abstract - -#endif // ODR_INTERNAL_ABSTRACT_HTML_SERVICE_HPP diff --git a/src/odr/internal/abstract/sheet_element.hpp b/src/odr/internal/abstract/sheet_element.hpp index 9dbb8a60..98aebc19 100644 --- a/src/odr/internal/abstract/sheet_element.hpp +++ b/src/odr/internal/abstract/sheet_element.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_INTERNAL_ABSTRACT_SHEET_ELEMENT_HPP -#define ODR_INTERNAL_ABSTRACT_SHEET_ELEMENT_HPP +#pragma once #include @@ -47,5 +46,3 @@ class SheetCell : public virtual Element { }; } // namespace odr::internal::abstract - -#endif // ODR_INTERNAL_ABSTRACT_SHEET_ELEMENT_HPP diff --git a/src/odr/internal/cfb/cfb_archive.hpp b/src/odr/internal/cfb/cfb_archive.hpp index 03e086bf..f024fd2e 100644 --- a/src/odr/internal/cfb/cfb_archive.hpp +++ b/src/odr/internal/cfb/cfb_archive.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_INTERNAL_CFB_ARCHIVE_HPP -#define ODR_INTERNAL_CFB_ARCHIVE_HPP +#pragma once #include #include @@ -43,5 +42,3 @@ class CfbArchive final : public abstract::Archive { }; } // namespace odr::internal::cfb - -#endif // ODR_INTERNAL_CFB_ARCHIVE_HPP diff --git a/src/odr/internal/cfb/cfb_file.hpp b/src/odr/internal/cfb/cfb_file.hpp index f5696f0e..0c55d11b 100644 --- a/src/odr/internal/cfb/cfb_file.hpp +++ b/src/odr/internal/cfb/cfb_file.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_INTERNAL_CFB_FILE_HPP -#define ODR_INTERNAL_CFB_FILE_HPP +#pragma once #include @@ -35,5 +34,3 @@ class CfbFile final : public abstract::ArchiveFile { }; } // namespace odr::internal::cfb - -#endif // ODR_INTERNAL_CFB_FILE_HPP diff --git a/src/odr/internal/cfb/cfb_impl.hpp b/src/odr/internal/cfb/cfb_impl.hpp index 6dd66a8f..df636bed 100644 --- a/src/odr/internal/cfb/cfb_impl.hpp +++ b/src/odr/internal/cfb/cfb_impl.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_INTERNAL_CFB_IMPL_HPP -#define ODR_INTERNAL_CFB_IMPL_HPP +#pragma once #include #include @@ -181,5 +180,3 @@ class PropertySetStream final { }; } // namespace odr::internal::cfb::impl - -#endif // ODR_INTERNAL_CFB_IMPL_HPP diff --git a/src/odr/internal/cfb/cfb_util.hpp b/src/odr/internal/cfb/cfb_util.hpp index 8ba21d51..f250db87 100644 --- a/src/odr/internal/cfb/cfb_util.hpp +++ b/src/odr/internal/cfb/cfb_util.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_INTERNAL_CFB_UTIL_HPP -#define ODR_INTERNAL_CFB_UTIL_HPP +#pragma once #include @@ -45,8 +44,8 @@ class Archive final : public std::enable_shared_from_this { : m_parent{&parent}, m_entry{&entry}, m_path{"/"} {} Entry(const Archive &parent, const impl::CompoundFileEntry &entry, const common::Path &parent_path) - : m_parent{&parent}, m_entry{&entry}, m_path{parent_path.join(name())} { - } + : m_parent{&parent}, m_entry{&entry}, + m_path{parent_path.join(common::Path(name()))} {} ~Entry() = default; Entry &operator=(const Entry &) = default; Entry &operator=(Entry &&) noexcept = default; @@ -136,5 +135,3 @@ class Archive final : public std::enable_shared_from_this { }; } // namespace odr::internal::cfb::util - -#endif // ODR_INTERNAL_CFB_UTIL_HPP diff --git a/src/odr/internal/common/document.hpp b/src/odr/internal/common/document.hpp index c1c7e720..972ba553 100644 --- a/src/odr/internal/common/document.hpp +++ b/src/odr/internal/common/document.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_INTERNAL_COMMON_DOCUMENT_HPP -#define ODR_INTERNAL_COMMON_DOCUMENT_HPP +#pragma once #include @@ -52,5 +51,3 @@ template class TemplateDocument : public Document { }; } // namespace odr::internal::common - -#endif // ODR_INTERNAL_COMMON_DOCUMENT_HPP diff --git a/src/odr/internal/common/document_element.hpp b/src/odr/internal/common/document_element.hpp index e786e463..25fb38e3 100644 --- a/src/odr/internal/common/document_element.hpp +++ b/src/odr/internal/common/document_element.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_INTERNAL_COMMON_DOCUMENT_ELEMENT_HPP -#define ODR_INTERNAL_COMMON_DOCUMENT_ELEMENT_HPP +#pragma once #include @@ -59,5 +58,3 @@ class Table : public virtual Element, public abstract::Table { }; } // namespace odr::internal::common - -#endif // ODR_INTERNAL_COMMON_DOCUMENT_ELEMENT_HPP diff --git a/src/odr/internal/common/file.hpp b/src/odr/internal/common/file.hpp index 84c7e0dd..cec30ab0 100644 --- a/src/odr/internal/common/file.hpp +++ b/src/odr/internal/common/file.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_INTERNAL_COMMON_FILE_HPP -#define ODR_INTERNAL_COMMON_FILE_HPP +#pragma once #include #include @@ -52,5 +51,3 @@ class MemoryFile final : public abstract::File { }; } // namespace odr::internal::common - -#endif // ODR_INTERNAL_COMMON_FILE_HPP diff --git a/src/odr/internal/common/filesystem.cpp b/src/odr/internal/common/filesystem.cpp index 771b4fff..df4f6d2d 100644 --- a/src/odr/internal/common/filesystem.cpp +++ b/src/odr/internal/common/filesystem.cpp @@ -10,7 +10,6 @@ #include #include #include -#include namespace odr::internal::common { @@ -65,7 +64,7 @@ class SystemFileWalker final : public abstract::FileWalker { SystemFilesystem::SystemFilesystem(Path root) : m_root{std::move(root)} {} Path SystemFilesystem::to_system_path_(const Path &path) const { - return m_root.join(path.rebase("/")); + return m_root.join(path.rebase(Path("/"))); } bool SystemFilesystem::exists(const Path &path) const { diff --git a/src/odr/internal/common/filesystem.hpp b/src/odr/internal/common/filesystem.hpp index edc3e2e2..579b0be1 100644 --- a/src/odr/internal/common/filesystem.hpp +++ b/src/odr/internal/common/filesystem.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_INTERNAL_COMMON_FILESYSTEM_HPP -#define ODR_INTERNAL_COMMON_FILESYSTEM_HPP +#pragma once #include #include @@ -74,5 +73,3 @@ class VirtualFilesystem final : public abstract::Filesystem { }; } // namespace odr::internal::common - -#endif // ODR_INTERNAL_COMMON_FILESYSTEM_HPP diff --git a/src/odr/internal/common/image_file.hpp b/src/odr/internal/common/image_file.hpp index 81024754..035292e3 100644 --- a/src/odr/internal/common/image_file.hpp +++ b/src/odr/internal/common/image_file.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_INTERNAL_COMMON_IMAGE_FILE_HPP -#define ODR_INTERNAL_COMMON_IMAGE_FILE_HPP +#pragma once #include @@ -23,5 +22,3 @@ class ImageFile : public abstract::ImageFile { }; } // namespace odr::internal::common - -#endif // ODR_INTERNAL_COMMON_IMAGE_FILE_HPP diff --git a/src/odr/internal/common/path.cpp b/src/odr/internal/common/path.cpp index 69873cbf..500b7a7b 100644 --- a/src/odr/internal/common/path.cpp +++ b/src/odr/internal/common/path.cpp @@ -11,25 +11,27 @@ namespace odr::internal::common { Path::Path() noexcept : Path("") {} -Path::Path(const char *path) : Path(std::string(path)) {} +Path::Path(const char *c_string) : Path(std::string(c_string)) {} -Path::Path(const std::string &path) { +Path::Path(const std::string &string) { // TODO throw on illegal chars // TODO remove forward slash - if (path.rfind("/..", 0) == 0) { + if (string.rfind("/..", 0) == 0) { throw std::invalid_argument("path"); } - m_absolute = !path.empty() && (path[0] == '/'); + m_absolute = !string.empty() && (string[0] == '/'); m_path = m_absolute ? "/" : ""; m_upwards = 0; m_downwards = 0; - for (auto it = Iterator(path, m_absolute ? 1 : 0); it != end(); ++it) { + for (auto it = Iterator(string, m_absolute ? 1 : 0); it != end(); ++it) { join_(*it); } } +Path::Path(std::string_view string_view) : Path(std::string(string_view)) {} + Path::Path(const std::filesystem::path &path) : Path(path.string()) {} void Path::parent_() { @@ -184,7 +186,7 @@ Path Path::join(const Path &b) const { } Path Path::rebase(const Path &b) const { - Path result = m_absolute ? "/" : ""; + Path result = Path(m_absolute ? "/" : ""); auto common_root = this->common_root(b); Path sub_a; @@ -231,7 +233,7 @@ Path Path::common_root(const Path &b) const { throw std::invalid_argument("parent directories unknown"); } - Path result = m_absolute ? "/" : ""; + Path result = Path(m_absolute ? "/" : ""); auto it_a = begin(); auto it_b = b.begin(); diff --git a/src/odr/internal/common/path.hpp b/src/odr/internal/common/path.hpp index 9c2e7d52..0cddee2e 100644 --- a/src/odr/internal/common/path.hpp +++ b/src/odr/internal/common/path.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_INTERNAL_COMMON_PATH_HPP -#define ODR_INTERNAL_COMMON_PATH_HPP +#pragma once #include #include @@ -12,9 +11,10 @@ namespace odr::internal::common { class Path final { public: Path() noexcept; - Path(const char *c_string); - Path(const std::string &string); - Path(const std::filesystem::path &path); + explicit Path(const char *c_string); + explicit Path(const std::string &string); + explicit Path(std::string_view string_view); + explicit Path(const std::filesystem::path &path); bool operator==(const Path &other) const noexcept; bool operator!=(const Path &other) const noexcept; @@ -99,5 +99,3 @@ template <> struct hash<::odr::internal::common::Path> { std::size_t operator()(const ::odr::internal::common::Path &p) const; }; } // namespace std - -#endif // ODR_INTERNAL_COMMON_PATH_HPP diff --git a/src/odr/internal/common/random.hpp b/src/odr/internal/common/random.hpp index 82c5940f..fd95e3ab 100644 --- a/src/odr/internal/common/random.hpp +++ b/src/odr/internal/common/random.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_INTERNAL_COMMON_RANDOM_HPP -#define ODR_INTERNAL_COMMON_RANDOM_HPP +#pragma once #include @@ -8,5 +7,3 @@ namespace odr::internal::common { std::string random_string(std::size_t length); } - -#endif // ODR_INTERNAL_COMMON_RANDOM_HPP diff --git a/src/odr/internal/common/style.hpp b/src/odr/internal/common/style.hpp index 1a82c9d2..037e17e3 100644 --- a/src/odr/internal/common/style.hpp +++ b/src/odr/internal/common/style.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_INTERNAL_COMMON_STYLE_HPP -#define ODR_INTERNAL_COMMON_STYLE_HPP +#pragma once #include @@ -20,5 +19,3 @@ struct ResolvedStyle final { }; } // namespace odr::internal::common - -#endif // ODR_INTERNAL_COMMON_STYLE_HPP diff --git a/src/odr/internal/common/table_cursor.hpp b/src/odr/internal/common/table_cursor.hpp index fd248156..0e953217 100644 --- a/src/odr/internal/common/table_cursor.hpp +++ b/src/odr/internal/common/table_cursor.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_INTERNAL_COMMON_TABLE_CURSOR_HPP -#define ODR_INTERNAL_COMMON_TABLE_CURSOR_HPP +#pragma once #include @@ -35,5 +34,3 @@ class TableCursor final { }; } // namespace odr::internal::common - -#endif // ODR_INTERNAL_COMMON_TABLE_CURSOR_HPP diff --git a/src/odr/internal/common/table_position.hpp b/src/odr/internal/common/table_position.hpp index 4fb48e06..2124e2ef 100644 --- a/src/odr/internal/common/table_position.hpp +++ b/src/odr/internal/common/table_position.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_INTERNAL_COMMON_TABLE_POSITION_HPP -#define ODR_INTERNAL_COMMON_TABLE_POSITION_HPP +#pragma once #include #include @@ -37,5 +36,3 @@ class TablePosition final { template <> struct std::hash { std::size_t operator()(const odr::internal::common::TablePosition &k) const; }; - -#endif // ODR_INTERNAL_COMMON_TABLE_POSITION_HPP diff --git a/src/odr/internal/common/table_range.hpp b/src/odr/internal/common/table_range.hpp index 5a86ce07..55059cfd 100644 --- a/src/odr/internal/common/table_range.hpp +++ b/src/odr/internal/common/table_range.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_INTERNAL_COMMON_TABLE_RANGE_HPP -#define ODR_INTERNAL_COMMON_TABLE_RANGE_HPP +#pragma once #include @@ -28,5 +27,3 @@ class TableRange final { }; } // namespace odr::internal::common - -#endif // ODR_INTERNAL_COMMON_TABLE_RANGE_HPP diff --git a/src/odr/internal/common/temporary_file.cpp b/src/odr/internal/common/temporary_file.cpp index 8ea006ce..a646cfed 100644 --- a/src/odr/internal/common/temporary_file.cpp +++ b/src/odr/internal/common/temporary_file.cpp @@ -1,19 +1,20 @@ #include +#include #include #include #include +#include namespace odr::internal::common { TemporaryDiskFile::TemporaryDiskFile(const char *path) : DiskFile{path} {} -TemporaryDiskFile::TemporaryDiskFile(std::string path) - : DiskFile{std::move(path)} {} +TemporaryDiskFile::TemporaryDiskFile(const std::string &path) + : DiskFile{path} {} -TemporaryDiskFile::TemporaryDiskFile(common::Path path) - : DiskFile{std::move(path)} {} +TemporaryDiskFile::TemporaryDiskFile(const Path &path) : DiskFile{path} {} TemporaryDiskFile::TemporaryDiskFile(const TemporaryDiskFile &) = default; @@ -31,7 +32,8 @@ TemporaryDiskFile::operator=(TemporaryDiskFile &&) noexcept = default; const TemporaryDiskFileFactory &TemporaryDiskFileFactory::system_default() { static TemporaryDiskFileFactory instance( - std::filesystem::temp_directory_path()); + Path(std::filesystem::temp_directory_path()), + default_random_file_name_generator()); return instance; } @@ -41,9 +43,9 @@ TemporaryDiskFileFactory::default_random_file_name_generator() { } TemporaryDiskFileFactory::TemporaryDiskFileFactory( - common::Path directory, RandomFileNameGenerator random_file_name_generator) + Path directory, RandomFileNameGenerator random_file_name_generator) : m_directory{std::move(directory)}, - m_random_file_name_generator{random_file_name_generator} {} + m_random_file_name_generator{std::move(random_file_name_generator)} {} TemporaryDiskFile TemporaryDiskFileFactory::copy(const abstract::File &file) const { @@ -56,7 +58,7 @@ TemporaryDiskFile TemporaryDiskFileFactory::copy(std::istream &in) const { while (true) { std::string file_name = m_random_file_name_generator(); - file_path = m_directory.join(file_name); + file_path = m_directory.join(Path(file_name)); file.open(file_path.string(), std::ios_base::in | std::ios_base::out); diff --git a/src/odr/internal/common/temporary_file.hpp b/src/odr/internal/common/temporary_file.hpp index d39ea7fa..3ccbd5b4 100644 --- a/src/odr/internal/common/temporary_file.hpp +++ b/src/odr/internal/common/temporary_file.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_INTERNAL_COMMON_TEMPORARY_FILE_HPP -#define ODR_INTERNAL_COMMON_TEMPORARY_FILE_HPP +#pragma once #include @@ -7,11 +6,13 @@ namespace odr::internal::common { +class Path; + class TemporaryDiskFile final : public DiskFile { public: explicit TemporaryDiskFile(const char *path); - explicit TemporaryDiskFile(std::string path); - explicit TemporaryDiskFile(common::Path path); + explicit TemporaryDiskFile(const std::string &path); + explicit TemporaryDiskFile(const Path &path); TemporaryDiskFile(const TemporaryDiskFile &); TemporaryDiskFile(TemporaryDiskFile &&) noexcept; ~TemporaryDiskFile() override; @@ -31,8 +32,8 @@ class TemporaryDiskFileFactory final { RandomFileNameGenerator random_file_name_generator = default_random_file_name_generator()); - TemporaryDiskFile copy(const abstract::File &file) const; - TemporaryDiskFile copy(std::istream &in) const; + [[nodiscard]] TemporaryDiskFile copy(const abstract::File &file) const; + [[nodiscard]] TemporaryDiskFile copy(std::istream &in) const; private: common::Path m_directory; @@ -40,5 +41,3 @@ class TemporaryDiskFileFactory final { }; } // namespace odr::internal::common - -#endif // ODR_INTERNAL_COMMON_TEMPORARY_FILE_HPP diff --git a/src/odr/internal/crypto/crypto_util.hpp b/src/odr/internal/crypto/crypto_util.hpp index e698f88c..777e0b7e 100644 --- a/src/odr/internal/crypto/crypto_util.hpp +++ b/src/odr/internal/crypto/crypto_util.hpp @@ -1,13 +1,10 @@ -#ifndef ODR_INTERNAL_CRYPTO_UTIL_HPP -#define ODR_INTERNAL_CRYPTO_UTIL_HPP +#pragma once #include #include #include -namespace odr::internal::crypto { - -namespace util { +namespace odr::internal::crypto::util { std::string base64_encode(const std::string &); std::string base64_decode(const std::string &); @@ -31,8 +28,4 @@ std::size_t padding(const std::string &input); std::string zlib_inflate(const std::string &input); -} // namespace util - -} // namespace odr::internal::crypto - -#endif // ODR_INTERNAL_CRYPTO_UTIL_HPP +} // namespace odr::internal::crypto::util diff --git a/src/odr/internal/csv/csv_file.hpp b/src/odr/internal/csv/csv_file.hpp index 00d67dd4..86ac51d8 100644 --- a/src/odr/internal/csv/csv_file.hpp +++ b/src/odr/internal/csv/csv_file.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_INTERNAL_CSV_FILE_HPP -#define ODR_INTERNAL_CSV_FILE_HPP +#pragma once #include @@ -25,5 +24,3 @@ class CsvFile final : public abstract::TextFile { }; } // namespace odr::internal::csv - -#endif // ODR_INTERNAL_CSV_FILE_HPP diff --git a/src/odr/internal/csv/csv_util.hpp b/src/odr/internal/csv/csv_util.hpp index d5bc688b..898d62b3 100644 --- a/src/odr/internal/csv/csv_util.hpp +++ b/src/odr/internal/csv/csv_util.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_INTERNAL_CSV_UTIL_HPP -#define ODR_INTERNAL_CSV_UTIL_HPP +#pragma once #include @@ -8,5 +7,3 @@ namespace odr::internal::csv { void check_csv_file(std::istream &in); } - -#endif // ODR_INTERNAL_CSV_UTIL_HPP diff --git a/src/odr/internal/git_info.hpp b/src/odr/internal/git_info.hpp index 168b0981..8ebcc9ef 100644 --- a/src/odr/internal/git_info.hpp +++ b/src/odr/internal/git_info.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_INTERNAL_GIT_INFO_HPP -#define ODR_INTERNAL_GIT_INFO_HPP +#pragma once namespace odr::internal::git_info { @@ -7,5 +6,3 @@ const char *commit() noexcept; bool is_dirty() noexcept; } // namespace odr::internal::git_info - -#endif // ODR_INTERNAL_GIT_INFO_HPP diff --git a/src/odr/internal/html/common.cpp b/src/odr/internal/html/common.cpp index 2cb8cad2..3264c4be 100644 --- a/src/odr/internal/html/common.cpp +++ b/src/odr/internal/html/common.cpp @@ -10,7 +10,6 @@ #include #include -#include #include namespace odr::internal { @@ -74,16 +73,16 @@ HtmlResourceLocator html::local_resource_locator(const std::string &output_path, if (is_core_resource && !config.external_resource_path.empty()) { auto resource_path = - common::Path(config.external_resource_path).join(path); + common::Path(config.external_resource_path).join(common::Path(path)); if (config.relative_resource_paths) { - resource_path = resource_path.rebase(output_path); + resource_path = resource_path.rebase(common::Path(output_path)); } return resource_path.string(); } // TODO relocate file if necessary - auto resource_path = common::Path(output_path).join(path); + auto resource_path = common::Path(output_path).join(common::Path(path)); std::filesystem::create_directories(resource_path.parent().path()); std::ofstream os(resource_path.path()); util::stream::pipe(*resource.stream(), os); diff --git a/src/odr/internal/html/common.hpp b/src/odr/internal/html/common.hpp index 83759615..0fe5b3d0 100644 --- a/src/odr/internal/html/common.hpp +++ b/src/odr/internal/html/common.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_INTERNAL_HTML_COMMON_HPP -#define ODR_INTERNAL_HTML_COMMON_HPP +#pragma once #include #include @@ -32,5 +31,3 @@ HtmlResourceLocator local_resource_locator(const std::string &output_path, const HtmlConfig &config); } // namespace odr::internal::html - -#endif // ODR_INTERNAL_HTML_COMMON_HPP diff --git a/src/odr/internal/html/document.cpp b/src/odr/internal/html/document.cpp index ec20726e..59acf123 100644 --- a/src/odr/internal/html/document.cpp +++ b/src/odr/internal/html/document.cpp @@ -18,7 +18,6 @@ #include #include -#include namespace odr::internal::html { namespace { @@ -38,7 +37,7 @@ void front(const Document &document, HtmlWriter &out, const HtmlConfig &config, "width=device-width,initial-scale=1.0,user-scalable=yes"); } - auto odr_css_file = Resources::open("odr.css"); + auto odr_css_file = Resources::open(common::Path("odr.css")); HtmlResourceLocation odr_css_location = resourceLocator( HtmlResourceType::css, "odr.css", "odr.css", odr_css_file, true); if (odr_css_location.has_value()) { @@ -50,7 +49,8 @@ void front(const Document &document, HtmlWriter &out, const HtmlConfig &config, } if (document.document_type() == DocumentType::spreadsheet) { - auto odr_spreadsheet_css_file = Resources::open("odr_spreadsheet.css"); + auto odr_spreadsheet_css_file = + Resources::open(common::Path("odr_spreadsheet.css")); HtmlResourceLocation odr_spreadsheet_css_location = resourceLocator(HtmlResourceType::css, "odr_spreadsheet.css", "odr_spreadsheet.css", odr_spreadsheet_css_file, true); @@ -86,7 +86,7 @@ void back(const Document &document, html::HtmlWriter &out, (void)document; (void)config; - auto odr_js_file = Resources::open("odr.js"); + auto odr_js_file = Resources::open(common::Path("odr.js")); HtmlResourceLocation odr_js_location = resourceLocator( HtmlResourceType::js, "odr.js", "odr.js", odr_js_file, true); if (odr_js_location.has_value()) { diff --git a/src/odr/internal/html/document.hpp b/src/odr/internal/html/document.hpp index e3ae784d..4f8b51c0 100644 --- a/src/odr/internal/html/document.hpp +++ b/src/odr/internal/html/document.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_INTERNAL_HTML_DOCUMENT_HPP -#define ODR_INTERNAL_HTML_DOCUMENT_HPP +#pragma once #include @@ -19,5 +18,3 @@ Html translate_document(const Document &document, const HtmlConfig &config); } // namespace odr::internal::html - -#endif // ODR_INTERNAL_HTML_DOCUMENT_HPP diff --git a/src/odr/internal/html/document_element.hpp b/src/odr/internal/html/document_element.hpp index 817aaa1d..7516a569 100644 --- a/src/odr/internal/html/document_element.hpp +++ b/src/odr/internal/html/document_element.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_INTERNAL_HTML_DOCUMENT_ELEMENT_HPP -#define ODR_INTERNAL_HTML_DOCUMENT_ELEMENT_HPP +#pragma once #include @@ -71,5 +70,3 @@ void translate_custom_shape(Element element, HtmlWriter &out, const HtmlResourceLocator &resourceLocator); } // namespace odr::internal::html - -#endif // ODR_INTERNAL_HTML_DOCUMENT_ELEMENT_HPP diff --git a/src/odr/internal/html/document_style.hpp b/src/odr/internal/html/document_style.hpp index 50f8c731..f538942c 100644 --- a/src/odr/internal/html/document_style.hpp +++ b/src/odr/internal/html/document_style.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_INTERNAL_HTML_DOCUMENT_STYLE_HPP -#define ODR_INTERNAL_HTML_DOCUMENT_STYLE_HPP +#pragma once #include #include @@ -51,5 +50,3 @@ std::string translate_circle_properties(const Circle &circle); std::string translate_custom_shape_properties(const CustomShape &custom_shape); } // namespace odr::internal::html - -#endif // ODR_INTERNAL_HTML_DOCUMENT_STYLE_HPP diff --git a/src/odr/internal/html/filesystem.cpp b/src/odr/internal/html/filesystem.cpp index 6f8ea42d..f42469b2 100644 --- a/src/odr/internal/html/filesystem.cpp +++ b/src/odr/internal/html/filesystem.cpp @@ -42,7 +42,7 @@ Html html::translate_filesystem(FileType file_type, out.write_body_begin(); for (; !file_walker.end(); file_walker.next()) { - common::Path file_path = file_walker.path(); + common::Path file_path = common::Path(file_walker.path()); bool is_file = file_walker.is_file(); out.write_element_begin("p"); diff --git a/src/odr/internal/html/filesystem.hpp b/src/odr/internal/html/filesystem.hpp index cf1238ee..df5fd547 100644 --- a/src/odr/internal/html/filesystem.hpp +++ b/src/odr/internal/html/filesystem.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_INTERNAL_HTML_FILESYSTEM_HPP -#define ODR_INTERNAL_HTML_FILESYSTEM_HPP +#pragma once #include @@ -17,5 +16,3 @@ Html translate_filesystem(FileType file_type, const Filesystem &filesystem, const HtmlConfig &config); } - -#endif // ODR_INTERNAL_HTML_FILESYSTEM_HPP diff --git a/src/odr/internal/html/html_writer.hpp b/src/odr/internal/html/html_writer.hpp index 85776796..87781a2c 100644 --- a/src/odr/internal/html/html_writer.hpp +++ b/src/odr/internal/html/html_writer.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_INTERNAL_HTML_HTML_WRITER_HPP -#define ODR_INTERNAL_HTML_HTML_WRITER_HPP +#pragma once #include @@ -96,5 +95,3 @@ class HtmlWriter { }; } // namespace odr::internal::html - -#endif // ODR_INTERNAL_HTML_HTML_WRITER_HPP diff --git a/src/odr/internal/html/image_file.hpp b/src/odr/internal/html/image_file.hpp index 8e6bb85a..70192904 100644 --- a/src/odr/internal/html/image_file.hpp +++ b/src/odr/internal/html/image_file.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_INTERNAL_HTML_IMAGE_FILE_HPP -#define ODR_INTERNAL_HTML_IMAGE_FILE_HPP +#pragma once #include @@ -23,5 +22,3 @@ Html translate_image_file(const ImageFile &image_file, const HtmlConfig &config); } // namespace odr::internal::html - -#endif // ODR_INTERNAL_HTML_IMAGE_FILE_HPP diff --git a/src/odr/internal/html/pdf2htmlex_wrapper.hpp b/src/odr/internal/html/pdf2htmlex_wrapper.hpp index 6d8589f9..1d67e50f 100644 --- a/src/odr/internal/html/pdf2htmlex_wrapper.hpp +++ b/src/odr/internal/html/pdf2htmlex_wrapper.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_INTERNAL_HTML_PDF2HTMLEX_WRAPPER_HPP -#define ODR_INTERNAL_HTML_PDF2HTMLEX_WRAPPER_HPP +#pragma once #include #include @@ -7,6 +6,7 @@ namespace odr { struct HtmlConfig; class Html; +class HtmlService; } // namespace odr namespace odr::internal { @@ -15,6 +15,8 @@ class PopplerPdfFile; namespace odr::internal::html { +HtmlService translate_document(const PopplerPdfFile &pdf_file); + Html translate_poppler_pdf_file(const PopplerPdfFile &pdf_file, const std::string &output_path, const HtmlConfig &config); @@ -25,5 +27,3 @@ class DocumentCopyProtectedException : public std::runtime_error { }; } // namespace odr::internal::html - -#endif // ODR_INTERNAL_HTML_PDF2HTMLEX_WRAPPER_HPP diff --git a/src/odr/internal/html/pdf_file.hpp b/src/odr/internal/html/pdf_file.hpp index 068b822a..4dc91132 100644 --- a/src/odr/internal/html/pdf_file.hpp +++ b/src/odr/internal/html/pdf_file.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_INTERNAL_HTML_PDF_FILE_HPP -#define ODR_INTERNAL_HTML_PDF_FILE_HPP +#pragma once #include @@ -16,5 +15,3 @@ Html translate_pdf_file(const PdfFile &pdf_file, const std::string &output_path, const HtmlConfig &config); } - -#endif // ODR_INTERNAL_HTML_PDF_FILE_HPP diff --git a/src/odr/internal/html/text_file.hpp b/src/odr/internal/html/text_file.hpp index b742ea4e..0efa74a8 100644 --- a/src/odr/internal/html/text_file.hpp +++ b/src/odr/internal/html/text_file.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_INTERNAL_HTML_TEXT_FILE_HPP -#define ODR_INTERNAL_HTML_TEXT_FILE_HPP +#pragma once #include @@ -17,5 +16,3 @@ Html translate_text_file(const TextFile &text_file, const HtmlConfig &config); } - -#endif // ODR_INTERNAL_HTML_TEXT_FILE_HPP diff --git a/src/odr/internal/html/wvware_wrapper.hpp b/src/odr/internal/html/wvware_wrapper.hpp index b7061ea4..705568dd 100644 --- a/src/odr/internal/html/wvware_wrapper.hpp +++ b/src/odr/internal/html/wvware_wrapper.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_INTERNAL_WVWARE_WRAPPER_HPP -#define ODR_INTERNAL_WVWARE_WRAPPER_HPP +#pragma once #include @@ -19,5 +18,3 @@ Html translate_wvware_oldms_file(const WvWareLegacyMicrosoftFile &oldms_file, const HtmlConfig &config); } - -#endif // ODR_INTERNAL_WVWARE_WRAPPER_HPP diff --git a/src/odr/internal/json/json_file.hpp b/src/odr/internal/json/json_file.hpp index 6640d2bc..10117204 100644 --- a/src/odr/internal/json/json_file.hpp +++ b/src/odr/internal/json/json_file.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_INTERNAL_JSON_FILE_HPP -#define ODR_INTERNAL_JSON_FILE_HPP +#pragma once #include @@ -25,5 +24,3 @@ class JsonFile final : public abstract::TextFile { }; } // namespace odr::internal::json - -#endif // ODR_INTERNAL_JSON_FILE_HPP diff --git a/src/odr/internal/json/json_util.hpp b/src/odr/internal/json/json_util.hpp index 0f6653fd..004203f5 100644 --- a/src/odr/internal/json/json_util.hpp +++ b/src/odr/internal/json/json_util.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_INTERNAL_JSON_UTIL_HPP -#define ODR_INTERNAL_JSON_UTIL_HPP +#pragma once #include @@ -8,5 +7,3 @@ namespace odr::internal::json { void check_json_file(std::istream &in); } - -#endif // ODR_INTERNAL_JSON_UTIL_HPP diff --git a/src/odr/internal/magic.hpp b/src/odr/internal/magic.hpp index ac5a05f5..c2e80401 100644 --- a/src/odr/internal/magic.hpp +++ b/src/odr/internal/magic.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_MAGIC_HPP -#define ODR_MAGIC_HPP +#pragma once #include #include @@ -19,5 +18,3 @@ FileType file_type(std::istream &in); FileType file_type(const internal::abstract::File &file); FileType file_type(const File &file); } // namespace odr::internal::magic - -#endif // ODR_MAGIC_HPP diff --git a/src/odr/internal/odf/odf_crypto.hpp b/src/odr/internal/odf/odf_crypto.hpp index 2a3d8e36..69680edf 100644 --- a/src/odr/internal/odf/odf_crypto.hpp +++ b/src/odr/internal/odf/odf_crypto.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_INTERNAL_ODF_CRYPTO_HPP -#define ODR_INTERNAL_ODF_CRYPTO_HPP +#pragma once #include #include @@ -34,5 +33,3 @@ bool decrypt(std::shared_ptr &, const Manifest &, const std::string &password); } // namespace odr::internal::odf - -#endif // ODR_INTERNAL_ODF_CRYPTO_HPP diff --git a/src/odr/internal/odf/odf_document.cpp b/src/odr/internal/odf/odf_document.cpp index 7c89c9ce..360fc025 100644 --- a/src/odr/internal/odf/odf_document.cpp +++ b/src/odr/internal/odf/odf_document.cpp @@ -10,7 +10,6 @@ #include #include -#include namespace odr::internal::odf { @@ -18,10 +17,10 @@ Document::Document(const FileType file_type, const DocumentType document_type, std::shared_ptr filesystem) : common::TemplateDocument(file_type, document_type, std::move(filesystem)) { - m_content_xml = util::xml::parse(*m_filesystem, "content.xml"); + m_content_xml = util::xml::parse(*m_filesystem, common::Path("content.xml")); - if (m_filesystem->exists("styles.xml")) { - m_styles_xml = util::xml::parse(*m_filesystem, "styles.xml"); + if (m_filesystem->exists(common::Path("styles.xml"))) { + m_styles_xml = util::xml::parse(*m_filesystem, common::Path("styles.xml")); } m_root_element = parse_tree( @@ -43,22 +42,22 @@ void Document::save(const common::Path &path) const { zip::ZipArchive archive; // `mimetype` has to be the first file and uncompressed - if (m_filesystem->is_file("mimetype")) { - archive.insert_file(std::end(archive), "mimetype", - m_filesystem->open("mimetype"), 0); + if (m_filesystem->is_file(common::Path("mimetype"))) { + archive.insert_file(std::end(archive), common::Path("mimetype"), + m_filesystem->open(common::Path("mimetype")), 0); } - for (auto walker = m_filesystem->file_walker(""); !walker->end(); - walker->next()) { + for (auto walker = m_filesystem->file_walker(common::Path("")); + !walker->end(); walker->next()) { auto p = walker->path(); - if (p == "mimetype") { + if (p == common::Path("mimetype")) { continue; } if (m_filesystem->is_directory(p)) { archive.insert_directory(std::end(archive), p); continue; } - if (p == "content.xml") { + if (p == common::Path("content.xml")) { // TODO stream std::stringstream out; m_content_xml.print(out, "", pugi::format_raw); @@ -66,9 +65,10 @@ void Document::save(const common::Path &path) const { archive.insert_file(std::end(archive), p, tmp); continue; } - if (p == "META-INF/manifest.xml") { + if (p == common::Path("META-INF/manifest.xml")) { // TODO - auto manifest = util::xml::parse(*m_filesystem, "META-INF/manifest.xml"); + auto manifest = util::xml::parse(*m_filesystem, + common::Path("META-INF/manifest.xml")); for (auto &&node : manifest.select_nodes("//manifest:encryption-data")) { node.node().parent().remove_child(node.node()); diff --git a/src/odr/internal/odf/odf_document.hpp b/src/odr/internal/odf/odf_document.hpp index d07fa732..c9b26415 100644 --- a/src/odr/internal/odf/odf_document.hpp +++ b/src/odr/internal/odf/odf_document.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_INTERNAL_ODF_DOCUMENT_HPP -#define ODR_INTERNAL_ODF_DOCUMENT_HPP +#pragma once #include @@ -40,5 +39,3 @@ class Document : public common::TemplateDocument { }; } // namespace odr::internal::odf - -#endif // ODR_INTERNAL_ODF_DOCUMENT_HPP diff --git a/src/odr/internal/odf/odf_element.cpp b/src/odr/internal/odf/odf_element.cpp index a9b9b2f1..0d9b3c86 100644 --- a/src/odr/internal/odf/odf_element.cpp +++ b/src/odr/internal/odf/odf_element.cpp @@ -441,7 +441,7 @@ bool Image::is_internal(const abstract::Document *document) const { return false; } try { - return doc->files()->is_file(href(document)); + return doc->files()->is_file(common::Path(href(document))); } catch (...) { } return false; @@ -452,7 +452,7 @@ std::optional Image::file(const abstract::Document *document) const { if (!doc || !is_internal(document)) { return {}; } - return File(doc->files()->open(href(document))); + return File(doc->files()->open(common::Path(href(document)))); } std::string Image::href(const abstract::Document *) const { diff --git a/src/odr/internal/odf/odf_element.hpp b/src/odr/internal/odf/odf_element.hpp index 2a30ffc5..64dd5fc8 100644 --- a/src/odr/internal/odf/odf_element.hpp +++ b/src/odr/internal/odf/odf_element.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_INTERNAL_ODF_ELEMENT_HPP -#define ODR_INTERNAL_ODF_ELEMENT_HPP +#pragma once #include #include @@ -284,5 +283,3 @@ class Image final : public Element, public abstract::Image { }; } // namespace odr::internal::odf - -#endif // ODR_INTERNAL_ODF_ELEMENT_HPP diff --git a/src/odr/internal/odf/odf_file.cpp b/src/odr/internal/odf/odf_file.cpp index 5e85d90a..3c6ba368 100644 --- a/src/odr/internal/odf/odf_file.cpp +++ b/src/odr/internal/odf/odf_file.cpp @@ -7,8 +7,6 @@ #include #include -#include - namespace odr::internal::abstract { class Document; class File; @@ -19,8 +17,9 @@ namespace odr::internal::odf { OpenDocumentFile::OpenDocumentFile( std::shared_ptr filesystem) : m_filesystem{std::move(filesystem)} { - if (m_filesystem->exists("META-INF/manifest.xml")) { - auto manifest = util::xml::parse(*m_filesystem, "META-INF/manifest.xml"); + if (m_filesystem->exists(common::Path("META-INF/manifest.xml"))) { + auto manifest = + util::xml::parse(*m_filesystem, common::Path("META-INF/manifest.xml")); m_file_meta = parse_file_meta(*m_filesystem, &manifest, false); m_manifest = parse_manifest(manifest); diff --git a/src/odr/internal/odf/odf_file.hpp b/src/odr/internal/odf/odf_file.hpp index 8d50525e..f4fe5ae1 100644 --- a/src/odr/internal/odf/odf_file.hpp +++ b/src/odr/internal/odf/odf_file.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_INTERNAL_ODF_FILE_HPP -#define ODR_INTERNAL_ODF_FILE_HPP +#pragma once #include @@ -47,5 +46,3 @@ class OpenDocumentFile final : public virtual abstract::DocumentFile { }; } // namespace odr::internal::odf - -#endif // ODR_INTERNAL_ODF_FILE_HPP diff --git a/src/odr/internal/odf/odf_manifest.cpp b/src/odr/internal/odf/odf_manifest.cpp index 8198e040..aef85fc2 100644 --- a/src/odr/internal/odf/odf_manifest.cpp +++ b/src/odr/internal/odf/odf_manifest.cpp @@ -67,7 +67,8 @@ Manifest parse_manifest(const pugi::xml_document &manifest) { std::optional smallest_file_size; for (auto &&e : manifest.child("manifest:manifest").children()) { - const common::Path path = e.attribute("manifest:full-path").as_string(); + const common::Path path = + common::Path(e.attribute("manifest:full-path").as_string()); const pugi::xml_node crypto = e.child("manifest:encryption-data"); if (!crypto) { continue; diff --git a/src/odr/internal/odf/odf_manifest.hpp b/src/odr/internal/odf/odf_manifest.hpp index a310ede6..611ff0d5 100644 --- a/src/odr/internal/odf/odf_manifest.hpp +++ b/src/odr/internal/odf/odf_manifest.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_INTERNAL_ODF_MANIFEST_HPP -#define ODR_INTERNAL_ODF_MANIFEST_HPP +#pragma once #include @@ -45,5 +44,3 @@ struct Manifest { Manifest parse_manifest(const pugi::xml_document &manifest); } // namespace odr::internal::odf - -#endif // ODR_INTERNAL_ODF_MANIFEST_HPP diff --git a/src/odr/internal/odf/odf_meta.cpp b/src/odr/internal/odf/odf_meta.cpp index a3ebb7ec..eb5bc106 100644 --- a/src/odr/internal/odf/odf_meta.cpp +++ b/src/odr/internal/odf/odf_meta.cpp @@ -10,7 +10,6 @@ #include #include -#include #include @@ -64,20 +63,20 @@ FileMeta parse_file_meta(const abstract::ReadableFilesystem &filesystem, const bool decrypted) { FileMeta result; - if (!filesystem.is_file("content.xml")) { + if (!filesystem.is_file(common::Path("content.xml"))) { throw NoOpenDocumentFile(); } - if (filesystem.is_file("mimetype")) { - const auto mimeType = - util::stream::read(*filesystem.open("mimetype")->stream()); + if (filesystem.is_file(common::Path("mimetype"))) { + const auto mimeType = util::stream::read( + *filesystem.open(common::Path("mimetype"))->stream()); lookup_file_type(mimeType, result.type); } if (manifest != nullptr) { for (auto &&e : manifest->select_nodes("//manifest:file-entry")) { const common::Path path = - e.node().attribute("manifest:full-path").as_string(); + common::Path(e.node().attribute("manifest:full-path").as_string()); if (path.root() && e.node().attribute("manifest:media-type")) { const std::string mimeType = e.node().attribute("manifest:media-type").as_string(); @@ -92,8 +91,9 @@ FileMeta parse_file_meta(const abstract::ReadableFilesystem &filesystem, DocumentMeta document_meta; if ((result.password_encrypted == decrypted) && - filesystem.is_file("meta.xml")) { - const auto meta_xml = util::xml::parse(filesystem, "meta.xml"); + filesystem.is_file(common::Path("meta.xml"))) { + const auto meta_xml = + util::xml::parse(filesystem, common::Path("meta.xml")); const pugi::xml_node statistics = meta_xml.child("office:document-meta") .child("office:meta") @@ -118,7 +118,7 @@ FileMeta parse_file_meta(const abstract::ReadableFilesystem &filesystem, } } - result.document_meta = std::move(document_meta); + result.document_meta = document_meta; return result; } diff --git a/src/odr/internal/odf/odf_meta.hpp b/src/odr/internal/odf/odf_meta.hpp index 3e408f31..531234b5 100644 --- a/src/odr/internal/odf/odf_meta.hpp +++ b/src/odr/internal/odf/odf_meta.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_INTERNAL_ODF_META_HPP -#define ODR_INTERNAL_ODF_META_HPP +#pragma once #include @@ -27,5 +26,3 @@ FileMeta parse_file_meta(const abstract::ReadableFilesystem &filesystem, const pugi::xml_document *manifest, bool decrypted); } // namespace odr::internal::odf - -#endif // ODR_INTERNAL_ODF_META_HPP diff --git a/src/odr/internal/odf/odf_parser.hpp b/src/odr/internal/odf/odf_parser.hpp index 62b86fb1..133d4d0f 100644 --- a/src/odr/internal/odf/odf_parser.hpp +++ b/src/odr/internal/odf/odf_parser.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_INTERNAL_ODF_PARSER_HPP -#define ODR_INTERNAL_ODF_PARSER_HPP +#pragma once #include @@ -59,5 +58,3 @@ void parse_element_children(Document &document, DrawingRoot *element, pugi::xml_node node); } // namespace odr::internal::odf - -#endif // ODR_INTERNAL_ODF_PARSER_HPP diff --git a/src/odr/internal/odf/odf_spreadsheet.hpp b/src/odr/internal/odf/odf_spreadsheet.hpp index 68c64293..c41db80c 100644 --- a/src/odr/internal/odf/odf_spreadsheet.hpp +++ b/src/odr/internal/odf/odf_spreadsheet.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_INTERNAL_ODF_SPREADSHEET_HPP -#define ODR_INTERNAL_ODF_SPREADSHEET_HPP +#pragma once #include #include @@ -106,5 +105,3 @@ std::tuple parse_element_tree(Document &document, pugi::xml_node node); } // namespace odr::internal::odf - -#endif // ODR_INTERNAL_ODF_SPREADSHEET_HPP diff --git a/src/odr/internal/odf/odf_style.hpp b/src/odr/internal/odf/odf_style.hpp index 3659cea6..000b6f43 100644 --- a/src/odr/internal/odf/odf_style.hpp +++ b/src/odr/internal/odf/odf_style.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_INTERNAL_ODF_STYLE_HPP -#define ODR_INTERNAL_ODF_STYLE_HPP +#pragma once #include @@ -110,5 +109,3 @@ class StyleRegistry final { }; } // namespace odr::internal::odf - -#endif // ODR_INTERNAL_ODF_STYLE_HPP diff --git a/src/odr/internal/oldms/oldms_file.cpp b/src/odr/internal/oldms/oldms_file.cpp index a8433df0..8bae6ef6 100644 --- a/src/odr/internal/oldms/oldms_file.cpp +++ b/src/odr/internal/oldms/oldms_file.cpp @@ -6,7 +6,6 @@ #include #include -#include namespace odr::internal::oldms { @@ -15,13 +14,14 @@ FileMeta parse_meta(const abstract::ReadableFilesystem &storage) { static const std::unordered_map types = { // MS-DOC: The "WordDocument" stream MUST be present in the file. // https://msdn.microsoft.com/en-us/library/dd926131(v=office.12).aspx - {"WordDocument", FileType::legacy_word_document}, + {common::Path("WordDocument"), FileType::legacy_word_document}, // MS-PPT: The "PowerPoint Document" stream MUST be present in the file. // https://msdn.microsoft.com/en-us/library/dd911009(v=office.12).aspx - {"PowerPoint Document", FileType::legacy_powerpoint_presentation}, + {common::Path("PowerPoint Document"), + FileType::legacy_powerpoint_presentation}, // MS-XLS: The "Workbook" stream MUST be present in the file. // https://docs.microsoft.com/en-us/openspecs/office_file_formats/ms-ppt/1fc22d56-28f9-4818-bd45-67c2bf721ccf - {"Workbook", FileType::legacy_excel_worksheets}, + {common::Path("Workbook"), FileType::legacy_excel_worksheets}, }; FileMeta result; diff --git a/src/odr/internal/oldms/oldms_file.hpp b/src/odr/internal/oldms/oldms_file.hpp index 7950b3e3..29307fd0 100644 --- a/src/odr/internal/oldms/oldms_file.hpp +++ b/src/odr/internal/oldms/oldms_file.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_INTERNAL_OLDMS_FILE_HPP -#define ODR_INTERNAL_OLDMS_FILE_HPP +#pragma once #include @@ -42,5 +41,3 @@ class LegacyMicrosoftFile final : public abstract::DocumentFile { }; } // namespace odr::internal::oldms - -#endif // ODR_INTERNAL_OLDMS_FILE_HPP diff --git a/src/odr/internal/oldms_wvware/wvware_oldms_file.hpp b/src/odr/internal/oldms_wvware/wvware_oldms_file.hpp index efc7a1fc..66ea8780 100644 --- a/src/odr/internal/oldms_wvware/wvware_oldms_file.hpp +++ b/src/odr/internal/oldms_wvware/wvware_oldms_file.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_INTERNAL_WVWARE_OLDMS_FILE_HPP -#define ODR_INTERNAL_WVWARE_OLDMS_FILE_HPP +#pragma once #include @@ -53,5 +52,3 @@ class WvWareLegacyMicrosoftFile final : public abstract::DocumentFile { }; } // namespace odr::internal - -#endif // ODR_INTERNAL_WVWARE_OLDMS_FILE_HPP diff --git a/src/odr/internal/ooxml/ooxml_crypto.hpp b/src/odr/internal/ooxml/ooxml_crypto.hpp index aaa94c1f..7dae0969 100644 --- a/src/odr/internal/ooxml/ooxml_crypto.hpp +++ b/src/odr/internal/ooxml/ooxml_crypto.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_INTERNAL_OOXML_CRYPTO_HPP -#define ODR_INTERNAL_OOXML_CRYPTO_HPP +#pragma once #include #include @@ -95,5 +94,3 @@ class Util final : public Algorithm { }; } // namespace odr::internal::ooxml::crypto - -#endif // ODR_INTERNAL_OOXML_CRYPTO_HPP diff --git a/src/odr/internal/ooxml/ooxml_file.cpp b/src/odr/internal/ooxml/ooxml_file.cpp index 6a1404be..61dec961 100644 --- a/src/odr/internal/ooxml/ooxml_file.cpp +++ b/src/odr/internal/ooxml/ooxml_file.cpp @@ -13,8 +13,6 @@ #include #include -#include - namespace odr::internal::abstract { class Document; } // namespace odr::internal::abstract @@ -60,16 +58,16 @@ EncryptionState OfficeOpenXmlFile::encryption_state() const noexcept { bool OfficeOpenXmlFile::decrypt(const std::string &password) { // TODO throw if not encrypted // TODO throw if decrypted - std::string encryption_info = - util::stream::read(*m_filesystem->open("/EncryptionInfo")->stream()); + std::string encryption_info = util::stream::read( + *m_filesystem->open(common::Path("/EncryptionInfo"))->stream()); // TODO cache Crypto::Util crypto::Util util(encryption_info); std::string key = util.derive_key(password); if (!util.verify(key)) { return false; } - std::string encrypted_package = - util::stream::read(*m_filesystem->open("/EncryptedPackage")->stream()); + std::string encrypted_package = util::stream::read( + *m_filesystem->open(common::Path("/EncryptedPackage"))->stream()); std::string decrypted_package = util.decrypt(encrypted_package, key); auto memory_file = std::make_shared(std::move(decrypted_package)); diff --git a/src/odr/internal/ooxml/ooxml_file.hpp b/src/odr/internal/ooxml/ooxml_file.hpp index e6b420fe..4e8e41f8 100644 --- a/src/odr/internal/ooxml/ooxml_file.hpp +++ b/src/odr/internal/ooxml/ooxml_file.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_INTERNAL_OOXML_FILE_HPP -#define ODR_INTERNAL_OOXML_FILE_HPP +#pragma once #include @@ -45,5 +44,3 @@ class OfficeOpenXmlFile final : public abstract::DocumentFile { }; } // namespace odr::internal::ooxml - -#endif // ODR_INTERNAL_OOXML_FILE_HPP diff --git a/src/odr/internal/ooxml/ooxml_meta.cpp b/src/odr/internal/ooxml/ooxml_meta.cpp index d7971905..e8254913 100644 --- a/src/odr/internal/ooxml/ooxml_meta.cpp +++ b/src/odr/internal/ooxml/ooxml_meta.cpp @@ -12,15 +12,16 @@ namespace odr::internal::ooxml { FileMeta parse_file_meta(abstract::ReadableFilesystem &filesystem) { static const std::unordered_map types = { - {"word/document.xml", FileType::office_open_xml_document}, - {"ppt/presentation.xml", FileType::office_open_xml_presentation}, - {"xl/workbook.xml", FileType::office_open_xml_workbook}, + {common::Path("word/document.xml"), FileType::office_open_xml_document}, + {common::Path("ppt/presentation.xml"), + FileType::office_open_xml_presentation}, + {common::Path("xl/workbook.xml"), FileType::office_open_xml_workbook}, }; FileMeta result; - if (filesystem.is_file("/EncryptionInfo") && - filesystem.is_file("/EncryptedPackage")) { + if (filesystem.is_file(common::Path("/EncryptionInfo")) && + filesystem.is_file(common::Path("/EncryptedPackage"))) { result.type = FileType::office_open_xml_encrypted; result.password_encrypted = true; return result; diff --git a/src/odr/internal/ooxml/ooxml_meta.hpp b/src/odr/internal/ooxml/ooxml_meta.hpp index 9b91a698..64f19f1d 100644 --- a/src/odr/internal/ooxml/ooxml_meta.hpp +++ b/src/odr/internal/ooxml/ooxml_meta.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_INTERNAL_OOXML_META_HPP -#define ODR_INTERNAL_OOXML_META_HPP +#pragma once #include #include @@ -17,5 +16,3 @@ namespace odr::internal::ooxml { FileMeta parse_file_meta(abstract::ReadableFilesystem &filesystem); } // namespace odr::internal::ooxml - -#endif // ODR_INTERNAL_OOXML_META_HPP diff --git a/src/odr/internal/ooxml/ooxml_util.cpp b/src/odr/internal/ooxml/ooxml_util.cpp index 7825f23a..e61c89b9 100644 --- a/src/odr/internal/ooxml/ooxml_util.cpp +++ b/src/odr/internal/ooxml/ooxml_util.cpp @@ -276,7 +276,9 @@ ooxml::parse_relationships(const pugi::xml_document &rels) { std::unordered_map ooxml::parse_relationships(const abstract::ReadableFilesystem &filesystem, const common::Path &path) { - auto rel_path = path.parent().join("_rels").join(path.basename() + ".rels"); + auto rel_path = path.parent() + .join(common::Path("_rels")) + .join(common::Path(path.basename() + ".rels")); if (!filesystem.is_file(rel_path)) { return {}; } diff --git a/src/odr/internal/ooxml/ooxml_util.hpp b/src/odr/internal/ooxml/ooxml_util.hpp index 0376c9b7..9d0e2eef 100644 --- a/src/odr/internal/ooxml/ooxml_util.hpp +++ b/src/odr/internal/ooxml/ooxml_util.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_INTERNAL_OOXML_UTIL_HPP -#define ODR_INTERNAL_OOXML_UTIL_HPP +#pragma once #include @@ -58,5 +57,3 @@ parse_relationships(const abstract::ReadableFilesystem &filesystem, const common::Path &path); } // namespace odr::internal::ooxml - -#endif // ODR_INTERNAL_OOXML_UTIL_HPP diff --git a/src/odr/internal/ooxml/presentation/ooxml_presentation_document.cpp b/src/odr/internal/ooxml/presentation/ooxml_presentation_document.cpp index c2d481aa..3897d420 100644 --- a/src/odr/internal/ooxml/presentation/ooxml_presentation_document.cpp +++ b/src/odr/internal/ooxml/presentation/ooxml_presentation_document.cpp @@ -14,12 +14,14 @@ Document::Document(std::shared_ptr filesystem) : common::TemplateDocument(FileType::office_open_xml_presentation, DocumentType::presentation, std::move(filesystem)) { - m_document_xml = util::xml::parse(*m_filesystem, "ppt/presentation.xml"); + m_document_xml = + util::xml::parse(*m_filesystem, common::Path("ppt/presentation.xml")); - for (auto relationships : - parse_relationships(*m_filesystem, "ppt/presentation.xml")) { + for (const auto &relationships : parse_relationships( + *m_filesystem, common::Path("ppt/presentation.xml"))) { m_slides_xml[relationships.first] = util::xml::parse( - *m_filesystem, common::Path("ppt").join(relationships.second)); + *m_filesystem, + common::Path("ppt").join(common::Path(relationships.second))); } m_root_element = parse_tree(*this, m_document_xml.document_element()); diff --git a/src/odr/internal/ooxml/presentation/ooxml_presentation_document.hpp b/src/odr/internal/ooxml/presentation/ooxml_presentation_document.hpp index 3884712e..fb50aece 100644 --- a/src/odr/internal/ooxml/presentation/ooxml_presentation_document.hpp +++ b/src/odr/internal/ooxml/presentation/ooxml_presentation_document.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_INTERNAL_OOXML_PRESENTATION_HPP -#define ODR_INTERNAL_OOXML_PRESENTATION_HPP +#pragma once #include #include @@ -31,5 +30,3 @@ class Document final : public common::TemplateDocument { }; } // namespace odr::internal::ooxml::presentation - -#endif // ODR_INTERNAL_OOXML_PRESENTATION_HPP diff --git a/src/odr/internal/ooxml/presentation/ooxml_presentation_element.hpp b/src/odr/internal/ooxml/presentation/ooxml_presentation_element.hpp index 1ac0aa4e..74b2a710 100644 --- a/src/odr/internal/ooxml/presentation/ooxml_presentation_element.hpp +++ b/src/odr/internal/ooxml/presentation/ooxml_presentation_element.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_INTERNAL_OOXML_PRESENTATION_ELEMENT_HPP -#define ODR_INTERNAL_OOXML_PRESENTATION_ELEMENT_HPP +#pragma once #include #include @@ -177,5 +176,3 @@ class ImageElement final : public Element, public abstract::Image { }; } // namespace odr::internal::ooxml::presentation - -#endif // ODR_INTERNAL_OOXML_PRESENTATION_ELEMENT_HPP diff --git a/src/odr/internal/ooxml/presentation/ooxml_presentation_parser.hpp b/src/odr/internal/ooxml/presentation/ooxml_presentation_parser.hpp index ca69f7af..9231d127 100644 --- a/src/odr/internal/ooxml/presentation/ooxml_presentation_parser.hpp +++ b/src/odr/internal/ooxml/presentation/ooxml_presentation_parser.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_INTERNAL_OOXML_PRESENTATION_PARSER_HPP -#define ODR_INTERNAL_OOXML_PRESENTATION_PARSER_HPP +#pragma once #include @@ -16,5 +15,3 @@ class Element; Element *parse_tree(Document &document, pugi::xml_node node); } // namespace odr::internal::ooxml::presentation - -#endif // ODR_INTERNAL_OOXML_PRESENTATION_PARSER_HPP diff --git a/src/odr/internal/ooxml/spreadsheet/ooxml_spreadsheet_document.cpp b/src/odr/internal/ooxml/spreadsheet/ooxml_spreadsheet_document.cpp index 960e1284..32f68326 100644 --- a/src/odr/internal/ooxml/spreadsheet/ooxml_spreadsheet_document.cpp +++ b/src/odr/internal/ooxml/spreadsheet/ooxml_spreadsheet_document.cpp @@ -16,24 +16,25 @@ Document::Document(std::shared_ptr filesystem) std::move(filesystem)) { auto workbook_path = common::Path("xl/workbook.xml"); auto [workbook_xml, workbook_relations] = parse_xml_(workbook_path); - auto [styles_xml, _] = parse_xml_("xl/styles.xml"); + auto [styles_xml, _] = parse_xml_(common::Path("xl/styles.xml")); for (pugi::xml_node sheet_node : workbook_xml.document_element().child("sheets").children("sheet")) { const char *id = sheet_node.attribute("r:id").value(); common::Path sheet_path = - workbook_path.parent().join(workbook_relations.at(id)); + workbook_path.parent().join(common::Path(workbook_relations.at(id))); auto [sheet_xml, sheet_relationships] = parse_xml_(sheet_path); if (auto drawing = sheet_xml.document_element().child("drawing")) { - auto drawing_path = sheet_path.parent().join( - sheet_relationships.at(drawing.attribute("r:id").value())); + auto drawing_path = sheet_path.parent().join(common::Path( + sheet_relationships.at(drawing.attribute("r:id").value()))); parse_xml_(drawing_path); } } - if (m_filesystem->exists("xl/sharedStrings.xml")) { - auto [shared_strings_xml, _] = parse_xml_("xl/sharedStrings.xml"); + if (m_filesystem->exists(common::Path("xl/sharedStrings.xml"))) { + auto [shared_strings_xml, _] = + parse_xml_(common::Path("xl/sharedStrings.xml")); for (auto shared_string : shared_strings_xml.document_element()) { m_shared_strings.push_back(shared_string); diff --git a/src/odr/internal/ooxml/spreadsheet/ooxml_spreadsheet_document.hpp b/src/odr/internal/ooxml/spreadsheet/ooxml_spreadsheet_document.hpp index 2ec75499..9c11047c 100644 --- a/src/odr/internal/ooxml/spreadsheet/ooxml_spreadsheet_document.hpp +++ b/src/odr/internal/ooxml/spreadsheet/ooxml_spreadsheet_document.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_INTERNAL_OOXML_SPREADSHEET_DOCUMENT_HPP -#define ODR_INTERNAL_OOXML_SPREADSHEET_DOCUMENT_HPP +#pragma once #include @@ -45,5 +44,3 @@ class Document final : public common::TemplateDocument { }; } // namespace odr::internal::ooxml::spreadsheet - -#endif // ODR_INTERNAL_OOXML_SPREADSHEET_DOCUMENT_HPP diff --git a/src/odr/internal/ooxml/spreadsheet/ooxml_spreadsheet_element.cpp b/src/odr/internal/ooxml/spreadsheet/ooxml_spreadsheet_element.cpp index 5a012d9a..e8924e28 100644 --- a/src/odr/internal/ooxml/spreadsheet/ooxml_spreadsheet_element.cpp +++ b/src/odr/internal/ooxml/spreadsheet/ooxml_spreadsheet_element.cpp @@ -1,7 +1,6 @@ #include #include -#include #include #include #include @@ -373,7 +372,7 @@ bool ImageElement::is_internal(const abstract::Document *document) const { return false; } try { - return doc->files()->is_file(href(document)); + return doc->files()->is_file(common::Path(href(document))); } catch (...) { } return false; @@ -385,14 +384,17 @@ ImageElement::file(const abstract::Document *document) const { if (doc == nullptr || !is_internal(document)) { return {}; } - return File(doc->files()->open(href(document))); + return File(doc->files()->open(common::Path(href(document)))); } std::string ImageElement::href(const abstract::Document *document) const { if (pugi::xml_attribute ref = m_node.attribute("r:embed")) { auto relations = document_relations_(document); if (auto rel = relations.find(ref.value()); rel != std::end(relations)) { - return document_path_(document).parent().join(rel->second).string(); + return document_path_(document) + .parent() + .join(common::Path(rel->second)) + .string(); } } return ""; // TODO diff --git a/src/odr/internal/ooxml/spreadsheet/ooxml_spreadsheet_element.hpp b/src/odr/internal/ooxml/spreadsheet/ooxml_spreadsheet_element.hpp index b1cc4608..65452307 100644 --- a/src/odr/internal/ooxml/spreadsheet/ooxml_spreadsheet_element.hpp +++ b/src/odr/internal/ooxml/spreadsheet/ooxml_spreadsheet_element.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_INTERNAL_OOXML_SPREADSHEET_ELEMENT_HPP -#define ODR_INTERNAL_OOXML_SPREADSHEET_ELEMENT_HPP +#pragma once #include #include @@ -232,5 +231,3 @@ class ImageElement final : public Element, public abstract::Image { }; } // namespace odr::internal::ooxml::spreadsheet - -#endif // ODR_INTERNAL_OOXML_SPREADSHEET_ELEMENT_HPP diff --git a/src/odr/internal/ooxml/spreadsheet/ooxml_spreadsheet_parser.cpp b/src/odr/internal/ooxml/spreadsheet/ooxml_spreadsheet_parser.cpp index 77bbe4fd..8324fd0e 100644 --- a/src/odr/internal/ooxml/spreadsheet/ooxml_spreadsheet_parser.cpp +++ b/src/odr/internal/ooxml/spreadsheet/ooxml_spreadsheet_parser.cpp @@ -12,21 +12,22 @@ namespace { template std::tuple parse_element_tree(Document &document, pugi::xml_node node, - common::Path document_path, + const common::Path &document_path, const Relations &document_relations); template <> std::tuple parse_element_tree(Document &document, pugi::xml_node node, - common::Path document_path, + const common::Path &document_path, const Relations &document_relations); std::tuple parse_any_element_tree(Document &document, pugi::xml_node node, - common::Path document_path, + const common::Path &document_path, const Relations &document_relations); void parse_element_children(Document &document, Element *element, - pugi::xml_node node, common::Path document_path, + pugi::xml_node node, + const common::Path &document_path, const Relations &document_relations) { for (pugi::xml_node child_node = node.first_child(); child_node;) { auto [child, next_sibling] = parse_any_element_tree( @@ -41,12 +42,13 @@ void parse_element_children(Document &document, Element *element, } void parse_element_children(Document &document, Root *element, - pugi::xml_node node, common::Path document_path, + pugi::xml_node node, + const common::Path &document_path, const Relations &document_relations) { for (pugi::xml_node child_node : node.child("sheets").children("sheet")) { const char *id = child_node.attribute("r:id").value(); common::Path sheet_path = - document_path.parent().join(document_relations.at(id)); + document_path.parent().join(common::Path(document_relations.at(id))); auto [sheet_xml, sheet_relations] = document.get_xml(sheet_path); auto [sheet, _] = parse_element_tree( document, sheet_xml.document_element(), sheet_path, sheet_relations); @@ -55,7 +57,8 @@ void parse_element_children(Document &document, Root *element, } void parse_element_children(Document &document, SheetCell *element, - pugi::xml_node node, common::Path document_path, + pugi::xml_node node, + const common::Path &document_path, const Relations &document_relations) { if (pugi::xml_attribute type_attr = node.attribute("t"); type_attr.value() == std::string("s")) { @@ -72,7 +75,8 @@ void parse_element_children(Document &document, SheetCell *element, } void parse_element_children(Document &document, Frame *element, - pugi::xml_node node, common::Path document_path, + pugi::xml_node node, + const common::Path &document_path, const Relations &document_relations) { if (pugi::xml_node image_node = node.child("xdr:pic").child("xdr:blipFill").child("a:blip")) { @@ -85,7 +89,7 @@ void parse_element_children(Document &document, Frame *element, template std::tuple parse_element_tree(Document &document, pugi::xml_node node, - common::Path document_path, + const common::Path &document_path, const Relations &document_relations) { if (!node) { return std::make_tuple(nullptr, pugi::xml_node()); @@ -105,7 +109,7 @@ parse_element_tree(Document &document, pugi::xml_node node, template <> std::tuple parse_element_tree(Document &document, pugi::xml_node node, - common::Path document_path, + const common::Path &document_path, const Relations &document_relations) { if (!node) { return std::make_tuple(nullptr, pugi::xml_node()); @@ -140,7 +144,7 @@ parse_element_tree(Document &document, pugi::xml_node node, std::string dimension_ref = node.child("dimension").attribute("ref").value(); common::TablePosition position_to; - if (dimension_ref.find(":") == std::string::npos) { + if (dimension_ref.find(':') == std::string::npos) { position_to = common::TablePosition(dimension_ref); } else { position_to = common::TableRange(dimension_ref).to(); @@ -152,7 +156,7 @@ parse_element_tree(Document &document, pugi::xml_node node, if (pugi::xml_node drawing_node = node.child("drawing")) { const char *id = drawing_node.attribute("r:id").value(); common::Path drawing_path = - document_path.parent().join(document_relations.at(id)); + document_path.parent().join(common::Path(document_relations.at(id))); auto [drawing_xml, drawing_relations] = document.get_xml(drawing_path); for (pugi::xml_node shape_node : @@ -188,7 +192,7 @@ bool is_text_node(const pugi::xml_node node) { template <> std::tuple parse_element_tree(Document &document, pugi::xml_node first, - common::Path document_path, + const common::Path &document_path, const Relations &document_relations) { if (!first) { return std::make_tuple(nullptr, pugi::xml_node()); @@ -208,11 +212,11 @@ parse_element_tree(Document &document, pugi::xml_node first, std::tuple parse_any_element_tree(Document &document, pugi::xml_node node, - common::Path document_path, + const common::Path &document_path, const Relations &document_relations) { using Parser = std::function( - Document & document, pugi::xml_node node, common::Path document_path, - const Relations &document_relations)>; + Document & document, pugi::xml_node node, + const common::Path &document_path, const Relations &document_relations)>; static std::unordered_map parser_table{ {"workbook", parse_element_tree}, @@ -240,10 +244,10 @@ namespace odr::internal::ooxml { spreadsheet::Element * spreadsheet::parse_tree(Document &document, pugi::xml_node node, - common::Path document_path, + const common::Path &document_path, const Relations &document_relations) { - auto [root_id, _] = parse_any_element_tree( - document, node, std::move(document_path), document_relations); + auto [root_id, _] = + parse_any_element_tree(document, node, document_path, document_relations); return root_id; } diff --git a/src/odr/internal/ooxml/spreadsheet/ooxml_spreadsheet_parser.hpp b/src/odr/internal/ooxml/spreadsheet/ooxml_spreadsheet_parser.hpp index 09fc04dc..34373236 100644 --- a/src/odr/internal/ooxml/spreadsheet/ooxml_spreadsheet_parser.hpp +++ b/src/odr/internal/ooxml/spreadsheet/ooxml_spreadsheet_parser.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_INTERNAL_OOXML_SPREADSHEET_PARSER_HPP -#define ODR_INTERNAL_OOXML_SPREADSHEET_PARSER_HPP +#pragma once #include @@ -17,9 +16,7 @@ class Document; class Element; Element *parse_tree(Document &document, pugi::xml_node node, - common::Path document_path, + const common::Path &document_path, const Relations &document_relations); } // namespace odr::internal::ooxml::spreadsheet - -#endif // ODR_INTERNAL_OOXML_SPREADSHEET_PARSER_HPP diff --git a/src/odr/internal/ooxml/spreadsheet/ooxml_spreadsheet_style.hpp b/src/odr/internal/ooxml/spreadsheet/ooxml_spreadsheet_style.hpp index a592ec88..6dbf4997 100644 --- a/src/odr/internal/ooxml/spreadsheet/ooxml_spreadsheet_style.hpp +++ b/src/odr/internal/ooxml/spreadsheet/ooxml_spreadsheet_style.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_INTERNAL_OOXML_SPREADSHEET_STYLE_HPP -#define ODR_INTERNAL_OOXML_SPREADSHEET_STYLE_HPP +#pragma once #include @@ -33,5 +32,3 @@ class StyleRegistry final { }; } // namespace odr::internal::ooxml::spreadsheet - -#endif // ODR_INTERNAL_OOXML_SPREADSHEET_STYLE_HPP diff --git a/src/odr/internal/ooxml/text/ooxml_text_document.cpp b/src/odr/internal/ooxml/text/ooxml_text_document.cpp index db428324..0c7c5893 100644 --- a/src/odr/internal/ooxml/text/ooxml_text_document.cpp +++ b/src/odr/internal/ooxml/text/ooxml_text_document.cpp @@ -11,7 +11,6 @@ #include #include -#include namespace odr::internal::ooxml::text { @@ -19,11 +18,13 @@ Document::Document(std::shared_ptr filesystem) : common::TemplateDocument(FileType::office_open_xml_document, DocumentType::text, std::move(filesystem)) { - m_document_xml = util::xml::parse(*m_filesystem, "word/document.xml"); - m_styles_xml = util::xml::parse(*m_filesystem, "word/styles.xml"); + m_document_xml = + util::xml::parse(*m_filesystem, common::Path("word/document.xml")); + m_styles_xml = + util::xml::parse(*m_filesystem, common::Path("word/styles.xml")); m_document_relations = - parse_relationships(*m_filesystem, "word/document.xml"); + parse_relationships(*m_filesystem, common::Path("word/document.xml")); m_root_element = parse_tree(*this, m_document_xml.document_element().child("w:body")); @@ -41,14 +42,14 @@ void Document::save(const common::Path &path) const { // TODO this would decrypt/inflate and encrypt/deflate again zip::ZipArchive archive; - for (auto walker = m_filesystem->file_walker(""); !walker->end(); - walker->next()) { + for (auto walker = m_filesystem->file_walker(common::Path("")); + !walker->end(); walker->next()) { auto p = walker->path(); if (m_filesystem->is_directory(p)) { archive.insert_directory(std::end(archive), p); continue; } - if (p == "word/document.xml") { + if (p == common::Path("word/document.xml")) { // TODO stream std::stringstream out; m_document_xml.print(out, "", pugi::format_raw); diff --git a/src/odr/internal/ooxml/text/ooxml_text_document.hpp b/src/odr/internal/ooxml/text/ooxml_text_document.hpp index 298cb6f9..f443e428 100644 --- a/src/odr/internal/ooxml/text/ooxml_text_document.hpp +++ b/src/odr/internal/ooxml/text/ooxml_text_document.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_INTERNAL_OOXML_TEXT_DOCUMENT_HPP -#define ODR_INTERNAL_OOXML_TEXT_DOCUMENT_HPP +#pragma once #include @@ -38,5 +37,3 @@ class Document final : public common::TemplateDocument { }; } // namespace odr::internal::ooxml::text - -#endif // ODR_INTERNAL_OOXML_TEXT_DOCUMENT_HPP diff --git a/src/odr/internal/ooxml/text/ooxml_text_element.cpp b/src/odr/internal/ooxml/text/ooxml_text_element.cpp index 451a5079..fe416f57 100644 --- a/src/odr/internal/ooxml/text/ooxml_text_element.cpp +++ b/src/odr/internal/ooxml/text/ooxml_text_element.cpp @@ -10,7 +10,6 @@ #include #include -#include #include @@ -275,7 +274,7 @@ bool Image::is_internal(const abstract::Document *document) const { return false; } try { - return doc->files()->is_file(href(document)); + return doc->files()->is_file(common::Path(href(document))); } catch (...) { } return false; @@ -286,7 +285,7 @@ std::optional Image::file(const abstract::Document *document) const { if (!doc || !is_internal(document)) { return {}; } - return File(doc->files()->open(href(document))); + return File(doc->files()->open(common::Path(href(document)))); } std::string Image::href(const abstract::Document *document) const { @@ -296,7 +295,7 @@ std::string Image::href(const abstract::Document *document) const { .attribute("r:embed")) { auto relations = document_relations_(document); if (auto rel = relations.find(ref.value()); rel != std::end(relations)) { - return common::Path("word").join(rel->second).string(); + return common::Path("word").join(common::Path(rel->second)).string(); } } return ""; // TODO diff --git a/src/odr/internal/ooxml/text/ooxml_text_element.hpp b/src/odr/internal/ooxml/text/ooxml_text_element.hpp index 17c30bd7..88ea9209 100644 --- a/src/odr/internal/ooxml/text/ooxml_text_element.hpp +++ b/src/odr/internal/ooxml/text/ooxml_text_element.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_INTERNAL_OOXML_TEXT_ELEMENT_HPP -#define ODR_INTERNAL_OOXML_TEXT_ELEMENT_HPP +#pragma once #include #include @@ -197,5 +196,3 @@ class Image final : public Element, public abstract::Image { }; } // namespace odr::internal::ooxml::text - -#endif // ODR_INTERNAL_OOXML_TEXT_ELEMENT_HPP diff --git a/src/odr/internal/ooxml/text/ooxml_text_parser.hpp b/src/odr/internal/ooxml/text/ooxml_text_parser.hpp index fb4d3742..6d98b37b 100644 --- a/src/odr/internal/ooxml/text/ooxml_text_parser.hpp +++ b/src/odr/internal/ooxml/text/ooxml_text_parser.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_INTERNAL_OOXML_TEXT_PARSER_HPP -#define ODR_INTERNAL_OOXML_TEXT_PARSER_HPP +#pragma once #include #include @@ -14,5 +13,3 @@ class Element; Element *parse_tree(Document &document, pugi::xml_node node); } // namespace odr::internal::ooxml::text - -#endif // ODR_INTERNAL_OOXML_TEXT_PARSER_HPP diff --git a/src/odr/internal/ooxml/text/ooxml_text_style.hpp b/src/odr/internal/ooxml/text/ooxml_text_style.hpp index 8bfbdeb2..45565aa8 100644 --- a/src/odr/internal/ooxml/text/ooxml_text_style.hpp +++ b/src/odr/internal/ooxml/text/ooxml_text_style.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_INTERNAL_OOXML_TEXT_STYLE_HPP -#define ODR_INTERNAL_OOXML_TEXT_STYLE_HPP +#pragma once #include @@ -58,5 +57,3 @@ class StyleRegistry final { }; } // namespace odr::internal::ooxml::text - -#endif // ODR_INTERNAL_OOXML_TEXT_STYLE_HPP diff --git a/src/odr/internal/open_strategy.hpp b/src/odr/internal/open_strategy.hpp index 704c28e0..319186b2 100644 --- a/src/odr/internal/open_strategy.hpp +++ b/src/odr/internal/open_strategy.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_OPEN_STRATEGY_HPP -#define ODR_OPEN_STRATEGY_HPP +#pragma once #include #include @@ -41,5 +40,3 @@ open_file(std::shared_ptr file, std::unique_ptr open_document_file(std::shared_ptr file); } // namespace odr::internal::open_strategy - -#endif // ODR_OPEN_STRATEGY_HPP diff --git a/src/odr/internal/pdf/pdf_cmap.hpp b/src/odr/internal/pdf/pdf_cmap.hpp index 086f1299..d21aff23 100644 --- a/src/odr/internal/pdf/pdf_cmap.hpp +++ b/src/odr/internal/pdf/pdf_cmap.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_INTERNAL_PDF_CMAP_HPP -#define ODR_INTERNAL_PDF_CMAP_HPP +#pragma once #include #include @@ -20,5 +19,3 @@ class CMap { }; } // namespace odr::internal::pdf - -#endif // ODR_INTERNAL_PDF_CMAP_HPP diff --git a/src/odr/internal/pdf/pdf_cmap_parser.hpp b/src/odr/internal/pdf/pdf_cmap_parser.hpp index 00808568..15fb7105 100644 --- a/src/odr/internal/pdf/pdf_cmap_parser.hpp +++ b/src/odr/internal/pdf/pdf_cmap_parser.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_INTERNAL_PDF_CMAP_PARSER_HPP -#define ODR_INTERNAL_PDF_CMAP_PARSER_HPP +#pragma once #include #include @@ -34,5 +33,3 @@ class CMapParser { }; } // namespace odr::internal::pdf - -#endif // ODR_INTERNAL_PDF_CMAP_PARSER_HPP diff --git a/src/odr/internal/pdf/pdf_document.hpp b/src/odr/internal/pdf/pdf_document.hpp index d49789e2..f926ccaf 100644 --- a/src/odr/internal/pdf/pdf_document.hpp +++ b/src/odr/internal/pdf/pdf_document.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_INTERNAL_PDF_DOCUMENT_HPP -#define ODR_INTERNAL_PDF_DOCUMENT_HPP +#pragma once #include #include @@ -22,5 +21,3 @@ struct Document { }; } // namespace odr::internal::pdf - -#endif // ODR_INTERNAL_PDF_DOCUMENT_HPP diff --git a/src/odr/internal/pdf/pdf_document_element.hpp b/src/odr/internal/pdf/pdf_document_element.hpp index 144b8668..af13c0d7 100644 --- a/src/odr/internal/pdf/pdf_document_element.hpp +++ b/src/odr/internal/pdf/pdf_document_element.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_INTERNAL_PDF_DOCUMENT_ELEMENT_HPP -#define ODR_INTERNAL_PDF_DOCUMENT_ELEMENT_HPP +#pragma once #include #include @@ -63,5 +62,3 @@ struct Font : Element { }; } // namespace odr::internal::pdf - -#endif // ODR_INTERNAL_PDF_DOCUMENT_ELEMENT_HPP diff --git a/src/odr/internal/pdf/pdf_document_parser.hpp b/src/odr/internal/pdf/pdf_document_parser.hpp index 3a55fdc6..d73e42d8 100644 --- a/src/odr/internal/pdf/pdf_document_parser.hpp +++ b/src/odr/internal/pdf/pdf_document_parser.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_INTERNAL_PDF_DOCUMENT_PARSER_HPP -#define ODR_INTERNAL_PDF_DOCUMENT_PARSER_HPP +#pragma once #include #include @@ -39,5 +38,3 @@ class DocumentParser { }; } // namespace odr::internal::pdf - -#endif // ODR_INTERNAL_PDF_DOCUMENT_PARSER_HPP diff --git a/src/odr/internal/pdf/pdf_file.hpp b/src/odr/internal/pdf/pdf_file.hpp index a19f89f1..5feaadc4 100644 --- a/src/odr/internal/pdf/pdf_file.hpp +++ b/src/odr/internal/pdf/pdf_file.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_INTERNAL_PDF_FILE_HPP -#define ODR_INTERNAL_PDF_FILE_HPP +#pragma once #include @@ -23,5 +22,3 @@ class PdfFile final : public abstract::PdfFile { }; } // namespace odr::internal - -#endif // ODR_INTERNAL_PDF_FILE_HPP diff --git a/src/odr/internal/pdf/pdf_file_object.hpp b/src/odr/internal/pdf/pdf_file_object.hpp index c0d29096..cf472627 100644 --- a/src/odr/internal/pdf/pdf_file_object.hpp +++ b/src/odr/internal/pdf/pdf_file_object.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_INTERNAL_PDF_FILE_OBJECT_HPP -#define ODR_INTERNAL_PDF_FILE_OBJECT_HPP +#pragma once #include @@ -90,5 +89,3 @@ class Entry { }; } // namespace odr::internal::pdf - -#endif // ODR_INTERNAL_PDF_FILE_OBJECT_HPP diff --git a/src/odr/internal/pdf/pdf_file_parser.hpp b/src/odr/internal/pdf/pdf_file_parser.hpp index ef178686..3084041f 100644 --- a/src/odr/internal/pdf/pdf_file_parser.hpp +++ b/src/odr/internal/pdf/pdf_file_parser.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_INTERNAL_PDF_FILE_PARSER_HPP -#define ODR_INTERNAL_PDF_FILE_PARSER_HPP +#pragma once #include @@ -39,5 +38,3 @@ class FileParser { }; } // namespace odr::internal::pdf - -#endif // ODR_INTERNAL_PDF_FILE_PARSER_HPP diff --git a/src/odr/internal/pdf/pdf_graphics_operator.hpp b/src/odr/internal/pdf/pdf_graphics_operator.hpp index 41d7fdcd..8d2ce78c 100644 --- a/src/odr/internal/pdf/pdf_graphics_operator.hpp +++ b/src/odr/internal/pdf/pdf_graphics_operator.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_INTERNAL_PDF_GRAPHICS_OPERATOR_HPP -#define ODR_INTERNAL_PDF_GRAPHICS_OPERATOR_HPP +#pragma once #include @@ -112,5 +111,3 @@ struct GraphicsOperator { }; } // namespace odr::internal::pdf - -#endif // ODR_INTERNAL_PDF_GRAPHICS_OPERATOR_HPP diff --git a/src/odr/internal/pdf/pdf_graphics_operator_parser.hpp b/src/odr/internal/pdf/pdf_graphics_operator_parser.hpp index 15174052..7a46f400 100644 --- a/src/odr/internal/pdf/pdf_graphics_operator_parser.hpp +++ b/src/odr/internal/pdf/pdf_graphics_operator_parser.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_INTERNAL_PDF_GRAPHICS_OPERATOR_PARSER_HPP -#define ODR_INTERNAL_PDF_GRAPHICS_OPERATOR_PARSER_HPP +#pragma once #include @@ -29,5 +28,3 @@ class GraphicsOperatorParser { }; } // namespace odr::internal::pdf - -#endif // ODR_INTERNAL_PDF_GRAPHICS_OPERATOR_PARSER_HPP diff --git a/src/odr/internal/pdf/pdf_graphics_state.hpp b/src/odr/internal/pdf/pdf_graphics_state.hpp index 0bc2806c..39237995 100644 --- a/src/odr/internal/pdf/pdf_graphics_state.hpp +++ b/src/odr/internal/pdf/pdf_graphics_state.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_INTERNAL_PDF_GRAPHICS_STATE_HPP -#define ODR_INTERNAL_PDF_GRAPHICS_STATE_HPP +#pragma once #include #include @@ -77,5 +76,3 @@ struct GraphicsState { }; } // namespace odr::internal::pdf - -#endif // ODR_INTERNAL_PDF_GRAPHICS_STATE_HPP diff --git a/src/odr/internal/pdf/pdf_object.hpp b/src/odr/internal/pdf/pdf_object.hpp index 1e367e14..2cc6a1a0 100644 --- a/src/odr/internal/pdf/pdf_object.hpp +++ b/src/odr/internal/pdf/pdf_object.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_INTERNAL_PDF_OBJECT_HPP -#define ODR_INTERNAL_PDF_OBJECT_HPP +#pragma once #include #include @@ -218,5 +217,3 @@ std::ostream &operator<<(std::ostream &, const Dictionary &); template <> struct std::hash { std::size_t operator()(const odr::internal::pdf::ObjectReference &k) const; }; - -#endif // ODR_INTERNAL_PDF_OBJECT_HPP diff --git a/src/odr/internal/pdf/pdf_object_parser.hpp b/src/odr/internal/pdf/pdf_object_parser.hpp index 833538b2..d9b21438 100644 --- a/src/odr/internal/pdf/pdf_object_parser.hpp +++ b/src/odr/internal/pdf/pdf_object_parser.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_INTERNAL_PDF_OBJECT_PARSER_HPP -#define ODR_INTERNAL_PDF_OBJECT_PARSER_HPP +#pragma once #include @@ -84,5 +83,3 @@ class ObjectParser { }; } // namespace odr::internal::pdf - -#endif // ODR_INTERNAL_PDF_OBJECT_PARSER_HPP diff --git a/src/odr/internal/pdf_poppler/poppler_pdf_file.hpp b/src/odr/internal/pdf_poppler/poppler_pdf_file.hpp index 47f7866e..d326b04b 100644 --- a/src/odr/internal/pdf_poppler/poppler_pdf_file.hpp +++ b/src/odr/internal/pdf_poppler/poppler_pdf_file.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_INTERNAL_POPPLER_PDF_FILE_HPP -#define ODR_INTERNAL_POPPLER_PDF_FILE_HPP +#pragma once #include @@ -35,5 +34,3 @@ class PopplerPdfFile final : public abstract::PdfFile { }; } // namespace odr::internal - -#endif // ODR_INTERNAL_POPPLER_PDF_FILE_HPP diff --git a/src/odr/internal/project_info.hpp b/src/odr/internal/project_info.hpp index 272cdc21..74466419 100644 --- a/src/odr/internal/project_info.hpp +++ b/src/odr/internal/project_info.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_INTERNAL_PROJECT_INFO_HPP -#define ODR_INTERNAL_PROJECT_INFO_HPP +#pragma once namespace odr::internal::project_info { @@ -13,5 +12,3 @@ const char *poppler_data_path() noexcept; const char *pdf2htmlex_data_path() noexcept; } // namespace odr::internal::project_info - -#endif // ODR_INTERNAL_PROJECT_INFO_HPP diff --git a/src/odr/internal/resource.cpp b/src/odr/internal/resource.cpp index 02afc56d..e38ea5ee 100644 --- a/src/odr/internal/resource.cpp +++ b/src/odr/internal/resource.cpp @@ -26,7 +26,7 @@ Resources::Resources() { filesystem->copy(std::make_shared( std::string(resource.data, resource.size)), - resource.path); + common::Path(resource.path)); } m_filesystem = std::move(filesystem); diff --git a/src/odr/internal/resource.hpp b/src/odr/internal/resource.hpp index a509f8a9..1d86c64f 100644 --- a/src/odr/internal/resource.hpp +++ b/src/odr/internal/resource.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_INTERNAL_RESOURCE_HPP -#define ODR_INTERNAL_RESOURCE_HPP +#pragma once #include @@ -35,5 +34,3 @@ class Resources final { }; } // namespace odr::internal - -#endif // ODR_INTERNAL_RESOURCE_HPP diff --git a/src/odr/internal/resource_data.hpp b/src/odr/internal/resource_data.hpp index 9ba94f2b..307b7090 100644 --- a/src/odr/internal/resource_data.hpp +++ b/src/odr/internal/resource_data.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_INTERNAL_RESOURCE_DATA_HPP -#define ODR_INTERNAL_RESOURCE_DATA_HPP +#pragma once #include @@ -24,5 +23,3 @@ extern const std::uint32_t files_count; // clang-format on } // namespace odr::internal::resources - -#endif // ODR_INTERNAL_RESOURCE_DATA_HPP diff --git a/src/odr/internal/svm/svm_file.hpp b/src/odr/internal/svm/svm_file.hpp index dd28cd6d..d5e7d7bb 100644 --- a/src/odr/internal/svm/svm_file.hpp +++ b/src/odr/internal/svm/svm_file.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_INTERNAL_SVM_FILE_HPP -#define ODR_INTERNAL_SVM_FILE_HPP +#pragma once #include #include @@ -29,5 +28,3 @@ class SvmFile final : public abstract::ImageFile { }; } // namespace odr::internal::svm - -#endif // ODR_INTERNAL_SVM_FILE_HPP diff --git a/src/odr/internal/svm/svm_format.hpp b/src/odr/internal/svm/svm_format.hpp index f1cbdd03..cc216c8f 100644 --- a/src/odr/internal/svm/svm_format.hpp +++ b/src/odr/internal/svm/svm_format.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_INTERNAL_SVM_FORMAT_HPP -#define ODR_INTERNAL_SVM_FORMAT_HPP +#pragma once #include #include @@ -245,5 +244,3 @@ TextRectangleAction read_text_rectangle_action(std::istream &in, TextLineAction read_text_line_action(std::istream &in, const VersionLength &vl); } // namespace odr::internal::svm - -#endif // ODR_INTERNAL_SVM_FORMAT_HPP diff --git a/src/odr/internal/svm/svm_to_svg.hpp b/src/odr/internal/svm/svm_to_svg.hpp index a110a91c..a5ecfcba 100644 --- a/src/odr/internal/svm/svm_to_svg.hpp +++ b/src/odr/internal/svm/svm_to_svg.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_INTERNAL_SVM_TO_SVG_HPP -#define ODR_INTERNAL_SVM_TO_SVG_HPP +#pragma once #include #include @@ -11,5 +10,3 @@ namespace Translator { void svg(const SvmFile &file, std::ostream &out); } } // namespace odr::internal::svm - -#endif // ODR_INTERNAL_SVM_TO_SVG_HPP diff --git a/src/odr/internal/text/text_file.hpp b/src/odr/internal/text/text_file.hpp index 69bad36b..f50a43bd 100644 --- a/src/odr/internal/text/text_file.hpp +++ b/src/odr/internal/text/text_file.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_INTERNAL_TEXT_FILE_HPP -#define ODR_INTERNAL_TEXT_FILE_HPP +#pragma once #include @@ -26,5 +25,3 @@ class TextFile final : public abstract::TextFile { }; } // namespace odr::internal::text - -#endif // ODR_INTERNAL_TEXT_FILE_HPP diff --git a/src/odr/internal/text/text_util.hpp b/src/odr/internal/text/text_util.hpp index 92c48e49..64d9f475 100644 --- a/src/odr/internal/text/text_util.hpp +++ b/src/odr/internal/text/text_util.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_INTERNAL_TEXT_UTIL_HPP -#define ODR_INTERNAL_TEXT_UTIL_HPP +#pragma once #include #include @@ -10,5 +9,3 @@ namespace odr::internal::text { std::string guess_charset(std::istream &in); } // namespace odr::internal::text - -#endif // ODR_INTERNAL_TEXT_UTIL_HPP diff --git a/src/odr/internal/util/byte_util.hpp b/src/odr/internal/util/byte_util.hpp index 864db941..4d046efa 100644 --- a/src/odr/internal/util/byte_util.hpp +++ b/src/odr/internal/util/byte_util.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_INTERNAL_BYTE_UTIL_HPP -#define ODR_INTERNAL_BYTE_UTIL_HPP +#pragma once #include #include @@ -20,5 +19,3 @@ void reverse_bytes(std::u16string &string); void reverse_bytes(std::u32string &string); } // namespace odr::internal::util - -#endif // ODR_INTERNAL_BYTE_UTIL_HPP diff --git a/src/odr/internal/util/file_util.hpp b/src/odr/internal/util/file_util.hpp index 12753f10..023d249b 100644 --- a/src/odr/internal/util/file_util.hpp +++ b/src/odr/internal/util/file_util.hpp @@ -1,10 +1,7 @@ -#ifndef ODR_INTERNAL_UTIL_FILE_HPP -#define ODR_INTERNAL_UTIL_FILE_HPP +#pragma once #include namespace odr::internal::util::file { std::string read(const std::string &path); } // namespace odr::internal::util::file - -#endif // ODR_INTERNAL_UTIL_FILE_UTIL_HPP diff --git a/src/odr/internal/util/hash_util.hpp b/src/odr/internal/util/hash_util.hpp index 9edea829..f3999d80 100644 --- a/src/odr/internal/util/hash_util.hpp +++ b/src/odr/internal/util/hash_util.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_INTERNAL_HASH_UTIL_HPP -#define ODR_INTERNAL_HASH_UTIL_HPP +#pragma once #include #include @@ -16,5 +15,3 @@ void hash_combine(std::size_t &seed, const T &v, Rest... rest) { } } // namespace odr::internal::util::hash - -#endif // ODR_INTERNAL_HASH_UTIL_HPP diff --git a/src/odr/internal/util/map_util.hpp b/src/odr/internal/util/map_util.hpp index 9ba40b3f..434aadef 100644 --- a/src/odr/internal/util/map_util.hpp +++ b/src/odr/internal/util/map_util.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_INTERNAL_UTIL_MAP_HPP -#define ODR_INTERNAL_UTIL_MAP_HPP +#pragma once #include @@ -50,5 +49,3 @@ typename Map::const_iterator lookup_greater_or_equals(const Map &map, } } // namespace odr::internal::util::map - -#endif // ODR_INTERNAL_UTIL_MAP_HPP diff --git a/src/odr/internal/util/odr_meta_util.hpp b/src/odr/internal/util/odr_meta_util.hpp index d55f4a20..8818fb49 100644 --- a/src/odr/internal/util/odr_meta_util.hpp +++ b/src/odr/internal/util/odr_meta_util.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_INTERNAL_META_UTIL_HPP -#define ODR_INTERNAL_META_UTIL_HPP +#pragma once #include @@ -10,5 +9,3 @@ struct FileMeta; namespace odr::internal::util::meta { nlohmann::json meta_to_json(const FileMeta &meta); } - -#endif // ODR_INTERNAL_META_UTIL_HPP diff --git a/src/odr/internal/util/stream_util.hpp b/src/odr/internal/util/stream_util.hpp index 0d252082..04ebbcc5 100644 --- a/src/odr/internal/util/stream_util.hpp +++ b/src/odr/internal/util/stream_util.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_INTERNAL_UTIL_STREAM_HPP -#define ODR_INTERNAL_UTIL_STREAM_HPP +#pragma once #include #include @@ -19,5 +18,3 @@ std::istream &pipe_until(std::istream &in, std::ostream &out, char until_char, std::string read_until(std::istream &in, char until_char, bool inclusive); } // namespace odr::internal::util::stream - -#endif // ODR_INTERNAL_UTIL_STREAM_HPP diff --git a/src/odr/internal/util/string_util.hpp b/src/odr/internal/util/string_util.hpp index 9da4d9fd..b803f249 100644 --- a/src/odr/internal/util/string_util.hpp +++ b/src/odr/internal/util/string_util.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_INTERNAL_STRING_UTIL_HPP -#define ODR_INTERNAL_STRING_UTIL_HPP +#pragma once #include #include @@ -28,5 +27,3 @@ std::string u16string_to_string(const std::u16string &string); std::u16string string_to_u16string(const std::string &string); std::string c16str_to_string(const char16_t *c16str, std::size_t length); } // namespace odr::internal::util::string - -#endif // ODR_INTERNAL_STRING_UTIL_HPP diff --git a/src/odr/internal/util/xml_util.hpp b/src/odr/internal/util/xml_util.hpp index b38caba9..a16e1f8f 100644 --- a/src/odr/internal/util/xml_util.hpp +++ b/src/odr/internal/util/xml_util.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_INTERNAL_UTIL_XML_HPP -#define ODR_INTERNAL_UTIL_XML_HPP +#pragma once #include #include @@ -39,5 +38,3 @@ struct StringToken { std::vector tokenize_text(const std::string &text); } // namespace odr::internal::util::xml - -#endif // ODR_INTERNAL_XML_UTIL_HPP diff --git a/src/odr/internal/zip/zip_archive.hpp b/src/odr/internal/zip/zip_archive.hpp index a48beaf3..78c807b8 100644 --- a/src/odr/internal/zip/zip_archive.hpp +++ b/src/odr/internal/zip/zip_archive.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_INTERNAL_ZIP_ARCHIVE_HPP -#define ODR_INTERNAL_ZIP_ARCHIVE_HPP +#pragma once #include #include @@ -75,5 +74,3 @@ class ZipArchive final : public abstract::Archive { }; } // namespace odr::internal::zip - -#endif // ODR_INTERNAL_ZIP_ARCHIVE_HPP diff --git a/src/odr/internal/zip/zip_exceptions.hpp b/src/odr/internal/zip/zip_exceptions.hpp index d589ba60..06eac9dc 100644 --- a/src/odr/internal/zip/zip_exceptions.hpp +++ b/src/odr/internal/zip/zip_exceptions.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_INTERNAL_ZIP_ZIP_EXCEPTIONS_HPP -#define ODR_INTERNAL_ZIP_ZIP_EXCEPTIONS_HPP +#pragma once #include @@ -18,5 +17,3 @@ struct MinizSaveError : public ZipSaveError { }; } // namespace odr::internal::zip - -#endif // ODR_INTERNAL_ZIP_ZIP_EXCEPTIONS_HPP diff --git a/src/odr/internal/zip/zip_file.hpp b/src/odr/internal/zip/zip_file.hpp index fde6f6db..cfb8bd97 100644 --- a/src/odr/internal/zip/zip_file.hpp +++ b/src/odr/internal/zip/zip_file.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_INTERNAL_ZIP_FILE_HPP -#define ODR_INTERNAL_ZIP_FILE_HPP +#pragma once #include @@ -36,5 +35,3 @@ class ZipFile final : public abstract::ArchiveFile { }; } // namespace odr::internal::zip - -#endif // ODR_INTERNAL_ZIP_FILE_HPP diff --git a/src/odr/internal/zip/zip_util.cpp b/src/odr/internal/zip/zip_util.cpp index 80531e04..e62fab99 100644 --- a/src/odr/internal/zip/zip_util.cpp +++ b/src/odr/internal/zip/zip_util.cpp @@ -5,7 +5,6 @@ #include #include -#include namespace odr::internal::zip::util { @@ -157,7 +156,7 @@ common::Path Archive::Entry::path() const { mz_zip_reader_get_filename(const_cast(m_parent->zip()), m_index, filename, MZ_ZIP_MAX_ARCHIVE_FILENAME_SIZE); - return {filename}; + return common::Path(filename); } Method Archive::Entry::method() const { diff --git a/src/odr/internal/zip/zip_util.hpp b/src/odr/internal/zip/zip_util.hpp index 5a6aebf5..af35ff20 100644 --- a/src/odr/internal/zip/zip_util.hpp +++ b/src/odr/internal/zip/zip_util.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_INTERNAL_ZIP_UTIL_HPP -#define ODR_INTERNAL_ZIP_UTIL_HPP +#pragma once #include @@ -134,5 +133,3 @@ bool append_file(mz_zip_archive &archive, const std::string &path, std::uint32_t level_and_flags); } // namespace odr::internal::zip::util - -#endif // ODR_INTERNAL_ZIP_UTIL_HPP diff --git a/src/odr/open_document_reader.cpp b/src/odr/open_document_reader.cpp index d2da7fa6..8ada3c9e 100644 --- a/src/odr/open_document_reader.cpp +++ b/src/odr/open_document_reader.cpp @@ -287,8 +287,8 @@ void OpenDocumentReader::edit(const Document &document, const char *diff) { void OpenDocumentReader::copy_resources(const std::string &to_path) { for (auto resource : internal::Resources::resources()) { - auto resource_output_path = - internal::common::Path(to_path).join(resource.path); + auto resource_output_path = internal::common::Path(to_path).join( + internal::common::Path(resource.path)); std::filesystem::create_directories(resource_output_path.parent()); std::ofstream out(resource_output_path.string(), std::ios::binary); out.write(resource.data, static_cast(resource.size)); diff --git a/src/odr/open_document_reader.hpp b/src/odr/open_document_reader.hpp index a6893f65..9c01b97e 100644 --- a/src/odr/open_document_reader.hpp +++ b/src/odr/open_document_reader.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_OPEN_DOCUMENT_READER_HPP -#define ODR_OPEN_DOCUMENT_READER_HPP +#pragma once #include #include @@ -182,5 +181,3 @@ class OpenDocumentReader final { }; } // namespace odr - -#endif // ODR_OPEN_DOCUMENT_READER_HPP diff --git a/src/odr/quantity.hpp b/src/odr/quantity.hpp index e69dc54e..382faf8e 100644 --- a/src/odr/quantity.hpp +++ b/src/odr/quantity.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_QUANTITY_HPP -#define ODR_QUANTITY_HPP +#pragma once #include #include @@ -81,5 +80,3 @@ std::ostream &operator<<(std::ostream &out, quantity.to_stream(out); return out; } - -#endif // ODR_QUANTITY_HPP diff --git a/src/odr/style.hpp b/src/odr/style.hpp index 79440200..4c9e712b 100644 --- a/src/odr/style.hpp +++ b/src/odr/style.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_STYLE_HPP -#define ODR_STYLE_HPP +#pragma once #include @@ -207,5 +206,3 @@ struct TableDimensions { }; } // namespace odr - -#endif // ODR_STYLE_HPP diff --git a/test/src/html_output_test.cpp b/test/src/html_output_test.cpp index 7fc2f3bf..61315d37 100644 --- a/test/src/html_output_test.cpp +++ b/test/src/html_output_test.cpp @@ -18,6 +18,7 @@ using namespace odr; using namespace odr::internal; +using namespace odr::internal::common; using namespace odr::test; namespace fs = std::filesystem; @@ -123,7 +124,7 @@ TEST_P(HtmlOutputTests, html_meta) { const std::string resource_path = common::Path(output_path_prefix) .parent() .parent() - .join("resources") + .join(Path("resources")) .string(); OpenDocumentReader::copy_resources(resource_path); @@ -168,12 +169,14 @@ TestParams create_test_params(const TestFile &test_file, const std::string test_file_path = test_file.short_path; const std::string test_repo = *common::Path(test_file_path).begin(); - const std::string output_path_prefix = - common::Path("output").join(test_repo).join("output").string(); + const std::string output_path_prefix = common::Path("output") + .join(Path(test_repo)) + .join(Path("output")) + .string(); const std::string output_path_suffix = engine_suffix(engine); const std::string output_path = common::Path(output_path_prefix) - .join(common::Path(test_file_path).rebase(test_repo)) + .join(common::Path(test_file_path).rebase(Path(test_repo))) .string() + output_path_suffix; diff --git a/test/src/internal/cfb/cfb_archive_test.cpp b/test/src/internal/cfb/cfb_archive_test.cpp index d28274a9..0791df10 100644 --- a/test/src/internal/cfb/cfb_archive_test.cpp +++ b/test/src/internal/cfb/cfb_archive_test.cpp @@ -12,6 +12,7 @@ using namespace odr; using namespace odr::internal; +using namespace odr::internal::common; using namespace odr::internal::cfb; using namespace odr::test; @@ -31,6 +32,6 @@ TEST(CfbArchive, open_encrypted_docx) { util::Archive cfb(std::make_shared(common::DiskFile( TestData::test_file_path("odr-public/docx/encrypted.docx")))); - EXPECT_TRUE(cfb.find("EncryptionInfo") == std::end(cfb)); - EXPECT_TRUE(cfb.find("/EncryptionInfo") != std::end(cfb)); + EXPECT_TRUE(cfb.find(Path("EncryptionInfo")) == std::end(cfb)); + EXPECT_TRUE(cfb.find(Path("/EncryptionInfo")) != std::end(cfb)); } diff --git a/test/src/internal/common/path_test.cpp b/test/src/internal/common/path_test.cpp index de5018bb..0d61ec96 100644 --- a/test/src/internal/common/path_test.cpp +++ b/test/src/internal/common/path_test.cpp @@ -24,15 +24,17 @@ TEST(Path, normalization) { TEST(Path, join) { EXPECT_EQ("/home/media/image8.png", - Path("/home").join("media/image8.png").string()); + Path("/home").join(Path("media/image8.png")).string()); } TEST(Path, join_relative) { EXPECT_EQ("ppt/media/image8.png", - Path("ppt/slides").join("../media/image8.png").string()); + Path("ppt/slides").join(Path("../media/image8.png")).string()); } -TEST(Path, join_root) { EXPECT_EQ("/tmp", Path("/").join("tmp").string()); } +TEST(Path, join_root) { + EXPECT_EQ("/tmp", Path("/").join(Path("tmp")).string()); +} TEST(Path, root_parent) { EXPECT_ANY_THROW(auto tmp = Path("/").parent()); } @@ -40,26 +42,28 @@ TEST(Path, one_parent) { EXPECT_EQ("/", Path("/tmp").parent().string()); } TEST(Path, rebase) { EXPECT_EQ("image8.png", - Path("./ppt/media/image8.png").rebase("ppt/media").string()); + Path("./ppt/media/image8.png").rebase(Path("ppt/media")).string()); } TEST(Path, rebase_separate_tree) { - EXPECT_EQ("../../other/directory", Path("ppt/media/other/directory") - .rebase("./ppt/media/some/directory") - .string()); + EXPECT_EQ("../../other/directory", + Path("ppt/media/other/directory") + .rebase(Path("./ppt/media/some/directory")) + .string()); } TEST(Path, rebase_relative) { EXPECT_EQ("other/directory", - Path("../../other/directory").rebase("../..").string()); + Path("../../other/directory").rebase(Path("../..")).string()); } TEST(Path, common_root) { - EXPECT_EQ("ppt/media", - Path("./ppt/media/image8.png").common_root("ppt/media").string()); + EXPECT_EQ( + "ppt/media", + Path("./ppt/media/image8.png").common_root(Path("ppt/media")).string()); } TEST(Path, common_root_relative) { EXPECT_EQ("../..", - Path("../../other/directory").common_root("../..").string()); + Path("../../other/directory").common_root(Path("../..")).string()); } diff --git a/test/src/internal/zip/zip_archive_test.cpp b/test/src/internal/zip/zip_archive_test.cpp index b88c61c6..3a6ef0dc 100644 --- a/test/src/internal/zip/zip_archive_test.cpp +++ b/test/src/internal/zip/zip_archive_test.cpp @@ -9,7 +9,6 @@ #include -#include #include #include @@ -44,10 +43,11 @@ TEST(ZipArchive, open) { TEST(ZipArchive, create_and_save) { ZipArchive zip; - zip.insert_file(std::end(zip), "a", std::make_shared("abc")); - zip.insert_file(std::end(zip), "hi", + zip.insert_file(std::end(zip), Path("a"), + std::make_shared("abc")); + zip.insert_file(std::end(zip), Path("hi"), std::make_shared("hello world!")); - zip.insert_directory(std::end(zip), "b"); + zip.insert_directory(std::end(zip), Path("b")); std::ofstream out("test.zip"); zip.save(out); @@ -59,18 +59,18 @@ TEST(ZipArchive, create) { { ZipArchive zip; - zip.insert_file(std::end(zip), "one.txt", + zip.insert_file(std::end(zip), Path("one.txt"), std::make_shared("this is written at once")); zip.insert_file( - std::end(zip), "two.txt", + std::end(zip), Path("two.txt"), std::make_shared("this is written at two stages")); - zip.insert_directory(std::end(zip), "empty"); - zip.insert_directory(std::end(zip), "notempty"); + zip.insert_directory(std::end(zip), Path("empty")); + zip.insert_directory(std::end(zip), Path("notempty")); - zip.insert_file(std::end(zip), "notempty/three.txt", + zip.insert_file(std::end(zip), Path("notempty/three.txt"), std::make_shared("asdf")); - zip.insert_file(std::end(zip), "./notempty/four.txt", + zip.insert_file(std::end(zip), Path("./notempty/four.txt"), std::make_shared("1234")); std::ofstream out(path); @@ -81,19 +81,19 @@ TEST(ZipArchive, create) { auto zip = std::make_shared(std::make_shared(path)); - EXPECT_TRUE(zip->find("one.txt")->is_file()); - EXPECT_TRUE(zip->find("two.txt")->is_file()); - EXPECT_TRUE(zip->find("empty")->is_directory()); - EXPECT_TRUE(zip->find("notempty")->is_directory()); - EXPECT_TRUE(zip->find("notempty/three.txt")->is_file()); - EXPECT_TRUE(zip->find("notempty/four.txt")->is_file()); - EXPECT_TRUE(zip->find("./notempty/four.txt")->is_file()); - - EXPECT_EQ(23, zip->find("one.txt")->file()->size()); - EXPECT_EQ(29, zip->find("two.txt")->file()->size()); - EXPECT_EQ(4, zip->find("notempty/three.txt")->file()->size()); - EXPECT_EQ(4, zip->find("notempty/four.txt")->file()->size()); - EXPECT_EQ(4, zip->find("./notempty/four.txt")->file()->size()); + EXPECT_TRUE(zip->find(Path("one.txt"))->is_file()); + EXPECT_TRUE(zip->find(Path("two.txt"))->is_file()); + EXPECT_TRUE(zip->find(Path("empty"))->is_directory()); + EXPECT_TRUE(zip->find(Path("notempty"))->is_directory()); + EXPECT_TRUE(zip->find(Path("notempty/three.txt"))->is_file()); + EXPECT_TRUE(zip->find(Path("notempty/four.txt"))->is_file()); + EXPECT_TRUE(zip->find(Path("./notempty/four.txt"))->is_file()); + + EXPECT_EQ(23, zip->find(Path("one.txt"))->file()->size()); + EXPECT_EQ(29, zip->find(Path("two.txt"))->file()->size()); + EXPECT_EQ(4, zip->find(Path("notempty/three.txt"))->file()->size()); + EXPECT_EQ(4, zip->find(Path("notempty/four.txt"))->file()->size()); + EXPECT_EQ(4, zip->find(Path("./notempty/four.txt"))->file()->size()); } } @@ -105,7 +105,7 @@ TEST(ZipArchive, create_order) { ZipArchive zip; for (auto &&e : entries) { - zip.insert_file(std::end(zip), e, std::make_shared("")); + zip.insert_file(std::end(zip), Path(e), std::make_shared("")); } std::ofstream out(path); diff --git a/test/src/test_util.cpp b/test/src/test_util.cpp index 0863a093..9b7ae173 100644 --- a/test/src/test_util.cpp +++ b/test/src/test_util.cpp @@ -7,12 +7,14 @@ #include #include +#include #include #include #include using namespace odr; using namespace odr::internal; +using namespace odr::internal::common; namespace fs = std::filesystem; namespace odr::test { @@ -123,7 +125,7 @@ TestFile::TestFile(std::string absolute_path, std::string short_path, password{std::move(password)} {} std::string TestData::data_input_directory() { - return common::Path(TestData::data_directory()).join("input").string(); + return common::Path(TestData::data_directory()).join(Path("input")).string(); } TestData &TestData::instance_() { diff --git a/test/src/test_util.hpp b/test/src/test_util.hpp index c5a05e87..3b860b65 100644 --- a/test/src/test_util.hpp +++ b/test/src/test_util.hpp @@ -1,5 +1,4 @@ -#ifndef ODR_TEST_META_HPP -#define ODR_TEST_META_HPP +#pragma once #include @@ -45,5 +44,3 @@ class TestData { }; } // namespace odr::test - -#endif // ODR_TEST_META_HPP