Skip to content

Commit

Permalink
Merge pull request #1603 from Project-OSRM/refactor/clang_modernize
Browse files Browse the repository at this point in the history
Modernize the code base to C++11 standards and beyond.
  • Loading branch information
TheMarex committed Aug 19, 2015
2 parents 84e72ed + 62b2076 commit ca7abd7
Show file tree
Hide file tree
Showing 24 changed files with 88 additions and 76 deletions.
9 changes: 5 additions & 4 deletions algorithms/bayes_classifier.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <cmath>

#include <vector>
#include <utility>

struct NormalDistribution
{
Expand Down Expand Up @@ -80,11 +81,11 @@ class BayesClassifier
};
using ClassificationT = std::pair<ClassLabel, double>;

BayesClassifier(const PositiveDistributionT &positive_distribution,
const NegativeDistributionT &negative_distribution,
BayesClassifier(PositiveDistributionT positive_distribution,
NegativeDistributionT negative_distribution,
const double positive_apriori_probability)
: positive_distribution(positive_distribution),
negative_distribution(negative_distribution),
: positive_distribution(std::move(positive_distribution)),
negative_distribution(std::move(negative_distribution)),
positive_apriori_probability(positive_apriori_probability),
negative_apriori_probability(1. - positive_apriori_probability)
{
Expand Down
4 changes: 2 additions & 2 deletions algorithms/douglas_peucker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ void DouglasPeucker::Run(RandomAccessIt begin, RandomAccessIt end, const unsigne

{
BOOST_ASSERT_MSG(zoom_level < DOUGLAS_PEUCKER_THRESHOLDS.size(), "unsupported zoom level");
RandomAccessIt left_border = begin;
RandomAccessIt right_border = std::next(begin);
auto left_border = begin;
auto right_border = std::next(begin);
// Sweep over array and identify those ranges that need to be checked
do
{
Expand Down
4 changes: 2 additions & 2 deletions algorithms/graph_compressor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

#include "../util/simple_logger.hpp"

GraphCompressor::GraphCompressor(const SpeedProfileProperties& speed_profile)
: speed_profile(speed_profile)
GraphCompressor::GraphCompressor(SpeedProfileProperties speed_profile)
: speed_profile(std::move(speed_profile))
{
}

Expand Down
2 changes: 1 addition & 1 deletion algorithms/graph_compressor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class GraphCompressor
using EdgeData = NodeBasedDynamicGraph::EdgeData;

public:
GraphCompressor(const SpeedProfileProperties& speed_profile);
GraphCompressor(SpeedProfileProperties speed_profile);

void Compress(const std::unordered_set<NodeID>& barrier_nodes,
const std::unordered_set<NodeID>& traffic_lights,
Expand Down
26 changes: 12 additions & 14 deletions contractor/edge_based_graph_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,18 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <iomanip>
#include <limits>

EdgeBasedGraphFactory::EdgeBasedGraphFactory(std::shared_ptr<NodeBasedDynamicGraph> node_based_graph,
const CompressedEdgeContainer& compressed_edge_container,
const std::unordered_set<NodeID>& barrier_nodes,
const std::unordered_set<NodeID>& traffic_lights,
std::shared_ptr<const RestrictionMap> restriction_map,
const std::vector<QueryNode> &node_info_list,
const SpeedProfileProperties &speed_profile)
: m_node_info_list(node_info_list),
m_node_based_graph(node_based_graph),
m_restriction_map(restriction_map),
m_barrier_nodes(barrier_nodes),
m_traffic_lights(traffic_lights),
m_compressed_edge_container(compressed_edge_container),
speed_profile(speed_profile)
EdgeBasedGraphFactory::EdgeBasedGraphFactory(
std::shared_ptr<NodeBasedDynamicGraph> node_based_graph,
const CompressedEdgeContainer &compressed_edge_container,
const std::unordered_set<NodeID> &barrier_nodes,
const std::unordered_set<NodeID> &traffic_lights,
std::shared_ptr<const RestrictionMap> restriction_map,
const std::vector<QueryNode> &node_info_list,
SpeedProfileProperties speed_profile)
: m_node_info_list(node_info_list), m_node_based_graph(std::move(node_based_graph)),
m_restriction_map(std::move(restriction_map)), m_barrier_nodes(barrier_nodes),
m_traffic_lights(traffic_lights), m_compressed_edge_container(compressed_edge_container),
speed_profile(std::move(speed_profile))
{
}

Expand Down
9 changes: 4 additions & 5 deletions contractor/edge_based_graph_factory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,13 @@ class EdgeBasedGraphFactory
EdgeBasedGraphFactory() = delete;
EdgeBasedGraphFactory(const EdgeBasedGraphFactory &) = delete;


explicit EdgeBasedGraphFactory(std::shared_ptr<NodeBasedDynamicGraph> node_based_graph,
const CompressedEdgeContainer& compressed_edge_container,
const std::unordered_set<NodeID>& barrier_nodes,
const std::unordered_set<NodeID>& traffic_lights,
const CompressedEdgeContainer &compressed_edge_container,
const std::unordered_set<NodeID> &barrier_nodes,
const std::unordered_set<NodeID> &traffic_lights,
std::shared_ptr<const RestrictionMap> restriction_map,
const std::vector<QueryNode> &node_info_list,
const SpeedProfileProperties &speed_profile);
SpeedProfileProperties speed_profile);

void Run(const std::string &original_edge_data_filename,
lua_State *lua_state);
Expand Down
3 changes: 1 addition & 2 deletions contractor/processing_chain.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ class Prepare
using InputEdge = DynamicGraph<EdgeData>::InputEdge;
using StaticEdge = StaticGraph<EdgeData>::InputEdge;

explicit Prepare(const ContractorConfig& contractor_config)
: config(contractor_config) {}
explicit Prepare(ContractorConfig contractor_config) : config(std::move(contractor_config)) {}
Prepare(const Prepare &) = delete;
~Prepare();

Expand Down
6 changes: 4 additions & 2 deletions data_structures/binary_heap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ class BinaryHeap
void DeleteAll()
{
auto iend = heap.end();
for (typename std::vector<HeapElement>::iterator i = heap.begin() + 1; i != iend; ++i)
for (auto i = heap.begin() + 1; i != iend; ++i)
{
inserted_nodes[i->index].key = 0;
}
Expand All @@ -237,7 +237,9 @@ class BinaryHeap
class HeapNode
{
public:
HeapNode(NodeID n, Key k, Weight w, Data d) : node(n), key(k), weight(w), data(d) {}
HeapNode(NodeID n, Key k, Weight w, Data d) : node(n), key(k), weight(w), data(std::move(d))
{
}

NodeID node;
Key key;
Expand Down
2 changes: 1 addition & 1 deletion data_structures/query_edge.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ struct QueryEdge
QueryEdge() : source(SPECIAL_NODEID), target(SPECIAL_NODEID) {}

QueryEdge(NodeID source, NodeID target, EdgeData data)
: source(source), target(target), data(data)
: source(source), target(target), data(std::move(data))
{
}

Expand Down
15 changes: 8 additions & 7 deletions data_structures/segment_information.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "../typedefs.h"

#include <osrm/coordinate.hpp>
#include <utility>

// Struct fits everything in one cache line
struct SegmentInformation
Expand All @@ -48,28 +49,28 @@ struct SegmentInformation
bool necessary;
bool is_via_location;

explicit SegmentInformation(const FixedPointCoordinate &location,
explicit SegmentInformation(FixedPointCoordinate location,
const NodeID name_id,
const EdgeWeight duration,
const float length,
const TurnInstruction turn_instruction,
const bool necessary,
const bool is_via_location,
const TravelMode travel_mode)
: location(location), name_id(name_id), duration(duration), length(length), bearing(0),
turn_instruction(turn_instruction), travel_mode(travel_mode), necessary(necessary),
is_via_location(is_via_location)
: location(std::move(location)), name_id(name_id), duration(duration), length(length),
bearing(0), turn_instruction(turn_instruction), travel_mode(travel_mode),
necessary(necessary), is_via_location(is_via_location)
{
}

explicit SegmentInformation(const FixedPointCoordinate &location,
explicit SegmentInformation(FixedPointCoordinate location,
const NodeID name_id,
const EdgeWeight duration,
const float length,
const TurnInstruction turn_instruction,
const TravelMode travel_mode)
: location(location), name_id(name_id), duration(duration), length(length), bearing(0),
turn_instruction(turn_instruction), travel_mode(travel_mode),
: location(std::move(location)), name_id(name_id), duration(duration), length(length),
bearing(0), turn_instruction(turn_instruction), travel_mode(travel_mode),
necessary(turn_instruction != TurnInstruction::NoTurn), is_via_location(false)
{
}
Expand Down
2 changes: 1 addition & 1 deletion data_structures/shared_memory_factory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class SharedMemory
shm = boost::interprocess::xsi_shared_memory(boost::interprocess::open_or_create, key,
size);
#ifdef __linux__
if (-1 == shmctl(shm.get_shmid(), SHM_LOCK, 0))
if (-1 == shmctl(shm.get_shmid(), SHM_LOCK, nullptr))
{
if (ENOMEM == errno)
{
Expand Down
6 changes: 3 additions & 3 deletions data_structures/static_rtree.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,8 @@ class StaticRTree
using IncrementalQueryNodeType = mapbox::util::variant<TreeNode, EdgeDataT>;
struct IncrementalQueryCandidate
{
explicit IncrementalQueryCandidate(const float dist, const IncrementalQueryNodeType &node)
: min_dist(dist), node(node)
explicit IncrementalQueryCandidate(const float dist, IncrementalQueryNodeType node)
: min_dist(dist), node(std::move(node))
{
}

Expand Down Expand Up @@ -553,7 +553,7 @@ class StaticRTree
const boost::filesystem::path &leaf_file,
std::shared_ptr<CoordinateListT> coordinate_list)
: m_search_tree(tree_node_ptr, number_of_nodes), m_leaf_node_filename(leaf_file.string()),
m_coordinate_list(coordinate_list)
m_coordinate_list(std::move(coordinate_list))
{
// open leaf node file and store thread specific pointer
if (!boost::filesystem::exists(leaf_file))
Expand Down
3 changes: 1 addition & 2 deletions extractor/extractor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
class extractor
{
public:
extractor(const ExtractorConfig &extractor_config)
: config(extractor_config) {}
extractor(ExtractorConfig extractor_config) : config(std::move(extractor_config)) {}
int run();
private:
ExtractorConfig config;
Expand Down
33 changes: 21 additions & 12 deletions extractor/internal_extractor_edge.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <boost/assert.hpp>

#include <osrm/coordinate.hpp>
#include <utility>

struct InternalExtractorEdge
{
Expand Down Expand Up @@ -68,18 +69,26 @@ struct InternalExtractorEdge
}

explicit InternalExtractorEdge(NodeID source,
NodeID target,
NodeID name_id,
const WeightData& weight_data,
bool forward,
bool backward,
bool roundabout,
bool access_restricted,
TravelMode travel_mode,
bool is_split)
: result(source, target, name_id, 0, forward, backward, roundabout,
access_restricted, travel_mode, is_split),
weight_data(weight_data)
NodeID target,
NodeID name_id,
WeightData weight_data,
bool forward,
bool backward,
bool roundabout,
bool access_restricted,
TravelMode travel_mode,
bool is_split)
: result(source,
target,
name_id,
0,
forward,
backward,
roundabout,
access_restricted,
travel_mode,
is_split),
weight_data(std::move(weight_data))
{
}

Expand Down
2 changes: 1 addition & 1 deletion include/osrm/json_container.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ struct String
{
String() {}
String(const char *value) : value(value) {}
String(const std::string &value) : value(value) {}
String(std::string value) : value(std::move(value)) {}
std::string value;
};

Expand Down
7 changes: 5 additions & 2 deletions include/osrm/libosrm_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,11 @@ struct libosrm_config
{
}

libosrm_config(const ServerPaths &paths, const bool sharedmemory_flag, const int max_table, const int max_matching)
: server_paths(paths), max_locations_distance_table(max_table),
libosrm_config(ServerPaths paths,
const bool sharedmemory_flag,
const int max_table,
const int max_matching)
: server_paths(std::move(paths)), max_locations_distance_table(max_table),
max_locations_map_matching(max_matching), use_shared_memory(sharedmemory_flag)
{
}
Expand Down
4 changes: 2 additions & 2 deletions plugins/match.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ template <class DataFacadeT> class MapMatchingPlugin : public BasePlugin

virtual ~MapMatchingPlugin() {}

const std::string GetDescriptor() const final { return descriptor_string; }
const std::string GetDescriptor() const final override { return descriptor_string; }

TraceClassification
classify(const float trace_length, const float matched_length, const int removed_points) const
Expand Down Expand Up @@ -211,7 +211,7 @@ template <class DataFacadeT> class MapMatchingPlugin : public BasePlugin
}

int HandleRequest(const RouteParameters &route_parameters,
osrm::json::Object &json_result) final
osrm::json::Object &json_result) final override
{
// check number of parameters
if (!check_all_coordinates(route_parameters.coordinates))
Expand Down
4 changes: 2 additions & 2 deletions routed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,12 @@ int main(int argc, const char *argv[])

#ifndef _WIN32
sigset_t wait_mask;
pthread_sigmask(SIG_SETMASK, &old_mask, 0);
pthread_sigmask(SIG_SETMASK, &old_mask, nullptr);
sigemptyset(&wait_mask);
sigaddset(&wait_mask, SIGINT);
sigaddset(&wait_mask, SIGQUIT);
sigaddset(&wait_mask, SIGTERM);
pthread_sigmask(SIG_BLOCK, &wait_mask, 0);
pthread_sigmask(SIG_BLOCK, &wait_mask, nullptr);
SimpleLogger().Write() << "running and waiting for requests";
sigwait(&wait_mask, &sig);
#else
Expand Down
2 changes: 1 addition & 1 deletion server/data_structures/internal_datafacade.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ template <class EdgeDataT> class InternalDataFacade final : public BaseDataFacad
throw osrm::exception("no names file given in ini file");
}

ServerPaths::const_iterator paths_iterator = server_paths.find("hsgrdata");
auto paths_iterator = server_paths.find("hsgrdata");
BOOST_ASSERT(server_paths.end() != paths_iterator);
const boost::filesystem::path &hsgr_path = paths_iterator->second;
paths_iterator = server_paths.find("timestamp");
Expand Down
2 changes: 1 addition & 1 deletion server/http/header.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ struct header
{
// explicitly use default copy c'tor as adding move c'tor
header &operator=(const header &other) = default;
header(const std::string &name, const std::string &value) : name(name), value(value) {}
header(std::string name, std::string value) : name(std::move(name)), value(std::move(value)) {}
header(header &&other) : name(std::move(other.name)), value(std::move(other.value)) {}

void clear()
Expand Down
2 changes: 1 addition & 1 deletion util/datastore_options.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ bool GenerateDataStoreOptions(const int argc, const char *argv[], ServerPaths &p
}

// parse config file
ServerPaths::iterator path_iterator = paths.find("config");
auto path_iterator = paths.find("config");
if (path_iterator != paths.end() && boost::filesystem::is_regular_file(path_iterator->second) &&
!option_variables.count("base"))
{
Expand Down
10 changes: 5 additions & 5 deletions util/matching_debug_info.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,16 @@ struct MatchingDebugInfo
}

osrm::json::Array states;
for (unsigned t = 0; t < candidates_list.size(); t++)
for (auto &elem : candidates_list)
{
osrm::json::Array timestamps;
for (unsigned s = 0; s < candidates_list[t].size(); s++)
for (unsigned s = 0; s < elem.size(); s++)
{
osrm::json::Object state;
state.values["transitions"] = osrm::json::Array();
state.values["coordinate"] = osrm::json::make_array(
candidates_list[t][s].first.location.lat / COORDINATE_PRECISION,
candidates_list[t][s].first.location.lon / COORDINATE_PRECISION);
state.values["coordinate"] =
osrm::json::make_array(elem[s].first.location.lat / COORDINATE_PRECISION,
elem[s].first.location.lon / COORDINATE_PRECISION);
state.values["viterbi"] =
osrm::json::clamp_float(osrm::matching::IMPOSSIBLE_LOG_PROB);
state.values["pruned"] = 0u;
Expand Down
Loading

0 comments on commit ca7abd7

Please sign in to comment.