Create public facing libraries for extractor, contractor and datastore

New libraries libosrm_extract, libosrm_contract, libosrm_store
This commit is contained in:
Patrick Niklaus
2016-01-07 19:19:55 +01:00
parent b36145e3c4
commit 439eb9da3d
68 changed files with 3266 additions and 3104 deletions
+71
View File
@@ -0,0 +1,71 @@
/*
Copyright (c) 2016, Project OSRM contributors
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef COORDINATE_HPP_
#define COORDINATE_HPP_
#include <iosfwd> //for std::ostream
#include <string>
#include <type_traits>
namespace osrm
{
constexpr const double COORDINATE_PRECISION = 1000000.0;
namespace util
{
struct FixedPointCoordinate
{
int lat;
int lon;
FixedPointCoordinate();
FixedPointCoordinate(int lat, int lon);
template <class T>
FixedPointCoordinate(const T &coordinate)
: lat(coordinate.lat), lon(coordinate.lon)
{
static_assert(std::is_same<decltype(lat), decltype(coordinate.lat)>::value,
"coordinate types incompatible");
static_assert(std::is_same<decltype(lon), decltype(coordinate.lon)>::value,
"coordinate types incompatible");
}
bool IsValid() const;
bool operator==(const FixedPointCoordinate &other) const;
friend std::ostream &operator<<(std::ostream &out, const FixedPointCoordinate &coordinate);
};
std::ostream &operator<<(std::ostream &out, const FixedPointCoordinate &coordinate);
}
}
#endif /* COORDINATE_HPP_ */
-264
View File
@@ -1,264 +0,0 @@
#ifndef DATASTORE_OPTIONS_HPP
#define DATASTORE_OPTIONS_HPP
#include "util/version.hpp"
#include "util/ini_file.hpp"
#include "util/osrm_exception.hpp"
#include "util/simple_logger.hpp"
#include <boost/any.hpp>
#include <boost/filesystem.hpp>
#include <boost/program_options.hpp>
#include <string>
#include <unordered_map>
namespace osrm
{
namespace util
{
// generate boost::program_options object for the routing part
bool GenerateDataStoreOptions(const int argc,
const char *argv[],
std::unordered_map<std::string, boost::filesystem::path> &paths)
{
// declare a group of options that will be allowed only on command line
boost::program_options::options_description generic_options("Options");
generic_options.add_options()("version,v", "Show version")("help,h", "Show this help message")(
"springclean,s", "Remove all regions in shared memory")(
"config,c", boost::program_options::value<boost::filesystem::path>(&paths["config"])
->default_value("server.ini"),
"Path to a configuration file");
// declare a group of options that will be allowed both on command line
// as well as in a config file
boost::program_options::options_description config_options("Configuration");
config_options.add_options()(
"hsgrdata", boost::program_options::value<boost::filesystem::path>(&paths["hsgrdata"]),
".hsgr file")("nodesdata",
boost::program_options::value<boost::filesystem::path>(&paths["nodesdata"]),
".nodes file")(
"edgesdata", boost::program_options::value<boost::filesystem::path>(&paths["edgesdata"]),
".edges file")("geometry",
boost::program_options::value<boost::filesystem::path>(&paths["geometry"]),
".geometry file")(
"ramindex", boost::program_options::value<boost::filesystem::path>(&paths["ramindex"]),
".ramIndex file")(
"fileindex", boost::program_options::value<boost::filesystem::path>(&paths["fileindex"]),
".fileIndex file")("core",
boost::program_options::value<boost::filesystem::path>(&paths["core"]),
".core file")(
"namesdata", boost::program_options::value<boost::filesystem::path>(&paths["namesdata"]),
".names file")("timestamp",
boost::program_options::value<boost::filesystem::path>(&paths["timestamp"]),
".timestamp file");
// hidden options, will be allowed both on command line and in config
// file, but will not be shown to the user
boost::program_options::options_description hidden_options("Hidden options");
hidden_options.add_options()(
"base,b", boost::program_options::value<boost::filesystem::path>(&paths["base"]),
"base path to .osrm file");
// positional option
boost::program_options::positional_options_description positional_options;
positional_options.add("base", 1);
// combine above options for parsing
boost::program_options::options_description cmdline_options;
cmdline_options.add(generic_options).add(config_options).add(hidden_options);
boost::program_options::options_description config_file_options;
config_file_options.add(config_options).add(hidden_options);
boost::program_options::options_description visible_options(
boost::filesystem::basename(argv[0]) + " [<options>] <configuration>");
visible_options.add(generic_options).add(config_options);
// parse command line options
boost::program_options::variables_map option_variables;
boost::program_options::store(boost::program_options::command_line_parser(argc, argv)
.options(cmdline_options)
.positional(positional_options)
.run(),
option_variables);
if (option_variables.count("version"))
{
SimpleLogger().Write() << OSRM_VERSION;
return false;
}
if (option_variables.count("help"))
{
SimpleLogger().Write() << visible_options;
return false;
}
boost::program_options::notify(option_variables);
const bool parameter_present =
(paths.find("hsgrdata") != paths.end() &&
!paths.find("hsgrdata")->second.string().empty()) ||
(paths.find("nodesdata") != paths.end() &&
!paths.find("nodesdata")->second.string().empty()) ||
(paths.find("edgesdata") != paths.end() &&
!paths.find("edgesdata")->second.string().empty()) ||
(paths.find("geometry") != paths.end() &&
!paths.find("geometry")->second.string().empty()) ||
(paths.find("ramindex") != paths.end() &&
!paths.find("ramindex")->second.string().empty()) ||
(paths.find("fileindex") != paths.end() &&
!paths.find("fileindex")->second.string().empty()) ||
(paths.find("core") != paths.end() && !paths.find("core")->second.string().empty()) ||
(paths.find("timestamp") != paths.end() &&
!paths.find("timestamp")->second.string().empty());
if (parameter_present)
{
if ((paths.find("config") != paths.end() &&
boost::filesystem::is_regular_file(paths.find("config")->second)) ||
option_variables.count("base"))
{
SimpleLogger().Write(logWARNING) << "conflicting parameters";
SimpleLogger().Write() << visible_options;
return false;
}
}
// parse config file
auto path_iterator = paths.find("config");
if (path_iterator != paths.end() && boost::filesystem::is_regular_file(path_iterator->second) &&
!option_variables.count("base"))
{
SimpleLogger().Write() << "Reading options from: " << path_iterator->second.string();
std::string ini_file_contents = read_file_lower_content(path_iterator->second);
std::stringstream config_stream(ini_file_contents);
boost::program_options::store(parse_config_file(config_stream, config_file_options),
option_variables);
boost::program_options::notify(option_variables);
}
else if (option_variables.count("base"))
{
path_iterator = paths.find("base");
BOOST_ASSERT(paths.end() != path_iterator);
std::string base_string = path_iterator->second.string();
path_iterator = paths.find("hsgrdata");
if (path_iterator != paths.end())
{
path_iterator->second = base_string + ".hsgr";
}
path_iterator = paths.find("nodesdata");
if (path_iterator != paths.end())
{
path_iterator->second = base_string + ".nodes";
}
path_iterator = paths.find("edgesdata");
if (path_iterator != paths.end())
{
path_iterator->second = base_string + ".edges";
}
path_iterator = paths.find("geometry");
if (path_iterator != paths.end())
{
path_iterator->second = base_string + ".geometry";
}
path_iterator = paths.find("ramindex");
if (path_iterator != paths.end())
{
path_iterator->second = base_string + ".ramIndex";
}
path_iterator = paths.find("fileindex");
if (path_iterator != paths.end())
{
path_iterator->second = base_string + ".fileIndex";
}
path_iterator = paths.find("core");
if (path_iterator != paths.end())
{
path_iterator->second = base_string + ".core";
}
path_iterator = paths.find("namesdata");
if (path_iterator != paths.end())
{
path_iterator->second = base_string + ".names";
}
path_iterator = paths.find("timestamp");
if (path_iterator != paths.end())
{
path_iterator->second = base_string + ".timestamp";
}
}
path_iterator = paths.find("hsgrdata");
if (path_iterator == paths.end() || path_iterator->second.string().empty() ||
!boost::filesystem::is_regular_file(path_iterator->second))
{
throw exception("valid .hsgr file must be specified");
}
path_iterator = paths.find("nodesdata");
if (path_iterator == paths.end() || path_iterator->second.string().empty() ||
!boost::filesystem::is_regular_file(path_iterator->second))
{
throw exception("valid .nodes file must be specified");
}
path_iterator = paths.find("edgesdata");
if (path_iterator == paths.end() || path_iterator->second.string().empty() ||
!boost::filesystem::is_regular_file(path_iterator->second))
{
throw exception("valid .edges file must be specified");
}
path_iterator = paths.find("geometry");
if (path_iterator == paths.end() || path_iterator->second.string().empty() ||
!boost::filesystem::is_regular_file(path_iterator->second))
{
throw exception("valid .geometry file must be specified");
}
path_iterator = paths.find("ramindex");
if (path_iterator == paths.end() || path_iterator->second.string().empty() ||
!boost::filesystem::is_regular_file(path_iterator->second))
{
throw exception("valid .ramindex file must be specified");
}
path_iterator = paths.find("fileindex");
if (path_iterator == paths.end() || path_iterator->second.string().empty() ||
!boost::filesystem::is_regular_file(path_iterator->second))
{
throw exception("valid .fileindex file must be specified");
}
path_iterator = paths.find("namesdata");
if (path_iterator == paths.end() || path_iterator->second.string().empty() ||
!boost::filesystem::is_regular_file(path_iterator->second))
{
throw exception("valid .names file must be specified");
}
path_iterator = paths.find("timestamp");
if (path_iterator == paths.end() || path_iterator->second.string().empty() ||
!boost::filesystem::is_regular_file(path_iterator->second))
{
throw exception("valid .timestamp file must be specified");
}
return true;
}
}
}
#endif /* DATASTORE_OPTIONS_HPP */
+1 -1
View File
@@ -1,7 +1,7 @@
#ifndef DEBUG_GEOMETRY_H
#define DEBUG_GEOMETRY_H
#include "contractor/contractor_options.hpp"
#include "contractor/contractor_config.hpp"
#include "extractor/query_node.hpp"
#ifndef DEBUG_GEOMETRY
+1 -1
View File
@@ -17,7 +17,7 @@ class FingerPrint
const boost::uuids::uuid &GetFingerPrint() const;
bool IsMagicNumberOK(const FingerPrint &other) const;
bool TestGraphUtil(const FingerPrint &other) const;
bool TestPrepare(const FingerPrint &other) const;
bool TestContractor(const FingerPrint &other) const;
bool TestRTree(const FingerPrint &other) const;
bool TestQueryObjects(const FingerPrint &other) const;
+1 -1
View File
@@ -62,7 +62,7 @@ bool FingerPrint::TestGraphUtil(const FingerPrint &other) const
return std::equal(md5_graph, md5_graph + 32, other.md5_graph);
}
bool FingerPrint::TestPrepare(const FingerPrint &other) const
bool FingerPrint::TestContractor(const FingerPrint &other) const
{
if (!IsMagicNumberOK(other))
{
+2 -2
View File
@@ -39,7 +39,7 @@ unsigned loadRestrictionsFromFile(std::istream &input_stream,
FingerPrint fingerprint_loaded;
unsigned number_of_usable_restrictions = 0;
input_stream.read((char *)&fingerprint_loaded, sizeof(FingerPrint));
if (!fingerprint_loaded.TestPrepare(fingerprint_valid))
if (!fingerprint_loaded.TestContractor(fingerprint_valid))
{
SimpleLogger().Write(logWARNING) << ".restrictions was prepared with different build.\n"
"Reprocess to get rid of this warning.";
@@ -71,7 +71,7 @@ NodeID loadNodesFromFile(std::istream &input_stream,
FingerPrint fingerprint_loaded;
input_stream.read(reinterpret_cast<char *>(&fingerprint_loaded), sizeof(FingerPrint));
if (!fingerprint_loaded.TestPrepare(fingerprint_valid))
if (!fingerprint_loaded.TestContractor(fingerprint_valid))
{
SimpleLogger().Write(logWARNING) << ".osrm was prepared with different build.\n"
"Reprocess to get rid of this warning.";
+1 -1
View File
@@ -33,7 +33,7 @@ inline bool readAndCheckFingerprint(std::istream &stream)
stream.read(reinterpret_cast<char *>(&fingerprint), sizeof(fingerprint));
// compare the compilation state stored in the fingerprint
return static_cast<bool>(stream) && valid.IsMagicNumberOK(fingerprint) &&
valid.TestPrepare(fingerprint) && valid.TestGraphUtil(fingerprint) &&
valid.TestContractor(fingerprint) && valid.TestGraphUtil(fingerprint) &&
valid.TestRTree(fingerprint) && valid.TestQueryObjects(fingerprint);
}
+102
View File
@@ -0,0 +1,102 @@
/*
Copyright (c) 2016, Project OSRM contributors
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
// based on
// https://svn.apache.org/repos/asf/mesos/tags/release-0.9.0-incubating-RC0/src/common/json.hpp
#ifndef JSON_CONTAINER_HPP
#define JSON_CONTAINER_HPP
#include <variant/variant.hpp>
#include <iostream>
#include <vector>
#include <string>
#include <unordered_map>
namespace osrm
{
namespace util
{
namespace json
{
struct Object;
struct Array;
struct String
{
String() {}
String(const char *value) : value(value) {}
String(std::string value) : value(std::move(value)) {}
std::string value;
};
struct Number
{
Number() {}
Number(double value) : value(static_cast<double>(value)) {}
double value;
};
struct True
{
};
struct False
{
};
struct Null
{
};
using Value = mapbox::util::variant<String,
Number,
mapbox::util::recursive_wrapper<Object>,
mapbox::util::recursive_wrapper<Array>,
True,
False,
Null>;
struct Object
{
std::unordered_map<std::string, Value> values;
};
struct Array
{
std::vector<Value> values;
};
} // namespace JSON
} // namespace util
} // namespace osrm
#endif // JSON_CONTAINER_HPP
-1
View File
@@ -2,7 +2,6 @@
#define RANGE_TABLE_HPP
#include "util/integer_range.hpp"
#include "datastore/shared_memory_factory.hpp"
#include "util/shared_memory_vector_wrapper.hpp"
#include <fstream>
-1
View File
@@ -4,7 +4,6 @@
#include "util/deallocating_vector.hpp"
#include "util/hilbert_value.hpp"
#include "util/rectangle.hpp"
#include "datastore/shared_memory_factory.hpp"
#include "util/shared_memory_vector_wrapper.hpp"
#include "util/bearing.hpp"
+46
View File
@@ -0,0 +1,46 @@
#ifndef STRONG_TYPEDEF_HPP
#define STRONG_TYPEDEF_HPP
#include <type_traits>
#include <functional>
namespace osrm
{
/* Creates strongly typed wrappers around scalar types.
* Useful for stopping accidental assignment of lats to lons,
* etc. Also clarifies what this random "int" value is
* being used for.
*/
#define OSRM_STRONG_TYPEDEF(From, To) \
class To final \
{ \
static_assert(std::is_arithmetic<From>(), ""); \
From x; \
\
public: \
To() = default; \
explicit To(const From x_) : x(x_) {} \
explicit operator From &() { return x; } \
explicit operator const From &() const { return x; } \
bool operator<(const To &z_) const { return x < static_cast<const From>(z_); } \
bool operator>(const To &z_) const { return x > static_cast<const From>(z_); } \
bool operator<=(const To &z_) const { return x <= static_cast<const From>(z_); } \
bool operator>=(const To &z_) const { return x >= static_cast<const From>(z_); } \
bool operator==(const To &z_) const { return x == static_cast<const From>(z_); } \
bool operator!=(const To &z_) const { return x != static_cast<const From>(z_); } \
}; \
inline From To##_to_##From(To to) { return static_cast<From>(to); } \
namespace std \
{ \
template <> struct hash<To> \
{ \
std::size_t operator()(const To &k) const \
{ \
return std::hash<From>()(static_cast<const From>(k)); \
} \
}; \
}
}
#endif // OSRM_STRONG_TYPEDEF_HPP
+1 -1
View File
@@ -1,7 +1,7 @@
#ifndef TYPEDEFS_H
#define TYPEDEFS_H
#include "osrm/strong_typedef.hpp"
#include "util/strong_typedef.hpp"
#include <limits>
#include <cstddef>