Skip to content

Commit 7ddd7ee

Browse files
authored
remove internal::common namespace (#438)
1 parent cd5264a commit 7ddd7ee

105 files changed

Lines changed: 521 additions & 562 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/odr/document.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ bool Document::is_savable(const bool encrypted) const noexcept {
2626
}
2727

2828
void Document::save(const std::string &path) const {
29-
m_impl->save(internal::common::Path(path));
29+
m_impl->save(internal::Path(path));
3030
}
3131

3232
void Document::save(const std::string &path,
3333
const std::string &password) const {
34-
m_impl->save(internal::common::Path(path), password.c_str());
34+
m_impl->save(internal::Path(path), password.c_str());
3535
}
3636

3737
FileType Document::file_type() const noexcept { return m_impl->file_type(); }

src/odr/file.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ File::File(std::shared_ptr<internal::abstract::File> impl)
3333
: m_impl{std::move(impl)} {}
3434

3535
File::File(const std::string &path)
36-
: m_impl{std::make_shared<internal::common::DiskFile>(path)} {}
36+
: m_impl{std::make_shared<internal::DiskFile>(path)} {}
3737

3838
FileLocation File::location() const noexcept { return m_impl->location(); }
3939

@@ -63,7 +63,7 @@ std::shared_ptr<internal::abstract::File> File::impl() const { return m_impl; }
6363
std::vector<FileType> DecodedFile::list_file_types(const std::string &path,
6464
Logger &logger) {
6565
return internal::open_strategy::list_file_types(
66-
std::make_shared<internal::common::DiskFile>(path), logger);
66+
std::make_shared<internal::DiskFile>(path), logger);
6767
}
6868

6969
std::vector<DecoderEngine> DecodedFile::list_decoder_engines(FileType as) {
@@ -86,17 +86,16 @@ DecodedFile::DecodedFile(const File &file, FileType as, Logger &logger)
8686

8787
DecodedFile::DecodedFile(const std::string &path, Logger &logger)
8888
: DecodedFile(internal::open_strategy::open_file(
89-
std::make_shared<internal::common::DiskFile>(path), logger)) {}
89+
std::make_shared<internal::DiskFile>(path), logger)) {}
9090

9191
DecodedFile::DecodedFile(const std::string &path, FileType as, Logger &logger)
9292
: DecodedFile(internal::open_strategy::open_file(
93-
std::make_shared<internal::common::DiskFile>(path), as, logger)) {}
93+
std::make_shared<internal::DiskFile>(path), as, logger)) {}
9494

9595
DecodedFile::DecodedFile(const std::string &path,
9696
const DecodePreference &preference, Logger &logger)
9797
: DecodedFile(internal::open_strategy::open_file(
98-
std::make_shared<internal::common::DiskFile>(path), preference,
99-
logger)) {}
98+
std::make_shared<internal::DiskFile>(path), preference, logger)) {}
10099

101100
File DecodedFile::file() const { return File(m_impl->file()); }
102101

@@ -230,7 +229,7 @@ DocumentFile::DocumentFile(
230229

231230
DocumentFile::DocumentFile(const std::string &path, Logger &logger)
232231
: DocumentFile(internal::open_strategy::open_document_file(
233-
std::make_shared<internal::common::DiskFile>(path), logger)) {}
232+
std::make_shared<internal::DiskFile>(path), logger)) {}
234233

235234
DocumentType DocumentFile::document_type() const {
236235
return m_impl->document_type();

src/odr/filesystem.cpp

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,42 +20,49 @@ FileWalker::FileWalker(FileWalker &&other) noexcept = default;
2020
FileWalker::~FileWalker() = default;
2121

2222
FileWalker &FileWalker::operator=(const odr::FileWalker &other) {
23+
if (this == &other) {
24+
return *this;
25+
}
2326
m_impl = other.m_impl->clone();
2427
return *this;
2528
}
2629

2730
FileWalker &FileWalker::operator=(odr::FileWalker &&) noexcept = default;
2831

29-
FileWalker::operator bool() const { return m_impl.operator bool(); }
32+
FileWalker::operator bool() const { return m_impl != nullptr; }
3033

31-
bool FileWalker::end() const { return m_impl ? m_impl->end() : true; }
34+
bool FileWalker::end() const { return m_impl == nullptr || m_impl->end(); }
3235

33-
std::uint32_t FileWalker::depth() const { return m_impl ? m_impl->depth() : 0; }
36+
std::uint32_t FileWalker::depth() const {
37+
return m_impl != nullptr ? m_impl->depth() : 0;
38+
}
3439

3540
std::string FileWalker::path() const {
36-
return m_impl ? m_impl->path().string() : std::string("");
41+
return m_impl != nullptr ? m_impl->path().string() : std::string("");
3742
}
3843

39-
bool FileWalker::is_file() const { return m_impl ? m_impl->is_file() : false; }
44+
bool FileWalker::is_file() const {
45+
return m_impl != nullptr && m_impl->is_file();
46+
}
4047

4148
bool FileWalker::is_directory() const {
42-
return m_impl ? m_impl->is_directory() : false;
49+
return m_impl != nullptr && m_impl->is_directory();
4350
}
4451

4552
void FileWalker::pop() {
46-
if (m_impl) {
53+
if (m_impl != nullptr) {
4754
m_impl->pop();
4855
}
4956
}
5057

5158
void FileWalker::next() {
52-
if (m_impl) {
59+
if (m_impl != nullptr) {
5360
m_impl->next();
5461
}
5562
}
5663

5764
void FileWalker::flat_next() {
58-
if (m_impl) {
65+
if (m_impl != nullptr) {
5966
m_impl->flat_next();
6067
}
6168
}
@@ -64,27 +71,28 @@ Filesystem::Filesystem(
6471
std::shared_ptr<internal::abstract::ReadableFilesystem> impl)
6572
: m_impl{std::move(impl)} {}
6673

67-
Filesystem::operator bool() const { return m_impl.operator bool(); }
74+
Filesystem::operator bool() const { return m_impl != nullptr; }
6875

6976
bool Filesystem::exists(const std::string &path) const {
70-
return m_impl ? m_impl->exists(internal::common::Path(path)) : false;
77+
return m_impl != nullptr && m_impl->exists(internal::Path(path));
7178
}
7279

7380
bool Filesystem::is_file(const std::string &path) const {
74-
return m_impl ? m_impl->is_file(internal::common::Path(path)) : false;
81+
return m_impl != nullptr && m_impl->is_file(internal::Path(path));
7582
}
7683

7784
bool Filesystem::is_directory(const std::string &path) const {
78-
return m_impl ? m_impl->is_directory(internal::common::Path(path)) : false;
85+
return m_impl != nullptr && m_impl->is_directory(internal::Path(path));
7986
}
8087

8188
FileWalker Filesystem::file_walker(const std::string &path) const {
82-
return m_impl ? FileWalker(m_impl->file_walker(internal::common::Path(path)))
83-
: FileWalker();
89+
return m_impl != nullptr
90+
? FileWalker(m_impl->file_walker(internal::Path(path)))
91+
: FileWalker();
8492
}
8593

8694
File Filesystem::open(const std::string &path) const {
87-
return m_impl ? File(m_impl->open(internal::common::Path(path))) : File();
95+
return m_impl != nullptr ? File(m_impl->open(internal::Path(path))) : File();
8896
}
8997

9098
} // namespace odr

src/odr/html.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ void bring_offline(const HtmlResources &resources,
4141
resource.is_external() || !resource.is_accessible()) {
4242
continue;
4343
}
44-
auto path = odr::internal::common::Path(output_path)
45-
.join(odr::internal::common::Path(*location));
44+
auto path =
45+
odr::internal::Path(output_path).join(odr::internal::Path(*location));
4646

4747
std::filesystem::create_directories(path.parent());
4848
std::ofstream ostream = internal::util::file::create(path.string());
@@ -116,8 +116,8 @@ Html HtmlService::bring_offline(const std::string &output_path,
116116
HtmlResources resources;
117117

118118
for (const auto &view : views) {
119-
auto path = odr::internal::common::Path(output_path)
120-
.join(odr::internal::common::Path(view.path()));
119+
auto path =
120+
odr::internal::Path(output_path).join(odr::internal::Path(view.path()));
121121

122122
std::filesystem::create_directories(path.parent());
123123
std::ofstream ostream = internal::util::file::create(path.string());
@@ -166,8 +166,8 @@ HtmlResources HtmlView::write_html(std::ostream &out) const {
166166
Html HtmlView::bring_offline(const std::string &output_path) const {
167167
HtmlResources resources;
168168

169-
auto path = odr::internal::common::Path(output_path)
170-
.join(odr::internal::common::Path(this->path()));
169+
auto path =
170+
odr::internal::Path(output_path).join(odr::internal::Path(this->path()));
171171

172172
{
173173
std::filesystem::create_directories(path.parent());
@@ -249,10 +249,10 @@ HtmlResourceLocator html::standard_resource_locator() {
249249
}
250250

251251
if (resource.is_shipped()) {
252-
auto resource_path = common::Path(config.resource_path)
253-
.join(common::Path(resource.path()));
252+
auto resource_path =
253+
Path(config.resource_path).join(Path(resource.path()));
254254
if (config.relative_resource_paths && config.output_path.has_value()) {
255-
resource_path = resource_path.rebase(common::Path(*config.output_path));
255+
resource_path = resource_path.rebase(Path(*config.output_path));
256256
}
257257
return resource_path.string();
258258
}

src/odr/internal/abstract/archive.hpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22

33
#include <memory>
44

5-
namespace odr::internal::common {
6-
class Path;
7-
} // namespace odr::internal::common
8-
95
namespace odr::internal::abstract {
106
class Filesystem;
117

src/odr/internal/abstract/document.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ enum class FileType;
1010
enum class DocumentType;
1111
} // namespace odr
1212

13-
namespace odr::internal::common {
13+
namespace odr::internal {
1414
class Path;
15-
} // namespace odr::internal::common
15+
} // namespace odr::internal
1616

1717
namespace odr::internal::abstract {
1818
class ReadableFilesystem;
@@ -30,11 +30,11 @@ class Document {
3030
[[nodiscard]] virtual bool is_savable(bool encrypted) const noexcept = 0;
3131

3232
/// \param path the destination path.
33-
virtual void save(const common::Path &path) const = 0;
33+
virtual void save(const Path &path) const = 0;
3434

3535
/// \param path the destination path.
3636
/// \param password the encryption password.
37-
virtual void save(const common::Path &path, const char *password) const = 0;
37+
virtual void save(const Path &path, const char *password) const = 0;
3838

3939
/// \return the type of the document.
4040
[[nodiscard]] virtual FileType file_type() const noexcept = 0;

src/odr/internal/abstract/file.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include <memory>
77
#include <string>
88

9-
namespace odr::internal::common {
9+
namespace odr::internal {
1010
class Path;
1111
}
1212

@@ -22,7 +22,7 @@ class File {
2222
[[nodiscard]] virtual FileLocation location() const noexcept = 0;
2323
[[nodiscard]] virtual std::size_t size() const = 0;
2424

25-
[[nodiscard]] virtual std::optional<common::Path> disk_path() const = 0;
25+
[[nodiscard]] virtual std::optional<Path> disk_path() const = 0;
2626
[[nodiscard]] virtual const char *memory_data() const = 0;
2727

2828
[[nodiscard]] virtual std::unique_ptr<std::istream> stream() const = 0;

src/odr/internal/abstract/filesystem.hpp

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
#include <cstdint>
44
#include <memory>
55

6-
namespace odr::internal::common {
6+
namespace odr::internal {
77
class Path;
8-
} // namespace odr::internal::common
8+
} // namespace odr::internal
99

1010
namespace odr::internal::abstract {
1111
class File;
@@ -20,7 +20,7 @@ class FileWalker {
2020
[[nodiscard]] virtual bool end() const = 0;
2121
[[nodiscard]] virtual std::uint32_t depth() const = 0;
2222
// TODO by reference?
23-
[[nodiscard]] virtual common::Path path() const = 0;
23+
[[nodiscard]] virtual Path path() const = 0;
2424
[[nodiscard]] virtual bool is_file() const = 0;
2525
[[nodiscard]] virtual bool is_directory() const = 0;
2626

@@ -33,32 +33,31 @@ class ReadableFilesystem {
3333
public:
3434
virtual ~ReadableFilesystem() = default;
3535

36-
[[nodiscard]] virtual bool exists(const common::Path &path) const = 0;
37-
[[nodiscard]] virtual bool is_file(const common::Path &path) const = 0;
38-
[[nodiscard]] virtual bool is_directory(const common::Path &path) const = 0;
36+
[[nodiscard]] virtual bool exists(const Path &path) const = 0;
37+
[[nodiscard]] virtual bool is_file(const Path &path) const = 0;
38+
[[nodiscard]] virtual bool is_directory(const Path &path) const = 0;
3939

4040
[[nodiscard]] virtual std::unique_ptr<FileWalker>
41-
file_walker(const common::Path &path) const = 0;
41+
file_walker(const Path &path) const = 0;
4242

4343
[[nodiscard]] virtual std::shared_ptr<abstract::File>
44-
open(const common::Path &path) const = 0;
44+
open(const Path &path) const = 0;
4545
};
4646

4747
class WriteableFilesystem {
4848
public:
4949
virtual ~WriteableFilesystem() = default;
5050

51-
virtual std::unique_ptr<std::ostream>
52-
create_file(const common::Path &path) = 0;
53-
virtual bool create_directory(const common::Path &path) = 0;
51+
virtual std::unique_ptr<std::ostream> create_file(const Path &path) = 0;
52+
virtual bool create_directory(const Path &path) = 0;
5453

55-
virtual bool remove(const common::Path &path) = 0;
56-
virtual bool copy(const common::Path &from, const common::Path &to) = 0;
54+
virtual bool remove(const Path &path) = 0;
55+
virtual bool copy(const Path &from, const Path &to) = 0;
5756
virtual std::shared_ptr<abstract::File> copy(const abstract::File &from,
58-
const common::Path &to) = 0;
57+
const Path &to) = 0;
5958
virtual std::shared_ptr<abstract::File>
60-
copy(std::shared_ptr<abstract::File> from, const common::Path &to) = 0;
61-
virtual bool move(const common::Path &from, const common::Path &to) = 0;
59+
copy(std::shared_ptr<abstract::File> from, const Path &to) = 0;
60+
virtual bool move(const Path &from, const Path &to) = 0;
6261
};
6362

6463
class Filesystem : public ReadableFilesystem, public WriteableFilesystem {};

src/odr/internal/cfb/cfb_archive.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ CfbArchive::CfbArchive(std::shared_ptr<util::Archive> archive)
1919
: m_cfb{std::move(archive)} {}
2020

2121
std::shared_ptr<abstract::Filesystem> CfbArchive::as_filesystem() const {
22-
auto filesystem = std::make_shared<common::VirtualFilesystem>();
22+
auto filesystem = std::make_shared<VirtualFilesystem>();
2323

2424
for (const auto &e : *m_cfb) {
2525
if (e.is_directory()) {

src/odr/internal/cfb/cfb_file.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
namespace odr::internal::cfb {
77

8-
CfbFile::CfbFile(const std::shared_ptr<common::MemoryFile> &file)
8+
CfbFile::CfbFile(const std::shared_ptr<MemoryFile> &file)
99
: m_cfb{std::make_shared<util::Archive>(file)} {}
1010

1111
std::shared_ptr<abstract::File> CfbFile::file() const noexcept {

0 commit comments

Comments
 (0)