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

traffic_stash.hpp « routing - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6cb4157c1d59625925477f1afc717f0bcf9cd673 (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
#pragma once

#include "routing/segment.hpp"

#include "traffic/traffic_cache.hpp"
#include "traffic/traffic_info.hpp"

#include "routing_common/num_mwm_id.hpp"

#include "indexer/mwm_set.hpp"

#include "base/assert.hpp"

#include <memory>
#include <unordered_map>
#include <utility>

namespace routing
{
class TrafficStash final
{
public:
  class Guard final
  {
  public:
    explicit Guard(std::shared_ptr<TrafficStash> stash) : m_stash(std::move(stash))
    {
      if (m_stash)
        m_stash->CopyTraffic();
    }

    ~Guard()
    {
      if (m_stash)
        m_stash->Clear();
    }

  private:
    std::shared_ptr<TrafficStash> m_stash;
  };

  TrafficStash(traffic::TrafficCache const & source, std::shared_ptr<NumMwmIds> numMwmIds);

  traffic::SpeedGroup GetSpeedGroup(Segment const & segment) const;
  void SetColoring(NumMwmId numMwmId, std::shared_ptr<const traffic::TrafficInfo::Coloring> coloring);
  bool Has(NumMwmId numMwmId) const;

private:
  void CopyTraffic();

  void Clear() { m_mwmToTraffic.clear(); }

  traffic::TrafficCache const & m_source;
  std::shared_ptr<NumMwmIds> m_numMwmIds;
  std::unordered_map<NumMwmId, std::shared_ptr<const traffic::TrafficInfo::Coloring>> m_mwmToTraffic;
};
}  // namespace routing