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
10 changes: 6 additions & 4 deletions siteupdate/cplusplus/classes/Datacheck/Datacheck.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -56,7 +56,7 @@ void Datacheck::read_fps(std::string& path, ErrorList &el)
// parse datacheckfps.csv line
size_t NumFields = 6;
std::string* fields = new std::string[6];
// deleted when FP is matched or on termination of program
// deleted when FP is matched or when writing unmatchedfps.log
std::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 DownExpand Up@@ -88,8 +88,8 @@ void Datacheck::mark_fps(std::string& path, ElapsedTime &et)
{ //std::cout << "Match!" << std::endl;
d.fp = 1;
fpcount++;
fps.erase(fp);
delete[] *fp;
fps.erase(fp);
break;
}
else
Expand All@@ -103,13 +103,15 @@ void Datacheck::mark_fps(std::string& path, ElapsedTime &et)
}

void Datacheck::unmatchedfps_log(std::string& path)
{ // write log of unmatched false positives from the datacheckfps.csv
{ // write log of unmatched false positives from datacheckfps.csv
std::ofstream fpfile(path+"/unmatchedfps.log");
time_t timestamp = time(0);
fpfile << "Log file created at: " << ctime(&timestamp);
if (fps.empty()) fpfile << "No unmatched FP entries.\n";
else for (std::string* entry : fps)
fpfile << entry[0] << ';' << entry[1] << ';' << entry[2] << ';' << entry[3] << ';' << entry[4] << ';' << entry[5] << '\n';
{ fpfile << entry[0] << ';' << entry[1] << ';' << entry[2] << ';' << entry[3] << ';' << entry[4] << ';' << entry[5] << '\n';
delete[] entry;
}
fpfile.close();
}

Expand Down
5 changes: 5 additions & 0 deletions siteupdate/cplusplus/classes/ElapsedTime/ElapsedTime.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,7 @@ ElapsedTime::ElapsedTime(int precision)
format = "[%.1f] ";
format[3] = '0' + precision;
str = new char[15+precision];
// deleted by ~ElapsedTime
}

std::string ElapsedTime::et()
Expand All@@ -13,3 +14,7 @@ std::string ElapsedTime::et()
sprintf(str, format.data(), elapsed.count());
return str;
}

ElapsedTime::~ElapsedTime()
{ delete[] str;
}
1 change: 1 addition & 0 deletions siteupdate/cplusplus/classes/ElapsedTime/ElapsedTime.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,5 +9,6 @@ class ElapsedTime

public:
ElapsedTime(int);
~ElapsedTime();
std::string et();
};
Original file line numberDiff line numberDiff line change
Expand Up@@ -20,7 +20,7 @@ GraphListEntry::GraphListEntry(std::string r, std::string d, char f, char c, std
std::string GraphListEntry::filename()
{ switch (form)
{ case 's': return root+"-simple.tmg";
case 'c': return root+"-collapsed.tmg";
case 'c': return root+".tmg";
case 't': return root+"-traveled.tmg";
default : return std::string("ERROR: GraphListEntry::filename() unexpected format token ('")+form+"')";
}
Expand Down
12 changes: 0 additions & 12 deletions siteupdate/cplusplus/classes/GraphGeneration/HGEdge.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -20,18 +20,6 @@ HGEdge::HGEdge(HighwaySegment *s, HighwayGraph *graph, int numthreads)
t_written[0] = 0;
vertex1 = s->waypoint1->hashpoint()->vertex;
vertex2 = s->waypoint2->hashpoint()->vertex;
// checks for the very unusual cases where an edge ends up
// in the system as itself and its "reverse"
for (HGEdge *e : vertex1->incident_s_edges)
if (e->vertex1 == vertex2 && e->vertex2 == vertex1)
{ delete this;
return;
}
for (HGEdge *e : vertex2->incident_s_edges)
if (e->vertex1 == vertex2 && e->vertex2 == vertex1)
{ delete this;
return;
}
format = simple | collapsed | traveled;
segment_name = s->segment_name();
vertex1->incident_s_edges.push_back(this);
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -203,7 +203,7 @@ inline void HighwayGraph::matching_vertices_and_edges
if (g.placeradius)
pvset = g.placeradius->vertices(qt, this);

// determine which vertices are within our region(s) and/or system(s)
// determine which vertices are within our PlaceRadius, region(s) and/or system(s)
if (g.regions)
{ mvset = rvset;
if (g.placeradius) mvset = mvset & pvset;
Expand DownExpand Up@@ -300,7 +300,7 @@ inline void HighwayGraph::matching_vertices_and_edges
//
void HighwayGraph::write_master_graphs_tmg()
{ std::ofstream simplefile(Args::graphfilepath + "/tm-master-simple.tmg");
std::ofstream collapfile(Args::graphfilepath + "/tm-master-collapsed.tmg");
std::ofstream collapfile(Args::graphfilepath + "/tm-master.tmg");
std::ofstream travelfile(Args::graphfilepath + "/tm-master-traveled.tmg");
simplefile << "TMG 1.0 simple\n";
collapfile << "TMG 1.0 collapsed\n";
Expand DownExpand Up@@ -401,7 +401,7 @@ void HighwayGraph::write_subgraphs_tmg
}
#ifdef threading_enabled
term->lock();
if (GRAPH(0).cat != GraphListEntry::entries[graphnum-1].cat)
if (GRAPH(0).cat != GRAPH(-1).cat)
std::cout << '\n' << et->et() << "Writing " << GRAPH(0).category() << " graphs.\n";
#endif
std::cout << GRAPH(0).tag()
Expand DownExpand Up@@ -462,6 +462,8 @@ void HighwayGraph::write_subgraphs_tmg
simplefile.close();
collapfile.close();
travelfile.close();
if (GRAPH(0).regions) delete GRAPH(0).regions;
if (GRAPH(0).systems) delete GRAPH(0).systems;

GRAPH(0).vertices = mv.size(); GRAPH(0).edges = mse.size(); GRAPH(0).travelers = 0;
GRAPH(1).vertices = cv_count; GRAPH(1).edges = mce.size(); GRAPH(1).travelers = 0;
Expand Down
9 changes: 8 additions & 1 deletion siteupdate/cplusplus/classes/Route/read_wpt.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -34,6 +34,7 @@ void Route::read_wpt(WaypointQuadtree *all_waypoints, ErrorList *el, bool usa_fl
unsigned long wptdatasize = file.tellg();
file.seekg(0, std::ios::beg);
char *wptdata = new char[wptdatasize+1];
// deleted after processing lines
file.read(wptdata, wptdatasize);
wptdata[wptdatasize] = 0; // add null terminator
file.close();
Expand All@@ -45,9 +46,15 @@ void Route::read_wpt(WaypointQuadtree *all_waypoints, ErrorList *el, bool usa_fl
{ for (spn = strcspn(c, "\n\r"); c[spn] == '\n' || c[spn] == '\r'; spn++) c[spn] = 0;
lines.emplace_back(c);
}
if (lines.empty())
{ delete[] wptdata;
el->add_error(filename + " is empty or begins with null zero");
return;
}
lines.push_back(wptdata+wptdatasize+1); // add a dummy "past-the-end" element to make lines[l+1]-2 work

for (unsigned int l = 0; l < lines.size()-1; l++)
// process lines
for (unsigned int l = lines[1] < wptdata+2; l < lines.size()-1; l++)
{ // strip whitespace from end...
char* endchar = lines[l+1]-2; // -2 skips over the 0 inserted while splitting wptdata into lines
while (*endchar == 0) endchar--; // skip back more for CRLF cases, and lines followed by blank lines
Expand Down
10 changes: 6 additions & 4 deletions siteupdate/cplusplus/classes/TravelerList/TravelerList.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -55,6 +55,7 @@ TravelerList::TravelerList(std::string travname, std::string* updarr[], ErrorLis
unsigned long listdatasize = file.tellg();
file.seekg(0, std::ios::beg);
char *listdata = new char[listdatasize+1];
// deleted after processing lines
file.read(listdata, listdatasize);
listdata[listdatasize] = 0; // add null terminator
file.close();
Expand DownExpand Up@@ -96,11 +97,12 @@ TravelerList::TravelerList(std::string travname, std::string* updarr[], ErrorLis
// strip whitespace
while (lines[l][0] == ' ' || lines[l][0] == '\t') lines[l]++;
char * endchar = lines[l+1]-2; // -2 skips over the 0 inserted while separating listdata into lines
while (*endchar == 0 && endchar > lines[l]) endchar--; // skip back more for CRLF cases, and lines followed by blank lines
while (*endchar == ' ' || *endchar == '\t')
{ *endchar = 0;
while (endchar > lines[l] && *endchar == 0) endchar--; // skip back more for CRLF cases, and lines followed by blank lines
if (endchar > lines[l])
while (*endchar == ' ' || *endchar == '\t')
{ *endchar = 0;
endchar--;
}
}
std::string trim_line(lines[l]);
// ignore empty or "comment" lines
if (lines[l][0] == 0 || lines[l][0] == '#')
Expand Down
2 changes: 2 additions & 0 deletions siteupdate/cplusplus/functions/sql_file.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -391,6 +391,7 @@ void sqlfile1
first = 0;
sqlfile << "('" << update[0] << "','" << double_quotes(update[1]) << "','" << double_quotes(update[2])
<< "','" << update[3] << "','" << double_quotes(update[4]) << "')\n";
delete[] update;
}
sqlfile << ";\n";

Expand All@@ -411,6 +412,7 @@ void sqlfile1
first = 0;
sqlfile << "('" << systemupdate[0] << "','" << double_quotes(systemupdate[1])
<< "','" << systemupdate[2] << "','" << double_quotes(systemupdate[3]) << "','" << systemupdate[4] << "')\n";
delete[] systemupdate;
}
sqlfile << ";\n";
sqlfile.close();
Expand Down
4 changes: 2 additions & 2 deletions siteupdate/cplusplus/siteupdate.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -269,7 +269,8 @@ int main(int argc, char *argv[])
unordered_set<string> nmpfps;
file.open(Args::highwaydatapath+"/nmpfps.log");
while (getline(file, line))
{ while (line.back() == 0x0D || line.back() == ' ') line.erase(line.end()-1); // trim DOS newlines & whitespace
{ while (line.size() && (line.back() == 0x0D || line.back() == ' '))
line.pop_back(); // trim DOS newlines & whitespace
if (line.size()) nmpfps.insert(line);
}
file.close();
Expand DownExpand Up@@ -467,7 +468,6 @@ int main(int argc, char *argv[])

// now augment any traveler clinched segments for concurrencies
cout << et.et() << "Augmenting travelers for detected concurrent segments." << flush;
//#include "debug/concurrency_augments.cpp"
#ifdef threading_enabled
list<string>* augment_lists = new list<string>[Args::numthreads];
TravelerList::tl_it = TravelerList::allusers.begin();
Expand Down
51 changes: 23 additions & 28 deletions siteupdate/cplusplus/tasks/concurrency_detection.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -8,34 +8,29 @@ for (HighwaySystem *h : HighwaySystem::syslist)
{ cout << '.' << flush;
for (Route *r : h->route_list)
for (HighwaySegment *s : r->segment_list)
if (s->waypoint1->colocated && s->waypoint2->colocated)
for ( Waypoint *w1 : *(s->waypoint1->colocated) )
if (w1->route != r)
for ( Waypoint *w2 : *(s->waypoint2->colocated) )
if (w1->route == w2->route)
{ HighwaySegment *other = w1->route->find_segment_by_waypoints(w1,w2);
if (other)
if (!s->concurrent)
{ s->concurrent = new list<HighwaySegment*>;
// deleted on termination of program
other->concurrent = s->concurrent;
s->concurrent->push_back(s);
s->concurrent->push_back(other);
concurrencyfile << "New concurrency [" << s->str() << "][" << other->str() << "] (" << s->concurrent->size() << ")\n";
}
else if (!contains(*s->concurrent, other))
{ other->concurrent = s->concurrent;
s->concurrent->push_back(other);
//concurrencyfile << "Added concurrency [" << s->str() << "]-[" \
<< other->str() << "] (" << s->concurrent->size() << ")\n";
concurrencyfile << "Extended concurrency ";
for (HighwaySegment *x : *(s->concurrent))
concurrencyfile << '[' << x->str() << ']';
concurrencyfile << " (" << s->concurrent->size() << ")\n";
}
}
// see https://github.com/TravelMapping/DataProcessing/issues/137
// changes not yet implemented in either the original Python or this C++ version.
if (!s->concurrent && s->waypoint1->colocated && s->waypoint2->colocated)
for ( Waypoint *w1 : *(s->waypoint1->colocated) )
for ( Waypoint *w2 : *(s->waypoint2->colocated) )
if (w1->route == w2->route && (w1 != s->waypoint1 || w2 != s->waypoint2) && (w1 != s->waypoint2 || w2 != s->waypoint1))
{ HighwaySegment *other = w1->route->find_segment_by_waypoints(w1,w2);
if (other)
if (!s->concurrent)
{ s->concurrent = new list<HighwaySegment*>;
// deleted by ~HighwaySegment
other->concurrent = s->concurrent;
s->concurrent->push_back(s);
s->concurrent->push_back(other);
concurrencyfile << "New concurrency [" << s->str() << "][" << other->str() << "] (2)\n";
}
else
{ other->concurrent = s->concurrent;
s->concurrent->push_back(other);
concurrencyfile << "Extended concurrency ";
for (HighwaySegment *x : *(s->concurrent))
concurrencyfile << '[' << x->str() << ']';
concurrencyfile << " (" << s->concurrent->size() << ")\n";
}
}
}
cout << "!\n";

Expand Down
4 changes: 2 additions & 2 deletions siteupdate/cplusplus/tasks/read_updates.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,7 +12,7 @@ while (getline(file, line))
// parse updates.csv line
size_t NumFields = 5;
string* fields = new string[5];
// deleted on termination of program
// deleted as DB table is written
string* ptr_array[5] = {&fields[0], &fields[1], &fields[2], &fields[3], &fields[4]};
split(line, ptr_array, NumFields, ';');
if (NumFields != 5)
Expand DownExpand Up@@ -74,7 +74,7 @@ while (getline(file, line))
// parse systemupdates.csv line
size_t NumFields = 5;
string* fields = new string[5];
// deleted on termination of program
// deleted as DB table is written
string* ptr_array[5] = {&fields[0], &fields[1], &fields[2], &fields[3], &fields[4]};
split(line, ptr_array, NumFields, ';');
if (NumFields != 5)
Expand Down
2 changes: 1 addition & 1 deletion siteupdate/cplusplus/tasks/subgraphs/continent.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -8,7 +8,7 @@ cout << et.et() << "Creating continent graphs." << endl;
// add entries to graph vector
for (size_t c = 0; c < continents.size()-1; c++)
{ regions = new list<Region*>;
// deleted on termination of program
// deleted @ end of HighwayGraph::write_subgraphs_tmg
for (Region* r : Region::allregions)
// does it match this continent and have routes?
if (&continents[c] == r->continent && r->active_preview_mileage)
Expand Down
2 changes: 1 addition & 1 deletion siteupdate/cplusplus/tasks/subgraphs/country.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -8,7 +8,7 @@ cout << et.et() << "Creating country graphs." << endl;
// add entries to graph vector
for (size_t c = 0; c < countries.size()-1; c++)
{ regions = new list<Region*>;
// deleted on termination of program
// deleted @ end of HighwayGraph::write_subgraphs_tmg
for (Region* r : Region::allregions)
// does it match this country and have routes?
if (&countries[c] == r->country && r->active_preview_mileage)
Expand Down
2 changes: 1 addition & 1 deletion siteupdate/cplusplus/tasks/subgraphs/multiregion.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -27,7 +27,7 @@ while (getline(file, line))
el.add_error("title > " + std::to_string(DBFieldLength::graphFilename-14)
+ " bytes in multiregion.csv line: " + line);
regions = new list<Region*>;
// deleted on termination of program
// deleted @ end of HighwayGraph::write_subgraphs_tmg
for(char* rg = strtok(fields[2], ","); rg; rg = strtok(0, ","))
for (Region* r : Region::allregions)
if (rg == r->code)
Expand Down
2 changes: 1 addition & 1 deletion siteupdate/cplusplus/tasks/subgraphs/multisystem.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -26,7 +26,7 @@ while (getline(file, line))
el.add_error("title > " + std::to_string(DBFieldLength::graphFilename-14)
+ " bytes in multisystem.csv line: " + line);
systems = new list<HighwaySystem*>;
// deleted on termination of program
// deleted @ end of HighwayGraph::write_subgraphs_tmg
for(char* s = strtok(fields[2], ","); s; s = strtok(0, ","))
for (HighwaySystem *h : HighwaySystem::syslist)
if (s == h->systemname)
Expand Down
2 changes: 1 addition & 1 deletion siteupdate/cplusplus/tasks/subgraphs/region.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -11,7 +11,7 @@ cout << et.et() << "Creating regional data graphs." << endl;
for (Region* region : Region::allregions)
{ if (region->active_preview_mileage == 0) continue;
regions = new list<Region*>(1, region);
// deleted on termination of program
// deleted @ end of HighwayGraph::write_subgraphs_tmg
ADDGRAPH('s');
ADDGRAPH('c');
ADDGRAPH('t');
Expand Down
2 changes: 1 addition & 1 deletion siteupdate/cplusplus/tasks/subgraphs/system.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -20,7 +20,7 @@ while (getline(file, line))
}
if (h)
{ systems = new list<HighwaySystem*>(1, h);
// deleted on termination of program
// deleted @ end of HighwayGraph::write_subgraphs_tmg
ADDGRAPH('s');
ADDGRAPH('c');
ADDGRAPH('t');
Expand Down
Loading