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
44 changes: 25 additions & 19 deletions siteupdate/cplusplus/classes/Arguments.cpp
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
//FIXME: argv[n+1] can smash the stack.
//FIXME: Try breaking --numthreads with garbage arguments
class Arguments
{ public:
/* w */ std::string highwaydatapath;
Expand All@@ -11,8 +9,9 @@ class Arguments
/* g */ std::string graphfilepath;
/* k */ bool skipgraphs;
/* n */ std::string nmpmergepath;
/* p */ std::string splitregion, splitregionpath;
/* U */ std::list<std::string> userlist;
/* t */ unsigned int numthreads;
/* t */ int numthreads;
/* e */ bool errorcheck;
/* h */ bool help;

Expand All@@ -27,38 +26,41 @@ class Arguments
/* g */ graphfilepath = ".";
/* k */ skipgraphs = 0;
/* n */ nmpmergepath = "";
/* p */ splitregionpath = "";
/* U */ // nothing to do here
/* t */ numthreads = 4;
/* e */ errorcheck = 0;
/* h */ help = 0;

// parsing
for (unsigned int n = 1; n < argc; n++)
{ if ( !strcmp(argv[n], "-w") || !strcmp(argv[n], "--highwaydatapath") ) {
{ if ( n+1 < argc && !strcmp(argv[n], "-w") || !strcmp(argv[n], "--highwaydatapath") ) {
highwaydatapath = argv[n+1]; n++; }
else if ( !strcmp(argv[n], "-s") || !strcmp(argv[n], "--systemsfile") ) {
else if ( n+1 < argc && !strcmp(argv[n], "-s") || !strcmp(argv[n], "--systemsfile") ) {
systemsfile = argv[n+1]; n++; }
else if ( !strcmp(argv[n], "-u") || !strcmp(argv[n], "--userlistfilepath") ) {
else if ( n+1 < argc && !strcmp(argv[n], "-u") || !strcmp(argv[n], "--userlistfilepath") ) {
userlistfilepath = argv[n+1]; n++; }
else if ( !strcmp(argv[n], "-d") || !strcmp(argv[n], "--databasename") ) {
else if ( n+1 < argc && !strcmp(argv[n], "-d") || !strcmp(argv[n], "--databasename") ) {
databasename = argv[n+1]; n++; }
else if ( !strcmp(argv[n], "-l") || !strcmp(argv[n], "--logfilepath") ) {
else if ( n+1 < argc && !strcmp(argv[n], "-l") || !strcmp(argv[n], "--logfilepath") ) {
logfilepath = argv[n+1]; n++; }
else if ( !strcmp(argv[n], "-c") || !strcmp(argv[n], "--csvstatfilepath") ) {
else if ( n+1 < argc && !strcmp(argv[n], "-c") || !strcmp(argv[n], "--csvstatfilepath") ) {
csvstatfilepath = argv[n+1]; n++; }
else if ( !strcmp(argv[n], "-g") || !strcmp(argv[n], "--graphfilepath") ) {
else if ( n+1 < argc && !strcmp(argv[n], "-g") || !strcmp(argv[n], "--graphfilepath") ) {
graphfilepath = argv[n+1]; n++; }
else if ( !strcmp(argv[n], "-k") || !strcmp(argv[n], "--skipgraphs") )
else if ( !strcmp(argv[n], "-k") || !strcmp(argv[n], "--skipgraphs") )
skipgraphs = 1;
else if ( !strcmp(argv[n], "-n") || !strcmp(argv[n], "--nmpmergepath") ) {
else if ( n+1 < argc && !strcmp(argv[n], "-n") || !strcmp(argv[n], "--nmpmergepath") ) {
nmpmergepath = argv[n+1]; n++; }
else if ( !strcmp(argv[n], "-t") || !strcmp(argv[n], "--numthreads") ) {
numthreads = strtol(argv[n+1], 0, 10); n++; }
else if ( !strcmp(argv[n], "-e") || !strcmp(argv[n], "--errorcheck") )
else if ( n+2 < argc && !strcmp(argv[n], "-p") || !strcmp(argv[n], "--splitregion") ) {
splitregionpath = argv[n+1]; splitregion = argv[n+2]; n +=2; }
else if ( n+1 < argc && !strcmp(argv[n], "-t") || !strcmp(argv[n], "--numthreads") ) {
numthreads = strtol(argv[n+1], 0, 10); n++; if (numthreads<1) numthreads=1; }
else if ( !strcmp(argv[n], "-e") || !strcmp(argv[n], "--errorcheck") )
errorcheck = 1;
else if ( !strcmp(argv[n], "-h") || !strcmp(argv[n], "--help") ) {
else if ( !strcmp(argv[n], "-h") || !strcmp(argv[n], "--help") ) {
help = 1; show_help(); }
else if ( !strcmp(argv[n], "-U") || !strcmp(argv[n], "--userlist") )
else if ( n+1 < argc && !strcmp(argv[n], "-U") || !strcmp(argv[n], "--userlist") )
while (n+1 < argc && argv[n+1][0] != '-')
{ userlist.push_back(argv[n+1]);
n++;
Expand All@@ -70,8 +72,8 @@ class Arguments
{ std::cout << "usage: siteupdate.py [-h] [-w HIGHWAYDATAPATH] [-s SYSTEMSFILE]\n";
std::cout << " [-u USERLISTFILEPATH] [-d DATABASENAME] [-l LOGFILEPATH]\n";
std::cout << " [-c CSVSTATFILEPATH] [-g GRAPHFILEPATH] [-k]\n";
std::cout << " [-n NMPMERGEPATH] [-U USERLIST [USERLIST ...]]\n";
std::cout << " [-t NUMTHREADS] [-e]\n";
std::cout << " [-n NMPMERGEPATH] [-p SPLITREGIONPATH SPLITREGION]\n";
std::cout << " [-U USERLIST [USERLIST ...]] [-t NUMTHREADS] [-e]\n";
std::cout << "\n";
std::cout << "Create SQL, stats, graphs, and log files from highway and user data for the\n";
std::cout << "Travel Mapping project.\n";
Expand All@@ -98,6 +100,10 @@ class Arguments
std::cout << " -n NMPMERGEPATH, --nmpmergepath NMPMERGEPATH\n";
std::cout << " Path to write data with NMPs merged (generated only if\n";
std::cout << " specified)\n";
std::cout << " -p SPLITREGIONPATH SPLITREGION, --splitregion SPLITREGIONPATH SPLITREGION\n";
std::cout << " Path to logs & .lists for a specific...\n";
std::cout << " Region being split into rubregions.\n";
std::cout << " For Development.\n";
std::cout << " -U USERLIST [USERLIST ...], --userlist USERLIST [USERLIST ...]\n";
std::cout << " For Development: list of users to use in dataset\n";
std::cout << " -t NUMTHREADS, --numthreads NUMTHREADS\n";
Expand Down
17 changes: 17 additions & 0 deletions siteupdate/cplusplus/classes/ConnectedRoute.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -74,6 +74,7 @@ class ConnectedRoute
{ Route *root = route_by_root(token, route_list);
if (!root) el.add_error("Could not find Route matching root " + std::string(token) + " in system " + system->systemname + '.');
else { roots.push_back(root);
root->con_route = this;
// save order of route in connected route
root->rootOrder = rootOrder;
}
Expand DownExpand Up@@ -107,4 +108,20 @@ class ConnectedRoute
if (!groupname.empty()) ans += " (" + groupname + ")";
return ans;
}

std::string list_lines(int pos, int len, std::string newline, size_t indent)
{ // return .list file lines marking (len) consecutive
// segments, starting at waypoint (pos) segments into route
//std::cout << "\nDEBUG: list_lines for " << readable_name() << " (" << roots.size() << " connected root(s))" << std::endl;
std::string lines;
for (Route *r : roots)
{ //std::cout << "DEBUG: [" << pos << " + " << len << " = " << pos+len << "] " << r->str() << std::endl;
std::string line = std::string(indent, ' ') + r->list_line(pos, pos+len);
if (line.size() > indent) lines += line + newline;
pos -= r->segment_list.size();
}
// strip final newline
while (lines.back() == '\n' || lines.back() == '\r') lines.pop_back();
return lines;
}
};
Original file line numberDiff line numberDiff line change
Expand Up@@ -34,6 +34,7 @@ std::string GraphListEntry::filename()
{ switch (form)
{ case 's': return root+"-simple.tmg";
case 'c': return root+".tmg";
case 't': return root+"-traveled.tmg";
default : return std::string("ERROR: GraphListEntry::filename() unexpected format token ('")+form+"')";
}
}
Expand All@@ -42,6 +43,7 @@ std::string GraphListEntry::format()
{ switch (form)
{ case 's': return "simple";
case 'c': return "collapsed";
case 't': return "traveled";
default : return std::string("ERROR: GraphListEntry::format() unexpected format token ('")+form+"')";
}
}
Expand Down
Loading