#pragma once #include "indexer/classificator.hpp" #include "indexer/feature_data.hpp" #include #include #include #include #include namespace ftypes { template class Matcher { public: using ConstIterator = typename Container::const_iterator; ConstIterator Find(feature::TypesHolder const & types) const { for (auto const t : types) { for (auto level = ftype::GetLevel(t); level; --level) { auto truncatedType = t; ftype::TruncValue(truncatedType, level); auto const it = m_mapping.find(truncatedType); if (it != m_mapping.cend()) return it; } } return m_mapping.cend(); } bool IsValid(ConstIterator it) const { return it != m_mapping.cend(); } bool Contains(feature::TypesHolder const & types) const { return IsValid(Find(types)); } template void Append(TypesPaths const & types, Args const & ... args) { for (auto const & type : types) { #if defined(DEBUG) feature::TypesHolder holder; holder.Assign(classif().GetTypeByPath(type)); ASSERT(Find(holder) == m_mapping.cend(), ("This type already exists", type)); #endif m_mapping.emplace(classif().GetTypeByPath(type), args...); } } private: Container m_mapping; }; template using HashMapMatcher = Matcher>; template using HashSetMatcher = Matcher>; } // namespace ftypes