From 6cc6524997411e7dbd3704e8db81f863df970ff7 Mon Sep 17 00:00:00 2001 From: Antonio SJ Musumeci Date: Sun, 16 Aug 2020 13:30:43 -0400 Subject: [PATCH] change category to enum class --- src/buildmap.hpp | 1 + src/category.cpp | 59 ------------------------------------ src/category.hpp | 68 +++--------------------------------------- src/policy.hpp | 49 +++++++++++++++--------------- src/policy_all.cpp | 12 ++++---- src/policy_epall.cpp | 16 +++++----- src/policy_epff.cpp | 16 +++++----- src/policy_eplfs.cpp | 16 +++++----- src/policy_eplus.cpp | 16 +++++----- src/policy_epmfs.cpp | 16 +++++----- src/policy_eprand.cpp | 10 +++---- src/policy_erofs.cpp | 10 +++---- src/policy_ff.cpp | 12 ++++---- src/policy_invalid.cpp | 10 +++---- src/policy_lfs.cpp | 12 ++++---- src/policy_lus.cpp | 12 ++++---- src/policy_mfs.cpp | 12 ++++---- src/policy_msplfs.cpp | 12 ++++---- src/policy_msplus.cpp | 12 ++++---- src/policy_mspmfs.cpp | 12 ++++---- src/policy_newest.cpp | 16 +++++----- src/policy_rand.cpp | 10 +++---- 22 files changed, 145 insertions(+), 264 deletions(-) delete mode 100644 src/category.cpp diff --git a/src/buildmap.hpp b/src/buildmap.hpp index 87a57d7f..6b9c78bd 100644 --- a/src/buildmap.hpp +++ b/src/buildmap.hpp @@ -17,6 +17,7 @@ #pragma once #include +#include template class buildmap diff --git a/src/category.cpp b/src/category.cpp deleted file mode 100644 index 9985b586..00000000 --- a/src/category.cpp +++ /dev/null @@ -1,59 +0,0 @@ -/* - Copyright (c) 2016, Antonio SJ Musumeci - - Permission to use, copy, modify, and/or distribute this software for any - purpose with or without fee is hereby granted, provided that the above - copyright notice and this permission notice appear in all copies. - - THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -*/ - -#include -#include - -#include "category.hpp" -#include "buildvector.hpp" - -#define CATEGORY(X) Category(Category::Enum::X,#X) - -const std::vector Category::_categories_ = - buildvector - (CATEGORY(invalid)) - (CATEGORY(action)) - (CATEGORY(create)) - (CATEGORY(search)); - -const Category * const Category::categories = &_categories_[1]; - -const Category &Category::invalid = Category::categories[Category::Enum::invalid]; -const Category &Category::action = Category::categories[Category::Enum::action]; -const Category &Category::create = Category::categories[Category::Enum::create]; -const Category &Category::search = Category::categories[Category::Enum::search]; - -const Category& -Category::find(const std::string &str) -{ - for(int i = Enum::BEGIN; i != Enum::END; ++i) - { - if(categories[i] == str) - return categories[i]; - } - - return invalid; -} - -const Category& -Category::find(const Category::Enum::Type i) -{ - if(i >= Category::Enum::BEGIN && - i < Category::Enum::END) - return categories[i]; - - return invalid; -} diff --git a/src/category.hpp b/src/category.hpp index d031f01d..08a7c00a 100644 --- a/src/category.hpp +++ b/src/category.hpp @@ -16,69 +16,9 @@ #pragma once -#include -#include - -class Category -{ -public: - struct Enum +enum class Category { - enum Type - { - invalid = -1, - BEGIN = 0, - action = BEGIN, - create, - search, - END - }; + ACTION, + CREATE, + SEARCH }; - -private: - Enum::Type _enum; - std::string _str; - -public: - Category() - : _enum(invalid), - _str(invalid) - { - } - - Category(const Enum::Type enum_, - const std::string &str_) - : _enum(enum_), - _str(str_) - { - } - -public: - operator const Enum::Type() const { return _enum; } - operator const std::string&() const { return _str; } - operator const Category*() const { return this; } - - bool operator==(const std::string &str_) const - { return _str == str_; } - - bool operator==(const Enum::Type enum_) const - { return _enum == enum_; } - - bool operator!=(const Category &r) const - { return _enum != r._enum; } - - bool operator<(const Category &r) const - { return _enum < r._enum; } - -public: - static const Category &find(const std::string&); - static const Category &find(const Enum::Type); - -public: - static const std::vector _categories_; - static const Category * const categories; - static const Category &invalid; - static const Category &action; - static const Category &create; - static const Category &search; -}; diff --git a/src/policy.hpp b/src/policy.hpp index 39a51d35..32fa9e11 100644 --- a/src/policy.hpp +++ b/src/policy.hpp @@ -63,11 +63,10 @@ public: typedef const string cstring; typedef const uint64_t cuint64_t; typedef const strvec cstrvec; - typedef const Category::Enum::Type CType; - typedef int (*Ptr)(CType,const Branches &,const char *,cuint64_t,strvec *); + typedef int (*Ptr)(Category,const Branches &,const char *,cuint64_t,strvec *); - template + template class Base { public: @@ -108,28 +107,28 @@ public: const Ptr func; }; - typedef Base Action; - typedef Base Create; - typedef Base Search; - - static int invalid(CType,const Branches&,const char *,cuint64_t,strvec*); - static int all(CType,const Branches&,const char*,cuint64_t,strvec*); - static int epall(CType,const Branches&,const char*,cuint64_t,strvec*); - static int epff(CType,const Branches&,const char *,cuint64_t,strvec*); - static int eplfs(CType,const Branches&,const char *,cuint64_t,strvec*); - static int eplus(CType,const Branches&,const char *,cuint64_t,strvec*); - static int epmfs(CType,const Branches&,const char *,cuint64_t,strvec*); - static int eprand(CType,const Branches&,const char *,cuint64_t,strvec*); - static int erofs(CType,const Branches&,const char *,cuint64_t,strvec*); - static int ff(CType,const Branches&,const char *,cuint64_t,strvec*); - static int lfs(CType,const Branches&,const char *,cuint64_t,strvec*); - static int lus(CType,const Branches&,const char *,cuint64_t,strvec*); - static int mfs(CType,const Branches&,const char *,cuint64_t,strvec*); - static int msplfs(CType,const Branches&,const char *,cuint64_t,strvec*); - static int msplus(CType,const Branches&,const char *,cuint64_t,strvec*); - static int mspmfs(CType,const Branches&,const char *,cuint64_t,strvec*); - static int newest(CType,const Branches&,const char *,cuint64_t,strvec*); - static int rand(CType,const Branches&,const char *,cuint64_t,strvec*); + typedef Base Action; + typedef Base Create; + typedef Base Search; + + static int invalid(Category,const Branches&,const char *,cuint64_t,strvec*); + static int all(Category,const Branches&,const char*,cuint64_t,strvec*); + static int epall(Category,const Branches&,const char*,cuint64_t,strvec*); + static int epff(Category,const Branches&,const char *,cuint64_t,strvec*); + static int eplfs(Category,const Branches&,const char *,cuint64_t,strvec*); + static int eplus(Category,const Branches&,const char *,cuint64_t,strvec*); + static int epmfs(Category,const Branches&,const char *,cuint64_t,strvec*); + static int eprand(Category,const Branches&,const char *,cuint64_t,strvec*); + static int erofs(Category,const Branches&,const char *,cuint64_t,strvec*); + static int ff(Category,const Branches&,const char *,cuint64_t,strvec*); + static int lfs(Category,const Branches&,const char *,cuint64_t,strvec*); + static int lus(Category,const Branches&,const char *,cuint64_t,strvec*); + static int mfs(Category,const Branches&,const char *,cuint64_t,strvec*); + static int msplfs(Category,const Branches&,const char *,cuint64_t,strvec*); + static int msplus(Category,const Branches&,const char *,cuint64_t,strvec*); + static int mspmfs(Category,const Branches&,const char *,cuint64_t,strvec*); + static int newest(Category,const Branches&,const char *,cuint64_t,strvec*); + static int rand(Category,const Branches&,const char *,cuint64_t,strvec*); }; private: diff --git a/src/policy_all.cpp b/src/policy_all.cpp index edb54e83..c3e73f80 100644 --- a/src/policy_all.cpp +++ b/src/policy_all.cpp @@ -69,13 +69,13 @@ namespace all } int -Policy::Func::all(const Category::Enum::Type type_, - const Branches &branches_, - const char *fusepath_, - const uint64_t minfreespace_, - vector *paths_) +Policy::Func::all(const Category type_, + const Branches &branches_, + const char *fusepath_, + const uint64_t minfreespace_, + vector *paths_) { - if(type_ == Category::Enum::create) + if(type_ == Category::CREATE) return all::create(branches_,minfreespace_,paths_); return Policy::Func::epall(type_,branches_,fusepath_,minfreespace_,paths_); diff --git a/src/policy_epall.cpp b/src/policy_epall.cpp index e932b341..08f41613 100644 --- a/src/policy_epall.cpp +++ b/src/policy_epall.cpp @@ -137,19 +137,19 @@ namespace epall } int -Policy::Func::epall(const Category::Enum::Type type, - const Branches &branches_, - const char *fusepath, - const uint64_t minfreespace, - vector *paths) +Policy::Func::epall(const Category type, + const Branches &branches_, + const char *fusepath, + const uint64_t minfreespace, + vector *paths) { switch(type) { - case Category::Enum::create: + case Category::CREATE: return epall::create(branches_,fusepath,minfreespace,paths); - case Category::Enum::action: + case Category::ACTION: return epall::action(branches_,fusepath,paths); - case Category::Enum::search: + case Category::SEARCH: default: return epall::search(branches_,fusepath,paths); } diff --git a/src/policy_epff.cpp b/src/policy_epff.cpp index 2361e7fd..95a4a9e7 100644 --- a/src/policy_epff.cpp +++ b/src/policy_epff.cpp @@ -134,19 +134,19 @@ namespace epff } int -Policy::Func::epff(const Category::Enum::Type type_, - const Branches &branches_, - const char *fusepath_, - const uint64_t minfreespace_, - vector *paths_) +Policy::Func::epff(const Category type_, + const Branches &branches_, + const char *fusepath_, + const uint64_t minfreespace_, + vector *paths_) { switch(type_) { - case Category::Enum::create: + case Category::CREATE: return epff::create(branches_,fusepath_,minfreespace_,paths_); - case Category::Enum::action: + case Category::ACTION: return epff::action(branches_,fusepath_,paths_); - case Category::Enum::search: + case Category::SEARCH: default: return epff::search(branches_,fusepath_,paths_); } diff --git a/src/policy_eplfs.cpp b/src/policy_eplfs.cpp index dc424da5..5dd1e6ee 100644 --- a/src/policy_eplfs.cpp +++ b/src/policy_eplfs.cpp @@ -170,19 +170,19 @@ namespace eplfs } int -Policy::Func::eplfs(const Category::Enum::Type type, - const Branches &branches_, - const char *fusepath, - const uint64_t minfreespace, - vector *paths) +Policy::Func::eplfs(const Category type, + const Branches &branches_, + const char *fusepath, + const uint64_t minfreespace, + vector *paths) { switch(type) { - case Category::Enum::create: + case Category::CREATE: return eplfs::create(branches_,fusepath,minfreespace,paths); - case Category::Enum::action: + case Category::ACTION: return eplfs::action(branches_,fusepath,paths); - case Category::Enum::search: + case Category::SEARCH: default: return eplfs::search(branches_,fusepath,paths); } diff --git a/src/policy_eplus.cpp b/src/policy_eplus.cpp index 7b0379b4..0d5c6be1 100644 --- a/src/policy_eplus.cpp +++ b/src/policy_eplus.cpp @@ -170,19 +170,19 @@ namespace eplus } int -Policy::Func::eplus(const Category::Enum::Type type, - const Branches &branches_, - const char *fusepath, - const uint64_t minfreespace, - vector *paths) +Policy::Func::eplus(const Category type, + const Branches &branches_, + const char *fusepath, + const uint64_t minfreespace, + vector *paths) { switch(type) { - case Category::Enum::create: + case Category::CREATE: return eplus::create(branches_,fusepath,minfreespace,paths); - case Category::Enum::action: + case Category::ACTION: return eplus::action(branches_,fusepath,paths); - case Category::Enum::search: + case Category::SEARCH: default: return eplus::search(branches_,fusepath,paths); } diff --git a/src/policy_epmfs.cpp b/src/policy_epmfs.cpp index c91b7d7e..51253df4 100644 --- a/src/policy_epmfs.cpp +++ b/src/policy_epmfs.cpp @@ -170,19 +170,19 @@ namespace epmfs } int -Policy::Func::epmfs(const Category::Enum::Type type_, - const Branches &branches_, - const char *fusepath_, - const uint64_t minfreespace_, - vector *paths_) +Policy::Func::epmfs(const Category type_, + const Branches &branches_, + const char *fusepath_, + const uint64_t minfreespace_, + vector *paths_) { switch(type_) { - case Category::Enum::create: + case Category::CREATE: return epmfs::create(branches_,fusepath_,minfreespace_,paths_); - case Category::Enum::action: + case Category::ACTION: return epmfs::action(branches_,fusepath_,paths_); - case Category::Enum::search: + case Category::SEARCH: default: return epmfs::search(branches_,fusepath_,paths_); } diff --git a/src/policy_eprand.cpp b/src/policy_eprand.cpp index eaa154e6..099162f1 100644 --- a/src/policy_eprand.cpp +++ b/src/policy_eprand.cpp @@ -25,11 +25,11 @@ using std::string; using std::vector; int -Policy::Func::eprand(const Category::Enum::Type type_, - const Branches &branches_, - const char *fusepath_, - const uint64_t minfreespace_, - vector *paths_) +Policy::Func::eprand(const Category type_, + const Branches &branches_, + const char *fusepath_, + const uint64_t minfreespace_, + vector *paths_) { int rv; diff --git a/src/policy_erofs.cpp b/src/policy_erofs.cpp index 8daea427..aa85d219 100644 --- a/src/policy_erofs.cpp +++ b/src/policy_erofs.cpp @@ -24,11 +24,11 @@ using std::string; using std::vector; int -Policy::Func::erofs(const Category::Enum::Type type_, - const Branches &branches_, - const char *fusepath_, - const uint64_t minfreespace_, - vector *paths) +Policy::Func::erofs(const Category type_, + const Branches &branches_, + const char *fusepath_, + const uint64_t minfreespace_, + vector *paths) { return (errno=EROFS,-1); } diff --git a/src/policy_ff.cpp b/src/policy_ff.cpp index e55fa28e..16d8bf61 100644 --- a/src/policy_ff.cpp +++ b/src/policy_ff.cpp @@ -69,13 +69,13 @@ namespace ff } int -Policy::Func::ff(const Category::Enum::Type type, - const Branches &branches_, - const char *fusepath, - const uint64_t minfreespace, - vector *paths) +Policy::Func::ff(const Category type, + const Branches &branches_, + const char *fusepath, + const uint64_t minfreespace, + vector *paths) { - if(type == Category::Enum::create) + if(type == Category::CREATE) return ff::create(branches_,minfreespace,paths); return Policy::Func::epff(type,branches_,fusepath,minfreespace,paths); diff --git a/src/policy_invalid.cpp b/src/policy_invalid.cpp index 7d0d97b8..588e424d 100644 --- a/src/policy_invalid.cpp +++ b/src/policy_invalid.cpp @@ -24,11 +24,11 @@ using std::string; using std::vector; int -Policy::Func::invalid(const Category::Enum::Type type, - const Branches &branches_, - const char *fusepath, - const uint64_t minfreespace, - vector *paths) +Policy::Func::invalid(const Category type_, + const Branches &branches_, + const char *fusepath_, + const uint64_t minfreespace_, + vector *paths_) { return (errno=EINVAL,-1); } diff --git a/src/policy_lfs.cpp b/src/policy_lfs.cpp index 4fb5d135..de4eb302 100644 --- a/src/policy_lfs.cpp +++ b/src/policy_lfs.cpp @@ -80,13 +80,13 @@ namespace lfs } int -Policy::Func::lfs(const Category::Enum::Type type, - const Branches &branches_, - const char *fusepath, - const uint64_t minfreespace, - vector *paths) +Policy::Func::lfs(const Category type, + const Branches &branches_, + const char *fusepath, + const uint64_t minfreespace, + vector *paths) { - if(type == Category::Enum::create) + if(type == Category::CREATE) return lfs::create(branches_,minfreespace,paths); return Policy::Func::eplfs(type,branches_,fusepath,minfreespace,paths); diff --git a/src/policy_lus.cpp b/src/policy_lus.cpp index 450ea227..a5812d9d 100644 --- a/src/policy_lus.cpp +++ b/src/policy_lus.cpp @@ -80,13 +80,13 @@ namespace lus } int -Policy::Func::lus(const Category::Enum::Type type, - const Branches &branches_, - const char *fusepath, - const uint64_t minfreespace, - vector *paths) +Policy::Func::lus(const Category type, + const Branches &branches_, + const char *fusepath, + const uint64_t minfreespace, + vector *paths) { - if(type == Category::Enum::create) + if(type == Category::CREATE) return lus::create(branches_,minfreespace,paths); return Policy::Func::eplus(type,branches_,fusepath,minfreespace,paths); diff --git a/src/policy_mfs.cpp b/src/policy_mfs.cpp index e60c194d..0fdd871d 100644 --- a/src/policy_mfs.cpp +++ b/src/policy_mfs.cpp @@ -79,13 +79,13 @@ namespace mfs } int -Policy::Func::mfs(const Category::Enum::Type type, - const Branches &branches_, - const char *fusepath, - const uint64_t minfreespace, - vector *paths) +Policy::Func::mfs(const Category type, + const Branches &branches_, + const char *fusepath, + const uint64_t minfreespace, + vector *paths) { - if(type == Category::Enum::create) + if(type == Category::CREATE) return mfs::create(branches_,minfreespace,paths); return Policy::Func::epmfs(type,branches_,fusepath,minfreespace,paths); diff --git a/src/policy_msplfs.cpp b/src/policy_msplfs.cpp index ea9e2a40..71037d94 100644 --- a/src/policy_msplfs.cpp +++ b/src/policy_msplfs.cpp @@ -110,13 +110,13 @@ namespace msplfs } int -Policy::Func::msplfs(const Category::Enum::Type type_, - const Branches &branches_, - const char *fusepath_, - const uint64_t minfreespace_, - vector *paths_) +Policy::Func::msplfs(const Category type_, + const Branches &branches_, + const char *fusepath_, + const uint64_t minfreespace_, + vector *paths_) { - if(type_ == Category::Enum::create) + if(type_ == Category::CREATE) return msplfs::create(branches_,fusepath_,minfreespace_,paths_); return Policy::Func::eplfs(type_,branches_,fusepath_,minfreespace_,paths_); diff --git a/src/policy_msplus.cpp b/src/policy_msplus.cpp index 7405eb55..e3b530b0 100644 --- a/src/policy_msplus.cpp +++ b/src/policy_msplus.cpp @@ -110,13 +110,13 @@ namespace msplus } int -Policy::Func::msplus(const Category::Enum::Type type_, - const Branches &branches_, - const char *fusepath_, - const uint64_t minfreespace_, - vector *paths_) +Policy::Func::msplus(const Category type_, + const Branches &branches_, + const char *fusepath_, + const uint64_t minfreespace_, + vector *paths_) { - if(type_ == Category::Enum::create) + if(type_ == Category::CREATE) return msplus::create(branches_,fusepath_,minfreespace_,paths_); return Policy::Func::eplus(type_,branches_,fusepath_,minfreespace_,paths_); diff --git a/src/policy_mspmfs.cpp b/src/policy_mspmfs.cpp index 685980d8..50d6b325 100644 --- a/src/policy_mspmfs.cpp +++ b/src/policy_mspmfs.cpp @@ -110,13 +110,13 @@ namespace mspmfs } int -Policy::Func::mspmfs(const Category::Enum::Type type_, - const Branches &branches_, - const char *fusepath_, - const uint64_t minfreespace_, - vector *paths_) +Policy::Func::mspmfs(const Category type_, + const Branches &branches_, + const char *fusepath_, + const uint64_t minfreespace_, + vector *paths_) { - if(type_ == Category::Enum::create) + if(type_ == Category::CREATE) return mspmfs::create(branches_,fusepath_,minfreespace_,paths_); return Policy::Func::epmfs(type_,branches_,fusepath_,minfreespace_,paths_); diff --git a/src/policy_newest.cpp b/src/policy_newest.cpp index d0416c28..ce8dde9c 100644 --- a/src/policy_newest.cpp +++ b/src/policy_newest.cpp @@ -170,19 +170,19 @@ namespace newest } int -Policy::Func::newest(const Category::Enum::Type type, - const Branches &branches_, - const char *fusepath, - const uint64_t minfreespace, - vector *paths) +Policy::Func::newest(const Category type, + const Branches &branches_, + const char *fusepath, + const uint64_t minfreespace, + vector *paths) { switch(type) { - case Category::Enum::create: + case Category::CREATE: return newest::create(branches_,fusepath,minfreespace,paths); - case Category::Enum::action: + case Category::ACTION: return newest::action(branches_,fusepath,paths); - case Category::Enum::search: + case Category::SEARCH: default: return newest::search(branches_,fusepath,paths); } diff --git a/src/policy_rand.cpp b/src/policy_rand.cpp index 7d38db94..2ffb2a92 100644 --- a/src/policy_rand.cpp +++ b/src/policy_rand.cpp @@ -25,11 +25,11 @@ using std::string; using std::vector; int -Policy::Func::rand(const Category::Enum::Type type_, - const Branches &branches_, - const char *fusepath_, - const uint64_t minfreespace_, - vector *paths_) +Policy::Func::rand(const Category type_, + const Branches &branches_, + const char *fusepath_, + const uint64_t minfreespace_, + vector *paths_) { int rv;