Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modernize the code base to C++11 standards and beyond. #1603

Merged
merged 1 commit into from
Aug 19, 2015
Merged
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
9 changes: 5 additions & 4 deletions algorithms/bayes_classifier.hpp
Original file line number Diff line number Diff line change
@@ -31,6 +31,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <cmath>

#include <vector>
#include <utility>

struct NormalDistribution
{
@@ -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)
{
4 changes: 2 additions & 2 deletions algorithms/douglas_peucker.cpp
Original file line number Diff line number Diff line change
@@ -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
{
4 changes: 2 additions & 2 deletions algorithms/graph_compressor.cpp
Original file line number Diff line number Diff line change
@@ -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))
{
}

2 changes: 1 addition & 1 deletion algorithms/graph_compressor.hpp
Original file line number Diff line number Diff line change
@@ -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,
26 changes: 12 additions & 14 deletions contractor/edge_based_graph_factory.cpp
Original file line number Diff line number Diff line change
@@ -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))
{
}

9 changes: 4 additions & 5 deletions contractor/edge_based_graph_factory.hpp
Original file line number Diff line number Diff line change
@@ -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);
3 changes: 1 addition & 2 deletions contractor/processing_chain.hpp
Original file line number Diff line number Diff line change
@@ -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();

6 changes: 4 additions & 2 deletions data_structures/binary_heap.hpp
Original file line number Diff line number Diff line change
@@ -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;
}
@@ -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;
2 changes: 1 addition & 1 deletion data_structures/query_edge.hpp
Original file line number Diff line number Diff line change
@@ -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))
{
}

15 changes: 8 additions & 7 deletions data_structures/segment_information.hpp
Original file line number Diff line number Diff line change
@@ -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
@@ -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),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this cause copy (for the parameter location) and one move parameter -> attribute (well since this are two int values it will be like a copy anyway)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

location is constructed in the SegmentInformation constructor from either an lvalue or an rvalue. If it's a rvalue it gets moved in (which probably is implemented as a copy for primitive types, no guarantees). The member attribute is then initialized by invoking its move constructor (which probably is implemented as a copy for primitives types, again).

Detailed explanation will follow in the PR.

bearing(0), turn_instruction(turn_instruction), travel_mode(travel_mode),
necessary(turn_instruction != TurnInstruction::NoTurn), is_via_location(false)
{
}
2 changes: 1 addition & 1 deletion data_structures/shared_memory_factory.hpp
Original file line number Diff line number Diff line change
@@ -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)
{
6 changes: 3 additions & 3 deletions data_structures/static_rtree.hpp
Original file line number Diff line number Diff line change
@@ -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))
{
}

@@ -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))
3 changes: 1 addition & 2 deletions extractor/extractor.hpp
Original file line number Diff line number Diff line change
@@ -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;
33 changes: 21 additions & 12 deletions extractor/internal_extractor_edge.hpp
Original file line number Diff line number Diff line change
@@ -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
{
@@ -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))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might also be a problem.

{
}

2 changes: 1 addition & 1 deletion include/osrm/json_container.hpp
Original file line number Diff line number Diff line change
@@ -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;
};

7 changes: 5 additions & 2 deletions include/osrm/libosrm_config.hpp
Original file line number Diff line number Diff line change
@@ -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)
{
}
4 changes: 2 additions & 2 deletions plugins/match.hpp
Original file line number Diff line number Diff line change
@@ -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
@@ -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))
4 changes: 2 additions & 2 deletions routed.cpp
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion server/data_structures/internal_datafacade.hpp
Original file line number Diff line number Diff line change
@@ -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");
2 changes: 1 addition & 1 deletion server/http/header.hpp
Original file line number Diff line number Diff line change
@@ -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()
2 changes: 1 addition & 1 deletion util/datastore_options.hpp
Original file line number Diff line number Diff line change
@@ -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"))
{
10 changes: 5 additions & 5 deletions util/matching_debug_info.hpp
Original file line number Diff line number Diff line change
@@ -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;
Loading