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

node_mixer.cpp « generator - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e84e06b7bdd2c9a61e7c1c8ffc5e805f7ffed9b7 (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
70
71
72
73
74
75
76
77
78
#include "generator/node_mixer.hpp"

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

using namespace std;

namespace generator
{
void MixFakeNodes(istream & stream, function<void(OsmElement *)> processor)
{
  if (stream.fail())
    return;

  // Max node id on 12.02.2018 times hundred — good enough until ~2030.
  uint64_t constexpr baseNodeId = 5396734321 * 100;
  uint8_t constexpr kCFLat = 1;
  uint8_t constexpr kCFLon = 2;
  uint8_t constexpr kCFTags = 4;
  uint8_t constexpr kCFAll = kCFLat | kCFLon | kCFTags;
  uint64_t count = 0;
  uint8_t completionFlag = 0;
  OsmElement p;
  p.id = baseNodeId;
  p.type = OsmElement::EntityType::Node;

  string line;
  while (getline(stream, line))
  {
    if (line.empty())
    {
      if (completionFlag == kCFAll)
      {
        processor(&p);
        count++;
        p.Clear();
        p.id = baseNodeId + count;
        p.type = OsmElement::EntityType::Node;
        completionFlag = 0;
      }
      continue;
    }

    auto const eqPos = line.find('=');
    if (eqPos != string::npos)
    {
      string key = line.substr(0, eqPos);
      string value = line.substr(eqPos + 1);
      strings::Trim(key);
      strings::Trim(value);

      if (key == "lat")
      {
        if (strings::to_double(value, p.lat))
          completionFlag |= kCFLat;
      }
      else if (key == "lon")
      {
        if (strings::to_double(value, p.lon))
          completionFlag |= kCFLon;
      }
      else
      {
        p.AddTag(key, value);
        completionFlag |= kCFTags;
      }
    }
  }

  if (completionFlag == kCFAll)
  {
    processor(&p);
    count++;
  }

  LOG(LINFO, ("Added", count, "fake nodes."));
}
}  // namespace generator