renamed: Util/* -> util/*

This commit is contained in:
Dennis Luxen
2015-01-27 17:44:46 +01:00
parent 203e3ef077
commit b20b7e65bf
113 changed files with 4533 additions and 971 deletions
+4 -7
View File
@@ -38,7 +38,8 @@ struct cast
{
// convert scoped enums to integers
template <typename Enumeration>
static auto enum_to_underlying(Enumeration const value) -> typename std::underlying_type<Enumeration>::type
static auto enum_to_underlying(Enumeration const value) ->
typename std::underlying_type<Enumeration>::type
{
return static_cast<typename std::underlying_type<Enumeration>::type>(value);
}
@@ -145,10 +146,7 @@ struct cast
template <typename T> struct scientific_policy : boost::spirit::karma::real_policies<T>
{
// we want the numbers always to be in fixed format
static int floatfield(T)
{
return boost::spirit::karma::real_policies<T>::fmtflags::fixed;
}
static int floatfield(T) { return boost::spirit::karma::real_policies<T>::fmtflags::fixed; }
static unsigned int precision(T) { return 6; }
};
typedef boost::spirit::karma::real_generator<double, scientific_policy<double>> science_type;
@@ -174,8 +172,7 @@ struct cast
return output;
}
static void double_with_two_digits_to_string(const double value,
std::string &output)
static void double_with_two_digits_to_string(const double value, std::string &output)
{
// The largest 32-bit integer is 4294967295, that is 10 chars
// On the safe side, add 1 for sign, and 1 for trailing zero
+1 -1
View File
@@ -28,7 +28,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "compute_angle.hpp"
#include "trigonometry_table.hpp"
#include "../Util/mercator.hpp"
#include "../util/mercator.hpp"
#include <osrm/coordinate.hpp>
+8 -5
View File
@@ -37,7 +37,8 @@ namespace osrm
template <typename T> void sort_unique_resize(std::vector<T> &vector)
{
std::sort(vector.begin(), vector.end());
const auto number_of_unique_elements = std::unique(vector.begin(), vector.end()) - vector.begin();
const auto number_of_unique_elements =
std::unique(vector.begin(), vector.end()) - vector.begin();
vector.resize(number_of_unique_elements);
}
@@ -47,9 +48,11 @@ template <typename T> void sort_unique_resize(std::vector<T> &vector)
// vector.shrink_to_fit();
// }
// template <typename T> inline void remove_consecutive_duplicates_from_vector(std::vector<T> &vector)
// template <typename T> inline void remove_consecutive_duplicates_from_vector(std::vector<T>
// &vector)
// {
// const auto number_of_unique_elements = std::unique(vector.begin(), vector.end()) - vector.begin();
// const auto number_of_unique_elements = std::unique(vector.begin(), vector.end()) -
// vector.begin();
// vector.resize(number_of_unique_elements);
// }
@@ -67,7 +70,8 @@ Function for_each_pair(ForwardIterator begin, ForwardIterator end, Function func
while (next != end)
{
function(*begin, *next);
begin = std::next(begin); next = std::next(next);
begin = std::next(begin);
next = std::next(next);
}
return function;
}
@@ -77,6 +81,5 @@ Function for_each_pair(ContainerT &container, Function function)
{
return for_each_pair(std::begin(container), std::end(container), function);
}
}
#endif /* CONTAINER_HPP_ */
+1 -1
View File
@@ -35,7 +35,7 @@ class FingerPrint
{
public:
FingerPrint();
FingerPrint(const FingerPrint&) = delete;
FingerPrint(const FingerPrint &) = delete;
~FingerPrint();
const boost::uuids::uuid &GetFingerPrint() const;
bool IsMagicNumberOK() const;
+1 -1
View File
@@ -30,4 +30,4 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
extern char g_GIT_DESCRIPTION[];
#endif //GIT_SHA_HPP
#endif // GIT_SHA_HPP
+19 -25
View File
@@ -28,13 +28,13 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef GRAPH_LOADER_HPP
#define GRAPH_LOADER_HPP
#include "fingerprint.hpp"
#include "osrm_exception.hpp"
#include "simple_logger.hpp"
#include "../data_structures/external_memory_node.hpp"
#include "../data_structures/import_edge.hpp"
#include "../data_structures/query_node.hpp"
#include "../data_structures/restriction.hpp"
#include "../Util/fingerprint.hpp"
#include "../Util/simple_logger.hpp"
#include "../typedefs.h"
#include <boost/assert.hpp>
@@ -80,7 +80,8 @@ NodeID readBinaryOSRMGraphFromStream(std::istream &input_stream,
for (NodeID i = 0; i < n; ++i)
{
input_stream.read((char *)&current_node, sizeof(ExternalMemoryNode));
int_to_ext_node_id_map->emplace_back(current_node.lat, current_node.lon, current_node.node_id);
int_to_ext_node_id_map->emplace_back(current_node.lat, current_node.lon,
current_node.node_id);
ext_to_int_id_map.emplace(current_node.node_id, i);
if (current_node.barrier)
{
@@ -102,7 +103,8 @@ NodeID readBinaryOSRMGraphFromStream(std::istream &input_stream,
auto internal_id_iter = ext_to_int_id_map.find(current_restriction.from.node);
if (internal_id_iter == ext_to_int_id_map.end())
{
SimpleLogger().Write(logDEBUG) << "Unmapped from node " << current_restriction.from.node << " of restriction";
SimpleLogger().Write(logDEBUG) << "Unmapped from node " << current_restriction.from.node
<< " of restriction";
continue;
}
current_restriction.from.node = internal_id_iter->second;
@@ -110,7 +112,8 @@ NodeID readBinaryOSRMGraphFromStream(std::istream &input_stream,
internal_id_iter = ext_to_int_id_map.find(current_restriction.via.node);
if (internal_id_iter == ext_to_int_id_map.end())
{
SimpleLogger().Write(logDEBUG) << "Unmapped via node " << current_restriction.via.node << " of restriction";
SimpleLogger().Write(logDEBUG) << "Unmapped via node " << current_restriction.via.node
<< " of restriction";
continue;
}
@@ -119,7 +122,8 @@ NodeID readBinaryOSRMGraphFromStream(std::istream &input_stream,
internal_id_iter = ext_to_int_id_map.find(current_restriction.to.node);
if (internal_id_iter == ext_to_int_id_map.end())
{
SimpleLogger().Write(logDEBUG) << "Unmapped to node " << current_restriction.to.node << " of restriction";
SimpleLogger().Write(logDEBUG) << "Unmapped to node " << current_restriction.to.node
<< " of restriction";
continue;
}
current_restriction.to.node = internal_id_iter->second;
@@ -195,17 +199,8 @@ NodeID readBinaryOSRMGraphFromStream(std::istream &input_stream,
std::swap(forward, backward);
}
edge_list.emplace_back(source,
target,
nameID,
weight,
forward,
backward,
is_roundabout,
ignore_in_grid,
is_access_restricted,
travel_mode,
is_split);
edge_list.emplace_back(source, target, nameID, weight, forward, backward, is_roundabout,
ignore_in_grid, is_access_restricted, travel_mode, is_split);
}
ext_to_int_id_map.clear();
@@ -216,9 +211,8 @@ NodeID readBinaryOSRMGraphFromStream(std::istream &input_stream,
if ((edge_list[i - 1].target == edge_list[i].target) &&
(edge_list[i - 1].source == edge_list[i].source))
{
const bool edge_flags_equivalent =
(edge_list[i - 1].forward == edge_list[i].forward) &&
(edge_list[i - 1].backward == edge_list[i].backward);
const bool edge_flags_equivalent = (edge_list[i - 1].forward == edge_list[i].forward) &&
(edge_list[i - 1].backward == edge_list[i].backward);
const bool edge_flags_are_superset1 =
(edge_list[i - 1].forward && edge_list[i - 1].backward) &&
(edge_list[i].forward != edge_list[i].backward);
@@ -263,11 +257,11 @@ NodeID readBinaryOSRMGraphFromStream(std::istream &input_stream,
}
}
}
const auto new_end_iter = std::remove_if(edge_list.begin(), edge_list.end(), [] (const EdgeT &edge)
{
return edge.source == SPECIAL_NODEID ||
edge.target == SPECIAL_NODEID;
});
const auto new_end_iter =
std::remove_if(edge_list.begin(), edge_list.end(), [](const EdgeT &edge)
{
return edge.source == SPECIAL_NODEID || edge.target == SPECIAL_NODEID;
});
edge_list.erase(new_end_iter, edge_list.end()); // remove excess candidates.
edge_list.shrink_to_fit();
SimpleLogger().Write() << "Graph loaded ok and has " << edge_list.size() << " edges";
+2 -1
View File
@@ -35,7 +35,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <osrm/json_container.hpp>
namespace JSON {
namespace JSON
{
struct Renderer : mapbox::util::static_visitor<>
{
+1 -1
View File
@@ -54,4 +54,4 @@ template <class T, class... Types>
typename std::enable_if<std::extent<T>::value != 0, void>::type make_unique(Types &&...) = delete;
}
#endif //MAKE_UNIQUE_H_
#endif // MAKE_UNIQUE_H_
+10 -10
View File
@@ -29,15 +29,15 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
namespace osrm
{
// This function exists to 'anchor' the class, and stop the compiler from
// copying vtable and RTTI info into every object file that includes
// this header. (Caught by -Wweak-vtables under Clang.)
// This function exists to 'anchor' the class, and stop the compiler from
// copying vtable and RTTI info into every object file that includes
// this header. (Caught by -Wweak-vtables under Clang.)
// More information from the LLVM Coding Standards:
// If a class is defined in a header file and has a vtable (either it has
// virtual methods or it derives from classes with virtual methods), it must
// always have at least one out-of-line virtual method in the class. Without
// this, the compiler will copy the vtable and RTTI into every .o file that
// #includes the header, bloating .o file sizes and increasing link times.
void exception::anchor() const { }
// More information from the LLVM Coding Standards:
// If a class is defined in a header file and has a vtable (either it has
// virtual methods or it derives from classes with virtual methods), it must
// always have at least one out-of-line virtual method in the class. Without
// this, the compiler will copy the vtable and RTTI into every .o file that
// #includes the header, bloating .o file sizes and increasing link times.
void exception::anchor() const {}
}
+6 -6
View File
@@ -23,20 +23,20 @@ or see http://www.gnu.org/licenses/agpl.txt.
#include <algorithm>
namespace osrm {
namespace osrm
{
template<class Container>
auto max_element(const Container & c) -> decltype(std::max_element(c.begin(), c.end()))
template <class Container>
auto max_element(const Container &c) -> decltype(std::max_element(c.begin(), c.end()))
{
return std::max_element(c.begin(), c.end());
}
template<class Container>
auto max_element(const Container & c) -> decltype(std::max_element(c.cbegin(), c.cend()))
template <class Container>
auto max_element(const Container &c) -> decltype(std::max_element(c.cbegin(), c.cend()))
{
return std::max_element(c.cbegin(), c.cend());
}
}
#endif // RANGE_ALGORITHMS_HPP
+5 -5
View File
@@ -47,10 +47,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
namespace
{
static const char COL_RESET[] { "\x1b[0m"};
static const char RED[] { "\x1b[31m"};
static const char COL_RESET[]{"\x1b[0m"};
static const char RED[]{"\x1b[31m"};
#ifndef NDEBUG
static const char YELLOW[] { "\x1b[33m"};
static const char YELLOW[]{"\x1b[33m"};
#endif
// static const char GREEN[] { "\x1b[32m"};
// static const char BLUE[] { "\x1b[34m"};
@@ -95,7 +95,7 @@ std::ostringstream &SimpleLogger::Write(LogLevel lvl)
os << "debug";
#endif
break;
default: //logINFO:
default: // logINFO:
os << "info";
break;
}
@@ -127,7 +127,7 @@ SimpleLogger::~SimpleLogger()
<< std::endl;
#endif
break;
default: //logINFO:
default: // logINFO:
std::cout << os.str() << (is_terminal ? COL_RESET : "") << std::endl;
break;
}
+9 -14
View File
@@ -33,29 +33,24 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// this is largely inspired by boost's hash combine as can be found in
// "The C++ Standard Library" 2nd Edition. Nicolai M. Josuttis. 2012.
namespace {
namespace
{
template<typename T>
void hash_combine(std::size_t &seed, const T& val)
template <typename T> void hash_combine(std::size_t &seed, const T &val)
{
seed ^= std::hash<T>()(val) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
}
template<typename T>
void hash_val(std::size_t &seed, const T& val)
template <typename T> void hash_val(std::size_t &seed, const T &val) { hash_combine(seed, val); }
template <typename T, typename... Types>
void hash_val(std::size_t &seed, const T &val, const Types &... args)
{
hash_combine(seed, val);
hash_val(seed, args...);
}
template<typename T, typename ... Types>
void hash_val(std::size_t &seed, const T& val, const Types& ... args)
{
hash_combine(seed, val);
hash_val(seed, args ...);
}
template<typename ... Types>
std::size_t hash_val(const Types&... args)
template <typename... Types> std::size_t hash_val(const Types &... args)
{
std::size_t seed = 0;
hash_val(seed, args...);
+22 -12
View File
@@ -42,39 +42,49 @@ struct GlobalTimer
class GlobalTimerFactory
{
public:
static GlobalTimerFactory& get()
public:
static GlobalTimerFactory &get()
{
static GlobalTimerFactory instance;
return instance;
}
GlobalTimer& getGlobalTimer(const std::string& name)
GlobalTimer &getGlobalTimer(const std::string &name)
{
std::lock_guard<std::mutex> lock(map_mutex);
return timer_map[name];
}
private:
private:
std::mutex map_mutex;
std::unordered_map<std::string, GlobalTimer> timer_map;
};
#define GLOBAL_TIMER_AQUIRE(_X) auto& _X##_global_timer = GlobalTimerFactory::get().getGlobalTimer(#_X)
#define GLOBAL_TIMER_AQUIRE(_X) \
auto &_X##_global_timer = GlobalTimerFactory::get().getGlobalTimer(#_X)
#define GLOBAL_TIMER_RESET(_X) _X##_global_timer.time = 0
#define GLOBAL_TIMER_START(_X) TIMER_START(_X)
#define GLOBAL_TIMER_STOP(_X) TIMER_STOP(_X); _X##_global_timer.time += TIMER_NSEC(_X)
#define GLOBAL_TIMER_STOP(_X) \
TIMER_STOP(_X); \
_X##_global_timer.time += TIMER_NSEC(_X)
#define GLOBAL_TIMER_NSEC(_X) static_cast<double>(_X##_global_timer.time)
#define GLOBAL_TIMER_USEC(_X) (_X##_global_timer.time / 1000.0)
#define GLOBAL_TIMER_MSEC(_X) (_X##_global_timer.time / 1000.0 / 1000.0)
#define GLOBAL_TIMER_SEC(_X) (_X##_global_timer.time / 1000.0 / 1000.0 / 1000.0)
#define GLOBAL_TIMER_SEC(_X) (_X##_global_timer.time / 1000.0 / 1000.0 / 1000.0)
#define TIMER_START(_X) auto _X##_start = std::chrono::steady_clock::now(), _X##_stop = _X##_start
#define TIMER_STOP(_X) _X##_stop = std::chrono::steady_clock::now()
#define TIMER_NSEC(_X) std::chrono::duration_cast<std::chrono::nanoseconds>(_X##_stop - _X##_start).count()
#define TIMER_USEC(_X) std::chrono::duration_cast<std::chrono::microseconds>(_X##_stop - _X##_start).count()
#define TIMER_MSEC(_X) (0.000001*std::chrono::duration_cast<std::chrono::nanoseconds>(_X##_stop - _X##_start).count())
#define TIMER_SEC(_X) (0.000001*std::chrono::duration_cast<std::chrono::microseconds>(_X##_stop - _X##_start).count())
#define TIMER_MIN(_X) std::chrono::duration_cast<std::chrono::minutes>(_X##_stop - _X##_start).count()
#define TIMER_NSEC(_X) \
std::chrono::duration_cast<std::chrono::nanoseconds>(_X##_stop - _X##_start).count()
#define TIMER_USEC(_X) \
std::chrono::duration_cast<std::chrono::microseconds>(_X##_stop - _X##_start).count()
#define TIMER_MSEC(_X) \
(0.000001 * \
std::chrono::duration_cast<std::chrono::nanoseconds>(_X##_stop - _X##_start).count())
#define TIMER_SEC(_X) \
(0.000001 * \
std::chrono::duration_cast<std::chrono::microseconds>(_X##_stop - _X##_start).count())
#define TIMER_MIN(_X) \
std::chrono::duration_cast<std::chrono::minutes>(_X##_stop - _X##_start).count()
#endif // TIMING_UTIL_HPP
+12 -13
View File
@@ -32,7 +32,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <osrm/json_container.hpp>
namespace JSON {
namespace JSON
{
struct XMLToArrayRenderer : mapbox::util::static_visitor<>
{
@@ -66,7 +67,6 @@ struct XMLToArrayRenderer : mapbox::util::static_visitor<>
out.push_back(' ');
out.insert(out.end(), ++(*iterator).first.begin(), (*iterator).first.end());
out.push_back('=');
}
mapbox::util::apply_visitor(XMLToArrayRenderer(out), (*iterator).second);
if (iterator->first.at(0) != '_')
@@ -111,29 +111,28 @@ struct XMLToArrayRenderer : mapbox::util::static_visitor<>
std::vector<char> &out;
};
template<class JSONObject>
inline void xml_render(std::vector<char> &out, const JSONObject &object)
template <class JSONObject> inline void xml_render(std::vector<char> &out, const JSONObject &object)
{
Value value = object;
mapbox::util::apply_visitor(XMLToArrayRenderer(out), value);
}
template<class JSONObject>
inline void gpx_render(std::vector<char> &out, const JSONObject &object)
template <class JSONObject> inline void gpx_render(std::vector<char> &out, const JSONObject &object)
{
// add header
const std::string header {"<?xml version=\"1.0\" encoding=\"UTF-8\"?><gpx creator=\"OSRM Routing Engine\""
" version=\"1.1\" xmlns=\"http://www.topografix.com/GPX/1/1\" xmlns:xsi=\"http:"
"//www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.topogr"
"afix.com/GPX/1/1 gpx.xsd\"><metadata><copyright author=\"Project OSRM\"><lice"
"nse>Data (c) OpenStreetMap contributors (ODbL)</license></copyright></metadat"
"a><rte>"};
const std::string header{
"<?xml version=\"1.0\" encoding=\"UTF-8\"?><gpx creator=\"OSRM Routing Engine\""
" version=\"1.1\" xmlns=\"http://www.topografix.com/GPX/1/1\" xmlns:xsi=\"http:"
"//www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.topogr"
"afix.com/GPX/1/1 gpx.xsd\"><metadata><copyright author=\"Project OSRM\"><lice"
"nse>Data (c) OpenStreetMap contributors (ODbL)</license></copyright></metadat"
"a><rte>"};
out.insert(out.end(), header.begin(), header.end());
xml_render(out, object);
const std::string footer {"</rte></gpx>"};
const std::string footer{"</rte></gpx>"};
out.insert(out.end(), footer.begin(), footer.end());
}
} // namespace JSON