Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions siteupdate/cplusplus/classes/HighwaySystem.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -32,7 +32,7 @@ class HighwaySystem

HighwaySystem(std::string &line, ErrorList &el, std::string path, std::string &systemsfile,
std::list<std::pair<std::string,std::string>> &countries,
std::list<Region> &all_regions)
std::unordered_map<std::string, Region*> &region_hash)
{ char *c_country = 0;
std::string filename;
std::ifstream file;
Expand DownExpand Up@@ -63,7 +63,7 @@ class HighwaySystem
else { getline(file, line); // ignore header line
while(getline(file, line))
{ if (line.back() == 0x0D) line.erase(line.end()-1); // trim DOS newlines
route_list.emplace_back(line, this, el, all_regions);
route_list.emplace_back(line, this, el, region_hash);
if (!route_list.back().is_valid()) route_list.pop_back();
}
}
Expand Down
7 changes: 0 additions & 7 deletions siteupdate/cplusplus/classes/Region.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -93,13 +93,6 @@ class Region
}
};

Region *region_by_code(std::string code, std::list<Region> &all_regions)
//FIXME replace with an unordered_map
{ for (std::list<Region>::iterator r = all_regions.begin(); r != all_regions.end(); r++)
if (r->code == code) return &*r;
return 0;
}

bool sort_regions_by_code(const Region *r1, const Region *r2)
{ return r1->code < r2->code;
}
8 changes: 5 additions & 3 deletions siteupdate/cplusplus/classes/Route/Route.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,7 +2,7 @@ std::mutex Route::liu_mtx;
std::mutex Route::ual_mtx;
std::mutex Route::awf_mtx;

Route::Route(std::string &line, HighwaySystem *sys, ErrorList &el, std::list<Region> &all_regions)
Route::Route(std::string &line, HighwaySystem *sys, ErrorList &el, std::unordered_map<std::string, Region*> &region_hash)
{ /* initialize object from a .csv file line,
but do not yet read in waypoint file */
con_route = 0;
Expand All@@ -28,9 +28,11 @@ Route::Route(std::string &line, HighwaySystem *sys, ErrorList &el, std::list<Reg
{ el.add_error("Could not parse " + system->systemname + ".csv line: [" + line + "], expected 8 fields, found 2");
return;
}
region = region_by_code(line.substr(left+1, right-left-1), all_regions);
if (!region)
try { region = region_hash.at(line.substr(left+1, right-left-1));
}
catch (const std::out_of_range& oor)
{ el.add_error("Unrecognized region in " + system->systemname + ".csv line: [" + line + "], " + line.substr(left+1, right-left-1));
region = 0;
return;
}

Expand Down
2 changes: 1 addition & 1 deletion siteupdate/cplusplus/classes/Route/Route.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -58,7 +58,7 @@ class Route
double mileage;
int rootOrder;

Route(std::string &, HighwaySystem *, ErrorList &, std::list<Region> &);
Route(std::string &, HighwaySystem *, ErrorList &, std::unordered_map<std::string, Region*> &);

std::string str();
void read_wpt(WaypointQuadtree *, ErrorList *, std::string, std::mutex *, DatacheckEntryList *, std::unordered_set<std::string> *);
Expand Down
4 changes: 2 additions & 2 deletions siteupdate/cplusplus/classes/Waypoint/Waypoint.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -225,7 +225,7 @@ inline Waypoint* Waypoint::hashpoint()
/* Datacheck */

inline void Waypoint::duplicate_label(DatacheckEntryList *datacheckerrors, std::unordered_set<std::string> &all_route_labels)
{ // duplicate labels //FIXME *MAYBE* see if the list changes could help siteupdate.py a tiny bit?
{ // duplicate labels
// first, check primary label
std::string lower_label = lower(label);
while (lower_label[0] == '+' || lower_label[0] == '*') lower_label.erase(lower_label.begin());
Expand All@@ -248,7 +248,7 @@ inline void Waypoint::duplicate_coords(DatacheckEntryList *datacheckerrors, std:
if (!coords_used.insert(w).second)
for (Waypoint *other_w : route->point_list)
{ if (this == other_w) break;
if (lat == other_w->lat && lng == other_w->lng /*&& label != other_w->label*/) //FIXME necessary? Try eliminating from siteupdate.py
if (lat == other_w->lat && lng == other_w->lng)
{ sprintf(fstr, "(%.15g,%.15g)", lat, lng);
datacheckerrors->add(route, other_w->label, label, "", "DUPLICATE_COORDS", fstr);
}
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -135,7 +135,7 @@ std::string Waypoint::canonical_waypoint_name(std::list<std::string> &log)
suffixes[other_index] = suffix;
}
}
else if (ap_coloc[check_index]->label.find(ap_coloc[other_index]->route->name_no_abbrev()) == 0) //FIXME -> elif in siteupdate.py
else if (ap_coloc[check_index]->label.find(ap_coloc[other_index]->route->name_no_abbrev()) == 0)
{ this_match = 1;
if (strchr(ap_coloc[check_index]->label.data(), '_'))
{ std::string suffix = strchr(ap_coloc[check_index]->label.data(), '_');
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -35,7 +35,7 @@ void WaypointQuadtree::insert(Waypoint *w)
{ // insert Waypoint *w into this quadtree node
//std::cout << "QTDEBUG: " << str() << " insert " << w->str() << std::endl;
if (!refined())
{ if (!waypoint_at_same_point(w)) //FIXME Try (!w->colocated) instead. Efficiency increase?
{ if (!waypoint_at_same_point(w))
{ //std::cout << "QTDEBUG: " << str() << " at " << unique_locations << " unique locations" << std::endl;
unique_locations++;
}
Expand DownExpand Up@@ -114,20 +114,19 @@ std::forward_list<Waypoint*> WaypointQuadtree::near_miss_waypoints(Waypoint *w,
return near_miss_points;
}

std::string WaypointQuadtree::str() //FIXME use sprintf
{ std::string s = "WaypointQuadtree at (" + \
std::to_string(min_lat) + "," + std::to_string(min_lng) + ") to (" + \
std::to_string(max_lat) + "," + std::to_string(max_lng) + ")";
std::string WaypointQuadtree::str()
{ char s[139];
sprintf(s, "WaypointQuadtree at (%.15g,%.15g) to (%.15g,%.15g)", min_lat, min_lng, max_lat, max_lng);
if (refined())
return s + " REFINED";
else return s + " contains " + std::to_string(std::distance(points.begin(), points.end())) + " waypoints";
return std::string(s) + " REFINED";
else return std::string(s) + " contains " + std::to_string(std::distance(points.begin(), points.end())) + " waypoints";
}

unsigned int WaypointQuadtree::size()
{ // return the number of Waypoints in the tree
if (refined())
return nw_child->size() + ne_child->size() + sw_child->size() + se_child->size();
else return std::distance(points.begin(), points.end()); //FIXME std::list faster here? Where & how often is WaypointQuadtree::size() used?
else return std::distance(points.begin(), points.end());
}

std::forward_list<Waypoint*> WaypointQuadtree::point_list()
Expand Down
4 changes: 2 additions & 2 deletions siteupdate/cplusplus/functions/concurrency_detection.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -26,8 +26,8 @@ for (HighwaySystem *h : highway_systems)
}
else
{ other->concurrent = s->concurrent;
std::list<HighwaySegment*>::iterator it = s->concurrent->begin(); //FIXME
while (it != s->concurrent->end() && *it != other) it++; //see HighwaySegment.h
std::list<HighwaySegment*>::iterator it = s->concurrent->begin();
while (it != s->concurrent->end() && *it != other) it++;
if (it == s->concurrent->end())
{ s->concurrent->push_back(other);
//concurrencyfile << "Added concurrency [" << s->str() << "]-[" \
Expand Down
4 changes: 3 additions & 1 deletion siteupdate/cplusplus/siteupdate.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -173,13 +173,15 @@ int main(int argc, char *argv[])

//regions
list<Region> all_regions;
unordered_map<string, Region*> region_hash;
filename = args.highwaydatapath+"/regions.csv";
file.open(filename.data());
if (!file) el.add_error("Could not open " + filename);
else { getline(file, line); // ignore header line
while(getline(file, line))
{ Region rg(line, countries, continents, el);
if (rg.is_valid()) all_regions.push_back(rg);
region_hash[all_regions.back().code] = &all_regions.back();
}
}
file.close();
Expand All@@ -198,7 +200,7 @@ int main(int argc, char *argv[])
{ ignoring.push_back("Ignored comment in " + args.systemsfile + ": " + line);
continue;
}
HighwaySystem *hs = new HighwaySystem(line, el, args.highwaydatapath+"/hwy_data/_systems", args.systemsfile, countries, all_regions);
HighwaySystem *hs = new HighwaySystem(line, el, args.highwaydatapath+"/hwy_data/_systems", args.systemsfile, countries, region_hash);
// deleted on termination of program
if (hs->is_valid()) highway_systems.push_back(hs);
else delete hs;
Expand Down