Browse Source

change category to enum class

pull/814/head
Antonio SJ Musumeci 4 years ago
parent
commit
6cc6524997
  1. 1
      src/buildmap.hpp
  2. 59
      src/category.cpp
  3. 68
      src/category.hpp
  4. 49
      src/policy.hpp
  5. 4
      src/policy_all.cpp
  6. 8
      src/policy_epall.cpp
  7. 8
      src/policy_epff.cpp
  8. 8
      src/policy_eplfs.cpp
  9. 8
      src/policy_eplus.cpp
  10. 8
      src/policy_epmfs.cpp
  11. 2
      src/policy_eprand.cpp
  12. 2
      src/policy_erofs.cpp
  13. 4
      src/policy_ff.cpp
  14. 8
      src/policy_invalid.cpp
  15. 4
      src/policy_lfs.cpp
  16. 4
      src/policy_lus.cpp
  17. 4
      src/policy_mfs.cpp
  18. 4
      src/policy_msplfs.cpp
  19. 4
      src/policy_msplus.cpp
  20. 4
      src/policy_mspmfs.cpp
  21. 8
      src/policy_newest.cpp
  22. 2
      src/policy_rand.cpp

1
src/buildmap.hpp

@ -17,6 +17,7 @@
#pragma once #pragma once
#include <algorithm> #include <algorithm>
#include <map>
template<typename K,typename V> template<typename K,typename V>
class buildmap class buildmap

59
src/category.cpp

@ -1,59 +0,0 @@
/*
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
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 <string>
#include <vector>
#include "category.hpp"
#include "buildvector.hpp"
#define CATEGORY(X) Category(Category::Enum::X,#X)
const std::vector<Category> Category::_categories_ =
buildvector<Category,true>
(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;
}

68
src/category.hpp

@ -16,69 +16,9 @@
#pragma once #pragma once
#include <string>
#include <vector>
class Category
{
public:
struct Enum
{
enum Type
enum class Category
{ {
invalid = -1,
BEGIN = 0,
action = BEGIN,
create,
search,
END
};
};
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<Category> _categories_;
static const Category * const categories;
static const Category &invalid;
static const Category &action;
static const Category &create;
static const Category &search;
ACTION,
CREATE,
SEARCH
}; };

49
src/policy.hpp

@ -63,11 +63,10 @@ public:
typedef const string cstring; typedef const string cstring;
typedef const uint64_t cuint64_t; typedef const uint64_t cuint64_t;
typedef const strvec cstrvec; 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 <CType T>
template <Category T>
class Base class Base
{ {
public: public:
@ -108,28 +107,28 @@ public:
const Ptr func; const Ptr func;
}; };
typedef Base<Category::Enum::action> Action;
typedef Base<Category::Enum::create> Create;
typedef Base<Category::Enum::search> 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<Category::ACTION> Action;
typedef Base<Category::CREATE> Create;
typedef Base<Category::SEARCH> 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: private:

4
src/policy_all.cpp

@ -69,13 +69,13 @@ namespace all
} }
int int
Policy::Func::all(const Category::Enum::Type type_,
Policy::Func::all(const Category type_,
const Branches &branches_, const Branches &branches_,
const char *fusepath_, const char *fusepath_,
const uint64_t minfreespace_, const uint64_t minfreespace_,
vector<string> *paths_) vector<string> *paths_)
{ {
if(type_ == Category::Enum::create)
if(type_ == Category::CREATE)
return all::create(branches_,minfreespace_,paths_); return all::create(branches_,minfreespace_,paths_);
return Policy::Func::epall(type_,branches_,fusepath_,minfreespace_,paths_); return Policy::Func::epall(type_,branches_,fusepath_,minfreespace_,paths_);

8
src/policy_epall.cpp

@ -137,7 +137,7 @@ namespace epall
} }
int int
Policy::Func::epall(const Category::Enum::Type type,
Policy::Func::epall(const Category type,
const Branches &branches_, const Branches &branches_,
const char *fusepath, const char *fusepath,
const uint64_t minfreespace, const uint64_t minfreespace,
@ -145,11 +145,11 @@ Policy::Func::epall(const Category::Enum::Type type,
{ {
switch(type) switch(type)
{ {
case Category::Enum::create:
case Category::CREATE:
return epall::create(branches_,fusepath,minfreespace,paths); return epall::create(branches_,fusepath,minfreespace,paths);
case Category::Enum::action:
case Category::ACTION:
return epall::action(branches_,fusepath,paths); return epall::action(branches_,fusepath,paths);
case Category::Enum::search:
case Category::SEARCH:
default: default:
return epall::search(branches_,fusepath,paths); return epall::search(branches_,fusepath,paths);
} }

8
src/policy_epff.cpp

@ -134,7 +134,7 @@ namespace epff
} }
int int
Policy::Func::epff(const Category::Enum::Type type_,
Policy::Func::epff(const Category type_,
const Branches &branches_, const Branches &branches_,
const char *fusepath_, const char *fusepath_,
const uint64_t minfreespace_, const uint64_t minfreespace_,
@ -142,11 +142,11 @@ Policy::Func::epff(const Category::Enum::Type type_,
{ {
switch(type_) switch(type_)
{ {
case Category::Enum::create:
case Category::CREATE:
return epff::create(branches_,fusepath_,minfreespace_,paths_); return epff::create(branches_,fusepath_,minfreespace_,paths_);
case Category::Enum::action:
case Category::ACTION:
return epff::action(branches_,fusepath_,paths_); return epff::action(branches_,fusepath_,paths_);
case Category::Enum::search:
case Category::SEARCH:
default: default:
return epff::search(branches_,fusepath_,paths_); return epff::search(branches_,fusepath_,paths_);
} }

8
src/policy_eplfs.cpp

@ -170,7 +170,7 @@ namespace eplfs
} }
int int
Policy::Func::eplfs(const Category::Enum::Type type,
Policy::Func::eplfs(const Category type,
const Branches &branches_, const Branches &branches_,
const char *fusepath, const char *fusepath,
const uint64_t minfreespace, const uint64_t minfreespace,
@ -178,11 +178,11 @@ Policy::Func::eplfs(const Category::Enum::Type type,
{ {
switch(type) switch(type)
{ {
case Category::Enum::create:
case Category::CREATE:
return eplfs::create(branches_,fusepath,minfreespace,paths); return eplfs::create(branches_,fusepath,minfreespace,paths);
case Category::Enum::action:
case Category::ACTION:
return eplfs::action(branches_,fusepath,paths); return eplfs::action(branches_,fusepath,paths);
case Category::Enum::search:
case Category::SEARCH:
default: default:
return eplfs::search(branches_,fusepath,paths); return eplfs::search(branches_,fusepath,paths);
} }

8
src/policy_eplus.cpp

@ -170,7 +170,7 @@ namespace eplus
} }
int int
Policy::Func::eplus(const Category::Enum::Type type,
Policy::Func::eplus(const Category type,
const Branches &branches_, const Branches &branches_,
const char *fusepath, const char *fusepath,
const uint64_t minfreespace, const uint64_t minfreespace,
@ -178,11 +178,11 @@ Policy::Func::eplus(const Category::Enum::Type type,
{ {
switch(type) switch(type)
{ {
case Category::Enum::create:
case Category::CREATE:
return eplus::create(branches_,fusepath,minfreespace,paths); return eplus::create(branches_,fusepath,minfreespace,paths);
case Category::Enum::action:
case Category::ACTION:
return eplus::action(branches_,fusepath,paths); return eplus::action(branches_,fusepath,paths);
case Category::Enum::search:
case Category::SEARCH:
default: default:
return eplus::search(branches_,fusepath,paths); return eplus::search(branches_,fusepath,paths);
} }

8
src/policy_epmfs.cpp

@ -170,7 +170,7 @@ namespace epmfs
} }
int int
Policy::Func::epmfs(const Category::Enum::Type type_,
Policy::Func::epmfs(const Category type_,
const Branches &branches_, const Branches &branches_,
const char *fusepath_, const char *fusepath_,
const uint64_t minfreespace_, const uint64_t minfreespace_,
@ -178,11 +178,11 @@ Policy::Func::epmfs(const Category::Enum::Type type_,
{ {
switch(type_) switch(type_)
{ {
case Category::Enum::create:
case Category::CREATE:
return epmfs::create(branches_,fusepath_,minfreespace_,paths_); return epmfs::create(branches_,fusepath_,minfreespace_,paths_);
case Category::Enum::action:
case Category::ACTION:
return epmfs::action(branches_,fusepath_,paths_); return epmfs::action(branches_,fusepath_,paths_);
case Category::Enum::search:
case Category::SEARCH:
default: default:
return epmfs::search(branches_,fusepath_,paths_); return epmfs::search(branches_,fusepath_,paths_);
} }

2
src/policy_eprand.cpp

@ -25,7 +25,7 @@ using std::string;
using std::vector; using std::vector;
int int
Policy::Func::eprand(const Category::Enum::Type type_,
Policy::Func::eprand(const Category type_,
const Branches &branches_, const Branches &branches_,
const char *fusepath_, const char *fusepath_,
const uint64_t minfreespace_, const uint64_t minfreespace_,

2
src/policy_erofs.cpp

@ -24,7 +24,7 @@ using std::string;
using std::vector; using std::vector;
int int
Policy::Func::erofs(const Category::Enum::Type type_,
Policy::Func::erofs(const Category type_,
const Branches &branches_, const Branches &branches_,
const char *fusepath_, const char *fusepath_,
const uint64_t minfreespace_, const uint64_t minfreespace_,

4
src/policy_ff.cpp

@ -69,13 +69,13 @@ namespace ff
} }
int int
Policy::Func::ff(const Category::Enum::Type type,
Policy::Func::ff(const Category type,
const Branches &branches_, const Branches &branches_,
const char *fusepath, const char *fusepath,
const uint64_t minfreespace, const uint64_t minfreespace,
vector<string> *paths) vector<string> *paths)
{ {
if(type == Category::Enum::create)
if(type == Category::CREATE)
return ff::create(branches_,minfreespace,paths); return ff::create(branches_,minfreespace,paths);
return Policy::Func::epff(type,branches_,fusepath,minfreespace,paths); return Policy::Func::epff(type,branches_,fusepath,minfreespace,paths);

8
src/policy_invalid.cpp

@ -24,11 +24,11 @@ using std::string;
using std::vector; using std::vector;
int int
Policy::Func::invalid(const Category::Enum::Type type,
Policy::Func::invalid(const Category type_,
const Branches &branches_, const Branches &branches_,
const char *fusepath,
const uint64_t minfreespace,
vector<string> *paths)
const char *fusepath_,
const uint64_t minfreespace_,
vector<string> *paths_)
{ {
return (errno=EINVAL,-1); return (errno=EINVAL,-1);
} }

4
src/policy_lfs.cpp

@ -80,13 +80,13 @@ namespace lfs
} }
int int
Policy::Func::lfs(const Category::Enum::Type type,
Policy::Func::lfs(const Category type,
const Branches &branches_, const Branches &branches_,
const char *fusepath, const char *fusepath,
const uint64_t minfreespace, const uint64_t minfreespace,
vector<string> *paths) vector<string> *paths)
{ {
if(type == Category::Enum::create)
if(type == Category::CREATE)
return lfs::create(branches_,minfreespace,paths); return lfs::create(branches_,minfreespace,paths);
return Policy::Func::eplfs(type,branches_,fusepath,minfreespace,paths); return Policy::Func::eplfs(type,branches_,fusepath,minfreespace,paths);

4
src/policy_lus.cpp

@ -80,13 +80,13 @@ namespace lus
} }
int int
Policy::Func::lus(const Category::Enum::Type type,
Policy::Func::lus(const Category type,
const Branches &branches_, const Branches &branches_,
const char *fusepath, const char *fusepath,
const uint64_t minfreespace, const uint64_t minfreespace,
vector<string> *paths) vector<string> *paths)
{ {
if(type == Category::Enum::create)
if(type == Category::CREATE)
return lus::create(branches_,minfreespace,paths); return lus::create(branches_,minfreespace,paths);
return Policy::Func::eplus(type,branches_,fusepath,minfreespace,paths); return Policy::Func::eplus(type,branches_,fusepath,minfreespace,paths);

4
src/policy_mfs.cpp

@ -79,13 +79,13 @@ namespace mfs
} }
int int
Policy::Func::mfs(const Category::Enum::Type type,
Policy::Func::mfs(const Category type,
const Branches &branches_, const Branches &branches_,
const char *fusepath, const char *fusepath,
const uint64_t minfreespace, const uint64_t minfreespace,
vector<string> *paths) vector<string> *paths)
{ {
if(type == Category::Enum::create)
if(type == Category::CREATE)
return mfs::create(branches_,minfreespace,paths); return mfs::create(branches_,minfreespace,paths);
return Policy::Func::epmfs(type,branches_,fusepath,minfreespace,paths); return Policy::Func::epmfs(type,branches_,fusepath,minfreespace,paths);

4
src/policy_msplfs.cpp

@ -110,13 +110,13 @@ namespace msplfs
} }
int int
Policy::Func::msplfs(const Category::Enum::Type type_,
Policy::Func::msplfs(const Category type_,
const Branches &branches_, const Branches &branches_,
const char *fusepath_, const char *fusepath_,
const uint64_t minfreespace_, const uint64_t minfreespace_,
vector<string> *paths_) vector<string> *paths_)
{ {
if(type_ == Category::Enum::create)
if(type_ == Category::CREATE)
return msplfs::create(branches_,fusepath_,minfreespace_,paths_); return msplfs::create(branches_,fusepath_,minfreespace_,paths_);
return Policy::Func::eplfs(type_,branches_,fusepath_,minfreespace_,paths_); return Policy::Func::eplfs(type_,branches_,fusepath_,minfreespace_,paths_);

4
src/policy_msplus.cpp

@ -110,13 +110,13 @@ namespace msplus
} }
int int
Policy::Func::msplus(const Category::Enum::Type type_,
Policy::Func::msplus(const Category type_,
const Branches &branches_, const Branches &branches_,
const char *fusepath_, const char *fusepath_,
const uint64_t minfreespace_, const uint64_t minfreespace_,
vector<string> *paths_) vector<string> *paths_)
{ {
if(type_ == Category::Enum::create)
if(type_ == Category::CREATE)
return msplus::create(branches_,fusepath_,minfreespace_,paths_); return msplus::create(branches_,fusepath_,minfreespace_,paths_);
return Policy::Func::eplus(type_,branches_,fusepath_,minfreespace_,paths_); return Policy::Func::eplus(type_,branches_,fusepath_,minfreespace_,paths_);

4
src/policy_mspmfs.cpp

@ -110,13 +110,13 @@ namespace mspmfs
} }
int int
Policy::Func::mspmfs(const Category::Enum::Type type_,
Policy::Func::mspmfs(const Category type_,
const Branches &branches_, const Branches &branches_,
const char *fusepath_, const char *fusepath_,
const uint64_t minfreespace_, const uint64_t minfreespace_,
vector<string> *paths_) vector<string> *paths_)
{ {
if(type_ == Category::Enum::create)
if(type_ == Category::CREATE)
return mspmfs::create(branches_,fusepath_,minfreespace_,paths_); return mspmfs::create(branches_,fusepath_,minfreespace_,paths_);
return Policy::Func::epmfs(type_,branches_,fusepath_,minfreespace_,paths_); return Policy::Func::epmfs(type_,branches_,fusepath_,minfreespace_,paths_);

8
src/policy_newest.cpp

@ -170,7 +170,7 @@ namespace newest
} }
int int
Policy::Func::newest(const Category::Enum::Type type,
Policy::Func::newest(const Category type,
const Branches &branches_, const Branches &branches_,
const char *fusepath, const char *fusepath,
const uint64_t minfreespace, const uint64_t minfreespace,
@ -178,11 +178,11 @@ Policy::Func::newest(const Category::Enum::Type type,
{ {
switch(type) switch(type)
{ {
case Category::Enum::create:
case Category::CREATE:
return newest::create(branches_,fusepath,minfreespace,paths); return newest::create(branches_,fusepath,minfreespace,paths);
case Category::Enum::action:
case Category::ACTION:
return newest::action(branches_,fusepath,paths); return newest::action(branches_,fusepath,paths);
case Category::Enum::search:
case Category::SEARCH:
default: default:
return newest::search(branches_,fusepath,paths); return newest::search(branches_,fusepath,paths);
} }

2
src/policy_rand.cpp

@ -25,7 +25,7 @@ using std::string;
using std::vector; using std::vector;
int int
Policy::Func::rand(const Category::Enum::Type type_,
Policy::Func::rand(const Category type_,
const Branches &branches_, const Branches &branches_,
const char *fusepath_, const char *fusepath_,
const uint64_t minfreespace_, const uint64_t minfreespace_,

Loading…
Cancel
Save