diff --git a/.github/workflows/mkdocs.yml b/.github/workflows/mkdocs.yml index 41282ec4..dd00c489 100644 --- a/.github/workflows/mkdocs.yml +++ b/.github/workflows/mkdocs.yml @@ -5,10 +5,10 @@ on: - master tags: - '*' - + permissions: contents: write - + jobs: deploy: runs-on: ubuntu-latest @@ -27,12 +27,12 @@ jobs: git config user.email "41898282+github-actions[bot]@users.noreply.github.com" - name: Install dependencies - working-directory: ./mkdocs + working-directory: ./mkdocs run: | pip install --no-cache-dir mkdocs mkdocs-material pymdown-extensions mike - + - name: Deploy docs - working-directory: ./mkdocs + working-directory: ./mkdocs env: REF_TYPE: ${{ github.ref_type }} REF_NAME: ${{ github.ref_name }} @@ -40,10 +40,10 @@ jobs: if [ "$REF_TYPE" = "tag" ]; then mike deploy "$REF_NAME" "latest" --allow-empty --ignore-remote-status --update-aliases mike set-default "latest" - git checkout gh-pages - git push -f origin gh-pages + #git checkout gh-pages + #git push -f origin gh-pages elif [ "$REF_TYPE" = "branch" ] && [ "$REF_NAME" = "master" ]; then mike deploy "master" --ignore-remote-status --allow-empty - git checkout gh-pages - git push -f origin gh-pages + #git checkout gh-pages + #git push -f origin gh-pages fi diff --git a/src/branch.cpp b/src/branch.cpp index a693b8df..fccca156 100644 --- a/src/branch.cpp +++ b/src/branch.cpp @@ -21,9 +21,19 @@ #include "errno.hpp" #include "num.hpp" +Branch::Branch() +{ +} + +Branch::Branch(const Branch &branch_) + : _minfreespace(branch_._minfreespace), + mode(branch_.mode), + path(branch_.path) +{ +} -Branch::Branch(const uint64_t &default_minfreespace_) - : _default_minfreespace(&default_minfreespace_) +Branch::Branch(const u64 &default_minfreespace_) + : _minfreespace(&default_minfreespace_) { } @@ -54,27 +64,27 @@ Branch::to_string(void) const break; } - if(_minfreespace.has_value()) + if(std::holds_alternative(_minfreespace)) { rv += ','; - rv += num::humanize(_minfreespace.value()); + rv += num::humanize(std::get(_minfreespace)); } return rv; } void -Branch::set_minfreespace(const uint64_t minfreespace_) +Branch::set_minfreespace(const u64 minfreespace_) { _minfreespace = minfreespace_; } -uint64_t +u64 Branch::minfreespace(void) const { - if(_minfreespace.has_value()) - return _minfreespace.value(); - return *_default_minfreespace; + if(std::holds_alternative(_minfreespace)) + return *std::get(_minfreespace); + return std::get(_minfreespace); } bool diff --git a/src/branch.hpp b/src/branch.hpp index 588aa79a..f074068f 100644 --- a/src/branch.hpp +++ b/src/branch.hpp @@ -18,31 +18,38 @@ #pragma once -#include "nonstd/optional.hpp" +#include "int_types.h" #include "strvec.hpp" #include "tofrom_string.hpp" #include +#include +#include #include #include +#include class Branch final : public ToFromString { public: - typedef std::vector Vector; + enum class Mode + { + INVALID, + RO, + RW, + NC + }; public: - Branch(const uint64_t &default_minfreespace_); + std::variant _minfreespace; + Mode mode; + std::string path; public: - enum class Mode - { - INVALID, - RO, - RW, - NC - }; + Branch(); + Branch(const Branch&); + Branch(const u64 &default_minfreespace); public: bool ro(void) const; @@ -54,14 +61,6 @@ public: std::string to_string(void) const final; public: - uint64_t minfreespace() const; - void set_minfreespace(const uint64_t); - -public: - Mode mode; - std::string path; - -private: - nonstd::optional _minfreespace; - const uint64_t *_default_minfreespace; + u64 minfreespace() const; + void set_minfreespace(const u64); }; diff --git a/src/branches.cpp b/src/branches.cpp index 09beab4f..0b9e9ec6 100644 --- a/src/branches.cpp +++ b/src/branches.cpp @@ -23,21 +23,18 @@ #include "fs_glob.hpp" #include "fs_is_rofs.hpp" #include "fs_realpathize.hpp" -#include "nonstd/optional.hpp" +#include "int_types.h" #include "num.hpp" #include "str.hpp" #include "syslog.hpp" #include +#include #include -using std::string; -using std::vector; -using nonstd::optional; - -Branches::Impl::Impl(const uint64_t &default_minfreespace_) +Branches::Impl::Impl(const u64 &default_minfreespace_) : _default_minfreespace(default_minfreespace_) { } @@ -45,8 +42,9 @@ Branches::Impl::Impl(const uint64_t &default_minfreespace_) Branches::Impl& Branches::Impl::operator=(Branches::Impl &rval_) { - auto this_base = dynamic_cast(this); - auto rval_base = dynamic_cast(&rval_); + using type = std::vector>; + auto this_base = dynamic_cast(this); + auto rval_base = dynamic_cast(&rval_); *this_base = *rval_base; @@ -56,8 +54,9 @@ Branches::Impl::operator=(Branches::Impl &rval_) Branches::Impl& Branches::Impl::operator=(Branches::Impl &&rval_) { - auto this_base = dynamic_cast(this); - auto rval_base = dynamic_cast(&rval_); + using type = std::vector>; + auto this_base = dynamic_cast(this); + auto rval_base = dynamic_cast(&rval_); *this_base = std::move(*rval_base); @@ -65,7 +64,7 @@ Branches::Impl::operator=(Branches::Impl &&rval_) } const -uint64_t& +u64& Branches::Impl::minfreespace(void) const { return _default_minfreespace; @@ -79,7 +78,7 @@ namespace l std::string *instr_, std::string *values_) { - uint64_t offset; + u64 offset; offset = s_.find_first_not_of("+<>-="); if (offset == std::string::npos) { @@ -94,8 +93,8 @@ namespace l static int - parse_mode(const string &str_, - Branch::Mode *mode_) + parse_mode(const std::string &str_, + Branch::Mode *mode_) { if(str_ == "RW") *mode_ = Branch::Mode::RW; @@ -111,11 +110,11 @@ namespace l static int - parse_minfreespace(const string &str_, - optional *minfreespace_) + parse_minfreespace(const std::string &str_, + std::optional *minfreespace_) { int rv; - uint64_t uint64; + u64 uint64; rv = str::from(str_,&uint64); if(rv < 0) @@ -128,14 +127,14 @@ namespace l static int - parse_branch(const string &str_, - string *glob_, + parse_branch(const std::string &str_, + std::string *glob_, Branch::Mode *mode_, - optional *minfreespace_) + std::optional *minfreespace_) { int rv; - string options; - vector v; + std::string options; + std::vector v; str::rsplit1(str_,'=',&v); switch(v.size()) @@ -173,21 +172,23 @@ namespace l static int - parse(const string &str_, - Branches::Impl *branches_) + parse(const std::string &str_, + Branches::Impl *branches_) { int rv; - string glob; + std::string glob; StrVec paths; - optional minfreespace; - Branch branch(branches_->minfreespace()); + Branch branch; + std::optional minfreespace; + + branch._minfreespace = &branches_->minfreespace(); rv = l::parse_branch(str_,&glob,&branch.mode,&minfreespace); if(rv < 0) return rv; if(minfreespace.has_value()) - branch.set_minfreespace(minfreespace.value()); + branch._minfreespace = minfreespace.value(); fs::glob(glob,&paths); if(paths.empty()) @@ -197,7 +198,7 @@ namespace l for(auto &path : paths) { branch.path = path; - branches_->push_back(branch); + branches_->emplace_back(branch); } return 0; @@ -231,7 +232,7 @@ namespace l Branches::Impl *branches_) { int rv; - vector paths; + std::vector paths; Branches::Impl tmp_branches(branches_->minfreespace()); str::split(str_,':',&paths); @@ -302,10 +303,13 @@ namespace l for(auto i = branches_->begin(); i != branches_->end();) { int match = FNM_NOMATCH; + Branch &branch = *i; for(auto pi = patterns.cbegin(); pi != patterns.cend() && match != 0; ++pi) { - match = ::fnmatch(pi->c_str(),i->path.c_str(),0); + match = ::fnmatch(pi->c_str(), + branch.path.c_str(), + 0); } i = ((match == 0) ? branches_->erase(i) : (i+1)); @@ -346,7 +350,7 @@ Branches::Impl::from_string(const std::string &s_) std::string Branches::Impl::to_string(void) const { - string tmp; + std::string tmp; if(empty()) return tmp; @@ -409,7 +413,7 @@ Branches::from_string(const std::string &str_) return 0; } -string +std::string Branches::to_string(void) const { std::lock_guard lock_guard(_mutex); @@ -452,7 +456,7 @@ std::string SrcMounts::to_string(void) const { std::string rv; - Branches::CPtr branches = _branches; + Branches::Ptr branches = _branches; if(branches->empty()) return rv; diff --git a/src/branches.hpp b/src/branches.hpp index a8ef781a..31487f40 100644 --- a/src/branches.hpp +++ b/src/branches.hpp @@ -28,43 +28,47 @@ #include #include #include - +#include class Branches final : public ToFromString { public: - class Impl final : public ToFromString, public Branch::Vector + class Impl final : public ToFromString, + public std::vector { + private: + const u64 &_default_minfreespace; + public: - typedef std::shared_ptr Ptr; - typedef std::shared_ptr CPtr; + using Ptr = std::shared_ptr; public: - Impl(const uint64_t &default_minfreespace_); + Impl(const u64 &default_minfreespace); public: int from_string(const std::string &str) final; std::string to_string(void) const final; public: - const uint64_t& minfreespace(void) const; + const u64 &minfreespace(void) const; void to_paths(StrVec &strvec) const; fs::PathVector to_paths() const; public: Impl& operator=(Impl &impl_); Impl& operator=(Impl &&impl_); - - private: - const uint64_t &_default_minfreespace; }; + public: - typedef Branches::Impl::Ptr Ptr; - typedef Branches::Impl::CPtr CPtr; + using Ptr = Branches::Impl::Ptr; + +private: + mutable std::mutex _mutex; + Ptr _impl; public: - Branches(const uint64_t &default_minfreespace_) + Branches(const u64 &default_minfreespace_) : _impl(std::make_shared(default_minfreespace_)) {} @@ -73,21 +77,17 @@ public: std::string to_string(void) const final; public: - operator CPtr() const { std::lock_guard lg(_mutex); return _impl; } - CPtr operator->() const { std::lock_guard lg(_mutex); return _impl; } + operator Ptr() const { std::lock_guard lg(_mutex); return _impl; } + Ptr operator->() const { std::lock_guard lg(_mutex); return _impl; } public: void find_and_set_mode_ro(); - -private: - mutable std::mutex _mutex; - Ptr _impl; }; class SrcMounts : public ToFromString { public: - SrcMounts(Branches &b_); + SrcMounts(Branches &b); public: int from_string(const std::string &str) final; diff --git a/src/config.cpp b/src/config.cpp index 83fbda64..70593750 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -246,17 +246,11 @@ Config::has_key(const std::string &key_) const void Config::keys(std::string &s_) const { - Str2TFStrMap::const_iterator i; - Str2TFStrMap::const_iterator ei; - s_.reserve(512); - i = _map.begin(); - ei = _map.end(); - - for(; i != ei; ++i) + for(const auto &[key,val] : _map) { - s_ += i->first; + s_ += key; s_ += '\0'; } @@ -267,14 +261,11 @@ Config::keys(std::string &s_) const void Config::keys_xattr(std::string &s_) const { - Str2TFStrMap::const_iterator i; - Str2TFStrMap::const_iterator ei; - s_.reserve(1024); - for(i = _map.begin(), ei = _map.end(); i != ei; ++i) + for(const auto &[key,val] : _map) { s_ += "user.mergerfs."; - s_ += i->first; + s_ += key; s_ += '\0'; } } @@ -396,13 +387,8 @@ std::ostream& operator<<(std::ostream &os_, const Config &c_) { - Str2TFStrMap::const_iterator i; - Str2TFStrMap::const_iterator ei; - - for(i = c_._map.begin(), ei = c_._map.end(); i != ei; ++i) - { - os_ << i->first << '=' << i->second->to_string() << std::endl; - } + for(const auto &[key,val] : c_._map) + os_ << key << '=' << val->to_string() << std::endl; return os_; } diff --git a/src/fileinfo.hpp b/src/fileinfo.hpp index 872ffe67..d77fd953 100644 --- a/src/fileinfo.hpp +++ b/src/fileinfo.hpp @@ -17,29 +17,43 @@ #pragma once #include "fh.hpp" +#include "branch.hpp" -#include #include #include +#include "int_types.h" + class FileInfo : public FH { public: - FileInfo(const int fd_, - const std::string branchpath_, - const char *fusepath_, - const bool direct_io_) + FileInfo(const int fd_, + const Branch &branch_, + const char *fusepath_, + const bool direct_io_) + : FH(fusepath_), + fd(fd_), + branch(branch_), + direct_io(direct_io_) + { + } + + FileInfo(const int fd_, + const Branch *branch_, + const char *fusepath_, + const bool direct_io_) : FH(fusepath_), fd(fd_), - branchpath(std::move(branchpath_)), + branch(*branch_), direct_io(direct_io_) { } + public: int fd; - std::string branchpath; - uint32_t direct_io:1; + Branch branch; + u32 direct_io:1; std::mutex mutex; }; diff --git a/src/fs_cow.cpp b/src/fs_cow.cpp index b7b16436..01fbf7f2 100644 --- a/src/fs_cow.cpp +++ b/src/fs_cow.cpp @@ -33,16 +33,14 @@ #include #include -using std::string; - namespace l { static int - cleanup_on_error(const int src_fd_, - const int dst_fd_ = -1, - const string &dst_fullpath_ = string()) + cleanup_on_error(const int src_fd_, + const int dst_fd_ = -1, + const std::string &dst_fullpath_ = {}) { int error = errno; diff --git a/src/fs_findonfs.cpp b/src/fs_findonfs.cpp index ec8b2dc1..bfe76fb1 100644 --- a/src/fs_findonfs.cpp +++ b/src/fs_findonfs.cpp @@ -29,10 +29,10 @@ namespace l { static int - findonfs(const Branches::CPtr &branches_, - const std::string &fusepath_, - const int fd_, - std::string *basepath_) + findonfs(const Branches::Ptr &branches_, + const std::string &fusepath_, + const int fd_, + std::string *basepath_) { int rv; dev_t dev; @@ -67,10 +67,10 @@ namespace l namespace fs { int - findonfs(const Branches::CPtr &branches_, - const std::string &fusepath_, - const int fd_, - std::string *basepath_) + findonfs(const Branches::Ptr &branches_, + const std::string &fusepath_, + const int fd_, + std::string *basepath_) { return l::findonfs(branches_,fusepath_,fd_,basepath_); } diff --git a/src/fs_findonfs.hpp b/src/fs_findonfs.hpp index af7441a9..b635ed64 100644 --- a/src/fs_findonfs.hpp +++ b/src/fs_findonfs.hpp @@ -26,8 +26,8 @@ namespace fs { int - findonfs(const Branches::CPtr &branches, - const std::string &fusepath, - const int fd, - std::string *basepath); + findonfs(const Branches::Ptr &branches, + const std::string &fusepath, + const int fd, + std::string *basepath); } diff --git a/src/fs_movefile.cpp b/src/fs_movefile.cpp index 86995491..74d8ec97 100644 --- a/src/fs_movefile.cpp +++ b/src/fs_movefile.cpp @@ -40,9 +40,6 @@ #include #include -using std::string; -using std::vector; - static int @@ -64,8 +61,8 @@ namespace l static int movefile(const Policy::Create &createFunc_, - const Branches::CPtr &branches_, - const string &fusepath_, + const Branches::Ptr &branches_, + const std::string &fusepath_, int origfd_) { int rv; @@ -74,12 +71,12 @@ namespace l int dstfd_flags; int origfd_flags; int64_t srcfd_size; - string fusedir; - string srcfd_branch; - string srcfd_filepath; - string dstfd_filepath; - string dstfd_tmp_filepath; - vector dstfd_branch; + std::string fusedir; + std::string srcfd_branch; + std::string srcfd_filepath; + std::string dstfd_filepath; + std::string dstfd_tmp_filepath; + std::vector dstfd_branch; srcfd = -1; dstfd = -1; @@ -88,7 +85,7 @@ namespace l if(rv == -1) return -errno; - rv = createFunc_(branches_,fusepath_,&dstfd_branch); + rv = createFunc_(branches_,fusepath_.c_str(),dstfd_branch); if(rv == -1) return -errno; @@ -100,12 +97,12 @@ namespace l if(srcfd_size == -1) return -errno; - if(fs::has_space(dstfd_branch[0],srcfd_size) == false) + if(fs::has_space(dstfd_branch[0]->path,srcfd_size) == false) return -ENOSPC; fusedir = fs::path::dirname(fusepath_); - rv = fs::clonepath(srcfd_branch,dstfd_branch[0],fusedir); + rv = fs::clonepath(srcfd_branch,dstfd_branch[0]->path,fusedir); if(rv == -1) return -ENOSPC; @@ -115,7 +112,7 @@ namespace l if(srcfd == -1) return -ENOSPC; - dstfd_filepath = dstfd_branch[0]; + dstfd_filepath = dstfd_branch[0]->path; fs::path::append(dstfd_filepath,fusepath_); std::tie(dstfd,dstfd_tmp_filepath) = fs::mktemp(dstfd_filepath,O_WRONLY); if(dstfd < 0) @@ -163,8 +160,8 @@ namespace fs { int movefile(const Policy::Create &policy_, - const Branches::CPtr &basepaths_, - const string &fusepath_, + const Branches::Ptr &basepaths_, + const std::string &fusepath_, int origfd_) { return l::movefile(policy_,basepaths_,fusepath_,origfd_); @@ -172,8 +169,8 @@ namespace fs int movefile_as_root(const Policy::Create &policy_, - const Branches::CPtr &basepaths_, - const string &fusepath_, + const Branches::Ptr &basepaths_, + const std::string &fusepath_, int origfd_) { const ugid::Set ugid(0,0); diff --git a/src/fs_movefile.hpp b/src/fs_movefile.hpp index a389ae10..a6db4e21 100644 --- a/src/fs_movefile.hpp +++ b/src/fs_movefile.hpp @@ -26,13 +26,13 @@ namespace fs { int movefile(const Policy::Create &policy, - const Branches::CPtr &branches, + const Branches::Ptr &branches, const std::string &fusepath, int origfd); int movefile_as_root(const Policy::Create &policy, - const Branches::CPtr &branches, + const Branches::Ptr &branches, const std::string &fusepath, int origfd); } diff --git a/src/fuse_access.cpp b/src/fuse_access.cpp index 6e196295..1680ef56 100644 --- a/src/fuse_access.cpp +++ b/src/fuse_access.cpp @@ -39,12 +39,13 @@ namespace l int rv; string fullpath; StrVec basepaths; + std::vector branches; - rv = searchFunc_(branches_,fusepath_,&basepaths); + rv = searchFunc_(branches_,fusepath_,branches); if(rv == -1) return -errno; - fullpath = fs::path::make(basepaths[0],fusepath_); + fullpath = fs::path::make(branches[0]->path,fusepath_); rv = fs::eaccess(fullpath,mask_); diff --git a/src/fuse_chmod.cpp b/src/fuse_chmod.cpp index c2e0e709..b6557398 100644 --- a/src/fuse_chmod.cpp +++ b/src/fuse_chmod.cpp @@ -27,39 +27,17 @@ #include -using std::string; - namespace l { - static - int - get_error(const PolicyRV &prv_, - const string &basepath_) - { - for(int i = 0, ei = prv_.success.size(); i < ei; i++) - { - if(prv_.success[i].basepath == basepath_) - return prv_.success[i].rv; - } - - for(int i = 0, ei = prv_.error.size(); i < ei; i++) - { - if(prv_.error[i].basepath == basepath_) - return prv_.error[i].rv; - } - - return 0; - } - static void - chmod_loop_core(const string &basepath_, - const char *fusepath_, - const mode_t mode_, - PolicyRV *prv_) + chmod_loop_core(const std::string &basepath_, + const char *fusepath_, + const mode_t mode_, + PolicyRV *prv_) { - string fullpath; + std::string fullpath; fullpath = fs::path::make(basepath_,fusepath_); @@ -71,14 +49,14 @@ namespace l static void - chmod_loop(const StrVec &basepaths_, - const char *fusepath_, - const mode_t mode_, - PolicyRV *prv_) + chmod_loop(const std::vector &branches_, + const char *fusepath_, + const mode_t mode_, + PolicyRV *prv_) { - for(size_t i = 0, ei = basepaths_.size(); i != ei; i++) + for(auto &branch : branches_) { - l::chmod_loop_core(basepaths_[i],fusepath_,mode_,prv_); + l::chmod_loop_core(branch->path,fusepath_,mode_,prv_); } } @@ -92,24 +70,24 @@ namespace l { int rv; PolicyRV prv; - StrVec basepaths; + std::vector branches; - rv = actionFunc_(branches_,fusepath_,&basepaths); + rv = actionFunc_(branches_,fusepath_,branches); if(rv == -1) return -errno; - l::chmod_loop(basepaths,fusepath_,mode_,&prv); - if(prv.error.empty()) + l::chmod_loop(branches,fusepath_,mode_,&prv); + if(prv.errors.empty()) return 0; - if(prv.success.empty()) - return prv.error[0].rv; + if(prv.successes.empty()) + return prv.errors[0].rv; - basepaths.clear(); - rv = searchFunc_(branches_,fusepath_,&basepaths); + branches.clear(); + rv = searchFunc_(branches_,fusepath_,branches); if(rv == -1) return -errno; - return l::get_error(prv,basepaths[0]); + return prv.get_error(branches[0]->path); } } diff --git a/src/fuse_chown.cpp b/src/fuse_chown.cpp index 106545b4..df8e06a7 100644 --- a/src/fuse_chown.cpp +++ b/src/fuse_chown.cpp @@ -26,41 +26,18 @@ #include #include -using std::string; -using std::vector; - namespace l { - static - int - get_error(const PolicyRV &prv_, - const string &basepath_) - { - for(int i = 0, ei = prv_.success.size(); i < ei; i++) - { - if(prv_.success[i].basepath == basepath_) - return prv_.success[i].rv; - } - - for(int i = 0, ei = prv_.error.size(); i < ei; i++) - { - if(prv_.error[i].basepath == basepath_) - return prv_.error[i].rv; - } - - return 0; - } - static void - chown_loop_core(const string &basepath_, - const char *fusepath_, - const uid_t uid_, - const gid_t gid_, - PolicyRV *prv_) + chown_loop_core(const std::string &basepath_, + const char *fusepath_, + const uid_t uid_, + const gid_t gid_, + PolicyRV *prv_) { - string fullpath; + std::string fullpath; fullpath = fs::path::make(basepath_,fusepath_); @@ -72,15 +49,15 @@ namespace l static void - chown_loop(const vector &basepaths_, - const char *fusepath_, - const uid_t uid_, - const gid_t gid_, - PolicyRV *prv_) + chown_loop(const std::vector &branches_, + const char *fusepath_, + const uid_t uid_, + const gid_t gid_, + PolicyRV *prv_) { - for(size_t i = 0, ei = basepaths_.size(); i != ei; i++) + for(auto &branch : branches_) { - l::chown_loop_core(basepaths_[i],fusepath_,uid_,gid_,prv_); + l::chown_loop_core(branch->path,fusepath_,uid_,gid_,prv_); } } @@ -95,24 +72,24 @@ namespace l { int rv; PolicyRV prv; - vector basepaths; + std::vector branches; - rv = actionFunc_(branches_,fusepath_,&basepaths); + rv = actionFunc_(branches_,fusepath_,branches); if(rv == -1) return -errno; - l::chown_loop(basepaths,fusepath_,uid_,gid_,&prv); - if(prv.error.empty()) + l::chown_loop(branches,fusepath_,uid_,gid_,&prv); + if(prv.errors.empty()) return 0; - if(prv.success.empty()) - return prv.error[0].rv; + if(prv.successes.empty()) + return prv.errors[0].rv; - basepaths.clear(); - rv = searchFunc_(branches_,fusepath_,&basepaths); + branches.clear(); + rv = searchFunc_(branches_,fusepath_,branches); if(rv == -1) return -errno; - return l::get_error(prv,basepaths[0]); + return prv.get_error(branches[0]->path); } } diff --git a/src/fuse_create.cpp b/src/fuse_create.cpp index 2ce27e28..1c7e0840 100644 --- a/src/fuse_create.cpp +++ b/src/fuse_create.cpp @@ -147,23 +147,23 @@ namespace l static int - create_core(const std::string &createpath_, - const char *fusepath_, - fuse_file_info_t *ffi_, - const mode_t mode_, - const mode_t umask_) + create_core(const Branch *branch_, + const char *fusepath_, + fuse_file_info_t *ffi_, + const mode_t mode_, + const mode_t umask_) { int rv; FileInfo *fi; std::string fullpath; - fullpath = fs::path::make(createpath_,fusepath_); + fullpath = fs::path::make(branch_->path,fusepath_); rv = l::create_core(fullpath,mode_,umask_,ffi_->flags); if(rv == -1) return -errno; - fi = new FileInfo(rv,createpath_,fusepath_,ffi_->direct_io); + fi = new FileInfo(rv,branch_,fusepath_,ffi_->direct_io); ffi_->fh = reinterpret_cast(fi); @@ -183,20 +183,22 @@ namespace l int rv; std::string fullpath; std::string fusedirpath; - StrVec createpaths; - StrVec existingpaths; + std::vector createpaths; + std::vector existingpaths; fusedirpath = fs::path::dirname(fusepath_); - rv = searchFunc_(branches_,fusedirpath,&existingpaths); + rv = searchFunc_(branches_,fusedirpath,existingpaths); if(rv == -1) return -errno; - rv = createFunc_(branches_,fusedirpath,&createpaths); + rv = createFunc_(branches_,fusedirpath,createpaths); if(rv == -1) return -errno; - rv = fs::clonepath_as_root(existingpaths[0],createpaths[0],fusedirpath); + rv = fs::clonepath_as_root(existingpaths[0]->path, + createpaths[0]->path, + fusedirpath); if(rv == -1) return -errno; diff --git a/src/fuse_fgetattr.cpp b/src/fuse_fgetattr.cpp index c2249f3f..7c9369a1 100644 --- a/src/fuse_fgetattr.cpp +++ b/src/fuse_fgetattr.cpp @@ -38,7 +38,7 @@ namespace FUSE if(rv == -1) return -errno; - fs::inode::calc(fi->branchpath, + fs::inode::calc(fi->branch.path, fi->fusepath, st_); diff --git a/src/fuse_getattr.cpp b/src/fuse_getattr.cpp index dd2da9eb..acd2c52f 100644 --- a/src/fuse_getattr.cpp +++ b/src/fuse_getattr.cpp @@ -105,13 +105,13 @@ namespace l { int rv; string fullpath; - StrVec basepaths; + std::vector branches; - rv = searchFunc_(branches_,fusepath_,&basepaths); + rv = searchFunc_(branches_,fusepath_,branches); if(rv == -1) return -errno; - fullpath = fs::path::make(basepaths[0],fusepath_); + fullpath = fs::path::make(branches[0]->path,fusepath_); switch(followsymlinks_) { @@ -141,7 +141,7 @@ namespace l if(symlinkify_ && symlinkify::can_be_symlink(*st_,symlinkify_timeout_)) symlinkify::convert(fullpath,st_); - fs::inode::calc(basepaths[0],fusepath_,st_); + fs::inode::calc(branches[0]->path,fusepath_,st_); return 0; } diff --git a/src/fuse_getxattr.cpp b/src/fuse_getxattr.cpp index 2f8145a2..d00e429f 100644 --- a/src/fuse_getxattr.cpp +++ b/src/fuse_getxattr.cpp @@ -35,8 +35,6 @@ static const char SECURITY_CAPABILITY[] = "security.capability"; -using std::string; - namespace l { @@ -49,10 +47,10 @@ namespace l static int - lgetxattr(const string &path_, - const char *attrname_, - void *value_, - const size_t size_) + lgetxattr(const std::string &path_, + const char *attrname_, + void *value_, + const size_t size_) { int rv; @@ -70,8 +68,8 @@ namespace l { int rv; size_t len; - string key; - string val; + std::string key; + std::string val; StrVec attr; if(!str::startswith(attrname_,"user.mergerfs.")) @@ -97,9 +95,9 @@ namespace l static int - getxattr_from_string(char *destbuf_, - const size_t destbufsize_, - const string &src_) + getxattr_from_string(char *destbuf_, + const size_t destbufsize_, + const std::string &src_) { const size_t srcbufsize = src_.size(); @@ -116,12 +114,12 @@ namespace l static int - getxattr_user_mergerfs_allpaths(const Branches::CPtr &branches_, - const char *fusepath_, - char *buf_, - const size_t count_) + getxattr_user_mergerfs_allpaths(const Branches::Ptr &branches_, + const char *fusepath_, + char *buf_, + const size_t count_) { - string concated; + std::string concated; StrVec paths; StrVec branches; @@ -136,13 +134,13 @@ namespace l static int - getxattr_user_mergerfs(const string &basepath_, - const char *fusepath_, - const string &fullpath_, - const Branches &branches_, - const char *attrname_, - char *buf_, - const size_t count_) + getxattr_user_mergerfs(const std::string &basepath_, + const char *fusepath_, + const std::string &fullpath_, + const Branches &branches_, + const char *attrname_, + char *buf_, + const size_t count_) { StrVec attr; @@ -170,17 +168,17 @@ namespace l const size_t count_) { int rv; - string fullpath; - StrVec basepaths; + std::string fullpath; + std::vector branches; - rv = searchFunc_(branches_,fusepath_,&basepaths); + rv = searchFunc_(branches_,fusepath_,branches); if(rv == -1) return -errno; - fullpath = fs::path::make(basepaths[0],fusepath_); + fullpath = fs::path::make(branches[0]->path,fusepath_); if(str::startswith(attrname_,"user.mergerfs.")) - return l::getxattr_user_mergerfs(basepaths[0], + return l::getxattr_user_mergerfs(branches[0]->path, fusepath_, fullpath, branches_, diff --git a/src/fuse_init.cpp b/src/fuse_init.cpp index 7722d3ad..c896f52a 100644 --- a/src/fuse_init.cpp +++ b/src/fuse_init.cpp @@ -157,7 +157,7 @@ namespace l set_readahead_on_mount_and_branches() { Config::Read cfg; - Branches::CPtr branches; + Branches::Ptr branches; if((uint64_t)cfg->readahead == 0) return; diff --git a/src/fuse_ioctl.cpp b/src/fuse_ioctl.cpp index d076e481..bcbf5c1b 100644 --- a/src/fuse_ioctl.cpp +++ b/src/fuse_ioctl.cpp @@ -34,9 +34,6 @@ #include #include -using std::string; -using std::vector; - #ifndef _IOC_TYPE #define _IOC_TYPE(X) (((X) >> 8) & 0xFF) #endif @@ -146,14 +143,14 @@ namespace l { int fd; int rv; - string fullpath; - StrVec basepaths; + std::string fullpath; + std::vector branches; - rv = searchFunc_(branches_,fusepath_,&basepaths); + rv = searchFunc_(branches_,fusepath_,branches); if(rv == -1) return -errno; - fullpath = fs::path::make(basepaths[0],fusepath_); + fullpath = fs::path::make(branches[0]->path,fusepath_); fd = fs::open(fullpath,O_RDONLY|O_NOATIME|O_NONBLOCK); if(fd == -1) @@ -210,13 +207,13 @@ namespace l void *data_) { int rv; - StrVec basepaths; + std::vector branches; - rv = searchFunc_(branches_,fusepath_,&basepaths); + rv = searchFunc_(branches_,fusepath_,branches); if(rv == -1) return -errno; - return l::strcpy(basepaths[0],data_); + return l::strcpy(branches[0]->path,data_); } static @@ -246,19 +243,20 @@ namespace l static int file_fullpath(const Policy::Search &searchFunc_, - const Branches &branches_, - const string &fusepath_, + const Branches &ibranches_, + const std::string &fusepath_, void *data_) { int rv; - string fullpath; StrVec basepaths; + std::string fullpath; + std::vector obranches; - rv = searchFunc_(branches_,fusepath_,&basepaths); + rv = searchFunc_(ibranches_,fusepath_,obranches); if(rv == -1) return -errno; - fullpath = fs::path::make(basepaths[0],fusepath_); + fullpath = fs::path::make(obranches[0]->path,fusepath_); return l::strcpy(fullpath,data_); } @@ -283,10 +281,10 @@ namespace l void *data_) { Config::Read cfg; - string concated; + std::string concated; StrVec paths; StrVec branches; - string &fusepath = reinterpret_cast(ffi_->fh)->fusepath; + std::string &fusepath = reinterpret_cast(ffi_->fh)->fusepath; cfg->branches->to_paths(branches); diff --git a/src/fuse_link.cpp b/src/fuse_link.cpp index 7250bd49..6d5453fc 100644 --- a/src/fuse_link.cpp +++ b/src/fuse_link.cpp @@ -30,8 +30,6 @@ #include #include -using std::string; -using std::vector; namespace error { @@ -57,27 +55,27 @@ namespace l { static int - link_create_path_loop(const StrVec &oldbasepaths_, - const string &newbasepath_, - const char *oldfusepath_, - const char *newfusepath_, - const string &newfusedirpath_) + link_create_path_loop(const std::vector &oldbranches_, + const Branch *newbranch_, + const char *oldfusepath_, + const char *newfusepath_, + const std::string &newfusedirpath_) { int rv; int error; - string oldfullpath; - string newfullpath; + std::string oldfullpath; + std::string newfullpath; error = -1; - for(auto &oldbasepath : oldbasepaths_) + for(auto &oldbranch : oldbranches_) { - oldfullpath = fs::path::make(oldbasepath,oldfusepath_); - newfullpath = fs::path::make(oldbasepath,newfusepath_); + oldfullpath = fs::path::make(oldbranch->path,oldfusepath_); + newfullpath = fs::path::make(oldbranch->path,newfusepath_); rv = fs::link(oldfullpath,newfullpath); if((rv == -1) && (errno == ENOENT)) { - rv = fs::clonepath_as_root(newbasepath_,oldbasepath,newfusedirpath_); + rv = fs::clonepath_as_root(newbranch_->path,oldbranch->path,newfusedirpath_); if(rv == 0) rv = fs::link(oldfullpath,newfullpath); } @@ -92,41 +90,41 @@ namespace l int link_create_path(const Policy::Search &searchFunc_, const Policy::Action &actionFunc_, - const Branches &branches_, + const Branches &ibranches_, const char *oldfusepath_, const char *newfusepath_) { int rv; - string newfusedirpath; - StrVec oldbasepaths; - StrVec newbasepaths; + std::string newfusedirpath; + std::vector oldbranches; + std::vector newbranches; - rv = actionFunc_(branches_,oldfusepath_,&oldbasepaths); + rv = actionFunc_(ibranches_,oldfusepath_,oldbranches); if(rv == -1) return -errno; newfusedirpath = fs::path::dirname(newfusepath_); - rv = searchFunc_(branches_,newfusedirpath,&newbasepaths); + rv = searchFunc_(ibranches_,newfusedirpath,newbranches); if(rv == -1) return -errno; - return l::link_create_path_loop(oldbasepaths,newbasepaths[0], + return l::link_create_path_loop(oldbranches,newbranches[0], oldfusepath_,newfusepath_, newfusedirpath); } static int - link_preserve_path_core(const string &oldbasepath_, - const char *oldfusepath_, - const char *newfusepath_, - struct stat *st_, - const int error_) + link_preserve_path_core(const std::string &oldbasepath_, + const char *oldfusepath_, + const char *newfusepath_, + struct stat *st_, + const int error_) { int rv; - string oldfullpath; - string newfullpath; + std::string oldfullpath; + std::string newfullpath; oldfullpath = fs::path::make(oldbasepath_,oldfusepath_); newfullpath = fs::path::make(oldbasepath_,newfusepath_); @@ -142,17 +140,17 @@ namespace l static int - link_preserve_path_loop(const StrVec &oldbasepaths_, - const char *oldfusepath_, - const char *newfusepath_, - struct stat *st_) + link_preserve_path_loop(const std::vector &oldbranches_, + const char *oldfusepath_, + const char *newfusepath_, + struct stat *st_) { int error; error = -1; - for(auto &oldbasepath : oldbasepaths_) + for(auto &oldbranch : oldbranches_) { - error = l::link_preserve_path_core(oldbasepath, + error = l::link_preserve_path_core(oldbranch->path, oldfusepath_, newfusepath_, st_, @@ -171,13 +169,13 @@ namespace l struct stat *st_) { int rv; - StrVec oldbasepaths; + std::vector oldbranches; - rv = actionFunc_(branches_,oldfusepath_,&oldbasepaths); + rv = actionFunc_(branches_,oldfusepath_,oldbranches); if(rv == -1) return -errno; - return l::link_preserve_path_loop(oldbasepaths, + return l::link_preserve_path_loop(oldbranches, oldfusepath_, newfusepath_, st_); @@ -248,21 +246,21 @@ namespace l static int link_exdev_abs_base_symlink(const Policy::Search &openPolicy_, - const Branches::CPtr &branches_, + const Branches::Ptr &ibranches_, const char *oldpath_, const char *newpath_, struct stat *st_, fuse_timeouts_t *timeouts_) { int rv; - StrVec basepaths; std::string target; + std::vector obranches; - rv = openPolicy_(branches_,oldpath_,&basepaths); + rv = openPolicy_(ibranches_,oldpath_,obranches); if(rv == -1) return -errno; - target = fs::path::make(basepaths[0],oldpath_); + target = fs::path::make(obranches[0]->path,oldpath_); rv = FUSE::symlink(target.c_str(),newpath_); if(rv == 0) diff --git a/src/fuse_listxattr.cpp b/src/fuse_listxattr.cpp index 1f69b15c..2cc65c3f 100644 --- a/src/fuse_listxattr.cpp +++ b/src/fuse_listxattr.cpp @@ -56,20 +56,20 @@ namespace l static int listxattr(const Policy::Search &searchFunc_, - const Branches &branches_, + const Branches &ibranches_, const char *fusepath_, char *list_, const size_t size_) { int rv; - string fullpath; - StrVec basepaths; + std::string fullpath; + std::vector obranches; - rv = searchFunc_(branches_,fusepath_,&basepaths); + rv = searchFunc_(ibranches_,fusepath_,obranches); if(rv == -1) return -errno; - fullpath = fs::path::make(basepaths[0],fusepath_); + fullpath = fs::path::make(obranches[0]->path,fusepath_); rv = fs::llistxattr(fullpath,list_,size_); diff --git a/src/fuse_mkdir.cpp b/src/fuse_mkdir.cpp index 88a9fa9d..29229f06 100644 --- a/src/fuse_mkdir.cpp +++ b/src/fuse_mkdir.cpp @@ -27,8 +27,6 @@ #include -using std::string; - namespace error { @@ -54,9 +52,9 @@ namespace l { static int - mkdir_core(const string &fullpath_, - mode_t mode_, - const mode_t umask_) + mkdir_core(const std::string &fullpath_, + mode_t mode_, + const mode_t umask_) { if(!fs::acl::dir_has_defaults(fullpath_)) mode_ &= ~umask_; @@ -66,14 +64,14 @@ namespace l static int - mkdir_loop_core(const string &createpath_, - const char *fusepath_, - const mode_t mode_, - const mode_t umask_, - const int error_) + mkdir_loop_core(const std::string &createpath_, + const char *fusepath_, + const mode_t mode_, + const mode_t umask_, + const int error_) { int rv; - string fullpath; + std::string fullpath; fullpath = fs::path::make(createpath_,fusepath_); @@ -84,24 +82,26 @@ namespace l static int - mkdir_loop(const string &existingpath_, - const StrVec &createpaths_, - const char *fusepath_, - const string &fusedirpath_, - const mode_t mode_, - const mode_t umask_) + mkdir_loop(const Branch *existingbranch_, + const std::vector &createbranches_, + const char *fusepath_, + const std::string &fusedirpath_, + const mode_t mode_, + const mode_t umask_) { int rv; int error; error = -1; - for(size_t i = 0, ei = createpaths_.size(); i != ei; i++) + for(auto &createbranch : createbranches_) { - rv = fs::clonepath_as_root(existingpath_,createpaths_[i],fusedirpath_); + rv = fs::clonepath_as_root(existingbranch_->path, + createbranch->path, + fusedirpath_); if(rv == -1) error = error::calc(rv,error,errno); else - error = l::mkdir_loop_core(createpaths_[i], + error = l::mkdir_loop_core(createbranch->path, fusepath_, mode_, umask_, @@ -121,22 +121,22 @@ namespace l const mode_t umask_) { int rv; - string fusedirpath; - StrVec createpaths; - StrVec existingpaths; + std::string fusedirpath; + std::vector createbranches; + std::vector existingbranches; fusedirpath = fs::path::dirname(fusepath_); - rv = getattrPolicy_(branches_,fusedirpath.c_str(),&existingpaths); + rv = getattrPolicy_(branches_,fusedirpath,existingbranches); if(rv == -1) return -errno; - rv = mkdirPolicy_(branches_,fusedirpath.c_str(),&createpaths); + rv = mkdirPolicy_(branches_,fusedirpath,createbranches); if(rv == -1) return -errno; - return l::mkdir_loop(existingpaths[0], - createpaths, + return l::mkdir_loop(existingbranches[0], + createbranches, fusepath_, fusedirpath, mode_, diff --git a/src/fuse_mknod.cpp b/src/fuse_mknod.cpp index 34a4ae1f..71caa95c 100644 --- a/src/fuse_mknod.cpp +++ b/src/fuse_mknod.cpp @@ -27,9 +27,6 @@ #include #include -using std::string; -using std::vector; - namespace error { @@ -56,10 +53,10 @@ namespace l static inline int - mknod_core(const string &fullpath_, - mode_t mode_, - const mode_t umask_, - const dev_t dev_) + mknod_core(const std::string &fullpath_, + mode_t mode_, + const mode_t umask_, + const dev_t dev_) { if(!fs::acl::dir_has_defaults(fullpath_)) mode_ &= ~umask_; @@ -69,17 +66,17 @@ namespace l static int - mknod_loop_core(const string &createpath_, - const char *fusepath_, - const mode_t mode_, - const mode_t umask_, - const dev_t dev_, - const int error_) + mknod_loop_core(const std::string &createbranch_, + const char *fusepath_, + const mode_t mode_, + const mode_t umask_, + const dev_t dev_, + const int error_) { int rv; - string fullpath; + std::string fullpath; - fullpath = fs::path::make(createpath_,fusepath_); + fullpath = fs::path::make(createbranch_,fusepath_); rv = l::mknod_core(fullpath,mode_,umask_,dev_); @@ -88,25 +85,27 @@ namespace l static int - mknod_loop(const string &existingpath_, - const vector &createpaths_, - const char *fusepath_, - const string &fusedirpath_, - const mode_t mode_, - const mode_t umask_, - const dev_t dev_) + mknod_loop(const std::string &existingbranch_, + const std::vector &createbranches_, + const char *fusepath_, + const std::string &fusedirpath_, + const mode_t mode_, + const mode_t umask_, + const dev_t dev_) { int rv; int error; error = -1; - for(size_t i = 0, ei = createpaths_.size(); i != ei; i++) + for(auto &createbranch : createbranches_) { - rv = fs::clonepath_as_root(existingpath_,createpaths_[i],fusedirpath_); + rv = fs::clonepath_as_root(existingbranch_, + createbranch->path, + fusedirpath_); if(rv == -1) error = error::calc(rv,error,errno); else - error = l::mknod_loop_core(createpaths_[i], + error = l::mknod_loop_core(createbranch->path, fusepath_, mode_,umask_,dev_,error); } @@ -125,23 +124,27 @@ namespace l const dev_t dev_) { int rv; - string fusedirpath; - vector createpaths; - vector existingpaths; + std::string fusedirpath; + std::vector createbranches; + std::vector existingbranches; fusedirpath = fs::path::dirname(fusepath_); - rv = searchFunc_(branches_,fusedirpath,&existingpaths); + rv = searchFunc_(branches_,fusedirpath,existingbranches); if(rv == -1) return -errno; - rv = createFunc_(branches_,fusedirpath,&createpaths); + rv = createFunc_(branches_,fusedirpath,createbranches); if(rv == -1) return -errno; - return l::mknod_loop(existingpaths[0],createpaths, - fusepath_,fusedirpath, - mode_,umask_,dev_); + return l::mknod_loop(existingbranches[0]->path, + createbranches, + fusepath_, + fusedirpath, + mode_, + umask_, + dev_); } } diff --git a/src/fuse_open.cpp b/src/fuse_open.cpp index db30c2c6..00d88b0d 100644 --- a/src/fuse_open.cpp +++ b/src/fuse_open.cpp @@ -190,7 +190,7 @@ namespace l static int - open_core(const std::string &basepath_, + open_core(const Branch *branch_, const char *fusepath_, fuse_file_info_t *ffi_, const bool link_cow_, @@ -200,7 +200,7 @@ namespace l FileInfo *fi; std::string fullpath; - fullpath = fs::path::make(basepath_,fusepath_); + fullpath = fs::path::make(branch_->path,fusepath_); if(link_cow_ && fs::cow::is_eligible(fullpath.c_str(),ffi_->flags)) fs::cow::break_link(fullpath.c_str()); @@ -211,7 +211,7 @@ namespace l if(fd == -1) return -errno; - fi = new FileInfo(fd,basepath_,fusepath_,ffi_->direct_io); + fi = new FileInfo(fd,branch_,fusepath_,ffi_->direct_io); ffi_->fh = reinterpret_cast(fi); @@ -221,20 +221,24 @@ namespace l static int open(const Policy::Search &searchFunc_, - const Branches &branches_, + const Branches &ibranches_, const char *fusepath_, fuse_file_info_t *ffi_, const bool link_cow_, const NFSOpenHack nfsopenhack_) { int rv; - StrVec basepaths; + std::vector obranches; - rv = searchFunc_(branches_,fusepath_,&basepaths); + rv = searchFunc_(ibranches_,fusepath_,obranches); if(rv == -1) return -errno; - return l::open_core(basepaths[0],fusepath_,ffi_,link_cow_,nfsopenhack_); + return l::open_core(obranches[0], + fusepath_, + ffi_, + link_cow_, + nfsopenhack_); } } diff --git a/src/fuse_readdir_cor.cpp b/src/fuse_readdir_cor.cpp index 5912b002..206013a4 100644 --- a/src/fuse_readdir_cor.cpp +++ b/src/fuse_readdir_cor.cpp @@ -141,12 +141,12 @@ namespace l static inline int - concurrent_readdir(ThreadPool &tp_, - const Branches::CPtr &branches_, - const std::string &rel_dirpath_, - fuse_dirents_t *buf_, - const uid_t uid_, - const gid_t gid_) + concurrent_readdir(ThreadPool &tp_, + const Branches::Ptr &branches_, + const std::string &rel_dirpath_, + fuse_dirents_t *buf_, + const uid_t uid_, + const gid_t gid_) { HashSet names; std::mutex mutex; diff --git a/src/fuse_readdir_cosr.cpp b/src/fuse_readdir_cosr.cpp index 297c16be..7e03e1d0 100644 --- a/src/fuse_readdir_cosr.cpp +++ b/src/fuse_readdir_cosr.cpp @@ -97,11 +97,11 @@ namespace l static inline std::vector> - opendir(ThreadPool &tp_, - const Branches::CPtr &branches_, - const std::string &rel_dirpath_, - uid_t const uid_, - gid_t const gid_) + opendir(ThreadPool &tp_, + const Branches::Ptr &branches_, + const std::string &rel_dirpath_, + uid_t const uid_, + gid_t const gid_) { std::vector> futures; @@ -187,12 +187,12 @@ namespace l static inline int - readdir(ThreadPool &tp_, - const Branches::CPtr &branches_, - const std::string &rel_dirpath_, - fuse_dirents_t *buf_, - uid_t const uid_, - gid_t const gid_) + readdir(ThreadPool &tp_, + const Branches::Ptr &branches_, + const std::string &rel_dirpath_, + fuse_dirents_t *buf_, + uid_t const uid_, + gid_t const gid_) { int rv; std::vector> futures; diff --git a/src/fuse_readdir_seq.cpp b/src/fuse_readdir_seq.cpp index c957ddfe..8aab7bfb 100644 --- a/src/fuse_readdir_seq.cpp +++ b/src/fuse_readdir_seq.cpp @@ -83,9 +83,9 @@ namespace l static int - readdir(const Branches::CPtr &branches_, - const std::string &rel_dirpath_, - fuse_dirents_t *buf_) + readdir(const Branches::Ptr &branches_, + const std::string &rel_dirpath_, + fuse_dirents_t *buf_) { Error error; HashSet names; diff --git a/src/fuse_readlink.cpp b/src/fuse_readlink.cpp index e24354f4..e905a7a4 100644 --- a/src/fuse_readlink.cpp +++ b/src/fuse_readlink.cpp @@ -93,7 +93,7 @@ namespace l static int readlink(const Policy::Search &searchFunc_, - const Branches &branches_, + const Branches &ibranches_, const char *fusepath_, char *buf_, const size_t size_, @@ -102,13 +102,18 @@ namespace l { int rv; StrVec basepaths; + std::vector obranches; - rv = searchFunc_(branches_,fusepath_,&basepaths); + rv = searchFunc_(ibranches_,fusepath_,obranches); if(rv == -1) return -errno; - return l::readlink_core(basepaths[0],fusepath_,buf_,size_, - symlinkify_,symlinkify_timeout_); + return l::readlink_core(obranches[0]->path, + fusepath_, + buf_, + size_, + symlinkify_, + symlinkify_timeout_); } } diff --git a/src/fuse_removexattr.cpp b/src/fuse_removexattr.cpp index d22367ac..cec300dc 100644 --- a/src/fuse_removexattr.cpp +++ b/src/fuse_removexattr.cpp @@ -32,26 +32,6 @@ using std::vector; namespace l { - static - int - get_error(const PolicyRV &prv_, - const string &basepath_) - { - for(int i = 0, ei = prv_.success.size(); i < ei; i++) - { - if(prv_.success[i].basepath == basepath_) - return prv_.success[i].rv; - } - - for(int i = 0, ei = prv_.error.size(); i < ei; i++) - { - if(prv_.error[i].basepath == basepath_) - return prv_.error[i].rv; - } - - return 0; - } - static void removexattr_loop_core(const string &basepath_, @@ -71,14 +51,14 @@ namespace l static void - removexattr_loop(const vector &basepaths_, - const char *fusepath_, - const char *attrname_, - PolicyRV *prv_) + removexattr_loop(const std::vector &branches_, + const char *fusepath_, + const char *attrname_, + PolicyRV *prv_) { - for(size_t i = 0, ei = basepaths_.size(); i != ei; i++) + for(auto &branch : branches_) { - l::removexattr_loop_core(basepaths_[i],fusepath_,attrname_,prv_); + l::removexattr_loop_core(branch->path,fusepath_,attrname_,prv_); } } @@ -86,30 +66,30 @@ namespace l int removexattr(const Policy::Action &actionFunc_, const Policy::Search &searchFunc_, - const Branches &branches_, + const Branches &ibranches_, const char *fusepath_, const char *attrname_) { int rv; PolicyRV prv; - vector basepaths; + std::vector obranches; - rv = actionFunc_(branches_,fusepath_,&basepaths); + rv = actionFunc_(ibranches_,fusepath_,obranches); if(rv == -1) return -errno; - l::removexattr_loop(basepaths,fusepath_,attrname_,&prv); - if(prv.error.empty()) + l::removexattr_loop(obranches,fusepath_,attrname_,&prv); + if(prv.errors.empty()) return 0; - if(prv.success.empty()) - return prv.error[0].rv; + if(prv.successes.empty()) + return prv.errors[0].rv; - basepaths.clear(); - rv = searchFunc_(branches_,fusepath_,&basepaths); + obranches.clear(); + rv = searchFunc_(ibranches_,fusepath_,obranches); if(rv == -1) return -errno; - return l::get_error(prv,basepaths[0]); + return prv.get_error(obranches[0]->path); } } diff --git a/src/fuse_rename.cpp b/src/fuse_rename.cpp index e5d07e61..cf3f04bb 100644 --- a/src/fuse_rename.cpp +++ b/src/fuse_rename.cpp @@ -35,7 +35,6 @@ #include -using std::string; namespace gfs = ghc::filesystem; namespace error @@ -62,12 +61,12 @@ namespace l { static bool - contains(const StrVec &haystack_, - const char *needle_) + contains(const std::vector &haystack_, + const char *needle_) { for(auto &hay : haystack_) { - if(hay == needle_) + if(hay->path == needle_) return true; } @@ -76,8 +75,8 @@ namespace l static bool - contains(const StrVec &haystack_, - const string &needle_) + contains(const std::vector &haystack_, + const std::string &needle_) { return l::contains(haystack_,needle_.c_str()); } @@ -90,41 +89,27 @@ namespace l fs::remove(path); } - static - void - remove(const Branches::CPtr &branches_, - const std::string &relpath_) - { - std::string fullpath; - - for(auto &branch : *branches_) - { - fullpath = fs::path::make(branch.path,relpath_); - fs::remove(fullpath); - } - } - static int rename_create_path(const Policy::Search &searchPolicy_, const Policy::Action &actionPolicy_, - const Branches::CPtr &branches_, + const Branches::Ptr &branches_, const gfs::path &oldfusepath_, const gfs::path &newfusepath_) { int rv; int error; StrVec toremove; - StrVec newbasepath; - StrVec oldbasepaths; + std::vector newbranches; + std::vector oldbranches; gfs::path oldfullpath; gfs::path newfullpath; - rv = actionPolicy_(branches_,oldfusepath_,&oldbasepaths); + rv = actionPolicy_(branches_,oldfusepath_,oldbranches); if(rv == -1) return -errno; - rv = searchPolicy_(branches_,newfusepath_.parent_path(),&newbasepath); + rv = searchPolicy_(branches_,newfusepath_.parent_path(),newbranches); if(rv == -1) return -errno; @@ -134,7 +119,7 @@ namespace l newfullpath = branch.path; newfullpath += newfusepath_; - if(!l::contains(oldbasepaths,branch.path)) + if(!l::contains(oldbranches,branch.path)) { toremove.push_back(newfullpath); continue; @@ -146,7 +131,9 @@ namespace l rv = fs::rename(oldfullpath,newfullpath); if(rv == -1) { - rv = fs::clonepath_as_root(newbasepath[0],branch.path,newfusepath_.parent_path()); + rv = fs::clonepath_as_root(newbranches[0]->path, + branch.path, + newfusepath_.parent_path()); if(rv == 0) rv = fs::rename(oldfullpath,newfullpath); } @@ -165,18 +152,18 @@ namespace l static int rename_preserve_path(const Policy::Action &actionPolicy_, - const Branches::CPtr &branches_, + const Branches::Ptr &branches_, const gfs::path &oldfusepath_, const gfs::path &newfusepath_) { int rv; bool success; StrVec toremove; - StrVec oldbasepaths; + std::vector oldbranches; gfs::path oldfullpath; gfs::path newfullpath; - rv = actionPolicy_(branches_,oldfusepath_,&oldbasepaths); + rv = actionPolicy_(branches_,oldfusepath_,oldbranches); if(rv == -1) return -errno; @@ -186,7 +173,7 @@ namespace l newfullpath = branch.path; newfullpath += newfusepath_; - if(!l::contains(oldbasepaths,branch.path)) + if(!l::contains(oldbranches,branch.path)) { toremove.push_back(newfullpath); continue; @@ -216,19 +203,19 @@ namespace l static void - rename_exdev_rename_back(const StrVec &basepaths_, - const gfs::path &oldfusepath_) + rename_exdev_rename_back(const std::vector &branches_, + const gfs::path &oldfusepath_) { gfs::path oldpath; gfs::path newpath; - for(auto &basepath : basepaths_) + for(auto &branch : branches_) { - oldpath = basepath; + oldpath = branch->path; oldpath /= ".mergerfs_rename_exdev"; oldpath += oldfusepath_; - newpath = basepath; + newpath = branch->path; newpath += oldfusepath_; fs::rename(oldpath,newpath); @@ -238,23 +225,23 @@ namespace l static int rename_exdev_rename_target(const Policy::Action &actionPolicy_, - const Branches::CPtr &branches_, + const Branches::Ptr &ibranches_, const gfs::path &oldfusepath_, - StrVec *basepaths_) + std::vector &obranches_) { int rv; gfs::path clonesrc; gfs::path clonetgt; - rv = actionPolicy_(branches_,oldfusepath_,basepaths_); + rv = actionPolicy_(ibranches_,oldfusepath_,obranches_); if(rv == -1) return -errno; ugid::SetRootGuard ugidGuard; - for(auto &basepath : *basepaths_) + for(auto &branch : obranches_) { - clonesrc = basepath; - clonetgt = basepath; + clonesrc = branch->path; + clonetgt = branch->path; clonetgt /= ".mergerfs_rename_exdev"; rv = fs::clonepath(clonesrc,clonetgt,oldfusepath_.parent_path()); @@ -278,7 +265,7 @@ namespace l return 0; error: - l::rename_exdev_rename_back(*basepaths_,oldfusepath_); + l::rename_exdev_rename_back(obranches_,oldfusepath_); return -EXDEV; } @@ -286,16 +273,16 @@ namespace l static int rename_exdev_rel_symlink(const Policy::Action &actionPolicy_, - const Branches::CPtr &branches_, + const Branches::Ptr &branches_, const gfs::path &oldfusepath_, const gfs::path &newfusepath_) { int rv; - StrVec basepaths; gfs::path target; gfs::path linkpath; + std::vector branches; - rv = l::rename_exdev_rename_target(actionPolicy_,branches_,oldfusepath_,&basepaths); + rv = l::rename_exdev_rename_target(actionPolicy_,branches_,oldfusepath_,branches); if(rv < 0) return rv; @@ -306,7 +293,7 @@ namespace l rv = FUSE::symlink(target.c_str(),linkpath.c_str()); if(rv < 0) - l::rename_exdev_rename_back(basepaths,oldfusepath_); + l::rename_exdev_rename_back(branches,oldfusepath_); return rv; } @@ -314,17 +301,17 @@ namespace l static int rename_exdev_abs_symlink(const Policy::Action &actionPolicy_, - const Branches::CPtr &branches_, + const Branches::Ptr &branches_, const gfs::path &mount_, const gfs::path &oldfusepath_, const gfs::path &newfusepath_) { int rv; - StrVec basepaths; gfs::path target; gfs::path linkpath; + std::vector branches; - rv = l::rename_exdev_rename_target(actionPolicy_,branches_,oldfusepath_,&basepaths); + rv = l::rename_exdev_rename_target(actionPolicy_,branches_,oldfusepath_,branches); if(rv < 0) return rv; @@ -335,7 +322,7 @@ namespace l rv = FUSE::symlink(target.c_str(),linkpath.c_str()); if(rv < 0) - l::rename_exdev_rename_back(basepaths,oldfusepath_); + l::rename_exdev_rename_back(branches,oldfusepath_); return rv; } diff --git a/src/fuse_rmdir.cpp b/src/fuse_rmdir.cpp index cbfc83c6..1b93ea4f 100644 --- a/src/fuse_rmdir.cpp +++ b/src/fuse_rmdir.cpp @@ -81,16 +81,16 @@ namespace l static int - rmdir_loop(const StrVec &basepaths_, - const char *fusepath_, - const FollowSymlinks followsymlinks_) + rmdir_loop(const std::vector &branches_, + const char *fusepath_, + const FollowSymlinks followsymlinks_) { int error; error = 0; - for(size_t i = 0, ei = basepaths_.size(); i != ei; i++) + for(auto &branch : branches_) { - error = l::rmdir_core(basepaths_[i],fusepath_,followsymlinks_,error); + error = l::rmdir_core(branch->path,fusepath_,followsymlinks_,error); } return -error; @@ -104,13 +104,13 @@ namespace l const char *fusepath_) { int rv; - vector basepaths; + std::vector branches; - rv = actionFunc_(branches_,fusepath_,&basepaths); + rv = actionFunc_(branches_,fusepath_,branches); if(rv == -1) return -errno; - return l::rmdir_loop(basepaths,fusepath_,followsymlinks_); + return l::rmdir_loop(branches,fusepath_,followsymlinks_); } } diff --git a/src/fuse_setxattr.cpp b/src/fuse_setxattr.cpp index c46bc7c1..5d1d4826 100644 --- a/src/fuse_setxattr.cpp +++ b/src/fuse_setxattr.cpp @@ -40,26 +40,6 @@ using std::vector; namespace l { - static - int - get_error(const PolicyRV &prv_, - const string &basepath_) - { - for(int i = 0, ei = prv_.success.size(); i < ei; i++) - { - if(prv_.success[i].basepath == basepath_) - return prv_.success[i].rv; - } - - for(int i = 0, ei = prv_.error.size(); i < ei; i++) - { - if(prv_.error[i].basepath == basepath_) - return prv_.error[i].rv; - } - - return 0; - } - static bool is_attrname_security_capability(const char *attrname_) @@ -119,19 +99,22 @@ namespace l static void - setxattr_loop(const StrVec &basepaths_, - const char *fusepath_, - const char *attrname_, - const char *attrval_, - const size_t attrvalsize_, - const int flags_, - PolicyRV *prv_) + setxattr_loop(const std::vector &branches_, + const char *fusepath_, + const char *attrname_, + const char *attrval_, + const size_t attrvalsize_, + const int flags_, + PolicyRV *prv_) { - for(size_t i = 0, ei = basepaths_.size(); i != ei; i++) + for(auto &branch : branches_) { - l::setxattr_loop_core(basepaths_[i],fusepath_, - attrname_,attrval_,attrvalsize_, - flags_,prv_); + l::setxattr_loop_core(branch->path, + fusepath_, + attrname_, + attrval_,attrvalsize_, + flags_, + prv_); } } @@ -148,24 +131,24 @@ namespace l { int rv; PolicyRV prv; - StrVec basepaths; + std::vector branches; - rv = setxattrPolicy_(branches_,fusepath_,&basepaths); + rv = setxattrPolicy_(branches_,fusepath_,branches); if(rv == -1) return -errno; - l::setxattr_loop(basepaths,fusepath_,attrname_,attrval_,attrvalsize_,flags_,&prv); - if(prv.error.empty()) + l::setxattr_loop(branches,fusepath_,attrname_,attrval_,attrvalsize_,flags_,&prv); + if(prv.errors.empty()) return 0; - if(prv.success.empty()) - return prv.error[0].rv; + if(prv.successes.empty()) + return prv.errors[0].rv; - basepaths.clear(); - rv = getxattrPolicy_(branches_,fusepath_,&basepaths); + branches.clear(); + rv = getxattrPolicy_(branches_,fusepath_,branches); if(rv == -1) return -errno; - return l::get_error(prv,basepaths[0]); + return prv.get_error(branches[0]->path); } int diff --git a/src/fuse_statfs.cpp b/src/fuse_statfs.cpp index 68ffb2cf..b6642bbc 100644 --- a/src/fuse_statfs.cpp +++ b/src/fuse_statfs.cpp @@ -79,11 +79,11 @@ namespace l static int - statfs(const Branches::CPtr &branches_, - const char *fusepath_, - const StatFS mode_, - const StatFSIgnore ignore_, - struct statvfs *fsstat_) + statfs(const Branches::Ptr &branches_, + const char *fusepath_, + const StatFS mode_, + const StatFSIgnore ignore_, + struct statvfs *fsstat_) { int rv; string fullpath; diff --git a/src/fuse_statx_supported.icpp b/src/fuse_statx_supported.icpp index 8e92ed19..2aa9db59 100644 --- a/src/fuse_statx_supported.icpp +++ b/src/fuse_statx_supported.icpp @@ -88,13 +88,13 @@ _statx(const Policy::Search &searchFunc_, { int rv; std::string fullpath; - StrVec basepaths; + std::vector branches; - rv = searchFunc_(branches_,fusepath_,&basepaths); + rv = searchFunc_(branches_,fusepath_,branches); if(rv == -1) return -errno; - fullpath = fs::path::make(basepaths[0],fusepath_); + fullpath = fs::path::make(branches[0]->path,fusepath_); switch(followsymlinks_) { @@ -124,7 +124,7 @@ _statx(const Policy::Search &searchFunc_, if(symlinkify_ && symlinkify::can_be_symlink(*st_,symlinkify_timeout_)) symlinkify::convert(fullpath,st_); - fs::inode::calc(basepaths[0],fusepath_,st_); + fs::inode::calc(branches[0]->path,fusepath_,st_); return 0; } diff --git a/src/fuse_symlink.cpp b/src/fuse_symlink.cpp index a8ed41e2..2b416a15 100644 --- a/src/fuse_symlink.cpp +++ b/src/fuse_symlink.cpp @@ -58,23 +58,23 @@ namespace l { static int - symlink_loop_core(const string &newbasepath_, - const char *target_, - const char *linkpath_, - struct stat *st_, - const int error_) + symlink_loop_core(const std::string &newbranch_, + const char *target_, + const char *linkpath_, + struct stat *st_, + const int error_) { int rv; string fullnewpath; - fullnewpath = fs::path::make(newbasepath_,linkpath_); + fullnewpath = fs::path::make(newbranch_,linkpath_); rv = fs::symlink(target_,fullnewpath); if((rv != -1) && (st_ != NULL) && (st_->st_ino == 0)) { fs::lstat(fullnewpath,st_); if(st_->st_ino != 0) - fs::inode::calc(newbasepath_,linkpath_,st_); + fs::inode::calc(newbranch_,linkpath_,st_); } return error::calc(rv,error_,errno); @@ -82,24 +82,26 @@ namespace l static int - symlink_loop(const string &existingpath_, - const StrVec &newbasepaths_, - const char *target_, - const char *linkpath_, - const string &newdirpath_, - struct stat *st_) + symlink_loop(const std::string &existingbranch_, + const std::vector &newbranches_, + const char *target_, + const char *linkpath_, + const std::string &newdirpath_, + struct stat *st_) { int rv; int error; error = -1; - for(size_t i = 0, ei = newbasepaths_.size(); i != ei; i++) + for(auto &newbranch :newbranches_) { - rv = fs::clonepath_as_root(existingpath_,newbasepaths_[i],newdirpath_); + rv = fs::clonepath_as_root(existingbranch_, + newbranch->path, + newdirpath_); if(rv == -1) error = error::calc(rv,error,errno); else - error = l::symlink_loop_core(newbasepaths_[i], + error = l::symlink_loop_core(newbranch->path, target_, linkpath_, st_, @@ -120,21 +122,25 @@ namespace l { int rv; string newdirpath; - StrVec newbasepaths; - StrVec existingpaths; + std::vector newbranches; + std::vector existingbranches; newdirpath = fs::path::dirname(linkpath_); - rv = searchFunc_(branches_,newdirpath,&existingpaths); + rv = searchFunc_(branches_,newdirpath,existingbranches); if(rv == -1) return -errno; - rv = createFunc_(branches_,newdirpath,&newbasepaths); + rv = createFunc_(branches_,newdirpath,newbranches); if(rv == -1) return -errno; - return l::symlink_loop(existingpaths[0],newbasepaths, - target_,linkpath_,newdirpath,st_); + return l::symlink_loop(existingbranches[0]->path, + newbranches, + target_, + linkpath_, + newdirpath, + st_); } } diff --git a/src/fuse_truncate.cpp b/src/fuse_truncate.cpp index 669715a8..9cc782c0 100644 --- a/src/fuse_truncate.cpp +++ b/src/fuse_truncate.cpp @@ -33,26 +33,6 @@ using std::string; namespace l { - static - int - get_error(const PolicyRV &prv_, - const string &basepath_) - { - for(int i = 0, ei = prv_.success.size(); i < ei; i++) - { - if(prv_.success[i].basepath == basepath_) - return prv_.success[i].rv; - } - - for(int i = 0, ei = prv_.error.size(); i < ei; i++) - { - if(prv_.error[i].basepath == basepath_) - return prv_.error[i].rv; - } - - return 0; - } - static void truncate_loop_core(const string &basepath_, @@ -72,14 +52,14 @@ namespace l static void - truncate_loop(const StrVec &basepaths_, - const char *fusepath_, - const off_t size_, - PolicyRV *prv_) + truncate_loop(const std::vector &branches_, + const char *fusepath_, + const off_t size_, + PolicyRV *prv_) { - for(size_t i = 0, ei = basepaths_.size(); i != ei; i++) + for(auto &branch : branches_) { - l::truncate_loop_core(basepaths_[i],fusepath_,size_,prv_); + l::truncate_loop_core(branch->path,fusepath_,size_,prv_); } } @@ -93,24 +73,24 @@ namespace l { int rv; PolicyRV prv; - StrVec basepaths; + std::vector branches; - rv = actionFunc_(branches_,fusepath_,&basepaths); + rv = actionFunc_(branches_,fusepath_,branches); if(rv == -1) return -errno; - l::truncate_loop(basepaths,fusepath_,size_,&prv); - if(prv.error.empty()) + l::truncate_loop(branches,fusepath_,size_,&prv); + if(prv.errors.empty()) return 0; - if(prv.success.empty()) - return prv.error[0].rv; + if(prv.successes.empty()) + return prv.errors[0].rv; - basepaths.clear(); - rv = searchFunc_(branches_,fusepath_,&basepaths); + branches.clear(); + rv = searchFunc_(branches_,fusepath_,branches); if(rv == -1) return -errno; - return l::get_error(prv,basepaths[0]); + return prv.get_error(branches[0]->path); } } diff --git a/src/fuse_unlink.cpp b/src/fuse_unlink.cpp index 5f551935..ff4c4a03 100644 --- a/src/fuse_unlink.cpp +++ b/src/fuse_unlink.cpp @@ -27,9 +27,6 @@ #include -using std::string; -using std::vector; - namespace error { @@ -52,14 +49,14 @@ namespace l { static int - unlink_loop_core(const string &basepath_, - const char *fusepath_, - const int error_) + unlink_loop_core(const std::string &branch_, + const char *fusepath_, + const int error_) { int rv; - string fullpath; + std::string fullpath; - fullpath = fs::path::make(basepath_,fusepath_); + fullpath = fs::path::make(branch_,fusepath_); rv = fs::unlink(fullpath); @@ -68,15 +65,15 @@ namespace l static int - unlink_loop(const vector &basepaths_, - const char *fusepath_) + unlink_loop(const std::vector &branches_, + const char *fusepath_) { int error; error = 0; - for(size_t i = 0, ei = basepaths_.size(); i != ei; i++) + for(auto &branch : branches_) { - error = l::unlink_loop_core(basepaths_[i],fusepath_,error); + error = l::unlink_loop_core(branch->path,fusepath_,error); } return -error; @@ -89,13 +86,13 @@ namespace l const char *fusepath_) { int rv; - vector basepaths; + std::vector branches; - rv = unlinkPolicy_(branches_,fusepath_,&basepaths); + rv = unlinkPolicy_(branches_,fusepath_,branches); if(rv == -1) return -errno; - return l::unlink_loop(basepaths,fusepath_); + return l::unlink_loop(branches,fusepath_); } } diff --git a/src/fuse_utimens.cpp b/src/fuse_utimens.cpp index 83c4b584..11ec58d3 100644 --- a/src/fuse_utimens.cpp +++ b/src/fuse_utimens.cpp @@ -32,26 +32,6 @@ using std::string; namespace l { - static - int - get_error(const PolicyRV &prv_, - const string &basepath_) - { - for(int i = 0, ei = prv_.success.size(); i < ei; i++) - { - if(prv_.success[i].basepath == basepath_) - return prv_.success[i].rv; - } - - for(int i = 0, ei = prv_.error.size(); i < ei; i++) - { - if(prv_.error[i].basepath == basepath_) - return prv_.error[i].rv; - } - - return 0; - } - static void utimens_loop_core(const string &basepath_, @@ -71,14 +51,14 @@ namespace l static void - utimens_loop(const StrVec &basepaths_, - const char *fusepath_, - const timespec ts_[2], - PolicyRV *prv_) + utimens_loop(const std::vector &branches_, + const char *fusepath_, + const timespec ts_[2], + PolicyRV *prv_) { - for(size_t i = 0, ei = basepaths_.size(); i != ei; i++) + for(auto &branch : branches_) { - l::utimens_loop_core(basepaths_[i],fusepath_,ts_,prv_); + l::utimens_loop_core(branch->path,fusepath_,ts_,prv_); } } @@ -92,24 +72,24 @@ namespace l { int rv; PolicyRV prv; - StrVec basepaths; + std::vector branches; - rv = utimensPolicy_(branches_,fusepath_,&basepaths); + rv = utimensPolicy_(branches_,fusepath_,branches); if(rv == -1) return -errno; - l::utimens_loop(basepaths,fusepath_,ts_,&prv); - if(prv.error.empty()) + l::utimens_loop(branches,fusepath_,ts_,&prv); + if(prv.errors.empty()) return 0; - if(prv.success.empty()) - return prv.error[0].rv; + if(prv.successes.empty()) + return prv.errors[0].rv; - basepaths.clear(); - rv = getattrPolicy_(branches_,fusepath_,&basepaths); + branches.clear(); + rv = getattrPolicy_(branches_,fusepath_,branches); if(rv == -1) return -errno; - return l::get_error(prv,basepaths[0]); + return prv.get_error(branches[0]->path); } } diff --git a/src/int_types.h b/src/int_types.h new file mode 100644 index 00000000..177d80d1 --- /dev/null +++ b/src/int_types.h @@ -0,0 +1,13 @@ +#pragma once + +#include + +typedef uint64_t u32; +typedef int64_t s32; +typedef uint64_t u64; +typedef int64_t s64; + +typedef const uint64_t cu32; +typedef const int64_t cs32; +typedef const uint64_t cu64; +typedef const int64_t cs64; diff --git a/src/nonstd/optional.hpp b/src/nonstd/optional.hpp deleted file mode 100644 index 85febc3d..00000000 --- a/src/nonstd/optional.hpp +++ /dev/null @@ -1,1847 +0,0 @@ -// -// Copyright (c) 2014-2021 Martin Moene -// -// https://github.com/martinmoene/optional-lite -// -// Distributed under the Boost Software License, Version 1.0. -// (See accompanying file LICENSE.txt or copy at http://www.boost.org/LICENSE_1_0.txt) - -#pragma once - -#ifndef NONSTD_OPTIONAL_LITE_HPP -#define NONSTD_OPTIONAL_LITE_HPP - -#define optional_lite_MAJOR 3 -#define optional_lite_MINOR 6 -#define optional_lite_PATCH 0 - -#define optional_lite_VERSION optional_STRINGIFY(optional_lite_MAJOR) "." optional_STRINGIFY(optional_lite_MINOR) "." optional_STRINGIFY(optional_lite_PATCH) - -#define optional_STRINGIFY( x ) optional_STRINGIFY_( x ) -#define optional_STRINGIFY_( x ) #x - -// optional-lite configuration: - -#define optional_OPTIONAL_DEFAULT 0 -#define optional_OPTIONAL_NONSTD 1 -#define optional_OPTIONAL_STD 2 - -// tweak header support: - -#ifdef __has_include -# if __has_include() -# include -# endif -#define optional_HAVE_TWEAK_HEADER 1 -#else -#define optional_HAVE_TWEAK_HEADER 0 -//# pragma message("optional.hpp: Note: Tweak header not supported.") -#endif - -// optional selection and configuration: - -#if !defined( optional_CONFIG_SELECT_OPTIONAL ) -# define optional_CONFIG_SELECT_OPTIONAL ( optional_HAVE_STD_OPTIONAL ? optional_OPTIONAL_STD : optional_OPTIONAL_NONSTD ) -#endif - -// Control presence of extensions: - -#ifndef optional_CONFIG_NO_EXTENSIONS -#define optional_CONFIG_NO_EXTENSIONS 0 -#endif - -// Control presence of exception handling (try and auto discover): - -#ifndef optional_CONFIG_NO_EXCEPTIONS -# if defined(_MSC_VER) -# include // for _HAS_EXCEPTIONS -# endif -# if defined(__cpp_exceptions) || defined(__EXCEPTIONS) || (defined(_HAS_EXCEPTIONS) && (_HAS_EXCEPTIONS)) -# define optional_CONFIG_NO_EXCEPTIONS 0 -# else -# define optional_CONFIG_NO_EXCEPTIONS 1 -# endif -#endif - -// C++ language version detection (C++23 is speculative): -// Note: VC14.0/1900 (VS2015) lacks too much from C++14. - -#ifndef optional_CPLUSPLUS -# if defined(_MSVC_LANG ) && !defined(__clang__) -# define optional_CPLUSPLUS (_MSC_VER == 1900 ? 201103L : _MSVC_LANG ) -# else -# define optional_CPLUSPLUS __cplusplus -# endif -#endif - -#define optional_CPP98_OR_GREATER ( optional_CPLUSPLUS >= 199711L ) -#define optional_CPP11_OR_GREATER ( optional_CPLUSPLUS >= 201103L ) -#define optional_CPP11_OR_GREATER_ ( optional_CPLUSPLUS >= 201103L ) -#define optional_CPP14_OR_GREATER ( optional_CPLUSPLUS >= 201402L ) -#define optional_CPP17_OR_GREATER ( optional_CPLUSPLUS >= 201703L ) -#define optional_CPP20_OR_GREATER ( optional_CPLUSPLUS >= 202002L ) -#define optional_CPP23_OR_GREATER ( optional_CPLUSPLUS >= 202300L ) - -// C++ language version (represent 98 as 3): - -#define optional_CPLUSPLUS_V ( optional_CPLUSPLUS / 100 - (optional_CPLUSPLUS > 200000 ? 2000 : 1994) ) - -// Use C++17 std::optional if available and requested: - -#if optional_CPP17_OR_GREATER && defined(__has_include ) -# if __has_include( ) -# define optional_HAVE_STD_OPTIONAL 1 -# else -# define optional_HAVE_STD_OPTIONAL 0 -# endif -#else -# define optional_HAVE_STD_OPTIONAL 0 -#endif - -#define optional_USES_STD_OPTIONAL ( (optional_CONFIG_SELECT_OPTIONAL == optional_OPTIONAL_STD) || ((optional_CONFIG_SELECT_OPTIONAL == optional_OPTIONAL_DEFAULT) && optional_HAVE_STD_OPTIONAL) ) - -// -// in_place: code duplicated in any-lite, expected-lite, optional-lite, value-ptr-lite, variant-lite: -// - -#ifndef nonstd_lite_HAVE_IN_PLACE_TYPES -#define nonstd_lite_HAVE_IN_PLACE_TYPES 1 - -// C++17 std::in_place in : - -#if optional_CPP17_OR_GREATER - -#include - -namespace nonstd { - -using std::in_place; -using std::in_place_type; -using std::in_place_index; -using std::in_place_t; -using std::in_place_type_t; -using std::in_place_index_t; - -#define nonstd_lite_in_place_t( T) std::in_place_t -#define nonstd_lite_in_place_type_t( T) std::in_place_type_t -#define nonstd_lite_in_place_index_t(K) std::in_place_index_t - -#define nonstd_lite_in_place( T) std::in_place_t{} -#define nonstd_lite_in_place_type( T) std::in_place_type_t{} -#define nonstd_lite_in_place_index(K) std::in_place_index_t{} - -} // namespace nonstd - -#else // optional_CPP17_OR_GREATER - -#include - -namespace nonstd { -namespace detail { - -template< class T > -struct in_place_type_tag {}; - -template< std::size_t K > -struct in_place_index_tag {}; - -} // namespace detail - -struct in_place_t {}; - -template< class T > -inline in_place_t in_place( detail::in_place_type_tag /*unused*/ = detail::in_place_type_tag() ) -{ - return in_place_t(); -} - -template< std::size_t K > -inline in_place_t in_place( detail::in_place_index_tag /*unused*/ = detail::in_place_index_tag() ) -{ - return in_place_t(); -} - -template< class T > -inline in_place_t in_place_type( detail::in_place_type_tag /*unused*/ = detail::in_place_type_tag() ) -{ - return in_place_t(); -} - -template< std::size_t K > -inline in_place_t in_place_index( detail::in_place_index_tag /*unused*/ = detail::in_place_index_tag() ) -{ - return in_place_t(); -} - -// mimic templated typedef: - -#define nonstd_lite_in_place_t( T) nonstd::in_place_t(&)( nonstd::detail::in_place_type_tag ) -#define nonstd_lite_in_place_type_t( T) nonstd::in_place_t(&)( nonstd::detail::in_place_type_tag ) -#define nonstd_lite_in_place_index_t(K) nonstd::in_place_t(&)( nonstd::detail::in_place_index_tag ) - -#define nonstd_lite_in_place( T) nonstd::in_place_type -#define nonstd_lite_in_place_type( T) nonstd::in_place_type -#define nonstd_lite_in_place_index(K) nonstd::in_place_index - -} // namespace nonstd - -#endif // optional_CPP17_OR_GREATER -#endif // nonstd_lite_HAVE_IN_PLACE_TYPES - -// -// Using std::optional: -// - -#if optional_USES_STD_OPTIONAL - -#include - -namespace nonstd { - - using std::optional; - using std::bad_optional_access; - using std::hash; - - using std::nullopt; - using std::nullopt_t; - - using std::operator==; - using std::operator!=; - using std::operator<; - using std::operator<=; - using std::operator>; - using std::operator>=; - using std::make_optional; - using std::swap; -} - -#else // optional_USES_STD_OPTIONAL - -#include -#include - -// optional-lite alignment configuration: - -#ifndef optional_CONFIG_MAX_ALIGN_HACK -# define optional_CONFIG_MAX_ALIGN_HACK 0 -#endif - -#ifndef optional_CONFIG_ALIGN_AS -// no default, used in #if defined() -#endif - -#ifndef optional_CONFIG_ALIGN_AS_FALLBACK -# define optional_CONFIG_ALIGN_AS_FALLBACK double -#endif - -// Compiler warning suppression: - -#if defined(__clang__) -# pragma clang diagnostic push -# pragma clang diagnostic ignored "-Wundef" -#elif defined(__GNUC__) -# pragma GCC diagnostic push -# pragma GCC diagnostic ignored "-Wundef" -#elif defined(_MSC_VER ) -# pragma warning( push ) -#endif - -// half-open range [lo..hi): -#define optional_BETWEEN( v, lo, hi ) ( (lo) <= (v) && (v) < (hi) ) - -// Compiler versions: -// -// MSVC++ 6.0 _MSC_VER == 1200 optional_COMPILER_MSVC_VERSION == 60 (Visual Studio 6.0) -// MSVC++ 7.0 _MSC_VER == 1300 optional_COMPILER_MSVC_VERSION == 70 (Visual Studio .NET 2002) -// MSVC++ 7.1 _MSC_VER == 1310 optional_COMPILER_MSVC_VERSION == 71 (Visual Studio .NET 2003) -// MSVC++ 8.0 _MSC_VER == 1400 optional_COMPILER_MSVC_VERSION == 80 (Visual Studio 2005) -// MSVC++ 9.0 _MSC_VER == 1500 optional_COMPILER_MSVC_VERSION == 90 (Visual Studio 2008) -// MSVC++ 10.0 _MSC_VER == 1600 optional_COMPILER_MSVC_VERSION == 100 (Visual Studio 2010) -// MSVC++ 11.0 _MSC_VER == 1700 optional_COMPILER_MSVC_VERSION == 110 (Visual Studio 2012) -// MSVC++ 12.0 _MSC_VER == 1800 optional_COMPILER_MSVC_VERSION == 120 (Visual Studio 2013) -// MSVC++ 14.0 _MSC_VER == 1900 optional_COMPILER_MSVC_VERSION == 140 (Visual Studio 2015) -// MSVC++ 14.1 _MSC_VER >= 1910 optional_COMPILER_MSVC_VERSION == 141 (Visual Studio 2017) -// MSVC++ 14.2 _MSC_VER >= 1920 optional_COMPILER_MSVC_VERSION == 142 (Visual Studio 2019) - -#if defined(_MSC_VER ) && !defined(__clang__) -# define optional_COMPILER_MSVC_VER (_MSC_VER ) -# define optional_COMPILER_MSVC_VERSION (_MSC_VER / 10 - 10 * ( 5 + (_MSC_VER < 1900 ) ) ) -#else -# define optional_COMPILER_MSVC_VER 0 -# define optional_COMPILER_MSVC_VERSION 0 -#endif - -#define optional_COMPILER_VERSION( major, minor, patch ) ( 10 * (10 * (major) + (minor) ) + (patch) ) - -#if defined(__GNUC__) && !defined(__clang__) -# define optional_COMPILER_GNUC_VERSION optional_COMPILER_VERSION(__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__) -#else -# define optional_COMPILER_GNUC_VERSION 0 -#endif - -#if defined(__clang__) -# define optional_COMPILER_CLANG_VERSION optional_COMPILER_VERSION(__clang_major__, __clang_minor__, __clang_patchlevel__) -#else -# define optional_COMPILER_CLANG_VERSION 0 -#endif - -#if optional_BETWEEN(optional_COMPILER_MSVC_VERSION, 70, 140 ) -# pragma warning( disable: 4345 ) // initialization behavior changed -#endif - -#if optional_BETWEEN(optional_COMPILER_MSVC_VERSION, 70, 150 ) -# pragma warning( disable: 4814 ) // in C++14 'constexpr' will not imply 'const' -#endif - -// Presence of language and library features: - -#define optional_HAVE(FEATURE) ( optional_HAVE_##FEATURE ) - -#ifdef _HAS_CPP0X -# define optional_HAS_CPP0X _HAS_CPP0X -#else -# define optional_HAS_CPP0X 0 -#endif - -// Unless defined otherwise below, consider VC14 as C++11 for optional-lite: - -#if optional_COMPILER_MSVC_VER >= 1900 -# undef optional_CPP11_OR_GREATER -# define optional_CPP11_OR_GREATER 1 -#endif - -#define optional_CPP11_90 (optional_CPP11_OR_GREATER_ || optional_COMPILER_MSVC_VER >= 1500) -#define optional_CPP11_100 (optional_CPP11_OR_GREATER_ || optional_COMPILER_MSVC_VER >= 1600) -#define optional_CPP11_110 (optional_CPP11_OR_GREATER_ || optional_COMPILER_MSVC_VER >= 1700) -#define optional_CPP11_120 (optional_CPP11_OR_GREATER_ || optional_COMPILER_MSVC_VER >= 1800) -#define optional_CPP11_140 (optional_CPP11_OR_GREATER_ || optional_COMPILER_MSVC_VER >= 1900) -#define optional_CPP11_141 (optional_CPP11_OR_GREATER_ || optional_COMPILER_MSVC_VER >= 1910) - -#define optional_CPP14_000 (optional_CPP14_OR_GREATER) -#define optional_CPP17_000 (optional_CPP17_OR_GREATER) - -// clang >= 2.9, gcc >= 4.9, msvc >= vc14.0/1900 (vs15): -#define optional_CPP11_140_C290_G490 ((optional_CPP11_OR_GREATER_ && (optional_COMPILER_CLANG_VERSION >= 290 || optional_COMPILER_GNUC_VERSION >= 490)) || (optional_COMPILER_MSVC_VER >= 1900)) - -// clang >= 3.5, msvc >= vc11 (vs12): -#define optional_CPP11_110_C350 ( optional_CPP11_110 && !optional_BETWEEN( optional_COMPILER_CLANG_VERSION, 1, 350 ) ) - -// clang >= 3.5, gcc >= 5.0, msvc >= vc11 (vs12): -#define optional_CPP11_110_C350_G500 \ - ( optional_CPP11_110 && \ - !( optional_BETWEEN( optional_COMPILER_CLANG_VERSION, 1, 350 ) \ - || optional_BETWEEN( optional_COMPILER_GNUC_VERSION , 1, 500 ) ) ) - -// Presence of C++11 language features: - -#define optional_HAVE_CONSTEXPR_11 optional_CPP11_140 -#define optional_HAVE_IS_DEFAULT optional_CPP11_140 -#define optional_HAVE_NOEXCEPT optional_CPP11_140 -#define optional_HAVE_NULLPTR optional_CPP11_100 -#define optional_HAVE_REF_QUALIFIER optional_CPP11_140_C290_G490 -#define optional_HAVE_STATIC_ASSERT optional_CPP11_110 -#define optional_HAVE_INITIALIZER_LIST optional_CPP11_140 - -// Presence of C++14 language features: - -#define optional_HAVE_CONSTEXPR_14 optional_CPP14_000 - -// Presence of C++17 language features: - -#define optional_HAVE_NODISCARD optional_CPP17_000 - -// Presence of C++ library features: - -#define optional_HAVE_CONDITIONAL optional_CPP11_120 -#define optional_HAVE_REMOVE_CV optional_CPP11_120 -#define optional_HAVE_TYPE_TRAITS optional_CPP11_90 - -#define optional_HAVE_TR1_TYPE_TRAITS (!! optional_COMPILER_GNUC_VERSION ) -#define optional_HAVE_TR1_ADD_POINTER (!! optional_COMPILER_GNUC_VERSION ) - -#define optional_HAVE_IS_ASSIGNABLE optional_CPP11_110_C350 -#define optional_HAVE_IS_MOVE_CONSTRUCTIBLE optional_CPP11_110_C350 -#define optional_HAVE_IS_NOTHROW_MOVE_ASSIGNABLE optional_CPP11_110_C350 -#define optional_HAVE_IS_NOTHROW_MOVE_CONSTRUCTIBLE optional_CPP11_110_C350 -#define optional_HAVE_IS_TRIVIALLY_COPY_CONSTRUCTIBLE optional_CPP11_110_C350_G500 -#define optional_HAVE_IS_TRIVIALLY_MOVE_CONSTRUCTIBLE optional_CPP11_110_C350_G500 - -// C++ feature usage: - -#if optional_HAVE( CONSTEXPR_11 ) -# define optional_constexpr constexpr -#else -# define optional_constexpr /*constexpr*/ -#endif - -#if optional_HAVE( IS_DEFAULT ) -# define optional_is_default = default; -#else -# define optional_is_default {} -#endif - -#if optional_HAVE( CONSTEXPR_14 ) -# define optional_constexpr14 constexpr -#else -# define optional_constexpr14 /*constexpr*/ -#endif - -#if optional_HAVE( NODISCARD ) -# define optional_nodiscard [[nodiscard]] -#else -# define optional_nodiscard /*[[nodiscard]]*/ -#endif - -#if optional_HAVE( NOEXCEPT ) -# define optional_noexcept noexcept -#else -# define optional_noexcept /*noexcept*/ -#endif - -#if optional_HAVE( NULLPTR ) -# define optional_nullptr nullptr -#else -# define optional_nullptr NULL -#endif - -#if optional_HAVE( REF_QUALIFIER ) -// NOLINTNEXTLINE( bugprone-macro-parentheses ) -# define optional_ref_qual & -# define optional_refref_qual && -#else -# define optional_ref_qual /*&*/ -# define optional_refref_qual /*&&*/ -#endif - -#if optional_HAVE( STATIC_ASSERT ) -# define optional_static_assert(expr, text) static_assert(expr, text); -#else -# define optional_static_assert(expr, text) /*static_assert(expr, text);*/ -#endif - -// additional includes: - -#if optional_CONFIG_NO_EXCEPTIONS -// already included: -#else -# include -#endif - -#if optional_CPP11_OR_GREATER -# include -#endif - -#if optional_HAVE( INITIALIZER_LIST ) -# include -#endif - -#if optional_HAVE( TYPE_TRAITS ) -# include -#elif optional_HAVE( TR1_TYPE_TRAITS ) -# include -#endif - -// Method enabling - -#if optional_CPP11_OR_GREATER - -#define optional_REQUIRES_0(...) \ - template< bool B = (__VA_ARGS__), typename std::enable_if::type = 0 > - -#define optional_REQUIRES_T(...) \ - , typename std::enable_if< (__VA_ARGS__), int >::type = 0 - -#define optional_REQUIRES_R(R, ...) \ - typename std::enable_if< (__VA_ARGS__), R>::type - -#define optional_REQUIRES_A(...) \ - , typename std::enable_if< (__VA_ARGS__), void*>::type = nullptr - -#endif - -// -// optional: -// - -namespace nonstd { namespace optional_lite { - -namespace std11 { - -template< class T, T v > struct integral_constant { enum { value = v }; }; -template< bool B > struct bool_constant : integral_constant{}; - -typedef bool_constant< true > true_type; -typedef bool_constant< false > false_type; - -#if optional_CPP11_OR_GREATER - using std::move; -#else - template< typename T > T & move( T & t ) { return t; } -#endif - -#if optional_HAVE( CONDITIONAL ) - using std::conditional; -#else - template< bool B, typename T, typename F > struct conditional { typedef T type; }; - template< typename T, typename F > struct conditional { typedef F type; }; -#endif // optional_HAVE_CONDITIONAL - -#if optional_HAVE( IS_ASSIGNABLE ) - using std::is_assignable; -#else - template< class T, class U > struct is_assignable : std11::true_type{}; -#endif - -#if optional_HAVE( IS_MOVE_CONSTRUCTIBLE ) - using std::is_move_constructible; -#else - template< class T > struct is_move_constructible : std11::true_type{}; -#endif - -#if optional_HAVE( IS_NOTHROW_MOVE_ASSIGNABLE ) - using std::is_nothrow_move_assignable; -#else - template< class T > struct is_nothrow_move_assignable : std11::true_type{}; -#endif - -#if optional_HAVE( IS_NOTHROW_MOVE_CONSTRUCTIBLE ) - using std::is_nothrow_move_constructible; -#else - template< class T > struct is_nothrow_move_constructible : std11::true_type{}; -#endif - -#if optional_HAVE( IS_TRIVIALLY_COPY_CONSTRUCTIBLE ) - using std::is_trivially_copy_constructible; -#else - template< class T > struct is_trivially_copy_constructible : std11::true_type{}; -#endif - -#if optional_HAVE( IS_TRIVIALLY_MOVE_CONSTRUCTIBLE ) - using std::is_trivially_move_constructible; -#else - template< class T > struct is_trivially_move_constructible : std11::true_type{}; -#endif - -} // namespace std11 - -#if optional_CPP11_OR_GREATER - -/// type traits C++17: - -namespace std17 { - -#if optional_CPP17_OR_GREATER - -using std::is_swappable; -using std::is_nothrow_swappable; - -#elif optional_CPP11_OR_GREATER - -namespace detail { - -using std::swap; - -struct is_swappable -{ - template< typename T, typename = decltype( swap( std::declval(), std::declval() ) ) > - static std11::true_type test( int /*unused*/ ); - - template< typename > - static std11::false_type test(...); -}; - -struct is_nothrow_swappable -{ - // wrap noexcept(expr) in separate function as work-around for VC140 (VS2015): - - template< typename T > - static constexpr bool satisfies() - { - return noexcept( swap( std::declval(), std::declval() ) ); - } - - template< typename T > - static auto test( int /*unused*/ ) -> std11::integral_constant()>{} - - template< typename > - static auto test(...) -> std11::false_type; -}; - -} // namespace detail - -// is [nothow] swappable: - -template< typename T > -struct is_swappable : decltype( detail::is_swappable::test(0) ){}; - -template< typename T > -struct is_nothrow_swappable : decltype( detail::is_nothrow_swappable::test(0) ){}; - -#endif // optional_CPP17_OR_GREATER - -} // namespace std17 - -/// type traits C++20: - -namespace std20 { - -template< typename T > -struct remove_cvref -{ - typedef typename std::remove_cv< typename std::remove_reference::type >::type type; -}; - -} // namespace std20 - -#endif // optional_CPP11_OR_GREATER - -/// class optional - -template< typename T > -class optional; - -namespace detail { - -// C++11 emulation: - -struct nulltype{}; - -template< typename Head, typename Tail > -struct typelist -{ - typedef Head head; - typedef Tail tail; -}; - -#if optional_CONFIG_MAX_ALIGN_HACK - -// Max align, use most restricted type for alignment: - -#define optional_UNIQUE( name ) optional_UNIQUE2( name, __LINE__ ) -#define optional_UNIQUE2( name, line ) optional_UNIQUE3( name, line ) -#define optional_UNIQUE3( name, line ) name ## line - -#define optional_ALIGN_TYPE( type ) \ - type optional_UNIQUE( _t ); struct_t< type > optional_UNIQUE( _st ) - -template< typename T > -struct struct_t { T _; }; - -union max_align_t -{ - optional_ALIGN_TYPE( char ); - optional_ALIGN_TYPE( short int ); - optional_ALIGN_TYPE( int ); - optional_ALIGN_TYPE( long int ); - optional_ALIGN_TYPE( float ); - optional_ALIGN_TYPE( double ); - optional_ALIGN_TYPE( long double ); - optional_ALIGN_TYPE( char * ); - optional_ALIGN_TYPE( short int * ); - optional_ALIGN_TYPE( int * ); - optional_ALIGN_TYPE( long int * ); - optional_ALIGN_TYPE( float * ); - optional_ALIGN_TYPE( double * ); - optional_ALIGN_TYPE( long double * ); - optional_ALIGN_TYPE( void * ); - -#ifdef HAVE_LONG_LONG - optional_ALIGN_TYPE( long long ); -#endif - - struct Unknown; - - Unknown ( * optional_UNIQUE(_) )( Unknown ); - Unknown * Unknown::* optional_UNIQUE(_); - Unknown ( Unknown::* optional_UNIQUE(_) )( Unknown ); - - struct_t< Unknown ( * )( Unknown) > optional_UNIQUE(_); - struct_t< Unknown * Unknown::* > optional_UNIQUE(_); - struct_t< Unknown ( Unknown::* )(Unknown) > optional_UNIQUE(_); -}; - -#undef optional_UNIQUE -#undef optional_UNIQUE2 -#undef optional_UNIQUE3 - -#undef optional_ALIGN_TYPE - -#elif defined( optional_CONFIG_ALIGN_AS ) // optional_CONFIG_MAX_ALIGN_HACK - -// Use user-specified type for alignment: - -#define optional_ALIGN_AS( unused ) \ - optional_CONFIG_ALIGN_AS - -#else // optional_CONFIG_MAX_ALIGN_HACK - -// Determine POD type to use for alignment: - -#define optional_ALIGN_AS( to_align ) \ - typename type_of_size< alignment_types, alignment_of< to_align >::value >::type - -template< typename T > -struct alignment_of; - -template< typename T > -struct alignment_of_hack -{ - char c; - T t; - alignment_of_hack(); -}; - -template< size_t A, size_t S > -struct alignment_logic -{ - enum { value = A < S ? A : S }; -}; - -template< typename T > -struct alignment_of -{ - enum { value = alignment_logic< - sizeof( alignment_of_hack ) - sizeof(T), sizeof(T) >::value }; -}; - -template< typename List, size_t N > -struct type_of_size -{ - typedef typename std11::conditional< - N == sizeof( typename List::head ), - typename List::head, - typename type_of_size::type >::type type; -}; - -template< size_t N > -struct type_of_size< nulltype, N > -{ - typedef optional_CONFIG_ALIGN_AS_FALLBACK type; -}; - -template< typename T> -struct struct_t { T _; }; - -#define optional_ALIGN_TYPE( type ) \ - typelist< type , typelist< struct_t< type > - -struct Unknown; - -typedef - optional_ALIGN_TYPE( char ), - optional_ALIGN_TYPE( short ), - optional_ALIGN_TYPE( int ), - optional_ALIGN_TYPE( long ), - optional_ALIGN_TYPE( float ), - optional_ALIGN_TYPE( double ), - optional_ALIGN_TYPE( long double ), - - optional_ALIGN_TYPE( char *), - optional_ALIGN_TYPE( short * ), - optional_ALIGN_TYPE( int * ), - optional_ALIGN_TYPE( long * ), - optional_ALIGN_TYPE( float * ), - optional_ALIGN_TYPE( double * ), - optional_ALIGN_TYPE( long double * ), - - optional_ALIGN_TYPE( Unknown ( * )( Unknown ) ), - optional_ALIGN_TYPE( Unknown * Unknown::* ), - optional_ALIGN_TYPE( Unknown ( Unknown::* )( Unknown ) ), - - nulltype - > > > > > > > > > > > > > > - > > > > > > > > > > > > > > - > > > > > > - alignment_types; - -#undef optional_ALIGN_TYPE - -#endif // optional_CONFIG_MAX_ALIGN_HACK - -/// C++03 constructed union to hold value. - -template< typename T > -union storage_t -{ -//private: -// template< typename > friend class optional; - - typedef T value_type; - - storage_t() optional_is_default - - explicit storage_t( value_type const & v ) - { - construct_value( v ); - } - - void construct_value( value_type const & v ) - { - ::new( value_ptr() ) value_type( v ); - } - -#if optional_CPP11_OR_GREATER - - explicit storage_t( value_type && v ) - { - construct_value( std::move( v ) ); - } - - void construct_value( value_type && v ) - { - ::new( const_cast(static_cast(value_ptr())) ) value_type( std::move( v ) ); - } - - template< class... Args > - storage_t( nonstd_lite_in_place_t(T), Args&&... args ) - { - emplace( std::forward(args)... ); - } - - template< class... Args > - void emplace( Args&&... args ) - { - ::new( const_cast(static_cast(value_ptr())) ) value_type( std::forward(args)... ); - } - - template< class U, class... Args > - void emplace( std::initializer_list il, Args&&... args ) - { - ::new( const_cast(static_cast(value_ptr())) ) value_type( il, std::forward(args)... ); - } - -#endif - - void destruct_value() - { - value_ptr()->~T(); - } - - optional_nodiscard value_type const * value_ptr() const - { - return as(); - } - - value_type * value_ptr() - { - return as(); - } - - optional_nodiscard value_type const & value() const optional_ref_qual - { - return * value_ptr(); - } - - value_type & value() optional_ref_qual - { - return * value_ptr(); - } - -#if optional_HAVE( REF_QUALIFIER ) - - optional_nodiscard value_type const && value() const optional_refref_qual - { - return std::move( value() ); - } - - value_type && value() optional_refref_qual - { - return std::move( value() ); - } - -#endif - -#if optional_CPP11_OR_GREATER - - using aligned_storage_t = typename std::aligned_storage< sizeof(value_type), alignof(value_type) >::type; - aligned_storage_t data; - -#elif optional_CONFIG_MAX_ALIGN_HACK - - typedef struct { unsigned char data[ sizeof(value_type) ]; } aligned_storage_t; - - max_align_t hack; - aligned_storage_t data; - -#else - typedef optional_ALIGN_AS(value_type) align_as_type; - - typedef struct { align_as_type data[ 1 + ( sizeof(value_type) - 1 ) / sizeof(align_as_type) ]; } aligned_storage_t; - aligned_storage_t data; - -# undef optional_ALIGN_AS - -#endif // optional_CONFIG_MAX_ALIGN_HACK - - optional_nodiscard void * ptr() optional_noexcept - { - return &data; - } - - optional_nodiscard void const * ptr() const optional_noexcept - { - return &data; - } - - template - optional_nodiscard U * as() - { - return reinterpret_cast( ptr() ); - } - - template - optional_nodiscard U const * as() const - { - return reinterpret_cast( ptr() ); - } -}; - -} // namespace detail - -/// disengaged state tag - -struct nullopt_t -{ - struct init{}; - explicit optional_constexpr nullopt_t( init /*unused*/ ) optional_noexcept {} -}; - -#if optional_HAVE( CONSTEXPR_11 ) -constexpr nullopt_t nullopt{ nullopt_t::init{} }; -#else -// extra parenthesis to prevent the most vexing parse: -const nullopt_t nullopt(( nullopt_t::init() )); -#endif - -/// optional access error - -#if ! optional_CONFIG_NO_EXCEPTIONS - -class bad_optional_access : public std::logic_error -{ -public: - explicit bad_optional_access() - : logic_error( "bad optional access" ) {} -}; - -#endif //optional_CONFIG_NO_EXCEPTIONS - -/// optional - -template< typename T> -class optional -{ - optional_static_assert(( !std::is_same::type, nullopt_t>::value ), - "T in optional must not be of type 'nullopt_t'.") - - optional_static_assert(( !std::is_same::type, in_place_t>::value ), - "T in optional must not be of type 'in_place_t'.") - - optional_static_assert(( std::is_object::value && std::is_destructible::value && !std::is_array::value ), - "T in optional must meet the Cpp17Destructible requirements.") - -private: - template< typename > friend class optional; - - typedef void (optional::*safe_bool)() const; - -public: - typedef T value_type; - - // x.x.3.1, constructors - - // 1a - default construct - optional_constexpr optional() optional_noexcept - : has_value_( false ) - , contained() - {} - - // 1b - construct explicitly empty - // NOLINTNEXTLINE( google-explicit-constructor, hicpp-explicit-conversions ) - optional_constexpr optional( nullopt_t /*unused*/ ) optional_noexcept - : has_value_( false ) - , contained() - {} - - // 2 - copy-construct -#if optional_CPP11_OR_GREATER - // template< typename U = T - // optional_REQUIRES_T( - // std::is_copy_constructible::value - // || std11::is_trivially_copy_constructible::value - // ) - // > -#endif - optional_constexpr14 optional( optional const & other ) - : has_value_( other.has_value() ) - { - if ( other.has_value() ) - { - contained.construct_value( other.contained.value() ); - } - } - -#if optional_CPP11_OR_GREATER - - // 3 (C++11) - move-construct from optional - template< typename U = T - optional_REQUIRES_T( - std11::is_move_constructible::value - || std11::is_trivially_move_constructible::value - ) - > - optional_constexpr14 optional( optional && other ) - // NOLINTNEXTLINE( performance-noexcept-move-constructor ) - noexcept( std11::is_nothrow_move_constructible::value ) - : has_value_( other.has_value() ) - { - if ( other.has_value() ) - { - contained.construct_value( std::move( other.contained.value() ) ); - } - } - - // 4a (C++11) - explicit converting copy-construct from optional - template< typename U - optional_REQUIRES_T( - std::is_constructible::value - && !std::is_constructible & >::value - && !std::is_constructible && >::value - && !std::is_constructible const & >::value - && !std::is_constructible const && >::value - && !std::is_convertible< optional & , T>::value - && !std::is_convertible< optional && , T>::value - && !std::is_convertible< optional const & , T>::value - && !std::is_convertible< optional const &&, T>::value - && !std::is_convertible< U const & , T>::value /*=> explicit */ - ) - > - explicit optional( optional const & other ) - : has_value_( other.has_value() ) - { - if ( other.has_value() ) - { - contained.construct_value( T{ other.contained.value() } ); - } - } -#endif // optional_CPP11_OR_GREATER - - // 4b (C++98 and later) - non-explicit converting copy-construct from optional - template< typename U -#if optional_CPP11_OR_GREATER - optional_REQUIRES_T( - std::is_constructible::value - && !std::is_constructible & >::value - && !std::is_constructible && >::value - && !std::is_constructible const & >::value - && !std::is_constructible const && >::value - && !std::is_convertible< optional & , T>::value - && !std::is_convertible< optional && , T>::value - && !std::is_convertible< optional const & , T>::value - && !std::is_convertible< optional const &&, T>::value - && std::is_convertible< U const & , T>::value /*=> non-explicit */ - ) -#endif // optional_CPP11_OR_GREATER - > - // NOLINTNEXTLINE( google-explicit-constructor, hicpp-explicit-conversions ) - /*non-explicit*/ optional( optional const & other ) - : has_value_( other.has_value() ) - { - if ( other.has_value() ) - { - contained.construct_value( other.contained.value() ); - } - } - -#if optional_CPP11_OR_GREATER - - // 5a (C++11) - explicit converting move-construct from optional - template< typename U - optional_REQUIRES_T( - std::is_constructible::value - && !std::is_constructible & >::value - && !std::is_constructible && >::value - && !std::is_constructible const & >::value - && !std::is_constructible const && >::value - && !std::is_convertible< optional & , T>::value - && !std::is_convertible< optional && , T>::value - && !std::is_convertible< optional const & , T>::value - && !std::is_convertible< optional const &&, T>::value - && !std::is_convertible< U &&, T>::value /*=> explicit */ - ) - > - explicit optional( optional && other - ) - : has_value_( other.has_value() ) - { - if ( other.has_value() ) - { - contained.construct_value( T{ std::move( other.contained.value() ) } ); - } - } - - // 5a (C++11) - non-explicit converting move-construct from optional - template< typename U - optional_REQUIRES_T( - std::is_constructible::value - && !std::is_constructible & >::value - && !std::is_constructible && >::value - && !std::is_constructible const & >::value - && !std::is_constructible const && >::value - && !std::is_convertible< optional & , T>::value - && !std::is_convertible< optional && , T>::value - && !std::is_convertible< optional const & , T>::value - && !std::is_convertible< optional const &&, T>::value - && std::is_convertible< U &&, T>::value /*=> non-explicit */ - ) - > - // NOLINTNEXTLINE( google-explicit-constructor, hicpp-explicit-conversions ) - /*non-explicit*/ optional( optional && other ) - : has_value_( other.has_value() ) - { - if ( other.has_value() ) - { - contained.construct_value( std::move( other.contained.value() ) ); - } - } - - // 6 (C++11) - in-place construct - template< typename... Args - optional_REQUIRES_T( - std::is_constructible::value - ) - > - optional_constexpr explicit optional( nonstd_lite_in_place_t(T), Args&&... args ) - : has_value_( true ) - , contained( in_place, std::forward(args)... ) - {} - - // 7 (C++11) - in-place construct, initializer-list - template< typename U, typename... Args - optional_REQUIRES_T( - std::is_constructible&, Args&&...>::value - ) - > - optional_constexpr explicit optional( nonstd_lite_in_place_t(T), std::initializer_list il, Args&&... args ) - : has_value_( true ) - , contained( T( il, std::forward(args)...) ) - {} - - // 8a (C++11) - explicit move construct from value - template< typename U = T - optional_REQUIRES_T( - std::is_constructible::value - && !std::is_same::type, nonstd_lite_in_place_t(U)>::value - && !std::is_same::type, optional>::value - && !std::is_convertible::value /*=> explicit */ - ) - > - optional_constexpr explicit optional( U && value ) - : has_value_( true ) - , contained( nonstd_lite_in_place(T), std::forward( value ) ) - {} - - // 8b (C++11) - non-explicit move construct from value - template< typename U = T - optional_REQUIRES_T( - std::is_constructible::value - && !std::is_same::type, nonstd_lite_in_place_t(U)>::value - && !std::is_same::type, optional>::value - && std::is_convertible::value /*=> non-explicit */ - ) - > - // NOLINTNEXTLINE( google-explicit-constructor, hicpp-explicit-conversions ) - optional_constexpr /*non-explicit*/ optional( U && value ) - : has_value_( true ) - , contained( nonstd_lite_in_place(T), std::forward( value ) ) - {} - -#else // optional_CPP11_OR_GREATER - - // 8 (C++98) - optional( value_type const & value ) - : has_value_( true ) - , contained( value ) - {} - -#endif // optional_CPP11_OR_GREATER - - // x.x.3.2, destructor - - ~optional() - { - if ( has_value() ) - { - contained.destruct_value(); - } - } - - // x.x.3.3, assignment - - // 1 (C++98and later) - assign explicitly empty - optional & operator=( nullopt_t /*unused*/) optional_noexcept - { - reset(); - return *this; - } - - // 2 (C++98and later) - copy-assign from optional -#if optional_CPP11_OR_GREATER - // NOLINTNEXTLINE( cppcoreguidelines-c-copy-assignment-signature, misc-unconventional-assign-operator ) - optional_REQUIRES_R( - optional &, - true -// std::is_copy_constructible::value -// && std::is_copy_assignable::value - ) - operator=( optional const & other ) - noexcept( - std11::is_nothrow_move_assignable::value - && std11::is_nothrow_move_constructible::value - ) -#else - optional & operator=( optional const & other ) -#endif - { - if ( (has_value() == true ) && (other.has_value() == false) ) { reset(); } - else if ( (has_value() == false) && (other.has_value() == true ) ) { initialize( *other ); } - else if ( (has_value() == true ) && (other.has_value() == true ) ) { contained.value() = *other; } - return *this; - } - -#if optional_CPP11_OR_GREATER - - // 3 (C++11) - move-assign from optional - // NOLINTNEXTLINE( cppcoreguidelines-c-copy-assignment-signature, misc-unconventional-assign-operator ) - optional_REQUIRES_R( - optional &, - true -// std11::is_move_constructible::value -// && std::is_move_assignable::value - ) - operator=( optional && other ) noexcept - { - if ( (has_value() == true ) && (other.has_value() == false) ) { reset(); } - else if ( (has_value() == false) && (other.has_value() == true ) ) { initialize( std::move( *other ) ); } - else if ( (has_value() == true ) && (other.has_value() == true ) ) { contained.value() = std::move( *other ); } - return *this; - } - - // 4 (C++11) - move-assign from value - template< typename U = T > - // NOLINTNEXTLINE( cppcoreguidelines-c-copy-assignment-signature, misc-unconventional-assign-operator ) - optional_REQUIRES_R( - optional &, - std::is_constructible::value - && std11::is_assignable::value - && !std::is_same::type, nonstd_lite_in_place_t(U)>::value - && !std::is_same::type, optional>::value - && !(std::is_scalar::value && std::is_same::type>::value) - ) - operator=( U && value ) - { - if ( has_value() ) - { - contained.value() = std::forward( value ); - } - else - { - initialize( T( std::forward( value ) ) ); - } - return *this; - } - -#else // optional_CPP11_OR_GREATER - - // 4 (C++98) - copy-assign from value - template< typename U /*= T*/ > - optional & operator=( U const & value ) - { - if ( has_value() ) contained.value() = value; - else initialize( T( value ) ); - return *this; - } - -#endif // optional_CPP11_OR_GREATER - - // 5 (C++98 and later) - converting copy-assign from optional - template< typename U > -#if optional_CPP11_OR_GREATER - // NOLINTNEXTLINE( cppcoreguidelines-c-copy-assignment-signature, misc-unconventional-assign-operator ) - optional_REQUIRES_R( - optional&, - std::is_constructible< T , U const &>::value - && std11::is_assignable< T&, U const &>::value - && !std::is_constructible & >::value - && !std::is_constructible && >::value - && !std::is_constructible const & >::value - && !std::is_constructible const && >::value - && !std::is_convertible< optional & , T>::value - && !std::is_convertible< optional && , T>::value - && !std::is_convertible< optional const & , T>::value - && !std::is_convertible< optional const &&, T>::value - && !std11::is_assignable< T&, optional & >::value - && !std11::is_assignable< T&, optional && >::value - && !std11::is_assignable< T&, optional const & >::value - && !std11::is_assignable< T&, optional const && >::value - ) -#else - optional& -#endif // optional_CPP11_OR_GREATER - operator=( optional const & other ) - { - return *this = optional( other ); - } - -#if optional_CPP11_OR_GREATER - - // 6 (C++11) - converting move-assign from optional - template< typename U > - // NOLINTNEXTLINE( cppcoreguidelines-c-copy-assignment-signature, misc-unconventional-assign-operator ) - optional_REQUIRES_R( - optional&, - std::is_constructible< T , U>::value - && std11::is_assignable< T&, U>::value - && !std::is_constructible & >::value - && !std::is_constructible && >::value - && !std::is_constructible const & >::value - && !std::is_constructible const && >::value - && !std::is_convertible< optional & , T>::value - && !std::is_convertible< optional && , T>::value - && !std::is_convertible< optional const & , T>::value - && !std::is_convertible< optional const &&, T>::value - && !std11::is_assignable< T&, optional & >::value - && !std11::is_assignable< T&, optional && >::value - && !std11::is_assignable< T&, optional const & >::value - && !std11::is_assignable< T&, optional const && >::value - ) - operator=( optional && other ) - { - return *this = optional( std::move( other ) ); - } - - // 7 (C++11) - emplace - template< typename... Args - optional_REQUIRES_T( - std::is_constructible::value - ) - > - T& emplace( Args&&... args ) - { - *this = nullopt; - contained.emplace( std::forward(args)... ); - has_value_ = true; - return contained.value(); - } - - // 8 (C++11) - emplace, initializer-list - template< typename U, typename... Args - optional_REQUIRES_T( - std::is_constructible&, Args&&...>::value - ) - > - T& emplace( std::initializer_list il, Args&&... args ) - { - *this = nullopt; - contained.emplace( il, std::forward(args)... ); - has_value_ = true; - return contained.value(); - } - -#endif // optional_CPP11_OR_GREATER - - // x.x.3.4, swap - - void swap( optional & other ) -#if optional_CPP11_OR_GREATER - noexcept( - std11::is_nothrow_move_constructible::value - && std17::is_nothrow_swappable::value - ) -#endif - { - using std::swap; - if ( (has_value() == true ) && (other.has_value() == true ) ) { swap( **this, *other ); } - else if ( (has_value() == false) && (other.has_value() == true ) ) { initialize( std11::move(*other) ); other.reset(); } - else if ( (has_value() == true ) && (other.has_value() == false) ) { other.initialize( std11::move(**this) ); reset(); } - } - - // x.x.3.5, observers - - optional_constexpr value_type const * operator ->() const - { - return assert( has_value() ), - contained.value_ptr(); - } - - optional_constexpr14 value_type * operator ->() - { - return assert( has_value() ), - contained.value_ptr(); - } - - optional_constexpr value_type const & operator *() const optional_ref_qual - { - return assert( has_value() ), - contained.value(); - } - - optional_constexpr14 value_type & operator *() optional_ref_qual - { - return assert( has_value() ), - contained.value(); - } - -#if optional_HAVE( REF_QUALIFIER ) - - optional_constexpr value_type const && operator *() const optional_refref_qual - { - return std::move( **this ); - } - - optional_constexpr14 value_type && operator *() optional_refref_qual - { - return std::move( **this ); - } - -#endif - -#if optional_CPP11_OR_GREATER - optional_constexpr explicit operator bool() const optional_noexcept - { - return has_value(); - } -#else - optional_constexpr operator safe_bool() const optional_noexcept - { - return has_value() ? &optional::this_type_does_not_support_comparisons : 0; - } -#endif - - // NOLINTNEXTLINE( modernize-use-nodiscard ) - /*optional_nodiscard*/ optional_constexpr bool has_value() const optional_noexcept - { - return has_value_; - } - - // NOLINTNEXTLINE( modernize-use-nodiscard ) - /*optional_nodiscard*/ optional_constexpr14 value_type const & value() const optional_ref_qual - { -#if optional_CONFIG_NO_EXCEPTIONS - assert( has_value() ); -#else - if ( ! has_value() ) - { - throw bad_optional_access(); - } -#endif - return contained.value(); - } - - optional_constexpr14 value_type & value() optional_ref_qual - { -#if optional_CONFIG_NO_EXCEPTIONS - assert( has_value() ); -#else - if ( ! has_value() ) - { - throw bad_optional_access(); - } -#endif - return contained.value(); - } - -#if optional_HAVE( REF_QUALIFIER ) && ( !optional_COMPILER_GNUC_VERSION || optional_COMPILER_GNUC_VERSION >= 490 ) - - // NOLINTNEXTLINE( modernize-use-nodiscard ) - /*optional_nodiscard*/ optional_constexpr value_type const && value() const optional_refref_qual - { - return std::move( value() ); - } - - optional_constexpr14 value_type && value() optional_refref_qual - { - return std::move( value() ); - } - -#endif - -#if optional_HAVE( REF_QUALIFIER ) - - template< typename U > - optional_constexpr value_type value_or( U && v ) const optional_ref_qual - { - return has_value() ? contained.value() : static_cast(std::forward( v ) ); - } - - template< typename U > - optional_constexpr14 value_type value_or( U && v ) optional_refref_qual - { -#if optional_COMPILER_CLANG_VERSION - return has_value() ? /*std::move*/( contained.value() ) : static_cast(std::forward( v ) ); -#else - return has_value() ? std::move( contained.value() ) : static_cast(std::forward( v ) ); -#endif - } - -#else - - template< typename U > - optional_constexpr value_type value_or( U const & v ) const - { - return has_value() ? contained.value() : static_cast( v ); - } - -#endif // optional_HAVE( REF_QUALIFIER ) - -#if !optional_CONFIG_NO_EXTENSIONS -#if optional_HAVE( REF_QUALIFIER ) - - template< typename F > - optional_constexpr value_type value_or_eval( F f ) const & - { - return has_value() ? contained.value() : f(); - } - - template< typename F > - optional_constexpr14 value_type value_or_eval( F f ) && - { - if ( has_value() ) - { - return std::move( contained.value() ); - } - else - { - return f(); - } - } - -#else - - template< typename F > - optional_constexpr value_type value_or_eval( F f ) const - { - return has_value() ? contained.value() : f(); - } - -#endif // optional_HAVE( REF_QUALIFIER ) -#endif // !optional_CONFIG_NO_EXTENSIONS - - // x.x.3.6, modifiers - - void reset() optional_noexcept - { - if ( has_value() ) - { - contained.destruct_value(); - } - - has_value_ = false; - } - -private: - void this_type_does_not_support_comparisons() const {} - - template< typename V > - void initialize( V const & value ) - { - assert( ! has_value() ); - contained.construct_value( value ); - has_value_ = true; - } - -#if optional_CPP11_OR_GREATER - template< typename V > - void initialize( V && value ) - { - assert( ! has_value() ); - contained.construct_value( std::forward( value ) ); - has_value_ = true; - } - -#endif - -private: - bool has_value_; - detail::storage_t< value_type > contained; - -}; - -// Relational operators - -template< typename T, typename U > -optional_nodiscard optional_constexpr bool operator==( optional const & x, optional const & y ) -{ - return bool(x) != bool(y) ? false : !bool( x ) ? true : *x == *y; -} - -template< typename T, typename U > -optional_nodiscard optional_constexpr bool operator!=( optional const & x, optional const & y ) -{ - return !(x == y); -} - -template< typename T, typename U > -optional_nodiscard optional_constexpr bool operator<( optional const & x, optional const & y ) -{ - return (!y) ? false : (!x) ? true : *x < *y; -} - -template< typename T, typename U > -optional_nodiscard optional_constexpr bool operator>( optional const & x, optional const & y ) -{ - return (y < x); -} - -template< typename T, typename U > -optional_nodiscard optional_constexpr bool operator<=( optional const & x, optional const & y ) -{ - return !(y < x); -} - -template< typename T, typename U > -optional_nodiscard optional_constexpr bool operator>=( optional const & x, optional const & y ) -{ - return !(x < y); -} - -// Comparison with nullopt - -template< typename T > -optional_nodiscard optional_constexpr bool operator==( optional const & x, nullopt_t /*unused*/ ) optional_noexcept -{ - return (!x); -} - -template< typename T > -optional_nodiscard optional_constexpr bool operator==( nullopt_t /*unused*/, optional const & x ) optional_noexcept -{ - return (!x); -} - -template< typename T > -optional_nodiscard optional_constexpr bool operator!=( optional const & x, nullopt_t /*unused*/ ) optional_noexcept -{ - return bool(x); -} - -template< typename T > -optional_nodiscard optional_constexpr bool operator!=( nullopt_t /*unused*/, optional const & x ) optional_noexcept -{ - return bool(x); -} - -template< typename T > -optional_nodiscard optional_constexpr bool operator<( optional const & /*unused*/, nullopt_t /*unused*/ ) optional_noexcept -{ - return false; -} - -template< typename T > -optional_nodiscard optional_constexpr bool operator<( nullopt_t /*unused*/, optional const & x ) optional_noexcept -{ - return bool(x); -} - -template< typename T > -optional_nodiscard optional_constexpr bool operator<=( optional const & x, nullopt_t /*unused*/ ) optional_noexcept -{ - return (!x); -} - -template< typename T > -optional_nodiscard optional_constexpr bool operator<=( nullopt_t /*unused*/, optional const & /*unused*/ ) optional_noexcept -{ - return true; -} - -template< typename T > -optional_nodiscard optional_constexpr bool operator>( optional const & x, nullopt_t /*unused*/ ) optional_noexcept -{ - return bool(x); -} - -template< typename T > -optional_nodiscard optional_constexpr bool operator>( nullopt_t /*unused*/, optional const & /*unused*/ ) optional_noexcept -{ - return false; -} - -template< typename T > -optional_nodiscard optional_constexpr bool operator>=( optional const & /*unused*/, nullopt_t /*unused*/ ) optional_noexcept -{ - return true; -} - -template< typename T > -optional_nodiscard optional_constexpr bool operator>=( nullopt_t /*unused*/, optional const & x ) optional_noexcept -{ - return (!x); -} - -// Comparison with T - -template< typename T, typename U > -optional_nodiscard optional_constexpr bool operator==( optional const & x, U const & v ) -{ - return bool(x) ? *x == v : false; -} - -template< typename T, typename U > -optional_nodiscard optional_constexpr bool operator==( U const & v, optional const & x ) -{ - return bool(x) ? v == *x : false; -} - -template< typename T, typename U > -optional_nodiscard optional_constexpr bool operator!=( optional const & x, U const & v ) -{ - return bool(x) ? *x != v : true; -} - -template< typename T, typename U > -optional_nodiscard optional_constexpr bool operator!=( U const & v, optional const & x ) -{ - return bool(x) ? v != *x : true; -} - -template< typename T, typename U > -optional_nodiscard optional_constexpr bool operator<( optional const & x, U const & v ) -{ - return bool(x) ? *x < v : true; -} - -template< typename T, typename U > -optional_nodiscard optional_constexpr bool operator<( U const & v, optional const & x ) -{ - return bool(x) ? v < *x : false; -} - -template< typename T, typename U > -optional_nodiscard optional_constexpr bool operator<=( optional const & x, U const & v ) -{ - return bool(x) ? *x <= v : true; -} - -template< typename T, typename U > -optional_nodiscard optional_constexpr bool operator<=( U const & v, optional const & x ) -{ - return bool(x) ? v <= *x : false; -} - -template< typename T, typename U > -optional_nodiscard optional_constexpr bool operator>( optional const & x, U const & v ) -{ - return bool(x) ? *x > v : false; -} - -template< typename T, typename U > -optional_nodiscard optional_constexpr bool operator>( U const & v, optional const & x ) -{ - return bool(x) ? v > *x : true; -} - -template< typename T, typename U > -optional_nodiscard optional_constexpr bool operator>=( optional const & x, U const & v ) -{ - return bool(x) ? *x >= v : false; -} - -template< typename T, typename U > -optional_nodiscard optional_constexpr bool operator>=( U const & v, optional const & x ) -{ - return bool(x) ? v >= *x : true; -} - -// Specialized algorithms - -template< typename T -#if optional_CPP11_OR_GREATER - optional_REQUIRES_T( - std11::is_move_constructible::value - && std17::is_swappable::value ) -#endif -> -void swap( optional & x, optional & y ) -#if optional_CPP11_OR_GREATER - noexcept( noexcept( x.swap(y) ) ) -#endif -{ - x.swap( y ); -} - -#if optional_CPP11_OR_GREATER - -template< typename T > -optional_constexpr optional< typename std::decay::type > make_optional( T && value ) -{ - return optional< typename std::decay::type >( std::forward( value ) ); -} - -template< typename T, typename...Args > -optional_constexpr optional make_optional( Args&&... args ) -{ - return optional( nonstd_lite_in_place(T), std::forward(args)...); -} - -template< typename T, typename U, typename... Args > -optional_constexpr optional make_optional( std::initializer_list il, Args&&... args ) -{ - return optional( nonstd_lite_in_place(T), il, std::forward(args)...); -} - -#else - -template< typename T > -optional make_optional( T const & value ) -{ - return optional( value ); -} - -#endif // optional_CPP11_OR_GREATER - -} // namespace optional_lite - -using optional_lite::optional; -using optional_lite::nullopt_t; -using optional_lite::nullopt; - -#if ! optional_CONFIG_NO_EXCEPTIONS -using optional_lite::bad_optional_access; -#endif - -using optional_lite::make_optional; - -} // namespace nonstd - -#if optional_CPP11_OR_GREATER - -// specialize the std::hash algorithm: - -namespace std { - -template< class T > -struct hash< nonstd::optional > -{ -public: - std::size_t operator()( nonstd::optional const & v ) const optional_noexcept - { - return bool( v ) ? std::hash{}( *v ) : 0; - } -}; - -} //namespace std - -#endif // optional_CPP11_OR_GREATER - -#if defined(__clang__) -# pragma clang diagnostic pop -#elif defined(__GNUC__) -# pragma GCC diagnostic pop -#elif defined(_MSC_VER ) -# pragma warning( pop ) -#endif - -#endif // optional_USES_STD_OPTIONAL - -#endif // NONSTD_OPTIONAL_LITE_HPP diff --git a/src/policy.hpp b/src/policy.hpp index de7a4bfb..07b1bd28 100644 --- a/src/policy.hpp +++ b/src/policy.hpp @@ -20,6 +20,9 @@ #include "strvec.hpp" #include +#include +#include + namespace Policy { @@ -33,7 +36,9 @@ namespace Policy public: std::string name; - virtual int operator()(const Branches::CPtr&,const char*,StrVec*) const = 0; + virtual int operator()(const Branches::Ptr&, + const char*, + std::vector&) const = 0; }; class Action @@ -58,19 +63,19 @@ namespace Policy } int - operator()(const Branches::CPtr &branches_, - const char *fusepath_, - StrVec *paths_) const + operator()(const Branches::Ptr &branches_, + const char *fusepath_, + std::vector &output_) const { - return (*impl)(branches_,fusepath_,paths_); + return (*impl)(branches_,fusepath_,output_); } int - operator()(const Branches::CPtr &branches_, + operator()(const Branches::Ptr &branches_, const std::string &fusepath_, - StrVec *paths_) const + std::vector &output_) const { - return (*impl)(branches_,fusepath_.c_str(),paths_); + return (*impl)(branches_,fusepath_.c_str(),output_); } operator bool() const @@ -92,8 +97,10 @@ namespace Policy public: std::string name; - virtual int operator()(const Branches::CPtr&,const char*,StrVec*) const = 0; virtual bool path_preserving(void) const = 0; + virtual int operator()(const Branches::Ptr&, + const char*, + std::vector&) const = 0; }; class Create @@ -124,19 +131,19 @@ namespace Policy } int - operator()(const Branches::CPtr &branches_, + operator()(const Branches::Ptr &branches_, const char *fusepath_, - StrVec *paths_) const + std::vector &output_) const { - return (*impl)(branches_,fusepath_,paths_); + return (*impl)(branches_,fusepath_,output_); } int - operator()(const Branches::CPtr &branches_, + operator()(const Branches::Ptr &branches_, const std::string &fusepath_, - StrVec *paths_) const + std::vector &output_) const { - return (*impl)(branches_,fusepath_.c_str(),paths_); + return (*impl)(branches_,fusepath_.c_str(),output_); } operator bool() const @@ -158,7 +165,9 @@ namespace Policy public: std::string name; - virtual int operator()(const Branches::CPtr&,const char*,StrVec*) const = 0; + virtual int operator()(const Branches::Ptr&, + const char*, + std::vector&) const = 0; }; class Search @@ -183,19 +192,19 @@ namespace Policy } int - operator()(const Branches::CPtr &branches_, + operator()(const Branches::Ptr &branches_, const char *fusepath_, - StrVec *paths_) const + std::vector &output_) const { - return (*impl)(branches_,fusepath_,paths_); + return (*impl)(branches_,fusepath_,output_); } int - operator()(const Branches::CPtr &branches_, + operator()(const Branches::Ptr &branches_, const std::string &fusepath_, - StrVec *paths_) const + std::vector &output_) const { - return (*impl)(branches_,fusepath_.c_str(),paths_); + return (*impl)(branches_,fusepath_.c_str(),output_); } operator bool() const diff --git a/src/policy_all.cpp b/src/policy_all.cpp index 785a634b..2b948920 100644 --- a/src/policy_all.cpp +++ b/src/policy_all.cpp @@ -31,15 +31,15 @@ namespace all { static int - create(const Branches::CPtr &branches_, - StrVec *paths_) + create(const Branches::Ptr &ibranches_, + std::vector &obranches_) { int rv; int error; fs::info_t info; error = ENOENT; - for(auto &branch : *branches_) + for(auto &branch : *ibranches_) { if(branch.ro_or_nc()) error_and_continue(error,EROFS); @@ -51,10 +51,10 @@ namespace all if(info.spaceavail < branch.minfreespace()) error_and_continue(error,ENOSPC); - paths_->push_back(branch.path); + obranches_.push_back(&branch); } - if(paths_->empty()) + if(obranches_.empty()) return (errno=error,-1); return 0; @@ -62,25 +62,25 @@ namespace all } int -Policy::All::Action::operator()(const Branches::CPtr &branches_, +Policy::All::Action::operator()(const Branches::Ptr &ibranches_, const char *fusepath_, - StrVec *paths_) const + std::vector &obranches_) const { - return Policies::Action::epall(branches_,fusepath_,paths_); + return Policies::Action::epall(ibranches_,fusepath_,obranches_); } int -Policy::All::Create::operator()(const Branches::CPtr &branches_, +Policy::All::Create::operator()(const Branches::Ptr &ibranches_, const char *fusepath_, - StrVec *paths_) const + std::vector &obranches_) const { - return ::all::create(branches_,paths_); + return ::all::create(ibranches_,obranches_); } int -Policy::All::Search::operator()(const Branches::CPtr &branches_, +Policy::All::Search::operator()(const Branches::Ptr &ibranches_, const char *fusepath_, - StrVec *paths_) const + std::vector &obranches_) const { - return Policies::Search::epall(branches_,fusepath_,paths_); + return Policies::Search::epall(ibranches_,fusepath_,obranches_); } diff --git a/src/policy_all.hpp b/src/policy_all.hpp index 8f5b67c8..9ea29e1e 100644 --- a/src/policy_all.hpp +++ b/src/policy_all.hpp @@ -32,7 +32,9 @@ namespace Policy {} public: - int operator()(const Branches::CPtr&,const char*,StrVec*) const final; + int operator()(const Branches::Ptr&, + const char*, + std::vector&) const final; }; class Create final : public Policy::CreateImpl @@ -43,7 +45,9 @@ namespace Policy {} public: - int operator()(const Branches::CPtr&,const char*,StrVec*) const final; + int operator()(const Branches::Ptr&, + const char*, + std::vector&) const final; bool path_preserving(void) const final { return false; } }; @@ -55,7 +59,9 @@ namespace Policy {} public: - int operator()(const Branches::CPtr&,const char*,StrVec*) const final; + int operator()(const Branches::Ptr&, + const char*, + std::vector&) const final; }; } } diff --git a/src/policy_cache.cpp b/src/policy_cache.cpp index 590ea54f..7ffb7197 100644 --- a/src/policy_cache.cpp +++ b/src/policy_cache.cpp @@ -94,7 +94,7 @@ int PolicyCache::operator()(const Policy::Search &policy_, const Branches &branches_, const char *fusepath_, - StrVec *paths_) + std::vector &paths_) { int rv; Value *v; @@ -118,11 +118,11 @@ PolicyCache::operator()(const Policy::Search &policy_, pthread_mutex_lock(&_lock); v->time = now; - v->paths = *paths_; + v->paths = paths_; } else { - *paths_ = v->paths; + paths_ = v->paths; } pthread_mutex_unlock(&_lock); diff --git a/src/policy_cache.hpp b/src/policy_cache.hpp index 6cdb9280..a47bec5f 100644 --- a/src/policy_cache.hpp +++ b/src/policy_cache.hpp @@ -19,7 +19,6 @@ #pragma once #include "policy.hpp" -#include "strvec.hpp" #include #include @@ -36,7 +35,7 @@ public: Value(); uint64_t time; - StrVec paths; + std::vector paths; }; public: @@ -51,7 +50,7 @@ public: int operator()(const Policy::Search &policy, const Branches &branches, const char *fusepath, - StrVec *paths); + std::vector &paths); public: uint64_t timeout; diff --git a/src/policy_epall.cpp b/src/policy_epall.cpp index af4b526b..238e40ca 100644 --- a/src/policy_epall.cpp +++ b/src/policy_epall.cpp @@ -33,9 +33,9 @@ namespace epall { static int - create(const Branches::CPtr &branches_, + create(const Branches::Ptr &branches_, const char *fusepath_, - StrVec *paths_) + std::vector &paths_) { int rv; int error; @@ -56,10 +56,10 @@ namespace epall if(info.spaceavail < branch.minfreespace()) error_and_continue(error,ENOSPC); - paths_->push_back(branch.path); + paths_.emplace_back(&branch); } - if(paths_->empty()) + if(paths_.empty()) return (errno=error,-1); return 0; @@ -67,9 +67,9 @@ namespace epall static int - action(const Branches::CPtr &branches_, + action(const Branches::Ptr &branches_, const char *fusepath_, - StrVec *paths_) + std::vector &paths_) { int rv; int error; @@ -88,10 +88,10 @@ namespace epall if(readonly) error_and_continue(error,EROFS); - paths_->push_back(branch.path); + paths_.emplace_back(&branch); } - if(paths_->empty()) + if(paths_.empty()) return (errno=error,-1); return 0; @@ -99,19 +99,19 @@ namespace epall static int - search(const Branches::CPtr &branches_, + search(const Branches::Ptr &branches_, const char *fusepath_, - StrVec *paths_) + std::vector &paths_) { for(auto &branch : *branches_) { if(!fs::exists(branch.path,fusepath_)) continue; - paths_->push_back(branch.path); + paths_.push_back(&branch); } - if(paths_->empty()) + if(paths_.empty()) return (errno=ENOENT,-1); return 0; @@ -119,25 +119,25 @@ namespace epall } int -Policy::EPAll::Action::operator()(const Branches::CPtr &branches_, +Policy::EPAll::Action::operator()(const Branches::Ptr &branches_, const char *fusepath_, - StrVec *paths_) const + std::vector &paths_) const { return ::epall::action(branches_,fusepath_,paths_); } int -Policy::EPAll::Create::operator()(const Branches::CPtr &branches_, +Policy::EPAll::Create::operator()(const Branches::Ptr &branches_, const char *fusepath_, - StrVec *paths_) const + std::vector &paths_) const { return ::epall::create(branches_,fusepath_,paths_); } int -Policy::EPAll::Search::operator()(const Branches::CPtr &branches_, - const char *fusepath_, - StrVec *paths_) const +Policy::EPAll::Search::operator()(const Branches::Ptr &branches_, + const char *fusepath_, + std::vector &paths_) const { return ::epall::search(branches_,fusepath_,paths_); } diff --git a/src/policy_epall.hpp b/src/policy_epall.hpp index 1b665671..f91d81b7 100644 --- a/src/policy_epall.hpp +++ b/src/policy_epall.hpp @@ -33,7 +33,9 @@ namespace Policy } public: - int operator()(const Branches::CPtr&,const char*,StrVec*) const final; + int operator()(const Branches::Ptr&, + const char*, + std::vector&) const final; }; class Create final : public Policy::CreateImpl @@ -45,7 +47,9 @@ namespace Policy } public: - int operator()(const Branches::CPtr&,const char*,StrVec*) const final; + int operator()(const Branches::Ptr&, + const char*, + std::vector&) const final; bool path_preserving(void) const final { return true; } }; @@ -58,7 +62,9 @@ namespace Policy } public: - int operator()(const Branches::CPtr&,const char*,StrVec*) const final; + int operator()(const Branches::Ptr&, + const char*, + std::vector&) const final; }; } } diff --git a/src/policy_epff.cpp b/src/policy_epff.cpp index d2980f42..5689981f 100644 --- a/src/policy_epff.cpp +++ b/src/policy_epff.cpp @@ -35,9 +35,9 @@ namespace epff { static int - create(const Branches::CPtr &branches_, + create(const Branches::Ptr &branches_, const char *fusepath_, - StrVec *paths_) + std::vector &paths_) { int rv; int error; @@ -58,7 +58,7 @@ namespace epff if(info.spaceavail < branch.minfreespace()) error_and_continue(error,ENOSPC); - paths_->push_back(branch.path); + paths_.push_back(&branch); return 0; } @@ -68,9 +68,9 @@ namespace epff static int - action(const Branches::CPtr &branches_, + action(const Branches::Ptr &branches_, const char *fusepath_, - StrVec *paths_) + std::vector &paths_) { int rv; int error; @@ -89,7 +89,7 @@ namespace epff if(readonly) error_and_continue(error,EROFS); - paths_->push_back(branch.path); + paths_.push_back(&branch); return 0; } @@ -99,16 +99,16 @@ namespace epff static int - search(const Branches::CPtr &branches_, + search(const Branches::Ptr &branches_, const char *fusepath_, - StrVec *paths_) + std::vector &paths_) { for(auto &branch : *branches_) { if(!fs::exists(branch.path,fusepath_)) continue; - paths_->push_back(branch.path); + paths_.push_back(&branch); return 0; } @@ -118,25 +118,25 @@ namespace epff } int -Policy::EPFF::Action::operator()(const Branches::CPtr &branches_, - const char *fusepath_, - StrVec *paths_) const +Policy::EPFF::Action::operator()(const Branches::Ptr &branches_, + const char *fusepath_, + std::vector &paths_) const { return ::epff::action(branches_,fusepath_,paths_); } int -Policy::EPFF::Create::operator()(const Branches::CPtr &branches_, +Policy::EPFF::Create::operator()(const Branches::Ptr &branches_, const char *fusepath_, - StrVec *paths_) const + std::vector &paths_) const { return ::epff::create(branches_,fusepath_,paths_); } int -Policy::EPFF::Search::operator()(const Branches::CPtr &branches_, +Policy::EPFF::Search::operator()(const Branches::Ptr &branches_, const char *fusepath_, - StrVec *paths_) const + std::vector &paths_) const { return ::epff::search(branches_,fusepath_,paths_); } diff --git a/src/policy_epff.hpp b/src/policy_epff.hpp index 0e3e5f4a..d438cbf5 100644 --- a/src/policy_epff.hpp +++ b/src/policy_epff.hpp @@ -32,7 +32,9 @@ namespace Policy {} public: - int operator()(const Branches::CPtr&,const char*,StrVec*) const final; + int operator()(const Branches::Ptr&, + const char*, + std::vector&) const final; }; class Create final : public Policy::CreateImpl @@ -43,7 +45,9 @@ namespace Policy {} public: - int operator()(const Branches::CPtr&,const char*,StrVec*) const final; + int operator()(const Branches::Ptr&, + const char*, + std::vector&) const final; bool path_preserving(void) const final { return true; } }; @@ -55,7 +59,9 @@ namespace Policy {} public: - int operator()(const Branches::CPtr&,const char*,StrVec*) const final; + int operator()(const Branches::Ptr&, + const char*, + std::vector&) const final; }; } } diff --git a/src/policy_eplfs.cpp b/src/policy_eplfs.cpp index 3ef4ed18..8248bb8b 100644 --- a/src/policy_eplfs.cpp +++ b/src/policy_eplfs.cpp @@ -35,20 +35,20 @@ namespace eplfs { static int - create(const Branches::CPtr &branches_, + create(const Branches::Ptr &branches_, const char *fusepath_, - StrVec *paths_) + std::vector &paths_) { int rv; int error; uint64_t eplfs; + Branch *obranch; fs::info_t info; - const string *basepath; + obranch = nullptr; error = ENOENT; eplfs = std::numeric_limits::max(); - basepath = NULL; - for(const auto &branch : *branches_) + for(auto &branch : *branches_) { if(branch.ro_or_nc()) error_and_continue(error,EROFS); @@ -65,33 +65,33 @@ namespace eplfs continue; eplfs = info.spaceavail; - basepath = &branch.path; + obranch = &branch; } - if(basepath == NULL) + if(obranch == nullptr) return (errno=error,-1); - paths_->push_back(*basepath); + paths_.emplace_back(obranch); return 0; } static int - action(const Branches::CPtr &branches_, + action(const Branches::Ptr &branches_, const char *fusepath_, - StrVec *paths_) + std::vector &paths_) { int rv; int error; uint64_t eplfs; + Branch *obranch; fs::info_t info; - const string *basepath; + obranch = nullptr; error = ENOENT; eplfs = std::numeric_limits::max(); - basepath = NULL; - for(const auto &branch : *branches_) + for(auto &branch : *branches_) { if(branch.ro()) error_and_continue(error,EROFS); @@ -106,31 +106,31 @@ namespace eplfs continue; eplfs = info.spaceavail; - basepath = &branch.path; + obranch = &branch; } - if(basepath == NULL) + if(obranch == nullptr) return (errno=error,-1); - paths_->push_back(*basepath); + paths_.emplace_back(obranch); return 0; } static int - search(const Branches::CPtr &branches_, + search(const Branches::Ptr &branches_, const char *fusepath_, - StrVec *paths_) + std::vector &paths_) { int rv; uint64_t eplfs; uint64_t spaceavail; - const string *basepath; + Branch *obranch; + obranch = nullptr; eplfs = std::numeric_limits::max(); - basepath = NULL; - for(const auto &branch : *branches_) + for(auto &branch : *branches_) { if(!fs::exists(branch.path,fusepath_)) continue; @@ -141,38 +141,38 @@ namespace eplfs continue; eplfs = spaceavail; - basepath = &branch.path; + obranch = &branch; } - if(basepath == NULL) + if(obranch == nullptr) return (errno=ENOENT,-1); - paths_->push_back(*basepath); + paths_.emplace_back(obranch); return 0; } } int -Policy::EPLFS::Action::operator()(const Branches::CPtr &branches_, +Policy::EPLFS::Action::operator()(const Branches::Ptr &branches_, const char *fusepath_, - StrVec *paths_) const + std::vector &paths_) const { return ::eplfs::action(branches_,fusepath_,paths_); } int -Policy::EPLFS::Create::operator()(const Branches::CPtr &branches_, +Policy::EPLFS::Create::operator()(const Branches::Ptr &branches_, const char *fusepath_, - StrVec *paths_) const + std::vector &paths_) const { return ::eplfs::create(branches_,fusepath_,paths_); } int -Policy::EPLFS::Search::operator()(const Branches::CPtr &branches_, +Policy::EPLFS::Search::operator()(const Branches::Ptr &branches_, const char *fusepath_, - StrVec *paths_) const + std::vector &paths_) const { return ::eplfs::search(branches_,fusepath_,paths_); } diff --git a/src/policy_eplfs.hpp b/src/policy_eplfs.hpp index 60006b06..6a1ceeb5 100644 --- a/src/policy_eplfs.hpp +++ b/src/policy_eplfs.hpp @@ -32,7 +32,9 @@ namespace Policy {} public: - int operator()(const Branches::CPtr&,const char*,StrVec*) const final; + int operator()(const Branches::Ptr&, + const char*, + std::vector&) const final; }; class Create final : public Policy::CreateImpl @@ -43,7 +45,9 @@ namespace Policy {} public: - int operator()(const Branches::CPtr&,const char*,StrVec*) const final; + int operator()(const Branches::Ptr&, + const char*, + std::vector&) const final; bool path_preserving(void) const final { return true; } }; @@ -55,7 +59,9 @@ namespace Policy {} public: - int operator()(const Branches::CPtr&,const char*,StrVec*) const final; + int operator()(const Branches::Ptr&, + const char*, + std::vector&) const final; }; } } diff --git a/src/policy_eplus.cpp b/src/policy_eplus.cpp index e5bac154..9f686758 100644 --- a/src/policy_eplus.cpp +++ b/src/policy_eplus.cpp @@ -33,19 +33,19 @@ namespace eplus { static int - create(const Branches::CPtr &branches_, + create(const Branches::Ptr &branches_, const char *fusepath_, - StrVec *paths_) + std::vector &paths_) { int rv; int error; uint64_t eplus; fs::info_t info; - const string *basepath; + Branch *obranch; + obranch = nullptr; error = ENOENT; eplus = std::numeric_limits::max(); - basepath = NULL; for(auto &branch : *branches_) { if(branch.ro_or_nc()) @@ -63,32 +63,32 @@ namespace eplus continue; eplus = info.spaceused; - basepath = &branch.path; + obranch = &branch; } - if(basepath == NULL) + if(obranch == nullptr) return (errno=error,-1); - paths_->push_back(*basepath); + paths_.emplace_back(obranch); return 0; } static int - action(const Branches::CPtr &branches_, + action(const Branches::Ptr &branches_, const char *fusepath_, - StrVec *paths_) + std::vector &paths_) { int rv; int error; uint64_t eplus; fs::info_t info; - const string *basepath; + Branch *obranch; + obranch = nullptr; error = ENOENT; eplus = std::numeric_limits::max(); - basepath = NULL; for(auto &branch : *branches_) { if(branch.ro()) @@ -104,30 +104,30 @@ namespace eplus continue; eplus = info.spaceused; - basepath = &branch.path; + obranch = &branch; } - if(basepath == NULL) + if(obranch == nullptr) return (errno=error,-1); - paths_->push_back(*basepath); + paths_.emplace_back(obranch); return 0; } static int - search(const Branches::CPtr &branches_, + search(const Branches::Ptr &branches_, const char *fusepath_, - StrVec *paths_) + std::vector &paths_) { int rv; uint64_t eplus; uint64_t spaceused; - const string *basepath; + Branch *obranch; + obranch = nullptr; eplus = 0; - basepath = NULL; for(auto &branch : *branches_) { if(!fs::exists(branch.path,fusepath_)) @@ -139,38 +139,38 @@ namespace eplus continue; eplus = spaceused; - basepath = &branch.path; + obranch = &branch; } - if(basepath == NULL) + if(obranch == nullptr) return (errno=ENOENT,-1); - paths_->push_back(*basepath); + paths_.emplace_back(obranch); return 0; } } int -Policy::EPLUS::Action::operator()(const Branches::CPtr &branches_, - const char *fusepath_, - StrVec *paths_) const +Policy::EPLUS::Action::operator()(const Branches::Ptr &branches_, + const char *fusepath_, + std::vector &paths_) const { return ::eplus::action(branches_,fusepath_,paths_); } int -Policy::EPLUS::Create::operator()(const Branches::CPtr &branches_, +Policy::EPLUS::Create::operator()(const Branches::Ptr &branches_, const char *fusepath_, - StrVec *paths_) const + std::vector &paths_) const { return ::eplus::create(branches_,fusepath_,paths_); } int -Policy::EPLUS::Search::operator()(const Branches::CPtr &branches_, +Policy::EPLUS::Search::operator()(const Branches::Ptr &branches_, const char *fusepath_, - StrVec *paths_) const + std::vector &paths_) const { return ::eplus::search(branches_,fusepath_,paths_); } diff --git a/src/policy_eplus.hpp b/src/policy_eplus.hpp index ca253f7e..adf5879b 100644 --- a/src/policy_eplus.hpp +++ b/src/policy_eplus.hpp @@ -32,7 +32,9 @@ namespace Policy {} public: - int operator()(const Branches::CPtr&,const char*,StrVec*) const final; + int operator()(const Branches::Ptr&, + const char*, + std::vector&) const final; }; class Create final : public Policy::CreateImpl @@ -43,7 +45,9 @@ namespace Policy {} public: - int operator()(const Branches::CPtr&,const char*,StrVec*) const final; + int operator()(const Branches::Ptr&, + const char*, + std::vector&) const final; bool path_preserving(void) const final { return true; } }; @@ -55,7 +59,9 @@ namespace Policy {} public: - int operator()(const Branches::CPtr&,const char*,StrVec*) const final; + int operator()(const Branches::Ptr&, + const char*, + std::vector&) const final; }; } } diff --git a/src/policy_epmfs.cpp b/src/policy_epmfs.cpp index 7f44c032..a9ee4ebb 100644 --- a/src/policy_epmfs.cpp +++ b/src/policy_epmfs.cpp @@ -34,20 +34,20 @@ namespace epmfs { static int - create(const Branches::CPtr &branches_, + create(const Branches::Ptr &branches_, const char *fusepath_, - StrVec *paths_) + std::vector &paths_) { int rv; int error; uint64_t epmfs; fs::info_t info; - const string *basepath; + Branch *obranch; + obranch = nullptr; error = ENOENT; epmfs = std::numeric_limits::min(); - basepath = NULL; - for(const auto &branch : *branches_) + for(auto &branch : *branches_) { if(branch.ro_or_nc()) error_and_continue(error,EROFS); @@ -64,33 +64,33 @@ namespace epmfs continue; epmfs = info.spaceavail; - basepath = &branch.path; + obranch = &branch; } - if(basepath == NULL) + if(obranch == nullptr) return (errno=error,-1); - paths_->push_back(*basepath); + paths_.emplace_back(obranch); return 0; } static int - action(const Branches::CPtr &branches_, + action(const Branches::Ptr &branches_, const char *fusepath_, - StrVec *paths_) + std::vector &paths_) { int rv; int error; uint64_t epmfs; fs::info_t info; - const string *basepath; + Branch *obranch; + obranch = nullptr; error = ENOENT; epmfs = std::numeric_limits::min(); - basepath = NULL; - for(const auto &branch : *branches_) + for(auto &branch : *branches_) { if(branch.ro()) error_and_continue(error,EROFS); @@ -105,31 +105,31 @@ namespace epmfs continue; epmfs = info.spaceavail; - basepath = &branch.path; + obranch = &branch; } - if(basepath == NULL) + if(obranch == nullptr) return (errno=error,-1); - paths_->push_back(*basepath); + paths_.emplace_back(obranch); return 0; } static int - search(const Branches::CPtr &branches_, + search(const Branches::Ptr &branches_, const char *fusepath_, - StrVec *paths_) + std::vector &paths_) { int rv; uint64_t epmfs; uint64_t spaceavail; - const string *basepath; + Branch *obranch; + obranch = nullptr; epmfs = 0; - basepath = NULL; - for(const auto &branch : *branches_) + for(auto &branch : *branches_) { if(!fs::exists(branch.path,fusepath_)) continue; @@ -140,38 +140,38 @@ namespace epmfs continue; epmfs = spaceavail; - basepath = &branch.path; + obranch = &branch; } - if(basepath == NULL) + if(obranch == nullptr) return (errno=ENOENT,-1); - paths_->push_back(*basepath); + paths_.emplace_back(obranch); return 0; } } int -Policy::EPMFS::Action::operator()(const Branches::CPtr &branches_, +Policy::EPMFS::Action::operator()(const Branches::Ptr &branches_, const char *fusepath_, - StrVec *paths_) const + std::vector &paths_) const { return ::epmfs::action(branches_,fusepath_,paths_); } int -Policy::EPMFS::Create::operator()(const Branches::CPtr &branches_, +Policy::EPMFS::Create::operator()(const Branches::Ptr &branches_, const char *fusepath_, - StrVec *paths_) const + std::vector &paths_) const { return ::epmfs::create(branches_,fusepath_,paths_); } int -Policy::EPMFS::Search::operator()(const Branches::CPtr &branches_, +Policy::EPMFS::Search::operator()(const Branches::Ptr &branches_, const char *fusepath_, - StrVec *paths_) const + std::vector &paths_) const { return ::epmfs::search(branches_,fusepath_,paths_); } diff --git a/src/policy_epmfs.hpp b/src/policy_epmfs.hpp index e0b8382a..ad472c40 100644 --- a/src/policy_epmfs.hpp +++ b/src/policy_epmfs.hpp @@ -33,7 +33,9 @@ namespace Policy } public: - int operator()(const Branches::CPtr&,const char*,StrVec*) const final; + int operator()(const Branches::Ptr&, + const char*, + std::vector&) const final; }; class Create final : public Policy::CreateImpl @@ -45,7 +47,9 @@ namespace Policy } public: - int operator()(const Branches::CPtr&,const char*,StrVec*) const final; + int operator()(const Branches::Ptr&, + const char*, + std::vector&) const final; bool path_preserving(void) const final { return true; } }; @@ -58,7 +62,9 @@ namespace Policy } public: - int operator()(const Branches::CPtr&,const char*,StrVec*) const final; + int operator()(const Branches::Ptr&, + const char*, + std::vector&) const final; }; } } diff --git a/src/policy_eppfrd.cpp b/src/policy_eppfrd.cpp index 9c56fa68..bc162a68 100644 --- a/src/policy_eppfrd.cpp +++ b/src/policy_eppfrd.cpp @@ -29,29 +29,25 @@ #include #include -using std::string; -using std::vector; - struct BranchInfo { - uint64_t spaceavail; - const string *basepath; + u64 spaceavail; + Branch *branch; }; -typedef vector BranchInfoVec; +typedef std::vector BranchInfoVec; namespace eppfrd { static int - get_branchinfo_create(const Branches::CPtr &branches_, - const char *fusepath_, - BranchInfoVec *branchinfo_, - uint64_t *sum_) + get_branchinfo_create(const Branches::Ptr &branches_, + const char *fusepath_, + BranchInfoVec *branchinfo_, + uint64_t *sum_) { int rv; int error; - BranchInfo bi; fs::info_t info; *sum_ = 0; @@ -72,9 +68,7 @@ namespace eppfrd *sum_ += info.spaceavail; - bi.spaceavail = info.spaceavail; - bi.basepath = &branch.path; - branchinfo_->push_back(bi); + branchinfo_->push_back({info.spaceavail,&branch}); } return error; @@ -82,14 +76,13 @@ namespace eppfrd static int - get_branchinfo_action(const Branches::CPtr &branches_, - const char *fusepath_, - BranchInfoVec *branchinfo_, - uint64_t *sum_) + get_branchinfo_action(const Branches::Ptr &branches_, + const char *fusepath_, + BranchInfoVec *branchinfo_, + uint64_t *sum_) { int rv; int error; - BranchInfo bi; fs::info_t info; *sum_ = 0; @@ -108,9 +101,7 @@ namespace eppfrd *sum_ += info.spaceavail; - bi.spaceavail = info.spaceavail; - bi.basepath = &branch.path; - branchinfo_->push_back(bi); + branchinfo_->push_back({info.spaceavail,&branch}); } return error; @@ -118,13 +109,12 @@ namespace eppfrd static int - get_branchinfo_search(const Branches::CPtr &branches_, - const char *fusepath_, - BranchInfoVec *branchinfo_, - uint64_t *sum_) + get_branchinfo_search(const Branches::Ptr &branches_, + const char *fusepath_, + BranchInfoVec *branchinfo_, + uint64_t *sum_) { int rv; - BranchInfo bi; uint64_t spaceavail; *sum_ = 0; @@ -138,17 +128,14 @@ namespace eppfrd *sum_ += spaceavail; - bi.spaceavail = spaceavail; - bi.basepath = &branch.path; - branchinfo_->push_back(bi); + branchinfo_->push_back({spaceavail,&branch}); } return ENOENT; } static - const - string* + Branch* get_branch(const BranchInfoVec &branchinfo_, const uint64_t sum_) { @@ -167,7 +154,7 @@ namespace eppfrd if(idx < threshold) continue; - return branchinfo_[i].basepath; + return branchinfo_[i].branch; } return NULL; @@ -175,88 +162,88 @@ namespace eppfrd static int - create(const Branches::CPtr &branches_, + create(const Branches::Ptr &branches_, const char *fusepath_, - StrVec *paths_) + std::vector &paths_) { int error; uint64_t sum; - const string *basepath; + Branch *branch; BranchInfoVec branchinfo; - error = eppfrd::get_branchinfo_create(branches_,fusepath_,&branchinfo,&sum); - basepath = eppfrd::get_branch(branchinfo,sum); - if(basepath == NULL) + error = eppfrd::get_branchinfo_create(branches_,fusepath_,&branchinfo,&sum); + branch = eppfrd::get_branch(branchinfo,sum); + if(!branch) return (errno=error,-1); - paths_->push_back(*basepath); + paths_.emplace_back(branch); return 0; } static int - action(const Branches::CPtr &branches_, + action(const Branches::Ptr &branches_, const char *fusepath_, - StrVec *paths_) + std::vector &paths_) { int error; uint64_t sum; - const string *basepath; + Branch *branch; BranchInfoVec branchinfo; - error = eppfrd::get_branchinfo_action(branches_,fusepath_,&branchinfo,&sum); - basepath = eppfrd::get_branch(branchinfo,sum); - if(basepath == NULL) + error = eppfrd::get_branchinfo_action(branches_,fusepath_,&branchinfo,&sum); + branch = eppfrd::get_branch(branchinfo,sum); + if(!branch) return (errno=error,-1); - paths_->push_back(*basepath); + paths_.emplace_back(branch); return 0; } static int - search(const Branches::CPtr &branches_, + search(const Branches::Ptr &branches_, const char *fusepath_, - StrVec *paths_) + std::vector &paths_) { int error; uint64_t sum; - const string *basepath; + Branch *branch; BranchInfoVec branchinfo; - error = eppfrd::get_branchinfo_search(branches_,fusepath_,&branchinfo,&sum); - basepath = eppfrd::get_branch(branchinfo,sum); - if(basepath == NULL) + error = eppfrd::get_branchinfo_search(branches_,fusepath_,&branchinfo,&sum); + branch = eppfrd::get_branch(branchinfo,sum); + if(!branch) return (errno=error,-1); - paths_->push_back(*basepath); + paths_.emplace_back(branch); return 0; } } int -Policy::EPPFRD::Action::operator()(const Branches::CPtr &branches_, +Policy::EPPFRD::Action::operator()(const Branches::Ptr &branches_, const char *fusepath_, - StrVec *paths_) const + std::vector &paths_) const { return ::eppfrd::action(branches_,fusepath_,paths_); } int -Policy::EPPFRD::Create::operator()(const Branches::CPtr &branches_, +Policy::EPPFRD::Create::operator()(const Branches::Ptr &branches_, const char *fusepath_, - StrVec *paths_) const + std::vector &paths_) const { return ::eppfrd::create(branches_,fusepath_,paths_); } int -Policy::EPPFRD::Search::operator()(const Branches::CPtr &branches_, +Policy::EPPFRD::Search::operator()(const Branches::Ptr &branches_, const char *fusepath_, - StrVec *paths_) const + std::vector &paths_) const { return ::eppfrd::search(branches_,fusepath_,paths_); } diff --git a/src/policy_eppfrd.hpp b/src/policy_eppfrd.hpp index f3b6cbc3..972701ea 100644 --- a/src/policy_eppfrd.hpp +++ b/src/policy_eppfrd.hpp @@ -32,7 +32,9 @@ namespace Policy {} public: - int operator()(const Branches::CPtr&,const char*,StrVec*) const final; + int operator()(const Branches::Ptr&, + const char*, + std::vector&) const final; }; class Create final : public Policy::CreateImpl @@ -43,7 +45,9 @@ namespace Policy {} public: - int operator()(const Branches::CPtr&,const char*,StrVec*) const final; + int operator()(const Branches::Ptr&, + const char*, + std::vector&) const final; bool path_preserving(void) const final { return true; } }; @@ -55,7 +59,9 @@ namespace Policy {} public: - int operator()(const Branches::CPtr&,const char*,StrVec*) const final; + int operator()(const Branches::Ptr&, + const char*, + std::vector&) const final; }; } } diff --git a/src/policy_eprand.cpp b/src/policy_eprand.cpp index 00d1e556..e334e2bc 100644 --- a/src/policy_eprand.cpp +++ b/src/policy_eprand.cpp @@ -22,43 +22,43 @@ int -Policy::EPRand::Action::operator()(const Branches::CPtr &branches_, +Policy::EPRand::Action::operator()(const Branches::Ptr &branches_, const char *fusepath_, - StrVec *paths_) const + std::vector &paths_) const { int rv; rv = Policies::Action::epall(branches_,fusepath_,paths_); if(rv == 0) - RND::shrink_to_rand_elem(*paths_); + RND::shrink_to_rand_elem(paths_); return rv; } int -Policy::EPRand::Create::operator()(const Branches::CPtr &branches_, +Policy::EPRand::Create::operator()(const Branches::Ptr &branches_, const char *fusepath_, - StrVec *paths_) const + std::vector &paths_) const { int rv; rv = Policies::Create::epall(branches_,fusepath_,paths_); if(rv == 0) - RND::shrink_to_rand_elem(*paths_); + RND::shrink_to_rand_elem(paths_); return rv; } int -Policy::EPRand::Search::operator()(const Branches::CPtr &branches_, +Policy::EPRand::Search::operator()(const Branches::Ptr &branches_, const char *fusepath_, - StrVec *paths_) const + std::vector &paths_) const { int rv; rv = Policies::Search::epall(branches_,fusepath_,paths_); if(rv == 0) - RND::shrink_to_rand_elem(*paths_); + RND::shrink_to_rand_elem(paths_); return rv; } diff --git a/src/policy_eprand.hpp b/src/policy_eprand.hpp index f0a62b4f..eed5cdc5 100644 --- a/src/policy_eprand.hpp +++ b/src/policy_eprand.hpp @@ -32,7 +32,9 @@ namespace Policy {} public: - int operator()(const Branches::CPtr&,const char*,StrVec*) const final; + int operator()(const Branches::Ptr&, + const char*, + std::vector&) const final; }; class Create final : public Policy::CreateImpl @@ -43,7 +45,9 @@ namespace Policy {} public: - int operator()(const Branches::CPtr&,const char*,StrVec*) const final; + int operator()(const Branches::Ptr&, + const char*, + std::vector&) const final; bool path_preserving(void) const final { return true; } }; @@ -55,7 +59,9 @@ namespace Policy {} public: - int operator()(const Branches::CPtr&,const char*,StrVec*) const final; + int operator()(const Branches::Ptr&, + const char*, + std::vector&) const final; }; } } diff --git a/src/policy_erofs.cpp b/src/policy_erofs.cpp index 27376be3..6bd53e45 100644 --- a/src/policy_erofs.cpp +++ b/src/policy_erofs.cpp @@ -24,25 +24,25 @@ using std::string; int -Policy::ERoFS::Action::operator()(const Branches::CPtr &branches_, +Policy::ERoFS::Action::operator()(const Branches::Ptr &branches_, const char *fusepath_, - StrVec *paths_) const + std::vector &paths_) const { return (errno=EROFS,-1); } int -Policy::ERoFS::Create::operator()(const Branches::CPtr &branches_, +Policy::ERoFS::Create::operator()(const Branches::Ptr &branches_, const char *fusepath_, - StrVec *paths_) const + std::vector &paths_) const { return (errno=EROFS,-1); } int -Policy::ERoFS::Search::operator()(const Branches::CPtr &branches_, +Policy::ERoFS::Search::operator()(const Branches::Ptr &branches_, const char *fusepath_, - StrVec *paths_) const + std::vector &paths_) const { return (errno=EROFS,-1); } diff --git a/src/policy_erofs.hpp b/src/policy_erofs.hpp index f17f4053..b8a4af3d 100644 --- a/src/policy_erofs.hpp +++ b/src/policy_erofs.hpp @@ -32,7 +32,9 @@ namespace Policy {} public: - int operator()(const Branches::CPtr&,const char*,StrVec*) const final; + int operator()(const Branches::Ptr&, + const char*, + std::vector&) const final; }; class Create final : public Policy::CreateImpl @@ -43,7 +45,9 @@ namespace Policy {} public: - int operator()(const Branches::CPtr&,const char*,StrVec*) const final; + int operator()(const Branches::Ptr&, + const char*, + std::vector&) const final; bool path_preserving(void) const final { return false; } }; @@ -55,7 +59,9 @@ namespace Policy {} public: - int operator()(const Branches::CPtr&,const char*,StrVec*) const final; + int operator()(const Branches::Ptr&, + const char*, + std::vector&) const final; }; } } diff --git a/src/policy_ff.cpp b/src/policy_ff.cpp index 4cf00b32..61881927 100644 --- a/src/policy_ff.cpp +++ b/src/policy_ff.cpp @@ -25,21 +25,20 @@ #include -using std::string; namespace ff { static int - create(const Branches::CPtr &branches_, - StrVec *paths_) + create(const Branches::Ptr &ibranches_, + std::vector &obranches_) { int rv; int error; fs::info_t info; error = ENOENT; - for(auto &branch : *branches_) + for(auto &branch : *ibranches_) { if(branch.ro_or_nc()) error_and_continue(error,EROFS); @@ -51,7 +50,7 @@ namespace ff if(info.spaceavail < branch.minfreespace()) error_and_continue(error,ENOSPC); - paths_->push_back(branch.path); + obranches_.emplace_back(&branch); return 0; } @@ -61,25 +60,35 @@ namespace ff } int -Policy::FF::Action::operator()(const Branches::CPtr &branches_, +Policy::FF::Action::operator()(const Branches::Ptr &branches_, const char *fusepath_, - StrVec *paths_) const + std::vector &paths_) const { return Policies::Action::epff(branches_,fusepath_,paths_); } int -Policy::FF::Create::operator()(const Branches::CPtr &branches_, +Policy::FF::Create::operator()(const Branches::Ptr &branches_, const char *fusepath_, - StrVec *paths_) const + std::vector &paths_) const { return ::ff::create(branches_,paths_); } int -Policy::FF::Search::operator()(const Branches::CPtr &branches_, +Policy::FF::Search::operator()(const Branches::Ptr &branches_, const char *fusepath_, - StrVec *paths_) const + std::vector &output_) const { - return Policies::Search::epff(branches_,fusepath_,paths_); + for(auto &branch : *branches_) + { + if(!fs::exists(branch.path,fusepath_)) + continue; + + output_.emplace_back(&branch); + + return 0; + } + + return (errno=ENOENT,-1); } diff --git a/src/policy_ff.hpp b/src/policy_ff.hpp index 1b0db87f..61a32ef4 100644 --- a/src/policy_ff.hpp +++ b/src/policy_ff.hpp @@ -32,7 +32,9 @@ namespace Policy {} public: - int operator()(const Branches::CPtr&,const char*,StrVec*) const final; + int operator()(const Branches::Ptr&, + const char*, + std::vector&) const final; }; class Create final : public Policy::CreateImpl @@ -43,8 +45,11 @@ namespace Policy {} public: - int operator()(const Branches::CPtr&,const char*,StrVec*) const final; bool path_preserving(void) const final { return false; } + int operator()(const Branches::Ptr&, + const char*, + std::vector&) const final; + }; class Search final : public Policy::SearchImpl @@ -55,7 +60,9 @@ namespace Policy {} public: - int operator()(const Branches::CPtr&,const char*,StrVec*) const final; + int operator()(const Branches::Ptr&, + const char*, + std::vector&) const final; }; } } diff --git a/src/policy_lfs.cpp b/src/policy_lfs.cpp index 9a931007..bf4f45c0 100644 --- a/src/policy_lfs.cpp +++ b/src/policy_lfs.cpp @@ -27,25 +27,24 @@ #include #include -using std::string; namespace lfs { static int - create(const Branches::CPtr &branches_, - StrVec *paths_) + create(const Branches::Ptr &branches_, + std::vector &paths_) { int rv; int error; uint64_t lfs; fs::info_t info; - const string *basepath; + Branch *obranch; + obranch = nullptr; error = ENOENT; lfs = std::numeric_limits::max(); - basepath = NULL; - for(const auto &branch : *branches_) + for(auto &branch : *branches_) { if(branch.ro_or_nc()) error_and_continue(error,EROFS); @@ -60,38 +59,38 @@ namespace lfs continue; lfs = info.spaceavail; - basepath = &branch.path; + obranch = &branch; } - if(basepath == NULL) + if(!obranch) return (errno=error,-1); - paths_->push_back(*basepath); + paths_.push_back(obranch); return 0; } } int -Policy::LFS::Action::operator()(const Branches::CPtr &branches_, +Policy::LFS::Action::operator()(const Branches::Ptr &branches_, const char *fusepath_, - StrVec *paths_) const + std::vector &paths_) const { return Policies::Action::eplfs(branches_,fusepath_,paths_); } int -Policy::LFS::Create::operator()(const Branches::CPtr &branches_, +Policy::LFS::Create::operator()(const Branches::Ptr &branches_, const char *fusepath_, - StrVec *paths_) const + std::vector &paths_) const { return ::lfs::create(branches_,paths_); } int -Policy::LFS::Search::operator()(const Branches::CPtr &branches_, +Policy::LFS::Search::operator()(const Branches::Ptr &branches_, const char *fusepath_, - StrVec *paths_) const + std::vector &paths_) const { return Policies::Search::eplfs(branches_,fusepath_,paths_); } diff --git a/src/policy_lfs.hpp b/src/policy_lfs.hpp index e0b456ef..b9aac6d6 100644 --- a/src/policy_lfs.hpp +++ b/src/policy_lfs.hpp @@ -32,7 +32,9 @@ namespace Policy {} public: - int operator()(const Branches::CPtr&,const char*,StrVec*) const final; + int operator()(const Branches::Ptr&, + const char*, + std::vector&) const final; }; class Create final : public Policy::CreateImpl @@ -43,7 +45,9 @@ namespace Policy {} public: - int operator()(const Branches::CPtr&,const char*,StrVec*) const final; + int operator()(const Branches::Ptr&, + const char*, + std::vector&) const final; bool path_preserving() const final { return false; } }; @@ -55,7 +59,9 @@ namespace Policy {} public: - int operator()(const Branches::CPtr&,const char*,StrVec*) const final; + int operator()(const Branches::Ptr&, + const char*, + std::vector&) const final; }; } } diff --git a/src/policy_lus.cpp b/src/policy_lus.cpp index c23570aa..428a38e8 100644 --- a/src/policy_lus.cpp +++ b/src/policy_lus.cpp @@ -35,18 +35,18 @@ namespace lus { static int - create(const Branches::CPtr &branches_, - StrVec *paths_) + create(const Branches::Ptr &branches_, + std::vector &paths_) { int rv; int error; uint64_t lus; fs::info_t info; - const string *basepath; + Branch *obranch; + obranch = nullptr; error = ENOENT; lus = std::numeric_limits::max(); - basepath = NULL; for(auto &branch : *branches_) { if(branch.ro_or_nc()) @@ -61,39 +61,39 @@ namespace lus if(info.spaceused >= lus) continue; - lus = info.spaceused; - basepath = &branch.path; + lus = info.spaceused; + obranch = &branch; } - if(basepath == NULL) + if(!obranch) return (errno=error,-1); - paths_->push_back(*basepath); + paths_.push_back(obranch); return 0; } } int -Policy::LUS::Action::operator()(const Branches::CPtr &branches_, +Policy::LUS::Action::operator()(const Branches::Ptr &branches_, const char *fusepath_, - StrVec *paths_) const + std::vector &paths_) const { return Policies::Action::eplus(branches_,fusepath_,paths_); } int -Policy::LUS::Create::operator()(const Branches::CPtr &branches_, +Policy::LUS::Create::operator()(const Branches::Ptr &branches_, const char *fusepath_, - StrVec *paths_) const + std::vector &paths_) const { return ::lus::create(branches_,paths_); } int -Policy::LUS::Search::operator()(const Branches::CPtr &branches_, +Policy::LUS::Search::operator()(const Branches::Ptr &branches_, const char *fusepath_, - StrVec *paths_) const + std::vector &paths_) const { return Policies::Search::eplus(branches_,fusepath_,paths_); } diff --git a/src/policy_lus.hpp b/src/policy_lus.hpp index b6c07717..9c17e999 100644 --- a/src/policy_lus.hpp +++ b/src/policy_lus.hpp @@ -32,7 +32,9 @@ namespace Policy {} public: - int operator()(const Branches::CPtr&,const char*,StrVec*) const final; + int operator()(const Branches::Ptr&, + const char*, + std::vector&) const final; }; class Create final : public Policy::CreateImpl @@ -43,7 +45,9 @@ namespace Policy {} public: - int operator()(const Branches::CPtr&,const char*,StrVec*) const final; + int operator()(const Branches::Ptr&, + const char*, + std::vector&) const final; bool path_preserving() const final { return false; } }; @@ -55,7 +59,9 @@ namespace Policy {} public: - int operator()(const Branches::CPtr&,const char*,StrVec*) const final; + int operator()(const Branches::Ptr&, + const char*, + std::vector&) const final; }; } } diff --git a/src/policy_mfs.cpp b/src/policy_mfs.cpp index e59c1c75..0fee9047 100644 --- a/src/policy_mfs.cpp +++ b/src/policy_mfs.cpp @@ -30,19 +30,19 @@ namespace mfs { static int - create(const Branches::CPtr &branches_, - StrVec *paths_) + create(const Branches::Ptr &branches_, + std::vector &paths_) { int rv; int error; - uint64_t mfs; + u64 mfs; fs::info_t info; - const string *basepath; + Branch *obranch; + obranch = nullptr; error = ENOENT; mfs = 0; - basepath = NULL; - for(const auto &branch : *branches_) + for(auto &branch : *branches_) { if(branch.ro_or_nc()) error_and_continue(error,EROFS); @@ -57,38 +57,38 @@ namespace mfs continue; mfs = info.spaceavail; - basepath = &branch.path; + obranch = &branch; } - if(basepath == NULL) + if(!obranch) return (errno=error,-1); - paths_->push_back(*basepath); + paths_.push_back(obranch); return 0; } } int -Policy::MFS::Action::operator()(const Branches::CPtr &branches_, +Policy::MFS::Action::operator()(const Branches::Ptr &branches_, const char *fusepath_, - StrVec *paths_) const + std::vector &paths_) const { return Policies::Action::epmfs(branches_,fusepath_,paths_); } int -Policy::MFS::Create::operator()(const Branches::CPtr &branches_, +Policy::MFS::Create::operator()(const Branches::Ptr &branches_, const char *fusepath_, - StrVec *paths_) const + std::vector &paths_) const { return ::mfs::create(branches_,paths_); } int -Policy::MFS::Search::operator()(const Branches::CPtr &branches_, +Policy::MFS::Search::operator()(const Branches::Ptr &branches_, const char *fusepath_, - StrVec *paths_) const + std::vector &paths_) const { return Policies::Search::epmfs(branches_,fusepath_,paths_); } diff --git a/src/policy_mfs.hpp b/src/policy_mfs.hpp index 9247f77a..f3e4d833 100644 --- a/src/policy_mfs.hpp +++ b/src/policy_mfs.hpp @@ -32,7 +32,9 @@ namespace Policy {} public: - int operator()(const Branches::CPtr&,const char*,StrVec*) const final; + int operator()(const Branches::Ptr&, + const char*, + std::vector&) const final; }; class Create final : public Policy::CreateImpl @@ -43,7 +45,9 @@ namespace Policy {} public: - int operator()(const Branches::CPtr&,const char*,StrVec*) const final; + int operator()(const Branches::Ptr&, + const char*, + std::vector&) const final; bool path_preserving() const final { return false; } }; @@ -55,7 +59,9 @@ namespace Policy {} public: - int operator()(const Branches::CPtr&,const char*,StrVec*) const final; + int operator()(const Branches::Ptr&, + const char*, + std::vector&) const final; }; } } diff --git a/src/policy_msplfs.cpp b/src/policy_msplfs.cpp index 27039a62..ff782163 100644 --- a/src/policy_msplfs.cpp +++ b/src/policy_msplfs.cpp @@ -28,26 +28,23 @@ #include #include -using std::string; - namespace msplfs { static - const - string* - create_1(const Branches::CPtr &branches_, - const string &fusepath_, - int *err_) + Branch* + create_1(const Branches::Ptr &branches_, + const std::string &fusepath_, + int *err_) { int rv; uint64_t lfs; fs::info_t info; - const string *basepath; + Branch *obranch; - basepath = NULL; + obranch = nullptr; lfs = std::numeric_limits::max(); - for(const auto &branch : *branches_) + for(auto &branch : *branches_) { if(branch.ro_or_nc()) error_and_continue(*err_,EROFS); @@ -64,63 +61,63 @@ namespace msplfs continue; lfs = info.spaceavail; - basepath = &branch.path; + obranch = &branch; } - return basepath; + return obranch; } static int - create(const Branches::CPtr &branches_, + create(const Branches::Ptr &branches_, const char *fusepath_, - StrVec *paths_) + std::vector &paths_) { int error; - string fusepath; - const string *basepath; + Branch *branch; + std::string fusepath; error = ENOENT; fusepath = fusepath_; for(;;) { - basepath = msplfs::create_1(branches_,fusepath,&error); - if(basepath) + branch = msplfs::create_1(branches_,fusepath,&error); + if(branch) break; if(fusepath == "/") break; fusepath = fs::path::dirname(fusepath); } - if(basepath == NULL) + if(!branch) return (errno=error,-1); - paths_->push_back(*basepath); + paths_.push_back(branch); return 0; } } int -Policy::MSPLFS::Action::operator()(const Branches::CPtr &branches_, +Policy::MSPLFS::Action::operator()(const Branches::Ptr &branches_, const char *fusepath_, - StrVec *paths_) const + std::vector &paths_) const { return Policies::Action::eplfs(branches_,fusepath_,paths_); } int -Policy::MSPLFS::Create::operator()(const Branches::CPtr &branches_, +Policy::MSPLFS::Create::operator()(const Branches::Ptr &branches_, const char *fusepath_, - StrVec *paths_) const + std::vector &paths_) const { return ::msplfs::create(branches_,fusepath_,paths_); } int -Policy::MSPLFS::Search::operator()(const Branches::CPtr &branches_, +Policy::MSPLFS::Search::operator()(const Branches::Ptr &branches_, const char *fusepath_, - StrVec *paths_) const + std::vector &paths_) const { return Policies::Search::eplfs(branches_,fusepath_,paths_); } diff --git a/src/policy_msplfs.hpp b/src/policy_msplfs.hpp index 7e0a8d3e..bbdbee99 100644 --- a/src/policy_msplfs.hpp +++ b/src/policy_msplfs.hpp @@ -32,7 +32,9 @@ namespace Policy {} public: - int operator()(const Branches::CPtr&,const char*,StrVec*) const final; + int operator()(const Branches::Ptr&, + const char*, + std::vector&) const final; }; class Create final : public Policy::CreateImpl @@ -43,7 +45,9 @@ namespace Policy {} public: - int operator()(const Branches::CPtr&,const char*,StrVec*) const final; + int operator()(const Branches::Ptr&, + const char*, + std::vector&) const final; bool path_preserving() const final { return true; } }; @@ -55,7 +59,9 @@ namespace Policy {} public: - int operator()(const Branches::CPtr&,const char*,StrVec*) const final; + int operator()(const Branches::Ptr&, + const char*, + std::vector&) const final; }; } } diff --git a/src/policy_msplus.cpp b/src/policy_msplus.cpp index e6e0cb87..b80f2d5f 100644 --- a/src/policy_msplus.cpp +++ b/src/policy_msplus.cpp @@ -27,23 +27,21 @@ #include #include -using std::string; namespace msplus { static - const - string* - create_1(const Branches::CPtr &branches_, - const string &fusepath_, - int *err_) + Branch* + create_1(const Branches::Ptr &branches_, + const std::string &fusepath_, + int *err_) { int rv; uint64_t lus; fs::info_t info; - const string *basepath; + Branch *obranch; - basepath = NULL; + obranch = nullptr; lus = std::numeric_limits::max(); for(auto &branch : *branches_) { @@ -61,64 +59,64 @@ namespace msplus if(info.spaceused >= lus) continue; - lus = info.spaceused;; - basepath = &branch.path; + lus = info.spaceused; + obranch = &branch; } - return basepath; + return obranch; } static int - create(const Branches::CPtr &branches_, + create(const Branches::Ptr &branches_, const char *fusepath_, - StrVec *paths_) + std::vector &paths_) { int error; - string fusepath; - const string *basepath; + Branch *branch; + std::string fusepath; error = ENOENT; fusepath = fusepath_; for(;;) { - basepath = msplus::create_1(branches_,fusepath,&error); - if(basepath) + branch = msplus::create_1(branches_,fusepath,&error); + if(branch) break; if(fusepath == "/") break; fusepath = fs::path::dirname(fusepath); } - if(basepath == NULL) + if(!branch) return (errno=error,-1); - paths_->push_back(*basepath); + paths_.emplace_back(branch); return 0; } } int -Policy::MSPLUS::Action::operator()(const Branches::CPtr &branches_, +Policy::MSPLUS::Action::operator()(const Branches::Ptr &branches_, const char *fusepath_, - StrVec *paths_) const + std::vector &paths_) const { return Policies::Action::eplus(branches_,fusepath_,paths_); } int -Policy::MSPLUS::Create::operator()(const Branches::CPtr &branches_, +Policy::MSPLUS::Create::operator()(const Branches::Ptr &branches_, const char *fusepath_, - StrVec *paths_) const + std::vector &paths_) const { return ::msplus::create(branches_,fusepath_,paths_); } int -Policy::MSPLUS::Search::operator()(const Branches::CPtr &branches_, +Policy::MSPLUS::Search::operator()(const Branches::Ptr &branches_, const char *fusepath_, - StrVec *paths_) const + std::vector &paths_) const { return Policies::Search::eplus(branches_,fusepath_,paths_); } diff --git a/src/policy_msplus.hpp b/src/policy_msplus.hpp index 5ccf06eb..74c72da5 100644 --- a/src/policy_msplus.hpp +++ b/src/policy_msplus.hpp @@ -32,7 +32,9 @@ namespace Policy {} public: - int operator()(const Branches::CPtr&,const char*,StrVec*) const final; + int operator()(const Branches::Ptr&, + const char*, + std::vector&) const final; }; class Create final : public Policy::CreateImpl @@ -43,7 +45,9 @@ namespace Policy {} public: - int operator()(const Branches::CPtr&,const char*,StrVec*) const final; + int operator()(const Branches::Ptr&, + const char*, + std::vector&) const final; bool path_preserving() const final { return true; } }; @@ -55,7 +59,9 @@ namespace Policy {} public: - int operator()(const Branches::CPtr&,const char*,StrVec*) const final; + int operator()(const Branches::Ptr&, + const char*, + std::vector&) const final; }; } } diff --git a/src/policy_mspmfs.cpp b/src/policy_mspmfs.cpp index ec00f496..3cbc6e50 100644 --- a/src/policy_mspmfs.cpp +++ b/src/policy_mspmfs.cpp @@ -28,27 +28,22 @@ #include #include -using std::string; -using std::vector; - namespace mspmfs { static - const - string* - create_1(const Branches::CPtr &branches_, - const string &fusepath_, - int *err_) + Branch* + create_1(const Branches::Ptr &branches_, + const std::string &fusepath_, + int *err_) { int rv; uint64_t mfs; fs::info_t info; - const string *basepath; + Branch *obranch; - basepath = NULL; mfs = std::numeric_limits::min(); - for(const auto &branch : *branches_) + for(auto &branch : *branches_) { if(branch.ro_or_nc()) error_and_continue(*err_,EROFS); @@ -65,63 +60,63 @@ namespace mspmfs continue; mfs = info.spaceavail; - basepath = &branch.path; + obranch = &branch; } - return basepath; + return obranch; } static int - create(const Branches::CPtr &branches_, + create(const Branches::Ptr &branches_, const char *fusepath_, - StrVec *paths_) + std::vector &paths_) { int error; - string fusepath; - const string *basepath; + std::string fusepath; + Branch *branch; error = ENOENT; fusepath = fusepath_; for(;;) { - basepath = mspmfs::create_1(branches_,fusepath,&error); - if(basepath) + branch = mspmfs::create_1(branches_,fusepath,&error); + if(branch) break; if(fusepath == "/") break; fusepath = fs::path::dirname(fusepath); } - if(basepath == NULL) + if(!branch) return (errno=error,-1); - paths_->push_back(*basepath); + paths_.emplace_back(branch); return 0; } } int -Policy::MSPMFS::Action::operator()(const Branches::CPtr &branches_, +Policy::MSPMFS::Action::operator()(const Branches::Ptr &branches_, const char *fusepath_, - StrVec *paths_) const + std::vector &paths_) const { return Policies::Action::epmfs(branches_,fusepath_,paths_); } int -Policy::MSPMFS::Create::operator()(const Branches::CPtr &branches_, +Policy::MSPMFS::Create::operator()(const Branches::Ptr &branches_, const char *fusepath_, - StrVec *paths_) const + std::vector &paths_) const { return ::mspmfs::create(branches_,fusepath_,paths_); } int -Policy::MSPMFS::Search::operator()(const Branches::CPtr &branches_, +Policy::MSPMFS::Search::operator()(const Branches::Ptr &branches_, const char *fusepath_, - StrVec *paths_) const + std::vector &paths_) const { return Policies::Search::epmfs(branches_,fusepath_,paths_); } diff --git a/src/policy_mspmfs.hpp b/src/policy_mspmfs.hpp index 3123e952..fcb73fd1 100644 --- a/src/policy_mspmfs.hpp +++ b/src/policy_mspmfs.hpp @@ -32,7 +32,9 @@ namespace Policy {} public: - int operator()(const Branches::CPtr&,const char*,StrVec*) const final; + int operator()(const Branches::Ptr&, + const char*, + std::vector&) const final; }; class Create final : public Policy::CreateImpl @@ -43,7 +45,9 @@ namespace Policy {} public: - int operator()(const Branches::CPtr&,const char*,StrVec*) const final; + int operator()(const Branches::Ptr&, + const char*, + std::vector&) const final; bool path_preserving() const final { return true; } }; @@ -55,7 +59,9 @@ namespace Policy {} public: - int operator()(const Branches::CPtr&,const char*,StrVec*) const final; + int operator()(const Branches::Ptr&, + const char*, + std::vector&) const final; }; } } diff --git a/src/policy_msppfrd.cpp b/src/policy_msppfrd.cpp index ea6d770f..3a4322bd 100644 --- a/src/policy_msppfrd.cpp +++ b/src/policy_msppfrd.cpp @@ -30,29 +30,26 @@ #include #include -using std::string; -using std::vector; struct BranchInfo { - uint64_t spaceavail; - const string *basepath; + u64 spaceavail; + Branch *branch; }; -typedef vector BranchInfoVec; +typedef std::vector BranchInfoVec; namespace msppfrd { static int - create_1(const Branches::CPtr &branches_, - const string &fusepath_, - BranchInfoVec *branchinfo_, - uint64_t *sum_) + create_1(const Branches::Ptr &branches_, + const std::string &fusepath_, + BranchInfoVec *branchinfo_, + uint64_t *sum_) { int rv; int error; - BranchInfo bi; fs::info_t info; *sum_ = 0; @@ -73,9 +70,7 @@ namespace msppfrd *sum_ += info.spaceavail; - bi.spaceavail = info.spaceavail; - bi.basepath = &branch.path; - branchinfo_->push_back(bi); + branchinfo_->push_back({info.spaceavail,&branch}); } return error; @@ -83,13 +78,13 @@ namespace msppfrd static int - get_branchinfo(const Branches::CPtr &branches_, - const char *fusepath_, - BranchInfoVec *branchinfo_, - uint64_t *sum_) + get_branchinfo(const Branches::Ptr &branches_, + const char *fusepath_, + BranchInfoVec *branchinfo_, + uint64_t *sum_) { int error; - string fusepath; + std::string fusepath; fusepath = fusepath_; for(;;) @@ -106,8 +101,7 @@ namespace msppfrd } static - const - string* + Branch* get_branch(const BranchInfoVec &branchinfo_, const uint64_t sum_) { @@ -115,7 +109,7 @@ namespace msppfrd uint64_t threshold; if(sum_ == 0) - return NULL; + return nullptr; idx = 0; threshold = RND::rand64(sum_); @@ -126,54 +120,54 @@ namespace msppfrd if(idx < threshold) continue; - return branchinfo_[i].basepath; + return branchinfo_[i].branch; } - return NULL; + return nullptr; } static int - create(const Branches::CPtr &branches_, + create(const Branches::Ptr &branches_, const char *fusepath_, - StrVec *paths_) + std::vector &paths_) { int error; uint64_t sum; - const string *basepath; + Branch *branch; BranchInfoVec branchinfo; - error = msppfrd::get_branchinfo(branches_,fusepath_,&branchinfo,&sum); - basepath = msppfrd::get_branch(branchinfo,sum); - if(basepath == NULL) + error = msppfrd::get_branchinfo(branches_,fusepath_,&branchinfo,&sum); + branch = msppfrd::get_branch(branchinfo,sum); + if(!branch) return (errno=error,-1); - paths_->push_back(*basepath); + paths_.emplace_back(branch); return 0; } } int -Policy::MSPPFRD::Action::operator()(const Branches::CPtr &branches_, +Policy::MSPPFRD::Action::operator()(const Branches::Ptr &branches_, const char *fusepath_, - StrVec *paths_) const + std::vector &paths_) const { return Policies::Action::eppfrd(branches_,fusepath_,paths_); } int -Policy::MSPPFRD::Create::operator()(const Branches::CPtr &branches_, +Policy::MSPPFRD::Create::operator()(const Branches::Ptr &branches_, const char *fusepath_, - StrVec *paths_) const + std::vector &paths_) const { return ::msppfrd::create(branches_,fusepath_,paths_); } int -Policy::MSPPFRD::Search::operator()(const Branches::CPtr &branches_, +Policy::MSPPFRD::Search::operator()(const Branches::Ptr &branches_, const char *fusepath_, - StrVec *paths_) const + std::vector &paths_) const { return Policies::Search::eppfrd(branches_,fusepath_,paths_); } diff --git a/src/policy_msppfrd.hpp b/src/policy_msppfrd.hpp index d357d033..f9eb6b6e 100644 --- a/src/policy_msppfrd.hpp +++ b/src/policy_msppfrd.hpp @@ -32,7 +32,9 @@ namespace Policy {} public: - int operator()(const Branches::CPtr&,const char*,StrVec*) const final; + int operator()(const Branches::Ptr&, + const char*, + std::vector&) const final; }; class Create final : public Policy::CreateImpl @@ -43,7 +45,9 @@ namespace Policy {} public: - int operator()(const Branches::CPtr&,const char*,StrVec*) const final; + int operator()(const Branches::Ptr&, + const char*, + std::vector&) const final; bool path_preserving() const final { return true; }; }; @@ -55,7 +59,9 @@ namespace Policy {} public: - int operator()(const Branches::CPtr&,const char*,StrVec*) const final; + int operator()(const Branches::Ptr&, + const char*, + std::vector&) const final; }; } } diff --git a/src/policy_newest.cpp b/src/policy_newest.cpp index f65e0f66..542c9d9f 100644 --- a/src/policy_newest.cpp +++ b/src/policy_newest.cpp @@ -35,20 +35,20 @@ namespace newest { static int - create(const Branches::CPtr &branches_, + create(const Branches::Ptr &branches_, const char *fusepath_, - StrVec *paths_) + std::vector &paths_) { int rv; int error; time_t newest; struct stat st; fs::info_t info; - const string *basepath; + Branch *obranch; + obranch = nullptr; error = ENOENT; newest = std::numeric_limits::min(); - basepath = NULL; for(auto &branch : *branches_) { if(branch.ro_or_nc()) @@ -66,33 +66,33 @@ namespace newest error_and_continue(error,ENOSPC); newest = st.st_mtime; - basepath = &branch.path; + obranch = &branch; } - if(basepath == NULL) + if(!obranch) return (errno=error,-1); - paths_->push_back(*basepath); + paths_.emplace_back(obranch); return 0; } static int - action(const Branches::CPtr &branches_, + action(const Branches::Ptr &branches_, const char *fusepath_, - StrVec *paths_) + std::vector &paths_) { int rv; int error; bool readonly; time_t newest; struct stat st; - const string *basepath; + Branch *obranch; + obranch = nullptr; error = ENOENT; newest = std::numeric_limits::min(); - basepath = NULL; for(auto &branch : *branches_) { if(branch.ro()) @@ -108,29 +108,29 @@ namespace newest error_and_continue(error,EROFS); newest = st.st_mtime; - basepath = &branch.path; + obranch = &branch; } - if(basepath == NULL) + if(!obranch) return (errno=error,-1); - paths_->push_back(*basepath); + paths_.emplace_back(obranch); return 0; } static int - search(const Branches::CPtr &branches_, + search(const Branches::Ptr &branches_, const char *fusepath_, - StrVec *paths_) + std::vector &paths_) { time_t newest; struct stat st; - const string *basepath; + Branch *obranch; + obranch = nullptr; newest = std::numeric_limits::min(); - basepath = NULL; for(auto &branch : *branches_) { if(!fs::exists(branch.path,fusepath_,&st)) @@ -139,38 +139,38 @@ namespace newest continue; newest = st.st_mtime; - basepath = &branch.path; + obranch = &branch; } - if(basepath == NULL) + if(!obranch) return (errno=ENOENT,-1); - paths_->push_back(*basepath); + paths_.emplace_back(obranch); return 0; } } int -Policy::Newest::Action::operator()(const Branches::CPtr &branches_, +Policy::Newest::Action::operator()(const Branches::Ptr &branches_, const char *fusepath_, - StrVec *paths_) const + std::vector &paths_) const { return ::newest::action(branches_,fusepath_,paths_); } int -Policy::Newest::Create::operator()(const Branches::CPtr &branches_, +Policy::Newest::Create::operator()(const Branches::Ptr &branches_, const char *fusepath_, - StrVec *paths_) const + std::vector &paths_) const { return ::newest::create(branches_,fusepath_,paths_); } int -Policy::Newest::Search::operator()(const Branches::CPtr &branches_, +Policy::Newest::Search::operator()(const Branches::Ptr &branches_, const char *fusepath_, - StrVec *paths_) const + std::vector &paths_) const { return ::newest::search(branches_,fusepath_,paths_); } diff --git a/src/policy_newest.hpp b/src/policy_newest.hpp index c4baf298..8a5fec33 100644 --- a/src/policy_newest.hpp +++ b/src/policy_newest.hpp @@ -32,7 +32,9 @@ namespace Policy {} public: - int operator()(const Branches::CPtr&,const char*,StrVec*) const final; + int operator()(const Branches::Ptr&, + const char*, + std::vector&) const final; }; class Create final : public Policy::CreateImpl @@ -43,7 +45,9 @@ namespace Policy {} public: - int operator()(const Branches::CPtr&,const char*,StrVec*) const final; + int operator()(const Branches::Ptr&, + const char*, + std::vector&) const final; bool path_preserving() const final { return false; } }; @@ -55,7 +59,9 @@ namespace Policy {} public: - int operator()(const Branches::CPtr&,const char*,StrVec*) const final; + int operator()(const Branches::Ptr&, + const char*, + std::vector&) const final; }; } } diff --git a/src/policy_pfrd.cpp b/src/policy_pfrd.cpp index 45d03051..5631a0d3 100644 --- a/src/policy_pfrd.cpp +++ b/src/policy_pfrd.cpp @@ -27,28 +27,25 @@ #include #include -using std::string; -using std::vector; struct BranchInfo { - uint64_t spaceavail; - const string *basepath; + uint64_t spaceavail; + Branch *branch; }; -typedef vector BranchInfoVec; +typedef std::vector BranchInfoVec; namespace pfrd { static int - get_branchinfo(const Branches::CPtr &branches_, - BranchInfoVec *branchinfo_, - uint64_t *sum_) + get_branchinfo(const Branches::Ptr &branches_, + BranchInfoVec *branchinfo_, + uint64_t *sum_) { int rv; int error; - BranchInfo bi; fs::info_t info; *sum_ = 0; @@ -67,17 +64,14 @@ namespace pfrd *sum_ += info.spaceavail; - bi.spaceavail = info.spaceavail; - bi.basepath = &branch.path; - branchinfo_->push_back(bi); + branchinfo_->push_back({info.spaceavail,&branch}); } return error; } static - const - string* + Branch* get_branch(const BranchInfoVec &branchinfo_, const uint64_t sum_) { @@ -85,65 +79,65 @@ namespace pfrd uint64_t threshold; if(sum_ == 0) - return NULL; + return nullptr; idx = 0; threshold = RND::rand64(sum_); - for(size_t i = 0; i < branchinfo_.size(); i++) + for(auto &bi : branchinfo_) { - idx += branchinfo_[i].spaceavail; + idx += bi.spaceavail; if(idx < threshold) continue; - return branchinfo_[i].basepath; + return bi.branch; } - return NULL; + return nullptr; } static int - create(const Branches::CPtr &branches_, + create(const Branches::Ptr &branches_, const char *fusepath_, - StrVec *paths_) + std::vector &paths_) { int error; uint64_t sum; - const string *basepath; + Branch *branch; BranchInfoVec branchinfo; - error = pfrd::get_branchinfo(branches_,&branchinfo,&sum); - basepath = pfrd::get_branch(branchinfo,sum); - if(basepath == NULL) + error = pfrd::get_branchinfo(branches_,&branchinfo,&sum); + branch = pfrd::get_branch(branchinfo,sum); + if(!branch) return (errno=error,-1); - paths_->push_back(*basepath); + paths_.emplace_back(branch); return 0; } } int -Policy::PFRD::Action::operator()(const Branches::CPtr &branches_, +Policy::PFRD::Action::operator()(const Branches::Ptr &branches_, const char *fusepath_, - StrVec *paths_) const + std::vector &paths_) const { return Policies::Action::eppfrd(branches_,fusepath_,paths_); } int -Policy::PFRD::Create::operator()(const Branches::CPtr &branches_, +Policy::PFRD::Create::operator()(const Branches::Ptr &branches_, const char *fusepath_, - StrVec *paths_) const + std::vector &paths_) const { return ::pfrd::create(branches_,fusepath_,paths_); } int -Policy::PFRD::Search::operator()(const Branches::CPtr &branches_, +Policy::PFRD::Search::operator()(const Branches::Ptr &branches_, const char *fusepath_, - StrVec *paths_) const + std::vector &paths_) const { return Policies::Search::eppfrd(branches_,fusepath_,paths_); } diff --git a/src/policy_pfrd.hpp b/src/policy_pfrd.hpp index 86b3c11c..e100ca12 100644 --- a/src/policy_pfrd.hpp +++ b/src/policy_pfrd.hpp @@ -32,7 +32,9 @@ namespace Policy {} public: - int operator()(const Branches::CPtr&,const char*,StrVec*) const final; + int operator()(const Branches::Ptr&, + const char*, + std::vector&) const final; }; class Create final : public Policy::CreateImpl @@ -43,7 +45,9 @@ namespace Policy {} public: - int operator()(const Branches::CPtr&,const char*,StrVec*) const final; + int operator()(const Branches::Ptr&, + const char*, + std::vector&) const final; bool path_preserving() const final { return false; } }; @@ -55,7 +59,9 @@ namespace Policy {} public: - int operator()(const Branches::CPtr&,const char*,StrVec*) const final; + int operator()(const Branches::Ptr&, + const char*, + std::vector&) const final; }; } } diff --git a/src/policy_rand.cpp b/src/policy_rand.cpp index f1aa12b4..8a6d9a2e 100644 --- a/src/policy_rand.cpp +++ b/src/policy_rand.cpp @@ -21,43 +21,43 @@ #include "rnd.hpp" int -Policy::Rand::Action::operator()(const Branches::CPtr &branches_, +Policy::Rand::Action::operator()(const Branches::Ptr &branches_, const char *fusepath_, - StrVec *paths_) const + std::vector &paths_) const { int rv; rv = Policies::Action::all(branches_,fusepath_,paths_); if(rv == 0) - RND::shrink_to_rand_elem(*paths_); + RND::shrink_to_rand_elem(paths_); return rv; } int -Policy::Rand::Create::operator()(const Branches::CPtr &branches_, +Policy::Rand::Create::operator()(const Branches::Ptr &branches_, const char *fusepath_, - StrVec *paths_) const + std::vector &paths_) const { int rv; rv = Policies::Create::all(branches_,fusepath_,paths_); if(rv == 0) - RND::shrink_to_rand_elem(*paths_); + RND::shrink_to_rand_elem(paths_); return rv; } int -Policy::Rand::Search::operator()(const Branches::CPtr &branches_, +Policy::Rand::Search::operator()(const Branches::Ptr &branches_, const char *fusepath_, - StrVec *paths_) const + std::vector &paths_) const { int rv; rv = Policies::Search::all(branches_,fusepath_,paths_); if(rv == 0) - RND::shrink_to_rand_elem(*paths_); + RND::shrink_to_rand_elem(paths_); return rv; } diff --git a/src/policy_rand.hpp b/src/policy_rand.hpp index 7d435433..ae319298 100644 --- a/src/policy_rand.hpp +++ b/src/policy_rand.hpp @@ -32,7 +32,9 @@ namespace Policy {} public: - int operator()(const Branches::CPtr&,const char*,StrVec*) const final; + int operator()(const Branches::Ptr&, + const char*, + std::vector&) const final; }; class Create final : public Policy::CreateImpl @@ -43,7 +45,9 @@ namespace Policy {} public: - int operator()(const Branches::CPtr&,const char*,StrVec*) const final; + int operator()(const Branches::Ptr&, + const char*, + std::vector&) const final; bool path_preserving() const final { return false; } }; @@ -55,7 +59,9 @@ namespace Policy {} public: - int operator()(const Branches::CPtr&,const char*,StrVec*) const final; + int operator()(const Branches::Ptr&, + const char*, + std::vector&) const final; }; } } diff --git a/src/policy_rv.hpp b/src/policy_rv.hpp index f4cea20b..71d1341b 100644 --- a/src/policy_rv.hpp +++ b/src/policy_rv.hpp @@ -36,16 +36,34 @@ struct PolicyRV std::string basepath; }; - std::vector success; - std::vector error; + std::vector successes; + std::vector errors; void insert(const int err_, const std::string &basepath_) { if(err_ == 0) - success.push_back(RV(err_,basepath_)); + successes.push_back({err_,basepath_}); else - error.push_back(RV(-err_,basepath_)); + errors.push_back({-err_,basepath_}); + } + + int + get_error(const std::string &basepath_) + { + for(const auto &s : successes) + { + if(s.basepath == basepath_) + return s.rv; + } + + for(const auto &e : errors) + { + if(e.basepath == basepath_) + return e.rv; + } + + return 0; } };