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. 12
      src/policy_all.cpp
  6. 16
      src/policy_epall.cpp
  7. 16
      src/policy_epff.cpp
  8. 16
      src/policy_eplfs.cpp
  9. 16
      src/policy_eplus.cpp
  10. 16
      src/policy_epmfs.cpp
  11. 10
      src/policy_eprand.cpp
  12. 10
      src/policy_erofs.cpp
  13. 12
      src/policy_ff.cpp
  14. 10
      src/policy_invalid.cpp
  15. 12
      src/policy_lfs.cpp
  16. 12
      src/policy_lus.cpp
  17. 12
      src/policy_mfs.cpp
  18. 12
      src/policy_msplfs.cpp
  19. 12
      src/policy_msplus.cpp
  20. 12
      src/policy_mspmfs.cpp
  21. 16
      src/policy_newest.cpp
  22. 10
      src/policy_rand.cpp

1
src/buildmap.hpp

@ -17,6 +17,7 @@
#pragma once
#include <algorithm>
#include <map>
template<typename K,typename V>
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
#include <string>
#include <vector>
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<Category> _categories_;
static const Category * const categories;
static const Category &invalid;
static const Category &action;
static const Category &create;
static const Category &search;
};

49
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 <CType T>
template <Category T>
class Base
{
public:
@ -108,28 +107,28 @@ public:
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:

12
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<string> *paths_)
Policy::Func::all(const Category type_,
const Branches &branches_,
const char *fusepath_,
const uint64_t minfreespace_,
vector<string> *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_);

16
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<string> *paths)
Policy::Func::epall(const Category type,
const Branches &branches_,
const char *fusepath,
const uint64_t minfreespace,
vector<string> *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);
}

16
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<string> *paths_)
Policy::Func::epff(const Category type_,
const Branches &branches_,
const char *fusepath_,
const uint64_t minfreespace_,
vector<string> *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_);
}

16
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<string> *paths)
Policy::Func::eplfs(const Category type,
const Branches &branches_,
const char *fusepath,
const uint64_t minfreespace,
vector<string> *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);
}

16
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<string> *paths)
Policy::Func::eplus(const Category type,
const Branches &branches_,
const char *fusepath,
const uint64_t minfreespace,
vector<string> *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);
}

16
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<string> *paths_)
Policy::Func::epmfs(const Category type_,
const Branches &branches_,
const char *fusepath_,
const uint64_t minfreespace_,
vector<string> *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_);
}

10
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<string> *paths_)
Policy::Func::eprand(const Category type_,
const Branches &branches_,
const char *fusepath_,
const uint64_t minfreespace_,
vector<string> *paths_)
{
int rv;

10
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<string> *paths)
Policy::Func::erofs(const Category type_,
const Branches &branches_,
const char *fusepath_,
const uint64_t minfreespace_,
vector<string> *paths)
{
return (errno=EROFS,-1);
}

12
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<string> *paths)
Policy::Func::ff(const Category type,
const Branches &branches_,
const char *fusepath,
const uint64_t minfreespace,
vector<string> *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);

10
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<string> *paths)
Policy::Func::invalid(const Category type_,
const Branches &branches_,
const char *fusepath_,
const uint64_t minfreespace_,
vector<string> *paths_)
{
return (errno=EINVAL,-1);
}

12
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<string> *paths)
Policy::Func::lfs(const Category type,
const Branches &branches_,
const char *fusepath,
const uint64_t minfreespace,
vector<string> *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);

12
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<string> *paths)
Policy::Func::lus(const Category type,
const Branches &branches_,
const char *fusepath,
const uint64_t minfreespace,
vector<string> *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);

12
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<string> *paths)
Policy::Func::mfs(const Category type,
const Branches &branches_,
const char *fusepath,
const uint64_t minfreespace,
vector<string> *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);

12
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<string> *paths_)
Policy::Func::msplfs(const Category type_,
const Branches &branches_,
const char *fusepath_,
const uint64_t minfreespace_,
vector<string> *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_);

12
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<string> *paths_)
Policy::Func::msplus(const Category type_,
const Branches &branches_,
const char *fusepath_,
const uint64_t minfreespace_,
vector<string> *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_);

12
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<string> *paths_)
Policy::Func::mspmfs(const Category type_,
const Branches &branches_,
const char *fusepath_,
const uint64_t minfreespace_,
vector<string> *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_);

16
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<string> *paths)
Policy::Func::newest(const Category type,
const Branches &branches_,
const char *fusepath,
const uint64_t minfreespace,
vector<string> *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);
}

10
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<string> *paths_)
Policy::Func::rand(const Category type_,
const Branches &branches_,
const char *fusepath_,
const uint64_t minfreespace_,
vector<string> *paths_)
{
int rv;

Loading…
Cancel
Save