diff --git a/src/policy.hpp b/src/policy.hpp index 58c47a34..1ee6809f 100644 --- a/src/policy.hpp +++ b/src/policy.hpp @@ -76,57 +76,41 @@ namespace mergerfs typedef int (*Ptr)(CType,cstrvec&,cstring&,csize_t,strvec&); - class Action + template + class Base { public: - Action(const Policy *p) + Base(const Policy *p) : func(p->_func) {} int operator()(cstrvec& b,cstring& c,csize_t d,strvec& e) { - return func(Category::Enum::action,b,c,d,e); + return func(T,b,c,d,e); } - private: - const Ptr func; - }; - - class Create - { - public: - Create(const Policy *p) - : func(p->_func) - {} - int - operator()(cstrvec& b,cstring& c,csize_t d,strvec& e) + operator()(cstrvec& b,cstring& c,csize_t d,string& e) { - return func(Category::Enum::create,b,c,d,e); - } + int rv; + strvec vec; - private: - const Ptr func; - }; + rv = func(T,b,c,d,vec); + if(!vec.empty()) + e = vec[0]; - class Search - { - public: - Search(const Policy *p) - : func(p->_func) - {} - - int - operator()(cstrvec& b,cstring& c,csize_t d,strvec& e) - { - return func(Category::Enum::search,b,c,d,e); + return rv; } private: const Ptr func; }; + typedef Base Action; + typedef Base Create; + typedef Base Search; + static int all(CType,cstrvec&,cstring&,csize_t,strvec&); static int einval(CType,cstrvec&,cstring&,csize_t,strvec&); static int enosys(CType,cstrvec&,cstring&,csize_t,strvec&);