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

restriction_generator.cpp « generator - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7f7d01178d3e1141b3d22a0db09c7c11859fb279 (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
#include "generator/restriction_generator.hpp"

#include "generator/restriction_collector.hpp"

#include "coding/file_container.hpp"
#include "coding/file_writer.hpp"

#include "base/checked_cast.hpp"
#include "base/logging.hpp"
#include "base/stl_helpers.hpp"

#include "defines.hpp"

#include <algorithm>

namespace routing
{
bool BuildRoadRestrictions(std::string const & mwmPath, std::string const & restrictionPath,
                           std::string const & osmIdsTofeatureIdsPath)
{
  LOG(LDEBUG, ("BuildRoadRestrictions(", mwmPath, ", ", restrictionPath, ", ",
              osmIdsTofeatureIdsPath, ");"));
  RestrictionCollector restrictionCollector(restrictionPath, osmIdsTofeatureIdsPath);
  if (!restrictionCollector.HasRestrictions())
  {
    LOG(LINFO, ("No restrictions for", mwmPath, "It's necessary to check that",
                   restrictionPath, "and", osmIdsTofeatureIdsPath, "are available."));
    return false;
  }
  if (!restrictionCollector.IsValid())
  {
    LOG(LWARNING, ("Found invalid restrictions for", mwmPath, "Are osm2ft files relevant?"));
    return false;
  }

  RestrictionVec const & restrictions = restrictionCollector.GetRestrictions();

  auto const firstOnlyIt =
      std::lower_bound(restrictions.cbegin(), restrictions.cend(),
                       Restriction(Restriction::Type::Only, {} /* links */),
                       base::LessBy(&Restriction::m_type));

  RestrictionHeader header;
  header.m_noRestrictionCount = base::checked_cast<uint32_t>(std::distance(restrictions.cbegin(), firstOnlyIt));
  header.m_onlyRestrictionCount = base::checked_cast<uint32_t>(restrictions.size() - header.m_noRestrictionCount);

  LOG(LINFO, ("Header info. There are", header.m_noRestrictionCount, "restrictions of type No and",
              header.m_onlyRestrictionCount, "restrictions of type Only"));

  FilesContainerW cont(mwmPath, FileWriter::OP_WRITE_EXISTING);
  FileWriter w = cont.GetWriter(RESTRICTIONS_FILE_TAG);
  header.Serialize(w);

  RestrictionSerializer::Serialize(header, restrictions.cbegin(), restrictions.cend(), w);

  return true;
}
}  // namespace routing