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;
const NodeID node_based_node_count = readBinaryOSRMGraphFromStream(input_stream,
const NodeID number_of_nodes = readBinaryOSRMGraphFromStream(input_stream,
edge_list,
bollard_node_IDs_vector,
traffic_light_node_IDs_vector,
@ -113,12 +113,13 @@ int main(int argc, char *argv[])
*/
SimpleLogger().Write() << "Starting SCC graph traversal";
std::shared_ptr<TarjanSCC> tarjan = std::make_shared<TarjanSCC>(node_based_node_count,
edge_list,
bollard_node_IDs_vector,
traffic_light_node_IDs_vector,
restrictions_vector,
internal_to_external_node_map);
std::shared_ptr<TarjanSCC> tarjan =
std::make_shared<TarjanSCC>(number_of_nodes,
edge_list,
bollard_node_IDs_vector,
traffic_light_node_IDs_vector,
restrictions_vector,
internal_to_external_node_map);
std::vector<ImportEdge>().swap(edge_list);
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/fstream.hpp>
#include <boost/ref.hpp>
#include <cmath>
#include <cstdio>
@ -101,7 +100,7 @@ int main(int argc, char *argv[])
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];
std::generate(random_array, random_array + number_of_elements, std::rand);
#ifdef __APPLE__
@ -110,7 +109,8 @@ int main(int argc, char *argv[])
fcntl(fileno(fd), F_RDAHEAD, 0);
time1 = std::chrono::steady_clock::now();
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);
#endif
#ifdef __linux__
@ -129,7 +129,7 @@ int main(int argc, char *argv[])
time2 = std::chrono::steady_clock::now();
close(f);
#endif
std::chrono::duration<double> elapsed_seconds = time2-time1;
std::chrono::duration<double> elapsed_seconds = time2 - time1;
delete[] random_array;
SimpleLogger().Write(logDEBUG) << "writing raw 1GB took " << elapsed_seconds.count()
<< "ms";
@ -142,11 +142,7 @@ int main(int argc, char *argv[])
}
else
{
//
// Run Non-Cached I/O benchmarks
//
if (!boost::filesystem::exists(test_path))
{
throw OSRMException("data file does not exist");
@ -190,7 +186,7 @@ int main(int argc, char *argv[])
#endif
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()
<< "ms";
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 <sstream>
//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)
// 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)
{
boost::property_tree::ptree::const_iterator end = property_tree.end();
for (boost::property_tree::ptree::const_iterator tree_iterator = property_tree.begin(); tree_iterator != end; ++tree_iterator)
auto end = property_tree.end();
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 << tree_iterator->first << ": " << tree_iterator->second.get_value<std::string>() << std::endl;
print_tree(tree_iterator->second, recursion_depth+1);
std::cout << tree_iterator->first << ": " << tree_iterator->second.get_value<std::string>()
<< 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();
try {
try
{
std::string ip_address;
int ip_port, requested_thread_num;
bool use_shared_memory = false, trial = false;
ServerPaths server_paths;
if( !GenerateServerProgramOptions(
argc,
argv,
server_paths,
ip_address,
ip_port,
requested_thread_num,
use_shared_memory,
trial
)
) {
if (!GenerateServerProgramOptions(argc,
argv,
server_paths,
ip_address,
ip_port,
requested_thread_num,
use_shared_memory,
trial))
{
return 0;
}
SimpleLogger().Write() <<
"starting up engines, " << g_GIT_DESCRIPTION << ", " <<
"compiled at " << __DATE__ << ", " __TIME__;
SimpleLogger().Write() << "starting up engines, " << g_GIT_DESCRIPTION << ", "
<< "compiled at " << __DATE__ << ", " __TIME__;
OSRM routing_machine( server_paths, use_shared_memory );
OSRM routing_machine(server_paths, use_shared_memory);
RouteParameters route_parameters;
route_parameters.zoom_level = 18; //no generalization
route_parameters.print_instructions = true; //turn by turn instructions
route_parameters.alternate_route = true; //get an alternate route, too
route_parameters.geometry = true; //retrieve geometry of route
route_parameters.compression = true; //polyline encoding
route_parameters.check_sum = UINT_MAX; //see wiki
route_parameters.service = "viaroute"; //that's routing
route_parameters.zoom_level = 18; // no generalization
route_parameters.print_instructions = true; // turn by turn instructions
route_parameters.alternate_route = true; // get an alternate route, too
route_parameters.geometry = true; // retrieve geometry of route
route_parameters.compression = true; // polyline encoding
route_parameters.check_sum = UINT_MAX; // see wiki
route_parameters.service = "viaroute"; // that's routing
route_parameters.output_format = "json";
route_parameters.jsonp_parameter = ""; //set for jsonp wrapping
route_parameters.language = ""; //unused atm
//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);
route_parameters.jsonp_parameter = ""; // set for jsonp wrapping
route_parameters.language = ""; // unused atm
// route_parameters.hints.push_back(); // see wiki, saves I/O if done properly
// 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;
routing_machine.RunQuery(route_parameters, osrm_reply);
//attention: super-inefficient hack below:
// attention: super-inefficient hack below:
std::stringstream my_stream;
for (const std::string & line : osrm_reply.content)
for (const std::string &line : osrm_reply.content)
{
std::cout << line;
my_stream << line;
@ -121,7 +121,9 @@ int main (int argc, const char * argv[]) {
boost::property_tree::read_json(my_stream, property_tree);
print_tree(property_tree, 0);
} catch (std::exception & current_exception) {
}
catch (std::exception &current_exception)
{
SimpleLogger().Write(logWARNING) << "caught exception: " << current_exception.what();
return -1;
}

View File

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