Merge remote-tracking branch 'origin/master' into dl_using_keyword
This commit is contained in:
@@ -1,22 +0,0 @@
|
||||
#ifndef CONTAINER_HPP
|
||||
#define CONTAINER_HPP
|
||||
|
||||
#include <utility>
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
namespace util
|
||||
{
|
||||
|
||||
template <class Container> void append_to_container(Container &&) {}
|
||||
|
||||
template <class Container, typename T, typename... Args>
|
||||
void append_to_container(Container &&container, T value, Args &&... args)
|
||||
{
|
||||
container.emplace_back(value);
|
||||
append_to_container(std::forward<Container>(container), std::forward<Args>(args)...);
|
||||
}
|
||||
} // namespace util
|
||||
} // namespace osrm
|
||||
|
||||
#endif
|
||||
@@ -27,8 +27,8 @@ namespace guidance
|
||||
// Name Change Logic
|
||||
// Used both during Extraction as well as during Post-Processing
|
||||
|
||||
inline util::StringView longest_common_substring(const util::StringView &lhs,
|
||||
const util::StringView &rhs)
|
||||
inline std::string_view longest_common_substring(const std::string_view lhs,
|
||||
const std::string_view rhs)
|
||||
{
|
||||
if (lhs.empty() || rhs.empty())
|
||||
return "";
|
||||
@@ -70,7 +70,11 @@ template <typename StringView> inline auto decompose(const StringView &lhs, cons
|
||||
const auto trim = [](StringView view) {
|
||||
// we compare suffixes based on this value, it might break UTF chars, but as long as we are
|
||||
// consistent in handling, we do not create bad results
|
||||
std::string str = boost::to_lower_copy(view.to_string());
|
||||
std::string str;
|
||||
str.reserve(view.size());
|
||||
std::transform(view.begin(), view.end(), std::back_inserter(str), [](unsigned char c) {
|
||||
return std::tolower(c);
|
||||
});
|
||||
auto front = str.find_first_not_of(' ');
|
||||
|
||||
if (front == std::string::npos)
|
||||
@@ -129,20 +133,20 @@ inline bool requiresNameAnnounced(const StringView &from_name,
|
||||
const auto name_is_contained =
|
||||
boost::starts_with(from_name, to_name) || boost::starts_with(to_name, from_name);
|
||||
|
||||
const auto checkForPrefixOrSuffixChange =
|
||||
[](const StringView &first, const StringView &second, const SuffixTable &suffix_table) {
|
||||
std::string first_prefix, first_suffix, second_prefix, second_suffix;
|
||||
std::tie(first_prefix, first_suffix, second_prefix, second_suffix) =
|
||||
decompose(first, second);
|
||||
|
||||
const auto checkTable = [&](const std::string &str) {
|
||||
return str.empty() || suffix_table.isSuffix(str);
|
||||
};
|
||||
|
||||
return checkTable(first_prefix) && checkTable(first_suffix) &&
|
||||
checkTable(second_prefix) && checkTable(second_suffix);
|
||||
const auto checkForPrefixOrSuffixChange = [](const std::string_view first,
|
||||
const std::string_view second,
|
||||
const SuffixTable &suffix_table) {
|
||||
std::string first_prefix, first_suffix, second_prefix, second_suffix;
|
||||
std::tie(first_prefix, first_suffix, second_prefix, second_suffix) =
|
||||
decompose(first, second);
|
||||
const auto checkTable = [&](const std::string &str) {
|
||||
return str.empty() || suffix_table.isSuffix(str);
|
||||
};
|
||||
|
||||
return checkTable(first_prefix) && checkTable(first_suffix) && checkTable(second_prefix) &&
|
||||
checkTable(second_suffix);
|
||||
};
|
||||
|
||||
const auto is_suffix_change = checkForPrefixOrSuffixChange(from_name, to_name, suffix_table);
|
||||
const auto names_are_equal = from_name == to_name || name_is_contained || is_suffix_change;
|
||||
const auto name_is_removed = !from_name.empty() && to_name.empty();
|
||||
@@ -201,17 +205,17 @@ inline bool requiresNameAnnounced(const std::string &from_name,
|
||||
struct NopSuffixTable final
|
||||
{
|
||||
NopSuffixTable() {}
|
||||
bool isSuffix(const StringView &) const { return false; }
|
||||
bool isSuffix(const std::string_view) const { return false; }
|
||||
} static const table;
|
||||
|
||||
return requiresNameAnnounced(util::StringView(from_name),
|
||||
util::StringView(from_ref),
|
||||
util::StringView(from_pronunciation),
|
||||
util::StringView(from_exits),
|
||||
util::StringView(to_name),
|
||||
util::StringView(to_ref),
|
||||
util::StringView(to_pronunciation),
|
||||
util::StringView(to_exits),
|
||||
return requiresNameAnnounced(std::string_view(from_name),
|
||||
std::string_view(from_ref),
|
||||
std::string_view(from_pronunciation),
|
||||
std::string_view(from_exits),
|
||||
std::string_view(to_name),
|
||||
std::string_view(to_ref),
|
||||
std::string_view(to_pronunciation),
|
||||
std::string_view(to_exits),
|
||||
table);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,16 +4,16 @@
|
||||
#include "storage/tar_fwd.hpp"
|
||||
|
||||
#include "util/exception.hpp"
|
||||
#include "util/string_view.hpp"
|
||||
#include "util/vector_view.hpp"
|
||||
|
||||
#include <boost/assert.hpp>
|
||||
#include <boost/function_output_iterator.hpp>
|
||||
#include <boost/iterator/function_output_iterator.hpp>
|
||||
|
||||
#include <array>
|
||||
#include <iterator>
|
||||
#include <limits>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <type_traits>
|
||||
|
||||
namespace osrm
|
||||
@@ -216,7 +216,7 @@ template <int N, typename T = std::string> struct FixedGroupBlock
|
||||
std::numeric_limits<std::make_unsigned_t<ValueType>>::max();
|
||||
|
||||
auto index = 0;
|
||||
std::array<ValueType, BLOCK_SIZE> prefix;
|
||||
std::array<ValueType, BLOCK_SIZE> prefix{};
|
||||
|
||||
for (OffsetIterator curr = first, next = std::next(first); curr != last; ++curr, ++next)
|
||||
{
|
||||
@@ -365,14 +365,14 @@ template <typename GroupBlockPolicy, storage::Ownership Ownership> struct Indexe
|
||||
std::enable_if_t<std::is_same<T, typename std::iterator_traits<Iter>::value_type>::value>;
|
||||
|
||||
template <typename T = ResultType, typename Iter, typename = IsValueIterator<Iter, ValueType>>
|
||||
typename std::enable_if<!std::is_same<T, StringView>::value, T>::type
|
||||
typename std::enable_if<!std::is_same<T, std::string_view>::value, T>::type
|
||||
adapt(const Iter first, const Iter last) const
|
||||
{
|
||||
return ResultType(first, last);
|
||||
}
|
||||
|
||||
template <typename T = ResultType, typename Iter, typename = IsValueIterator<Iter, ValueType>>
|
||||
typename std::enable_if<std::is_same<T, StringView>::value, T>::type
|
||||
typename std::enable_if<std::is_same<T, std::string_view>::value, T>::type
|
||||
adapt(const Iter first, const Iter last) const
|
||||
{
|
||||
auto diff = std::distance(first, last);
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
#define JSON_UTIL_HPP
|
||||
|
||||
#include "osrm/json_container.hpp"
|
||||
#include "util/container.hpp"
|
||||
|
||||
#include <cmath>
|
||||
#include <limits>
|
||||
@@ -27,30 +26,6 @@ template <typename T> T clamp_float(T d)
|
||||
|
||||
return d;
|
||||
}
|
||||
|
||||
template <typename... Args> Array make_array(Args... args)
|
||||
{
|
||||
Array a;
|
||||
// TODO: check why a.values.emplace_back(args...); is not an option here
|
||||
append_to_container(a.values, args...);
|
||||
return a;
|
||||
}
|
||||
|
||||
// Easy acces to object hierachies
|
||||
inline Value &get(Value &value) { return value; }
|
||||
|
||||
template <typename... Keys> Value &get(Value &value, const char *key, Keys... keys)
|
||||
{
|
||||
using recursive_object_t = mapbox::util::recursive_wrapper<Object>;
|
||||
return get(value.get<recursive_object_t>().get().values[key], keys...);
|
||||
}
|
||||
|
||||
template <typename... Keys> Value &get(Value &value, unsigned key, Keys... keys)
|
||||
{
|
||||
using recursive_array_t = mapbox::util::recursive_wrapper<Array>;
|
||||
return get(value.get<recursive_array_t>().get().values[key], keys...);
|
||||
}
|
||||
|
||||
} // namespace json
|
||||
} // namespace util
|
||||
} // namespace osrm
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
#ifndef OSRM_STRING_VIEW_HPP
|
||||
#define OSRM_STRING_VIEW_HPP
|
||||
|
||||
#include <boost/functional/hash.hpp>
|
||||
#include <boost/utility/string_ref.hpp>
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
namespace util
|
||||
{
|
||||
// Convenience typedef: boost::string_ref, boost::string_view or C++17's string_view
|
||||
using StringView = boost::string_ref;
|
||||
|
||||
} // namespace util
|
||||
} // namespace osrm
|
||||
|
||||
// Specializing hash<> for user-defined type in std namespace, this is standard conforming.
|
||||
namespace std
|
||||
{
|
||||
template <> struct hash<::osrm::util::StringView> final
|
||||
{
|
||||
std::size_t operator()(::osrm::util::StringView v) const noexcept
|
||||
{
|
||||
// Bring into scope and call un-qualified for ADL:
|
||||
// remember we want to be able to switch impl. above.
|
||||
using std::begin;
|
||||
using std::end;
|
||||
|
||||
return boost::hash_range(begin(v), end(v));
|
||||
}
|
||||
};
|
||||
} // namespace std
|
||||
|
||||
#endif /* OSRM_STRING_VIEW_HPP */
|
||||
Reference in New Issue
Block a user