/* */ #ifndef D_HASH_FUNC_ENTRY_H #define D_HASH_FUNC_ENTRY_H #include "common.h" #include #include #include "DlAbortEx.h" #include "fmt.h" namespace aria2 { template struct HashFuncEntry { typedef HashFunc HashFuncType; std::string hashType; HashFunc hashFunc; HashFuncEntry(const std::string& hashType, const HashFunc& hashFunc): hashType(hashType), hashFunc(hashFunc) {} }; template class FindHashFunc { private: const std::string& hashType_; public: FindHashFunc(const std::string& hashType):hashType_(hashType) {} bool operator()(const HashFuncEntry& entry) const { return entry.hashType == hashType_; } }; template const typename HashFuncEntry::HashFuncType& getHashFunc (HashFuncEntry* first, HashFuncEntry* last, const std::string& hashType) { HashFuncEntry* e = std::find_if(first, last, FindHashFunc (hashType)); if(e == last) { throw DL_ABORT_EX (fmt("Hash type %s is not supported.", hashType.c_str())); } return e->hashFunc; } } // namespace aria2 #endif // D_HASH_FUNC_ENTRY_H