/* */ #ifndef _D_A2_FUNCTIONAL_H_ #define _D_A2_FUNCTIONAL_H_ #include #include "SharedHandle.h" #include namespace aria2 { // mem_fun_t for SharedHandle template class mem_fun_sh_t:public std::unary_function< SharedHandle, ReturnType> { private: ReturnType (ClassType::*f)(); public: mem_fun_sh_t(ReturnType (ClassType::*f)()):f(f) {} ReturnType operator()(const SharedHandle& x) const { return (x.get()->*f)(); } }; // const_mem_fun_t for SharedHandle template class const_mem_fun_sh_t:public std::unary_function< SharedHandle, ReturnType> { private: ReturnType (ClassType::*f)() const; public: const_mem_fun_sh_t(ReturnType (ClassType::*f)() const):f(f) {} ReturnType operator()(const SharedHandle& x) const { return (x.get()->*f)(); } }; template mem_fun_sh_t mem_fun_sh(ReturnType (ClassType::*f)()) { return mem_fun_sh_t(f); }; template const_mem_fun_sh_t mem_fun_sh(ReturnType (ClassType::*f)() const) { return const_mem_fun_sh_t(f); }; template class adopt2nd_t:public std::binary_function { private: BinaryOp _binaryOp; UnaryOp _unaryOp; public: adopt2nd_t(const BinaryOp& b, const UnaryOp& u): _binaryOp(b), _unaryOp(u) {} typename BinaryOp::result_type operator()(const typename BinaryOp::first_argument_type& x, const typename UnaryOp::argument_type& y) { return _binaryOp(x, _unaryOp(y)); } }; template inline adopt2nd_t adopt2nd(const BinaryOp& binaryOp, const UnaryOp& unaryOp) { return adopt2nd_t(binaryOp, unaryOp); }; template class Ascend1st:public std::binary_function { public: bool operator()(const Pair& p1, const Pair& p2) const { return p1.first < p2.first; } }; template class select2nd { public: typename Pair::second_type operator()(const Pair& p) const { return p.second; } typename Pair::second_type operator()(Pair& p) const { return p.second; } }; class Concat { private: std::string _delim; public: Concat(const std::string& delim = ""):_delim(delim) {} std::string operator()(const std::string& s1, const std::string& s2) const { return s1+_delim+s2; } }; class Deleter { public: template void operator()(T* ptr) { delete ptr; } }; } // namespace aria2 #endif // _D_A2_FUNCTIONAL_H_