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: bf672dd81e3760d2bf42a0d87ef83632d7a3f6a8 (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
#include "generator/restriction_generator.hpp"

#include "generator/restriction_collector.hpp"

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

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

#include "defines.hpp"

#include "std/algorithm.hpp"

namespace routing
{
bool BuildRoadRestrictions(string const & mwmPath, string const & restrictionPath,
                           string const & osmIdsTofeatureIdsPath)
{
  LOG(LINFO, ("BuildRoadRestrictions(", mwmPath, ", ", restrictionPath, ", ",
              osmIdsTofeatureIdsPath, ");"));
  RestrictionCollector restrictionCollector(restrictionPath, osmIdsTofeatureIdsPath);
  if (!restrictionCollector.HasRestrictions() || !restrictionCollector.IsValid())
  {
    LOG(LWARNING, ("No valid restrictions for", mwmPath, "It's necessary to check that",
                   restrictionPath, "and", osmIdsTofeatureIdsPath, "are available."));
    return false;
  }

  RestrictionVec const & restrictions = restrictionCollector.GetRestrictions();

  auto const firstOnlyIt =
      lower_bound(restrictions.cbegin(), restrictions.cend(),
                  Restriction(Restriction::Type::Only, {} /* links */), my::LessBy(&Restriction::m_type));
  RoutingHeader header;
  header.m_noRestrictionCount = distance(restrictions.cbegin(), firstOnlyIt);
  header.m_onlyRestrictionCount = restrictions.size() - header.m_noRestrictionCount;
  LOG(LINFO, ("Header info. There are", header.m_noRestrictionCount, "of type No restrictions and",
              header.m_onlyRestrictionCount, "of type Only restrictions"));

  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