diff options
author | Ilya Zverev <zverik@textual.ru> | 2017-07-27 16:11:18 +0300 |
---|---|---|
committer | Roman Kuznetsov <r.kuznetsow@gmail.com> | 2017-08-11 18:15:40 +0300 |
commit | cc4684d697200e0ab6b259a4bf8fad396ed4d694 (patch) | |
tree | f0f14672bcf383c5e4f672a889195a28ebfeb293 /indexer/drules_selector.cpp | |
parent | 24be21937413f41eac710c3909ff62c5d9ece5c9 (diff) |
[styles] Employ extra_tag apply_if attribute
Diffstat (limited to 'indexer/drules_selector.cpp')
-rw-r--r-- | indexer/drules_selector.cpp | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/indexer/drules_selector.cpp b/indexer/drules_selector.cpp index 2538753a04..f5c0a8b920 100644 --- a/indexer/drules_selector.cpp +++ b/indexer/drules_selector.cpp @@ -1,3 +1,4 @@ +#include "indexer/classificator.hpp" #include "indexer/drules_selector.hpp" #include "indexer/drules_selector_parser.hpp" #include "indexer/ftypes_matcher.hpp" @@ -96,6 +97,38 @@ private: TType const m_value; }; +uint32_t TagSelectorToType(string value) +{ + vector<string> path; + strings::ParseCSVRow(value, '=', path); + return path.size() > 0 && path.size() <= 2 ? classif().GetTypeByPathSafe(path) : 0; +} + +class TypeSelector : public ISelector +{ +public: + TypeSelector(uint32_t type, SelectorOperatorType op) : m_type(type) + { + m_equals = op == SelectorOperatorEqual; + } + + bool Test(FeatureType const & ft) const override + { + bool found = false; + ft.ForEachType([&found, this](uint32_t type) + { + ftype::TruncValue(type, ftype::GetLevel(m_type)); + if (type == m_type) + found = true; + }); + return found == m_equals; + } + +private: + uint32_t m_type; + bool m_equals; +}; + // Feature tag value evaluator for tag 'population' bool GetPopulation(FeatureType const & ft, uint64_t & population) { @@ -188,6 +221,17 @@ unique_ptr<ISelector> ParseSelector(string const & str) } return make_unique<Selector<double>>(&GetRating, e.m_operator, value); } + else if (e.m_tag == "extra_tag") + { + uint32_t const type = TagSelectorToType(e.m_value); + if (type == 0) + { + // Type was not found. + LOG(LDEBUG, ("Invalid selector:", str)); + return unique_ptr<ISelector>(); + } + return make_unique<TypeSelector>(type, e.m_operator); + } // Add new tag here |