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
23 changes: 16 additions & 7 deletions siteupdate/cplusplus/classes/ConnectedRoute/ConnectedRoute.cpp
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
ConnectedRoute::ConnectedRoute(std::string &line, HighwaySystem *sys, ErrorList &el, std::list<Route> &route_list)
ConnectedRoute::ConnectedRoute(std::string &line, HighwaySystem *sys, ErrorList &el)
{ mileage = 0;

// parse chopped routes csv line
Expand DownExpand Up@@ -29,19 +29,28 @@ ConnectedRoute::ConnectedRoute(std::string &line, HighwaySystem *sys, ErrorList
el.add_error("groupname > " + std::to_string(DBFieldLength::city)
+ " bytes in " + system->systemname + "_con.csv line: " + line);
// roots
lower(roots_str.data());
int rootOrder = 0;
size_t l = 0;
for (size_t r = 0; r != -1; l = r+1)
{ r = roots_str.find(',', l);
Route *root = route_by_root(roots_str.substr(l, r-l), route_list);
if (!root) el.add_error("Could not find Route matching ConnectedRoute root " + roots_str.substr(l, r-l) +
" in system " + system->systemname + '.');
else { roots.push_back(root);
try { Route *root = Route::root_hash.at(roots_str.substr(l, r-l));
roots.push_back(root);
if (root->con_route)
el.add_error("Duplicate root in " + sys->systemname + "_con.csv: " + root->root +
" already in " + root->con_route->system->systemname + "_con.csv");
if (system != root->system)
el.add_error("System mismatch: chopped route " + root->root + " from " + root->system->systemname +
".csv in connected route in " + system->systemname + "_con.csv");
root->con_route = this;
// save order of route in connected route
root->rootOrder = rootOrder;
}
rootOrder++;
rootOrder++;
}
catch (std::out_of_range& oor)
{ el.add_error("Could not find Route matching ConnectedRoute root " + roots_str.substr(l, r-l) +
" in system " + system->systemname + '.');
}
}
if (roots.size() < 1) el.add_error("No roots in " + system->systemname + "_con.csv line: " + line);
}
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,7 +12,7 @@ class ConnectedRoute

double mileage; // will be computed for routes in active & preview systems

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

std::string connected_rtes_line();
std::string csv_line();
Expand Down
5 changes: 0 additions & 5 deletions siteupdate/cplusplus/classes/GraphGeneration/HGEdge.cpp
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
// constants for more human-readable format masks
const unsigned char HGEdge::simple = 1;
const unsigned char HGEdge::collapsed = 2;
const unsigned char HGEdge::traveled = 4;

HGEdge::HGEdge(HighwaySegment *s, HighwayGraph *graph)
{ // initial construction is based on a HighwaySegment
s_written = 0; // simple
Expand Down
6 changes: 3 additions & 3 deletions siteupdate/cplusplus/classes/GraphGeneration/HGEdge.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,9 +12,9 @@ class HGEdge
unsigned char format;

// constants for more human-readable format masks
static const unsigned char simple;
static const unsigned char collapsed;
static const unsigned char traveled;
static const unsigned char simple = 1;
static const unsigned char collapsed = 2;
static const unsigned char traveled = 4;

HGEdge(HighwaySegment *, HighwayGraph *);
HGEdge(HGVertex *, unsigned char);
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -96,7 +96,7 @@ class HighwayGraph
// compress edges adjacent to hidden vertices
counter = 0;
std::cout << et.et() + "Compressing collapsed edges" << std::flush;
for (std::pair<const Waypoint*, HGVertex*> wv : vertices)
for (std::pair<Waypoint* const, HGVertex*>& wv : vertices)
{ if (counter % 10000 == 0) std::cout << '.' << std::flush;
counter++;
if (!wv.second->visibility)
Expand DownExpand Up@@ -146,7 +146,7 @@ class HighwayGraph
} // end ctor

void clear()
{ for (std::pair<const Waypoint*, HGVertex*> wv : vertices) delete wv.second;
{ for (std::pair<Waypoint* const, HGVertex*>& wv : vertices) delete wv.second;
vertex_names.clear();
waypoint_naming_log.clear();
vertices.clear();
Expand Down
16 changes: 8 additions & 8 deletions siteupdate/cplusplus/classes/GraphGeneration/PlaceRadius.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,10 +10,10 @@ bool PlaceRadius::contains_vertex(HGVertex *v) {return contains_vertex(v->lat, v
bool PlaceRadius::contains_vertex(double vlat, double vlng)
{ /* return whether coordinates are within this area */
// convert to radians to compute distance
double rlat1 = lat * (Waypoint::pi/180);
double rlng1 = lng * (Waypoint::pi/180);
double rlat2 = vlat * (Waypoint::pi/180);
double rlng2 = vlng * (Waypoint::pi/180);
double rlat1 = lat * (pi/180);
double rlng1 = lng * (pi/180);
double rlat2 = vlat * (pi/180);
double rlng2 = vlng * (pi/180);

/* original formula
double ans = acos(cos(rlat1)*cos(rlng1)*cos(rlat2)*cos(rlng2) +\
Expand DownExpand Up@@ -48,10 +48,10 @@ std::unordered_set<HGVertex*> PlaceRadius::vertices(WaypointQuadtree *qt, Highwa

// N/S sanity check: If lat is <= r/2 miles to the N or S pole, lngdelta calculation will fail.
// In these cases, our place radius will span the entire "width" of the world, from -180 to +180 degrees.
if (90-fabs(lat)*(Waypoint::pi/180) <= r/7926.2) return v_search(qt, g, -180, +180);
if (90-fabs(lat)*(pi/180) <= r/7926.2) return v_search(qt, g, -180, +180);

// width, in degrees longitude, of our bounding box for quadtree search
double lngdelta = acos((cos(r/3963.1) - pow(sin(lat*(Waypoint::pi/180)),2)) / pow(cos(lat*(Waypoint::pi/180)),2)) / (Waypoint::pi/180);
double lngdelta = acos((cos(r/3963.1) - pow(sin(lat*(pi/180)),2)) / pow(cos(lat*(pi/180)),2)) / (pi/180);
double w_bound = lng-lngdelta;
double e_bound = lng+lngdelta;

Expand DownExpand Up@@ -92,8 +92,8 @@ std::unordered_set<HGVertex*> PlaceRadius::v_search(WaypointQuadtree *qt, Highwa
// if we're not a terminal quadrant, we need to determine which
// of our child quadrants we need to search and recurse into each
else { //printf("DEBUG: recursive case, mid_lat=%.17g mid_lng=%.17g\n", qt->mid_lat, qt->mid_lng); fflush(stdout);
bool look_n = (lat + r/3963.1/(Waypoint::pi/180)) >= qt->mid_lat;
bool look_s = (lat - r/3963.1/(Waypoint::pi/180)) <= qt->mid_lat;
bool look_n = (lat + r/3963.1/(pi/180)) >= qt->mid_lat;
bool look_s = (lat - r/3963.1/(pi/180)) <= qt->mid_lat;
bool look_e = e_bound >= qt->mid_lng;
bool look_w = w_bound <= qt->mid_lng;
//std::cout << "DEBUG: recursive case, " << look_n << " " << look_s << " " << look_e << " " << look_w << std::endl;
Expand Down
16 changes: 6 additions & 10 deletions siteupdate/cplusplus/classes/HighwaySegment/HighwaySegment.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -49,19 +49,15 @@ unsigned int HighwaySegment::index()
/*std::string HighwaySegment::concurrent_travelers_sanity_check()
{ if (route->system->devel()) return "";
if (concurrent)
for (HighwaySegment *conc : *concurrent)
{ if (clinched_by.size() != conc->clinched_by.size())
{ if (conc->route->system->devel()) continue;
for (HighwaySegment *other : *concurrent)
{ if (clinched_by.size() != other->clinched_by.size())
{ if (other->route->system->devel()) continue;
return "[" + str() + "] clinched by " + std::to_string(clinched_by.size()) + " travelers; [" \
+ conc->str() + "] clinched by " + std::to_string(conc->clinched_by.size()) + '\n';
+ other->str() + "] clinched by " + std::to_string(other->clinched_by.size()) + '\n';
}
else for (TravelerList *t : clinched_by)
{ std::list<TravelerList*>::iterator ct;
for (ct = conc->clinched_by.begin(); ct != conc->clinched_by.end(); ct++)
if (*ct == t) break;
if (ct == conc->clinched_by.end())
return t->traveler_name + " has clinched [" + str() + "], but not [" + conc->str() + "]\n";
}
if (other->clinched_by.find(t) == other->clinched_by.end())
return t->traveler_name + " has clinched [" + str() + "], but not [" + other->str() + "]\n";
}
return "";
}//*/
Expand Down
10 changes: 6 additions & 4 deletions siteupdate/cplusplus/classes/HighwaySystem.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -79,7 +79,8 @@ class HighwaySystem
if (!file) el.add_error("Could not open "+path+"/"+systemname+".csv");
else { getline(file, line); // ignore header line
while(getline(file, line))
{ if (line.back() == 0x0D) line.erase(line.end()-1); // trim DOS newlines
{ // trim DOS newlines & trailing whitespace
while ( strchr("\r\t ", line.back()) ) line.pop_back();
if (line.empty()) continue;
route_list.emplace_back(line, this, el, region_hash);
if (route_list.back().root.empty())
Expand All@@ -95,9 +96,10 @@ class HighwaySystem
if (!file) el.add_error("Could not open "+path+"/"+systemname+"_con.csv");
else { getline(file, line); // ignore header line
while(getline(file, line))
{ if (line.back() == 0x0D) line.erase(line.end()-1); // trim DOS newlines
{ // trim DOS newlines & trailing whitespace
while ( strchr("\r\t ", line.back()) ) line.pop_back();
if (line.empty()) continue;
con_route_list.emplace_back(line, this, el, route_list);
con_route_list.emplace_back(line, this, el);
}
}
file.close();
Expand DownExpand Up@@ -126,7 +128,7 @@ class HighwaySystem
/* Return total system mileage across all regions */
double total_mileage()
{ double mi = 0;
for (std::pair<Region*, double> rm : mileage_by_region) mi += rm.second;
for (std::pair<Region* const, double>& rm : mileage_by_region) mi += rm.second;
return mi;
}

Expand Down
4 changes: 2 additions & 2 deletions siteupdate/cplusplus/classes/Region.cpp
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
std::pair<std::string, std::string> *country_or_continent_by_code(std::string code, std::vector<std::pair<std::string, std::string>> &pair_vector)
{ for (std::vector<std::pair<std::string, std::string>>::iterator c = pair_vector.begin(); c != pair_vector.end(); c++)
if (c->first == code) return &*c;
{ for (std::pair<std::string, std::string>& c : pair_vector)
if (c.first == code) return &c;
return 0;
}

Expand Down
31 changes: 21 additions & 10 deletions siteupdate/cplusplus/classes/Route/Route.cpp
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
std::unordered_map<std::string, Route*> Route::root_hash, Route::list_hash;
std::mutex Route::awf_mtx;

Route::Route(std::string &line, HighwaySystem *sys, ErrorList &el, std::unordered_map<std::string, Region*> &region_hash)
Expand DownExpand Up@@ -52,12 +53,28 @@ Route::Route(std::string &line, HighwaySystem *sys, ErrorList &el, std::unordere
if (root.size() > DBFieldLength::root)
el.add_error("Root > " + std::to_string(DBFieldLength::root)
+ " bytes in " + system->systemname + ".csv line: " + line);
lower(root.data());
// alt_route_names
size_t l = 0;
for (size_t r = 0; r != -1; l = r+1)
{ r = arn_str.find(',', l);
alt_route_names.emplace_back(arn_str, l, r-l);
upper(arn_str.data());
size_t len;
for (size_t pos = 0; pos < arn_str.size(); pos += len+1)
{ len = strcspn(arn_str.data()+pos, ",");
alt_route_names.emplace_back(arn_str, pos, len);
}

// insert into root_hash, checking for duplicate root entries
if (!root_hash.insert(std::pair<std::string, Route*>(root, this)).second)
el.add_error("Duplicate root in " + system->systemname + ".csv: " + root +
" already in " + root_hash.at(root)->system->systemname + ".csv");
// insert into list_hash with list name, checking for duplicate .list names
if (!list_hash.insert(std::pair<std::string, Route*>(upper(readable_name()), this)).second)
el.add_error("Duplicate main list name in " + root + ": '" + readable_name() +
"' already points to " + list_hash.at( upper(readable_name()) )->root);
// insert into list_hash with alt names, checking for duplicate .list names
for (std::string& a : alt_route_names)
if (!list_hash.insert(std::pair<std::string, Route*>(upper(rg_str + " " + a), this)).second)
el.add_error("Duplicate alt route name in " + root + ": '" + region->code + ' ' + a +
"' already points to " + list_hash.at(upper(rg_str + " " + a))->root);
}

std::string Route::str()
Expand DownExpand Up@@ -179,9 +196,3 @@ void Route::write_nmp_merged(std::string filename)
}
wptfile.close();
}

Route *route_by_root(std::string root, std::list<Route> &route_list)
{ for (std::list<Route>::iterator r = route_list.begin(); r != route_list.end(); r++)
if (r->root == root) return &*r;
return 0;
}
1 change: 1 addition & 0 deletions siteupdate/cplusplus/classes/Route/Route.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -51,6 +51,7 @@ class Route
std::vector<Waypoint*> point_list;
std::unordered_set<std::string> labels_in_use;
std::unordered_set<std::string> unused_alt_labels;
static std::unordered_map<std::string, Route*> root_hash, list_hash;
static std::mutex awf_mtx; // for locking the all_wpt_files set when erasing processed WPTs
std::mutex liu_mtx; // for locking the labels_in_use set when inserting labels during TravelerList processing
std::mutex ual_mtx; // for locking the unused_alt_labels set when removing in-use alt_labels
Expand Down
10 changes: 0 additions & 10 deletions siteupdate/cplusplus/classes/Route/read_wpt.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -63,16 +63,6 @@ void Route::read_wpt
continue;
}
point_list.push_back(w);
// populate unused alt labels
for (size_t i = 0; i < w->alt_labels.size(); i++)
{ std::string al = w->alt_labels[i];
// strip out leading '+'
while (al[0] == '+') al.erase(0, 1); //TODO would erase via iterator be any faster?
// convert to upper case
for (size_t c = 0; c < al.size(); c++)
if (al[c] >= 'a' && al[c] <= 'z') al[c] -= 32;
unused_alt_labels.insert(al);
}
all_waypoints->insert(w, 1);

// single-point Datachecks, and HighwaySegment
Expand Down
52 changes: 26 additions & 26 deletions siteupdate/cplusplus/classes/TravelerList/TravelerList.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -29,7 +29,7 @@ class TravelerList
unsigned int preview_systems_clinched;
static std::mutex alltrav_mtx; // for locking the traveler_lists list when reading .lists from disk

TravelerList(std::string travname, std::unordered_map<std::string, Route*> *route_hash, ErrorList *el, Arguments *args, std::mutex *strtok_mtx)
TravelerList(std::string travname, ErrorList *el, Arguments *args, std::mutex *strtok_mtx)
{ active_systems_traveled = 0;
active_systems_clinched = 0;
preview_systems_traveled = 0;
Expand DownExpand Up@@ -116,11 +116,11 @@ class TravelerList
}

// find the root that matches in some system and when we do, match labels
std::string route_entry = lower(std::string(fields[1]));
std::string lookup = std::string(lower(fields[0])) + " " + route_entry;
try { Route *r = route_hash->at(lookup);
for (std::string a : r->alt_route_names)
if (route_entry == lower(a))
std::string route_entry = upper(std::string(fields[1])); // leave fields[1] intact for potential AltRouteName note
std::string lookup = std::string(upper(fields[0])) + " " + route_entry;
try { Route *r = Route::list_hash.at(lookup);
for (std::string& a : r->alt_route_names)
if (route_entry == a)
{ log << "Note: deprecated route name " << fields[1]
<< " -> canonical name " << r->list_entry_name() << " in line " << trim_line << '\n';
break;
Expand All@@ -135,28 +135,28 @@ class TravelerList
// "+" or "*" when matching
std::vector<unsigned int> point_indices;
unsigned int checking_index = 0;
while (*fields[2] == '*' || *fields[2] == '+') fields[2]++;
while (*fields[3] == '*' || *fields[3] == '+') fields[3]++;
upper(fields[2]);
upper(fields[3]);
for (Waypoint *w : r->point_list)
{ std::string lower_label = lower(w->label);
while (*lower(fields[2]) == '*' || *fields[2] == '+') fields[2]++;
while (*lower(fields[3]) == '*' || *fields[3] == '+') fields[3]++;
while (lower_label.front() == '+' || lower_label.front() == '*') lower_label.erase(lower_label.begin());
if (fields[2] == lower_label || fields[3] == lower_label)
{ std::string upper_label = upper(w->label);
while (upper_label.front() == '+' || upper_label.front() == '*') upper_label = upper_label.substr(1);
if (fields[2] == upper_label || fields[3] == upper_label)
{ point_indices.push_back(checking_index);
r->liu_mtx.lock();
r->labels_in_use.insert(upper(lower_label));
r->labels_in_use.insert(upper_label);
r->liu_mtx.unlock();
}
else { for (std::string &alt : w->alt_labels)
{ lower_label = lower(alt);
while (lower_label.front() == '+') lower_label.erase(lower_label.begin());
if (fields[2] == lower_label || fields[3] == lower_label)
{ if (fields[2] == alt || fields[3] == alt)
{ point_indices.push_back(checking_index);
r->liu_mtx.lock();
r->labels_in_use.insert(upper(lower_label));
r->labels_in_use.insert(alt);
r->liu_mtx.unlock();
// if we have not yet used this alt label, remove it from the unused set
r->ual_mtx.lock();
r->unused_alt_labels.erase(upper(lower_label));
r->unused_alt_labels.erase(alt);
r->ual_mtx.unlock();
}
}
Expand All@@ -165,9 +165,9 @@ class TravelerList
}
if (point_indices.size() != 2)
{ bool invalid_char = 0;
for (size_t c = 0; c < trim_line.size(); c++)
if (iscntrl(trim_line[c]))
{ trim_line[c] = '?';
for (char& c : trim_line)
if (iscntrl(c))
{ c = '?';
invalid_char = 1;
}
log << "Waypoint label(s) not found in line: " << trim_line;
Expand All@@ -189,9 +189,9 @@ class TravelerList
}
catch (const std::out_of_range& oor)
{ bool invalid_char = 0;
for (size_t c = 0; c < trim_line.size(); c++)
if (iscntrl(trim_line[c]))
{ trim_line[c] = '?';
for (char& c : trim_line)
if (iscntrl(c))
{ c = '?';
invalid_char = 1;
}
log << "Unknown region/highway combo in line: " << trim_line;
Expand All@@ -209,21 +209,21 @@ class TravelerList
/* Return active mileage across all regions */
double active_only_miles()
{ double mi = 0;
for (std::pair<Region*, double> rm : active_only_mileage_by_region) mi += rm.second;
for (std::pair<Region* const, double>& rm : active_only_mileage_by_region) mi += rm.second;
return mi;
}

/* Return active+preview mileage across all regions */
double active_preview_miles()
{ double mi = 0;
for (std::pair<Region*, double> rm : active_preview_mileage_by_region) mi += rm.second;
for (std::pair<Region* const, double>& rm : active_preview_mileage_by_region) mi += rm.second;
return mi;
}

/* Return mileage across all regions for a specified system */
double system_region_miles(HighwaySystem *h)
{ double mi = 0;
for (std::pair<Region*, double> rm : system_region_mileages.at(h)) mi += rm.second;
for (std::pair<Region* const, double>& rm : system_region_mileages.at(h)) mi += rm.second;
return mi;
}

Expand Down
Loading