refactor Tools dir for C++11

This commit is contained in:
Dennis Luxen 2014-05-08 18:33:38 +02:00
parent 3074a0146e
commit 1960c38468
4 changed files with 64 additions and 65 deletions

View File

@ -92,7 +92,7 @@ int main(int argc, char *argv[])
} }
std::vector<ImportEdge> edge_list; std::vector<ImportEdge> edge_list;
const NodeID node_based_node_count = readBinaryOSRMGraphFromStream(input_stream, const NodeID number_of_nodes = readBinaryOSRMGraphFromStream(input_stream,
edge_list, edge_list,
bollard_node_IDs_vector, bollard_node_IDs_vector,
traffic_light_node_IDs_vector, traffic_light_node_IDs_vector,
@ -113,12 +113,13 @@ int main(int argc, char *argv[])
*/ */
SimpleLogger().Write() << "Starting SCC graph traversal"; SimpleLogger().Write() << "Starting SCC graph traversal";
std::shared_ptr<TarjanSCC> tarjan = std::make_shared<TarjanSCC>(node_based_node_count, std::shared_ptr<TarjanSCC> tarjan =
edge_list, std::make_shared<TarjanSCC>(number_of_nodes,
bollard_node_IDs_vector, edge_list,
traffic_light_node_IDs_vector, bollard_node_IDs_vector,
restrictions_vector, traffic_light_node_IDs_vector,
internal_to_external_node_map); restrictions_vector,
internal_to_external_node_map);
std::vector<ImportEdge>().swap(edge_list); std::vector<ImportEdge>().swap(edge_list);
tarjan->Run(); tarjan->Run();

View File

@ -31,7 +31,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp> #include <boost/filesystem/fstream.hpp>
#include <boost/ref.hpp>
#include <cmath> #include <cmath>
#include <cstdio> #include <cstdio>
@ -101,7 +100,7 @@ int main(int argc, char *argv[])
throw OSRMException("Data file already exists"); throw OSRMException("Data file already exists");
} }
std::chrono::time_point<std::chrono::steady_clock> time1, time2; std::chrono::time_point<std::chrono::steady_clock> time1, time2;
int *random_array = new int[number_of_elements]; int *random_array = new int[number_of_elements];
std::generate(random_array, random_array + number_of_elements, std::rand); std::generate(random_array, random_array + number_of_elements, std::rand);
#ifdef __APPLE__ #ifdef __APPLE__
@ -110,7 +109,8 @@ int main(int argc, char *argv[])
fcntl(fileno(fd), F_RDAHEAD, 0); fcntl(fileno(fd), F_RDAHEAD, 0);
time1 = std::chrono::steady_clock::now(); time1 = std::chrono::steady_clock::now();
write(fileno(fd), (char *)random_array, number_of_elements * sizeof(unsigned)); write(fileno(fd), (char *)random_array, number_of_elements * sizeof(unsigned));
time2 = std::chrono::steady_clock::now();; time2 = std::chrono::steady_clock::now();
;
fclose(fd); fclose(fd);
#endif #endif
#ifdef __linux__ #ifdef __linux__
@ -129,7 +129,7 @@ int main(int argc, char *argv[])
time2 = std::chrono::steady_clock::now(); time2 = std::chrono::steady_clock::now();
close(f); close(f);
#endif #endif
std::chrono::duration<double> elapsed_seconds = time2-time1; std::chrono::duration<double> elapsed_seconds = time2 - time1;
delete[] random_array; delete[] random_array;
SimpleLogger().Write(logDEBUG) << "writing raw 1GB took " << elapsed_seconds.count() SimpleLogger().Write(logDEBUG) << "writing raw 1GB took " << elapsed_seconds.count()
<< "ms"; << "ms";
@ -142,11 +142,7 @@ int main(int argc, char *argv[])
} }
else else
{ {
//
// Run Non-Cached I/O benchmarks // Run Non-Cached I/O benchmarks
//
if (!boost::filesystem::exists(test_path)) if (!boost::filesystem::exists(test_path))
{ {
throw OSRMException("data file does not exist"); throw OSRMException("data file does not exist");
@ -190,7 +186,7 @@ int main(int argc, char *argv[])
#endif #endif
time2 = std::chrono::steady_clock::now(); time2 = std::chrono::steady_clock::now();
std::chrono::duration<double> elapsed_seconds = time2-time1; std::chrono::duration<double> elapsed_seconds = time2 - time1;
SimpleLogger().Write(logDEBUG) << "reading raw 1GB took " << elapsed_seconds.count() SimpleLogger().Write(logDEBUG) << "reading raw 1GB took " << elapsed_seconds.count()
<< "ms"; << "ms";
SimpleLogger().Write() << "raw read performance: " << std::setprecision(5) << std::fixed SimpleLogger().Write() << "raw read performance: " << std::setprecision(5) << std::fixed

View File

@ -42,75 +42,75 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <string> #include <string>
#include <sstream> #include <sstream>
//Dude, real recursions on the OS stack? You must be brave... // Dude, real recursions on the OS stack? You must be brave...
void print_tree(boost::property_tree::ptree const& property_tree, const unsigned recursion_depth) void print_tree(boost::property_tree::ptree const &property_tree, const unsigned recursion_depth)
{ {
boost::property_tree::ptree::const_iterator end = property_tree.end(); auto end = property_tree.end();
for (boost::property_tree::ptree::const_iterator tree_iterator = property_tree.begin(); tree_iterator != end; ++tree_iterator) for (auto tree_iterator = property_tree.begin(); tree_iterator != end; ++tree_iterator)
{ {
for (unsigned current_recursion = 0; current_recursion < recursion_depth; ++current_recursion) for (unsigned current_recursion = 0; current_recursion < recursion_depth;
++current_recursion)
{ {
std::cout << " " << std::flush; std::cout << " " << std::flush;
} }
std::cout << tree_iterator->first << ": " << tree_iterator->second.get_value<std::string>() << std::endl; std::cout << tree_iterator->first << ": " << tree_iterator->second.get_value<std::string>()
print_tree(tree_iterator->second, recursion_depth+1); << std::endl;
print_tree(tree_iterator->second, recursion_depth + 1);
} }
} }
int main(int argc, const char *argv[])
int main (int argc, const char * argv[]) { {
LogPolicy::GetInstance().Unmute(); LogPolicy::GetInstance().Unmute();
try { try
{
std::string ip_address; std::string ip_address;
int ip_port, requested_thread_num; int ip_port, requested_thread_num;
bool use_shared_memory = false, trial = false; bool use_shared_memory = false, trial = false;
ServerPaths server_paths; ServerPaths server_paths;
if( !GenerateServerProgramOptions( if (!GenerateServerProgramOptions(argc,
argc, argv,
argv, server_paths,
server_paths, ip_address,
ip_address, ip_port,
ip_port, requested_thread_num,
requested_thread_num, use_shared_memory,
use_shared_memory, trial))
trial {
)
) {
return 0; return 0;
} }
SimpleLogger().Write() << SimpleLogger().Write() << "starting up engines, " << g_GIT_DESCRIPTION << ", "
"starting up engines, " << g_GIT_DESCRIPTION << ", " << << "compiled at " << __DATE__ << ", " __TIME__;
"compiled at " << __DATE__ << ", " __TIME__;
OSRM routing_machine( server_paths, use_shared_memory ); OSRM routing_machine(server_paths, use_shared_memory);
RouteParameters route_parameters; RouteParameters route_parameters;
route_parameters.zoom_level = 18; //no generalization route_parameters.zoom_level = 18; // no generalization
route_parameters.print_instructions = true; //turn by turn instructions route_parameters.print_instructions = true; // turn by turn instructions
route_parameters.alternate_route = true; //get an alternate route, too route_parameters.alternate_route = true; // get an alternate route, too
route_parameters.geometry = true; //retrieve geometry of route route_parameters.geometry = true; // retrieve geometry of route
route_parameters.compression = true; //polyline encoding route_parameters.compression = true; // polyline encoding
route_parameters.check_sum = UINT_MAX; //see wiki route_parameters.check_sum = UINT_MAX; // see wiki
route_parameters.service = "viaroute"; //that's routing route_parameters.service = "viaroute"; // that's routing
route_parameters.output_format = "json"; route_parameters.output_format = "json";
route_parameters.jsonp_parameter = ""; //set for jsonp wrapping route_parameters.jsonp_parameter = ""; // set for jsonp wrapping
route_parameters.language = ""; //unused atm route_parameters.language = ""; // unused atm
//route_parameters.hints.push_back(); // see wiki, saves I/O if done properly // route_parameters.hints.push_back(); // see wiki, saves I/O if done properly
FixedPointCoordinate start_coordinate(52.519930*COORDINATE_PRECISION,13.438640*COORDINATE_PRECISION);
FixedPointCoordinate target_coordinate(52.513191*COORDINATE_PRECISION,13.415852*COORDINATE_PRECISION);
route_parameters.coordinates.push_back(start_coordinate);
route_parameters.coordinates.push_back(target_coordinate);
// start_coordinate
route_parameters.coordinates.emplace_back(52.519930 * COORDINATE_PRECISION,
13.438640 * COORDINATE_PRECISION);
// target_coordinate
route_parameters.coordinates.emplace_back(52.513191 * COORDINATE_PRECISION,
13.415852 * COORDINATE_PRECISION);
http::Reply osrm_reply; http::Reply osrm_reply;
routing_machine.RunQuery(route_parameters, osrm_reply); routing_machine.RunQuery(route_parameters, osrm_reply);
//attention: super-inefficient hack below: // attention: super-inefficient hack below:
std::stringstream my_stream; std::stringstream my_stream;
for (const std::string & line : osrm_reply.content) for (const std::string &line : osrm_reply.content)
{ {
std::cout << line; std::cout << line;
my_stream << line; my_stream << line;
@ -121,7 +121,9 @@ int main (int argc, const char * argv[]) {
boost::property_tree::read_json(my_stream, property_tree); boost::property_tree::read_json(my_stream, property_tree);
print_tree(property_tree, 0); print_tree(property_tree, 0);
} catch (std::exception & current_exception) { }
catch (std::exception &current_exception)
{
SimpleLogger().Write(logWARNING) << "caught exception: " << current_exception.what(); SimpleLogger().Write(logWARNING) << "caught exception: " << current_exception.what();
return -1; return -1;
} }

View File

@ -31,20 +31,20 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <iostream> #include <iostream>
int main() { int main()
{
LogPolicy::GetInstance().Unmute(); LogPolicy::GetInstance().Unmute();
try try
{ {
SimpleLogger().Write() << SimpleLogger().Write() << "starting up engines, " << g_GIT_DESCRIPTION << ", "
"starting up engines, " << g_GIT_DESCRIPTION << ", " << << "compiled at " << __DATE__ << ", " __TIME__;
"compiled at " << __DATE__ << ", " __TIME__;
SimpleLogger().Write() << "Releasing all locks"; SimpleLogger().Write() << "Releasing all locks";
SharedBarriers barrier; SharedBarriers barrier;
barrier.pending_update_mutex.unlock(); barrier.pending_update_mutex.unlock();
barrier.query_mutex.unlock(); barrier.query_mutex.unlock();
barrier.update_mutex.unlock(); barrier.update_mutex.unlock();
} }
catch(const std::exception & e) catch (const std::exception &e)
{ {
SimpleLogger().Write(logWARNING) << "[excpetion] " << e.what(); SimpleLogger().Write(logWARNING) << "[excpetion] " << e.what();
} }