Skip to content

Commit

Permalink
updates entries; waypoint.h
Browse files Browse the repository at this point in the history
* C arrays for updates entries
* colocated moved with Waypoint (there appear to be sizeof/offset issues in clang, as noted in TravelMapping#375)
  • Loading branch information
yakra committed Jan 31, 2021
1 parent 3f64755 commit 94badf2
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 32 deletions.
8 changes: 4 additions & 4 deletions siteupdate/cplusplus/classes/Route/Route.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,8 @@ void Route::store_traveled_segments(TravelerList* t, std::ofstream& log, unsigne
hs->add_clinched_by(t);
t->clinched_segments.insert(hs);
}
if (t->routes.insert(this).second && last_update && t->update && (*last_update)[0] >= *t->update)
log << "Route updated " << (*last_update)[0] << ": " << readable_name() << '\n';
if (t->routes.insert(this).second && last_update && t->update && last_update[0] >= *t->update)
log << "Route updated " << last_update[0] << ": " << readable_name() << '\n';
}

Waypoint* Route::con_beg()
Expand All @@ -247,8 +247,8 @@ Waypoint* Route::con_end()
// sort routes by most recent update for use at end of user logs
// all should have a valid updates entry pointer before being passed here
bool sort_route_updates_oldest(const Route *r1, const Route *r2)
{ int p = strcmp((*r1->last_update)[0].data(), (*r2->last_update)[0].data());
if (!p) return (*r1->last_update)[3] < (*r2->last_update)[3];
{ int p = strcmp(r1->last_update[0].data(), r2->last_update[0].data());
if (!p) return r1->last_update[3] < r2->last_update[3];
return p < 0;
}

Expand Down
2 changes: 1 addition & 1 deletion siteupdate/cplusplus/classes/Route/Route.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class Route
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
std::vector<HighwaySegment*> segment_list;
std::array<std::string, 5> *last_update;
std::string* last_update;
double mileage;
int rootOrder;
bool is_reversed;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ if (lit1 == r->alt_label_hash.end() || lit2 == r->alt_label_hash.end())
if (invalid_char) log << " [contains invalid character(s)]";
log << '\n';
splist << orig_line << endlines[l];
if (routes.insert(r).second && r->last_update && update && (*r->last_update)[0] >= *update)
log << "Route updated " << (*r->last_update)[0] << ": " << r->readable_name() << '\n';
if (routes.insert(r).second && r->last_update && update && r->last_update[0] >= *update)
log << "Route updated " << r->last_update[0] << ": " << r->readable_name() << '\n';
continue;
}
// are either of the labels used duplicates?
Expand All @@ -80,16 +80,16 @@ if (r->duplicate_labels.find(fields[3]) != r->duplicate_labels.end())
}
if (duplicate)
{ splist << orig_line << endlines[l];
if (routes.insert(r).second && r->last_update && update && (*r->last_update)[0] >= *update)
log << "Route updated " << (*r->last_update)[0] << ": " << r->readable_name() << '\n';
if (routes.insert(r).second && r->last_update && update && r->last_update[0] >= *update)
log << "Route updated " << r->last_update[0] << ": " << r->readable_name() << '\n';
continue;
}
// if both labels reference the same waypoint...
if (lit1->second == lit2->second)
{ log << "Equivalent waypoint labels mark zero distance traveled in line: " << trim_line << '\n';
splist << orig_line << endlines[l];
if (routes.insert(r).second && r->last_update && update && (*r->last_update)[0] >= *update)
log << "Route updated " << (*r->last_update)[0] << ": " << r->readable_name() << '\n';
if (routes.insert(r).second && r->last_update && update && r->last_update[0] >= *update)
log << "Route updated " << r->last_update[0] << ": " << r->readable_name() << '\n';
}
// otherwise both labels are valid; mark in use & proceed
else { r->system->lniu_mtx.lock();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,20 @@ if (r1->con_route != r2->con_route)
splist << orig_line << endlines[l];
// log updates for routes beginning/ending r1's ConnectedRoute
Route* cr = r1->con_route->roots.front();
if (routes.insert(cr).second && cr->last_update && update && (*cr->last_update)[0] >= *update)
if (routes.insert(cr).second && cr->last_update && update && cr->last_update[0] >= *update)
log << "Route updated " << (*cr->last_update)[0] << ": " << cr->readable_name() << '\n';
if (r1->con_route->roots.size() > 1)
{ Route* cr = r1->con_route->roots.back();
if (routes.insert(cr).second && cr->last_update && update && (*cr->last_update)[0] >= *update)
if (routes.insert(cr).second && cr->last_update && update && cr->last_update[0] >= *update)
log << "Route updated " << (*cr->last_update)[0] << ": " << cr->readable_name() << '\n';
}
// log updates for routes beginning/ending r2's ConnectedRoute
cr = r2->con_route->roots.front();
if (routes.insert(cr).second && cr->last_update && update && (*cr->last_update)[0] >= *update)
if (routes.insert(cr).second && cr->last_update && update && cr->last_update[0] >= *update)
log << "Route updated " << (*cr->last_update)[0] << ": " << cr->readable_name() << '\n';
if (r2->con_route->roots.size() > 1)
{ Route* cr = r2->con_route->roots.back();
if (routes.insert(cr).second && cr->last_update && update && (*cr->last_update)[0] >= *update)
if (routes.insert(cr).second && cr->last_update && update && cr->last_update[0] >= *update)
log << "Route updated " << (*cr->last_update)[0] << ": " << cr->readable_name() << '\n';
}
continue;
Expand Down Expand Up @@ -129,7 +129,7 @@ if (r1 == r2)
if (index1 == index2)
{ log << "Equivalent waypoint labels mark zero distance traveled in line: " << trim_line << '\n';
splist << orig_line << endlines[l];
if (routes.insert(r1).second && r1->last_update && update && (*r1->last_update)[0] >= *update)
if (routes.insert(r1).second && r1->last_update && update && r1->last_update[0] >= *update)
log << "Route updated " << (*r1->last_update)[0] << ": " << r1->readable_name() << '\n';
continue;
}
Expand Down
4 changes: 2 additions & 2 deletions siteupdate/cplusplus/classes/TravelerList/userlog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ void TravelerList::userlog
routes.clear();
route_list.sort(sort_route_updates_oldest);
for (Route* r : route_list)
log << (*r->last_update)[0] << " | " << (*r->last_update)[1] << " | " << (*r->last_update)[2] << " | "
<< (*r->last_update)[3] << " | " << (*r->last_update)[4] << '\n';
log << r->last_update[0] << " | " << r->last_update[1] << " | " << r->last_update[2] << " | "
<< r->last_update[3] << " | " << r->last_update[4] << '\n';

log.close();
}
2 changes: 1 addition & 1 deletion siteupdate/cplusplus/classes/Waypoint/Waypoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ class Waypoint

public:
Route *route;
std::list<Waypoint*> *colocated;
double lat, lng;
unsigned int point_num;
std::string label;
std::deque<std::string> alt_labels;
std::list<Waypoint*> *colocated;
std::vector<Waypoint*> ap_coloc;
std::forward_list<Waypoint*> near_miss_points;
bool is_hidden;
Expand Down
8 changes: 4 additions & 4 deletions siteupdate/cplusplus/functions/sql_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ void sqlfile1
std::list<HighwaySystem*> *highway_systems,
std::list<TravelerList*> *traveler_lists,
ClinchedDBValues *clin_db_val,
std::list<std::array<std::string,5>> *updates,
std::list<std::array<std::string,5>> *systemupdates
std::list<std::string*> *updates,
std::list<std::string*> *systemupdates
){
// Once all data is read in and processed, create a .sql file that will
// create all of the DB tables to be used by other parts of the project
Expand Down Expand Up @@ -389,7 +389,7 @@ void sqlfile1
<< "));\n";
sqlfile << "INSERT INTO updates VALUES\n";
first = 1;
for (std::array<std::string,5> &update : *updates)
for (std::string* &update : *updates)
{ if (!first) sqlfile << ',';
first = 0;
sqlfile << "('" << update[0] << "','" << double_quotes(update[1]) << "','" << double_quotes(update[2])
Expand All @@ -409,7 +409,7 @@ void sqlfile1
<< "));\n";
sqlfile << "INSERT INTO systemUpdates VALUES\n";
first = 1;
for (std::array<std::string,5> &systemupdate : *systemupdates)
for (std::string* &systemupdate : *systemupdates)
{ if (!first) sqlfile << ',';
first = 0;
sqlfile << "('" << systemupdate[0] << "','" << double_quotes(systemupdate[1])
Expand Down
4 changes: 2 additions & 2 deletions siteupdate/cplusplus/functions/sql_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ void sqlfile1
std::list<HighwaySystem*>*,
std::list<TravelerList*>*,
ClinchedDBValues*,
std::list<std::array<std::string,5>>*,
std::list<std::array<std::string,5>>*
std::list<std::string*>*,
std::list<std::string*>*
);

void sqlfile2(ElapsedTime*, Arguments*, std::list<std::array<std::string,3>>*, std::vector<GraphListEntry>*);
3 changes: 2 additions & 1 deletion siteupdate/cplusplus/siteupdate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -859,9 +859,10 @@ int main(int argc, char *argv[])
while (line[0] == ' ' || line[0] == '\t')
line = line.substr(1);
if (line.empty()) continue;
// parse system updates.csv line
// parse datacheckfps.csv line
size_t NumFields = 6;
string* fields = new string[6];
// deleted when FP is matched or on termination of program
string* ptr_array[6] = {&fields[0], &fields[1], &fields[2], &fields[3], &fields[4], &fields[5]};
split(line, ptr_array, NumFields, ';');
if (NumFields != 6)
Expand Down
14 changes: 8 additions & 6 deletions siteupdate/cplusplus/tasks/read_updates.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Read updates.csv file, just keep in the fields list for now since we're
// just going to drop this into the DB later anyway
list<array<string, 5>> updates;
list<string*> updates;
cout << et.et() << "Reading updates file." << endl;
file.open(args.highwaydatapath+"/updates.csv");
getline(file, line); // ignore header line
Expand All @@ -11,7 +11,8 @@ while (getline(file, line))
if (line.empty()) continue;
// parse updates.csv line
size_t NumFields = 5;
array<string, 5> fields;
string* fields = new string[5];
// deleted on termination of program
string* ptr_array[5] = {&fields[0], &fields[1], &fields[2], &fields[3], &fields[4]};
split(line, ptr_array, NumFields, ';');
if (NumFields != 5)
Expand Down Expand Up @@ -41,8 +42,8 @@ while (getline(file, line))
+ " bytes in updates.csv line " + line);
updates.push_back(fields);
try { Route* r = Route::root_hash.at(fields[3]);
if (r->last_update == 0 || (*r->last_update)[0] < fields[0])
r->last_update = &updates.back();
if (r->last_update == 0 || r->last_update[0] < fields[0])
r->last_update = updates.back();
}
catch (const std::out_of_range& oor) {}
}
Expand All @@ -51,7 +52,7 @@ file.close();
// Same plan for systemupdates.csv file, again just keep in the fields
// list for now since we're just going to drop this into the DB later
// anyway
list<array<string, 5>> systemupdates;
list<string*> systemupdates;
cout << et.et() << "Reading systemupdates file." << endl;
file.open(args.highwaydatapath+"/systemupdates.csv");
getline(file, line); // ignore header line
Expand All @@ -60,7 +61,8 @@ while (getline(file, line))
if (line.empty()) continue;
// parse systemupdates.csv line
size_t NumFields = 5;
array<string, 5> fields;
string* fields = new string[5];
// deleted on termination of program
string* ptr_array[5] = {&fields[0], &fields[1], &fields[2], &fields[3], &fields[4]};
split(line, ptr_array, NumFields, ';');
if (NumFields != 5)
Expand Down

0 comments on commit 94badf2

Please sign in to comment.