blob: 3aaa9158cd0211d429e259be7b7c2a0f8c5cd564 (
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
|
#include "routing/traffic_stash.hpp"
#include "base/checked_cast.hpp"
#include <map>
namespace routing
{
TrafficStash::TrafficStash(traffic::TrafficCache const & source, shared_ptr<NumMwmIds> numMwmIds)
: m_source(source), m_numMwmIds(std::move(numMwmIds))
{
CHECK(m_numMwmIds, ());
}
traffic::SpeedGroup TrafficStash::GetSpeedGroup(Segment const & segment) const
{
auto itMwm = m_mwmToTraffic.find(segment.GetMwmId());
if (itMwm == m_mwmToTraffic.cend())
return traffic::SpeedGroup::Unknown;
auto const & coloring = itMwm->second;
auto const itSeg = coloring->find(traffic::TrafficInfo::RoadSegmentId(
segment.GetFeatureId(), base::asserted_cast<uint16_t>(segment.GetSegmentIdx()),
segment.IsForward() ? traffic::TrafficInfo::RoadSegmentId::kForwardDirection
: traffic::TrafficInfo::RoadSegmentId::kReverseDirection));
if (itSeg == coloring->cend())
return traffic::SpeedGroup::Unknown;
return itSeg->second;
}
void TrafficStash::SetColoring(NumMwmId numMwmId,
std::shared_ptr<traffic::TrafficInfo::Coloring> coloring)
{
m_mwmToTraffic[numMwmId] = coloring;
}
bool TrafficStash::Has(NumMwmId numMwmId) const
{
return m_mwmToTraffic.find(numMwmId) != m_mwmToTraffic.cend();
}
void TrafficStash::CopyTraffic()
{
std::map<MwmSet::MwmId, std::shared_ptr<traffic::TrafficInfo::Coloring>> copy;
m_source.CopyTraffic(copy);
for (auto const & kv : copy)
{
auto const numMwmId = m_numMwmIds->GetId(kv.first.GetInfo()->GetLocalFile().GetCountryFile());
CHECK(kv.second, ());
SetColoring(numMwmId, kv.second);
}
}
} // namespace routing
|