MCPcopy Create free account
hub / github.com/comaps/comaps / MixFakeNodes

Function MixFakeNodes

generator/node_mixer.cpp:8–76  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6namespace generator
7{
8void MixFakeNodes(std::istream & stream, std::function<void(OsmElement &)> const & processor)
9{
10 if (stream.fail())
11 return;
12
13 // Max node id on 12.02.2018 times hundred — good enough until ~2030.
14 uint64_t constexpr baseNodeId = 5396734321 * 100;
15 uint8_t constexpr kCFLat = 1;
16 uint8_t constexpr kCFLon = 2;
17 uint8_t constexpr kCFTags = 4;
18 uint8_t constexpr kCFAll = kCFLat | kCFLon | kCFTags;
19 uint64_t count = 0;
20 uint8_t completionFlag = 0;
21 OsmElement p;
22 p.m_id = baseNodeId;
23 p.m_type = OsmElement::EntityType::Node;
24
25 using std::string;
26 string line;
27 while (std::getline(stream, line))
28 {
29 if (line.empty())
30 {
31 if (completionFlag == kCFAll)
32 {
33 processor(p);
34 count++;
35 p.Clear();
36 p.m_id = baseNodeId + count;
37 p.m_type = OsmElement::EntityType::Node;
38 completionFlag = 0;
39 }
40 continue;
41 }
42
43 auto const eqPos = line.find('=');
44 if (eqPos != string::npos)
45 {
46 string key = line.substr(0, eqPos);
47 string value = line.substr(eqPos + 1);
48 strings::Trim(key);
49 strings::Trim(value);
50
51 if (key == "lat")
52 {
53 if (strings::to_double(value, p.m_lat))
54 completionFlag |= kCFLat;
55 }
56 else if (key == "lon")
57 {
58 if (strings::to_double(value, p.m_lon))
59 completionFlag |= kCFLon;
60 }
61 else
62 {
63 p.AddTag(key, value);
64 completionFlag |= kCFTags;
65 }

Callers 2

AddFakeNodesMethod · 0.70
UNIT_TESTFunction · 0.50

Calls 6

TrimFunction · 0.85
to_doubleFunction · 0.50
emptyMethod · 0.45
ClearMethod · 0.45
findMethod · 0.45
AddTagMethod · 0.45

Tested by 1

UNIT_TESTFunction · 0.40