#pragma once #include "drawing_rule_def.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" class LineDefProto; class AreaRuleProto; class SymbolRuleProto; class CaptionDefProto; class CircleRuleProto; namespace drule { class BaseRule { mutable buffer_vector m_id1, m_id2; char m_type; // obsolete for new styles, can be removed 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(); uint32_t GetID2(size_t threadSlot) const; void SetID2(size_t threadSlot, uint32_t id) const; void MakeEmptyID2(size_t threadSlot); void MakeEmptyID2(); 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 CircleRuleProto const * GetCircle() const; }; 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; public: ~RulesHolder(); size_t 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; #ifndef OMIM_PRODUCTION 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]]); } } } } }; RulesHolder & rules(); }