Welcome to mirror list, hosted at ThFree Co, Russian Federation.

drawing_rules.hpp « indexer - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 575673cee687870b98f35a856ffc56ead22e3976 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#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<uint32_t, 4> 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<BaseRule*> rule_vec_t;
    array<rule_vec_t, count_of_rules> m_container;

    /// scale -> array of rules by type -> index of rule in m_container
    typedef map<int32_t, array<vector<uint32_t>, 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 <class ToDo> 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<uint32_t> 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();
}