#pragma once #include "indexer/drawing_rule_def.hpp" #include "indexer/drules_selector.hpp" #include "indexer/map_style.hpp" #include "base/base.hpp" #include "base/buffer_vector.hpp" #include "std/map.hpp" #include "std/vector.hpp" #include "std/array.hpp" #include "std/string.hpp" #include "std/iostream.hpp" #include "std/target_os.hpp" #include class LineDefProto; class AreaRuleProto; class SymbolRuleProto; class CaptionDefProto; class ShieldRuleProto; class ContainerProto; class FeatureType; namespace drule { class BaseRule { mutable buffer_vector m_id1; char m_type; // obsolete for new styles, can be removed unique_ptr m_selector; public: static uint32_t const empty_id = 0xFFFFFFFF; BaseRule(); virtual ~BaseRule(); void CheckCacheSize(size_t s); uint32_t GetID(size_t threadSlot) const; void SetID(size_t threadSlot, uint32_t id) const; void MakeEmptyID(size_t threadSlot); void MakeEmptyID(); void SetType(char type) { m_type = type; } inline char GetType() const { return m_type; } virtual LineDefProto const * GetLine() const; virtual AreaRuleProto const * GetArea() const; virtual SymbolRuleProto const * GetSymbol() const; virtual CaptionDefProto const * GetCaption(int) const; virtual text_type_t GetCaptionTextType(int) const; virtual ShieldRuleProto const * GetShield() const; // Test feature by runtime feature style selector // Returns true if rule is applicable for feature, otherwise it returns false bool TestFeature(FeatureType const & ft, int zoom) const; // Set runtime feature style selector void SetSelector(unique_ptr && selector); }; class RulesHolder { // container of rules by type typedef vector rule_vec_t; array m_container; /// scale -> array of rules by type -> index of rule in m_container typedef map, count_of_rules> > rules_map_t; rules_map_t m_rules; /// background color for scales in range [0...scales::UPPER_STYLE_SCALE] vector m_bgColors; std::unordered_map m_colors; public: RulesHolder(); ~RulesHolder(); Key AddRule(int scale, rule_type_t type, BaseRule * p); void Clean(); void ClearCaches(); void ResizeCaches(size_t Size); BaseRule const * Find(Key const & k) const; uint32_t GetBgColor(int scale) const; uint32_t GetColor(std::string const & name) const; #ifdef OMIM_OS_DESKTOP void LoadFromTextProto(string const & buffer); static void SaveToBinaryProto(string const & buffer, ostream & s); #endif void LoadFromBinaryProto(string const & s); template void ForEachRule(ToDo toDo) { for (rules_map_t::const_iterator i = m_rules.begin(); i != m_rules.end(); ++i) { for (int j = 0; j < count_of_rules; ++j) { vector const & v = i->second[j]; for (size_t k = 0; k < v.size(); ++k) { // scale, type, rule toDo(i->first, j, v[k], m_container[j][v[k]]); } } } } private: void InitBackgroundColors(ContainerProto const & cp); void InitColors(ContainerProto const & cp); }; RulesHolder & rules(); void LoadRules(); }