add a cmake option to switch between std and boost filesystem

This commit is contained in:
Chunting Gu
2021-05-27 11:15:08 +08:00
parent 39719c4ded
commit df96f969bc
31 changed files with 227 additions and 195 deletions
+8 -11
View File
@@ -1,15 +1,12 @@
#ifndef WEBCC_BODY_H_
#define WEBCC_BODY_H_
#include <fstream>
#include <memory>
#include <string>
#include <utility>
#include "boost/filesystem/fstream.hpp"
#include "boost/filesystem/path.hpp"
#include "webcc/common.h"
#include "webcc/fs.h"
namespace webcc {
@@ -154,14 +151,14 @@ private:
class FileBody : public Body {
public:
// For message to be sent out.
FileBody(const boost::filesystem::path& path, std::size_t chunk_size);
FileBody(const fs::path& path, std::size_t chunk_size);
// For message received.
// No |chunk_size| is needed since you don't iterate the payload of a
// received message.
// If |auto_delete| is true, the file will be deleted on destructor unless it
// is moved to another path (see Move()).
FileBody(const boost::filesystem::path& path, bool auto_delete = false);
FileBody(const fs::path& path, bool auto_delete = false);
~FileBody() override;
@@ -175,7 +172,7 @@ public:
void Dump(std::ostream& os, const std::string& prefix) const override;
const boost::filesystem::path& path() const {
const fs::path& path() const {
return path_;
}
@@ -188,17 +185,17 @@ public:
// If |new_path| resolves to an existing non-directory file, it is removed.
// If |new_path| resolves to an existing directory, it is removed if empty
// on ISO/IEC 9945 but is an error on Windows.
// See boost::filesystem::rename() for more details.
bool Move(const boost::filesystem::path& new_path);
// See fs::rename() for more details.
bool Move(const fs::path& new_path);
private:
boost::filesystem::path path_;
fs::path path_;
std::size_t chunk_size_;
bool auto_delete_;
std::size_t size_; // File size in bytes
boost::filesystem::ifstream ifstream_;
fs::ifstream ifstream_;
std::string chunk_;
};