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

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

#include "generator/utils.hpp"

#include "coding/file_reader.hpp"
#include "coding/reader.hpp"

#include "base/logging.hpp"

using std::map;
using std::string;

namespace
{
template <class ToDo>
bool ForEachRoadFromFile(string const & filename, ToDo && toDo)
{
  return generator::ForEachOsmId2FeatureId(
      filename, [&](base::GeoObjectId const & osmId, uint32_t const featureId) {
        if (osmId.GetType() == base::GeoObjectId::Type::ObsoleteOsmWay)
          toDo(featureId, osmId);
      });
}
}  // namespace

namespace routing
{
void AddFeatureId(base::GeoObjectId osmId, uint32_t featureId,
                  map<base::GeoObjectId, uint32_t> & osmIdToFeatureId)
{
  // Failing to insert here usually means that two features were created
  // from one osm id, for example an area and its boundary.
  osmIdToFeatureId.emplace(osmId, featureId);
}

bool ParseRoadsOsmIdToFeatureIdMapping(string const & osmIdsToFeatureIdPath,
                                       map<base::GeoObjectId, uint32_t> & osmIdToFeatureId)
{
  return ForEachRoadFromFile(osmIdsToFeatureIdPath,
                             [&](uint32_t featureId, base::GeoObjectId osmId) {
                               AddFeatureId(osmId, featureId, osmIdToFeatureId);
                             });
}

bool ParseRoadsFeatureIdToOsmIdMapping(string const & osmIdsToFeatureIdPath,
                                       map<uint32_t, base::GeoObjectId> & featureIdToOsmId)
{
  featureIdToOsmId.clear();
  bool idsAreOk = true;

  bool const readSuccess = ForEachRoadFromFile(
      osmIdsToFeatureIdPath, [&](uint32_t featureId, base::GeoObjectId const & osmId) {
        auto const emplaced = featureIdToOsmId.emplace(featureId, osmId);
        if (emplaced.second)
          return;

        idsAreOk = false;
        LOG(LERROR, ("Feature id", featureId, "is included in two osm ids:", emplaced.first->second,
                     osmId));
      });

  if (readSuccess && idsAreOk)
    return true;

  LOG(LERROR, ("Can't load osm id mapping from", osmIdsToFeatureIdPath));
  featureIdToOsmId.clear();
  return false;
}
}  // namespace routing