-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathfullcustom.cpp
More file actions
96 lines (93 loc) · 3.92 KB
/
fullcustom.cpp
File metadata and controls
96 lines (93 loc) · 3.92 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// fully customizable graphs using any combination of PlaceRadius, region(s) & system(s)
file.open(Args::datapath+"/graphs/fullcustom.csv");
if (file.is_open())
{ getline(file, line); // ignore header line
while (getline(file, line))
{ // parse fullcustom.csv line
if (line.empty()) continue;
size_t NumFields = 7;
std::string descr, root, lat_s, lng_s, radius, regionlist, systemlist;
std::string* fields[7] = {&descr, &root, &lat_s, &lng_s, &radius, ®ionlist, &systemlist};
split(line, fields, NumFields, ';');
if (NumFields != 7)
{ el.add_error("Could not parse fullcustom.csv line: [" + line
+ "], expected 7 fields, found " + std::to_string(NumFields));
continue;
}
if (descr.size() > DBFieldLength::graphDescr)
el.add_error("description > " + std::to_string(DBFieldLength::graphDescr)
+ " bytes in fullcustom.csv line: " + line);
if (root.size() > DBFieldLength::graphFilename-14)
el.add_error("title > " + std::to_string(DBFieldLength::graphFilename-14)
+ " bytes in fullcustom.csv line: " + line);
bool ok = 1;
// 3 columns of PlaceRadius data
PlaceRadius* a = 0;
char blanks = lat_s.empty() + lng_s.empty() + radius.empty();
if (!blanks)
{ // convert numeric fields
char* endptr;
double lat = strtod(lat_s.data(), &endptr);
if (*endptr) {el.add_error("invalid lat in fullcustom.csv line: " + line); ok = 0;}
double lng = strtod(lng_s.data(), &endptr);
if (*endptr) {el.add_error("invalid lng in fullcustom.csv line: " + line); ok = 0;}
double r = strtod(radius.data(), &endptr);
if (*endptr || r <= 0) {el.add_error("invalid radius in fullcustom.csv line: " + line); ok = 0;}
a = new PlaceRadius(descr.data(), root.data(), lat, lng, r);
} // deleted @ end of HighwayGraph::write_subgraphs_tmg
else if (blanks != 3)
{ el.add_error("lat/lng/radius error in fullcustom.csv line: [" + line
+ "], either all or none must be populated");
ok = 0;
}
else if (regionlist.empty() && systemlist.empty())
{ el.add_error("Disallowed full custom graph in line: [" + line
+ "], functionally identical to tm-master");
continue;
}
// regionlist
if (regionlist.empty()) regions = 0;
else { regions = new vector<Region*>;
// deleted @ end of HighwayGraph::write_subgraphs_tmg
char* field = new char[regionlist.size()+1];
// deleted once region tokens are processed
strcpy(field, regionlist.data());
for(char* rg = strtok(field, ","); rg; rg = strtok(0, ","))
try { regions->push_back(Region::code_hash.at(rg));
}
catch (const std::out_of_range& oor)
{ el.add_error("unrecognized region code "+string(rg)+" in fullcustom.csv line: "+line);
ok = 0;
}
delete[] field;
}
// systemlist
if (systemlist.empty()) systems = 0;
else { systems = new vector<HighwaySystem*>;
// deleted @ end of HighwayGraph::write_subgraphs_tmg
char* field = new char[systemlist.size()+1];
// deleted once system tokens are processed
strcpy(field, systemlist.data());
for(char* s = strtok(field, ","); s; s = strtok(0, ","))
try { HighwaySystem* const h = HighwaySystem::sysname_hash.at(s);
if (h->active_or_preview())
{ systems->push_back(h);
h->is_subgraph_system = 1;
} else el.add_error("devel system "+h->systemname+" in fullcustom.csv line: "+line);
}
catch (const std::out_of_range&)
{ el.add_error("unrecognized system code "+string(s)+" in fullcustom.csv line: "+line);
ok = 0;
}
delete[] field;
}
if (ok) GraphListEntry::add_group(std::move(root), std::move(descr), 'f', regions, systems, a, el);
else { delete regions;
delete systems;
delete a;
}
}
file.close();
graph_types.push_back({"fullcustom", "Full Custom Graphs",
"These graphs can be restricted by any combination of one more more regions and one or more highway systems, and optionally within the given distance radius of a given place."});
}