2017-05-05 04:23:09 -04:00
|
|
|
#ifndef OSRM_IO_CONFIG_HPP
|
|
|
|
#define OSRM_IO_CONFIG_HPP
|
2017-04-19 02:59:45 -04:00
|
|
|
|
2017-06-16 04:45:24 -04:00
|
|
|
#include "util/exception.hpp"
|
|
|
|
|
|
|
|
#include <array>
|
2017-06-05 02:34:44 -04:00
|
|
|
#include <boost/algorithm/string/predicate.hpp>
|
2017-06-16 04:45:24 -04:00
|
|
|
#include <boost/filesystem.hpp>
|
2017-04-19 02:59:45 -04:00
|
|
|
#include <boost/filesystem/path.hpp>
|
2017-06-16 04:45:24 -04:00
|
|
|
#include <string>
|
2017-04-19 02:59:45 -04:00
|
|
|
|
|
|
|
namespace osrm
|
|
|
|
{
|
|
|
|
namespace storage
|
|
|
|
{
|
|
|
|
struct IOConfig
|
|
|
|
{
|
2017-06-28 11:53:54 -04:00
|
|
|
IOConfig(std::vector<boost::filesystem::path> required_input_files_,
|
|
|
|
std::vector<boost::filesystem::path> optional_input_files_,
|
|
|
|
std::vector<boost::filesystem::path> output_files_)
|
|
|
|
: required_input_files(required_input_files_), optional_input_files(optional_input_files_),
|
|
|
|
output_files(output_files_)
|
2017-06-16 04:45:24 -04:00
|
|
|
{
|
|
|
|
}
|
2017-04-19 02:59:45 -04:00
|
|
|
|
2017-07-07 10:42:07 -04:00
|
|
|
bool IsValid() const;
|
|
|
|
boost::filesystem::path GetPath(const std::string &fileName) const
|
|
|
|
{
|
|
|
|
if (!IsConfigured(fileName, required_input_files) &&
|
|
|
|
!IsConfigured(fileName, optional_input_files) && !IsConfigured(fileName, output_files))
|
|
|
|
{
|
|
|
|
throw util::exception("Tried to access file which is not configured: " + fileName);
|
|
|
|
}
|
|
|
|
|
|
|
|
return {base_path.string() + fileName};
|
|
|
|
}
|
|
|
|
|
|
|
|
boost::filesystem::path base_path;
|
|
|
|
|
|
|
|
protected:
|
2017-06-05 02:34:44 -04:00
|
|
|
// Infer the base path from the path of the .osrm file
|
|
|
|
void UseDefaultOutputNames(const boost::filesystem::path &base)
|
|
|
|
{
|
2017-06-16 04:45:24 -04:00
|
|
|
// potentially strip off the .osrm (or other) extensions for
|
|
|
|
// determining the base path=
|
|
|
|
std::string path = base.string();
|
|
|
|
|
|
|
|
std::array<std::string, 6> known_extensions{
|
|
|
|
{".osm.bz2", ".osm.pbf", ".osm.xml", ".pbf", ".osm", ".osrm"}};
|
|
|
|
for (auto ext : known_extensions)
|
2017-06-05 02:34:44 -04:00
|
|
|
{
|
2017-06-16 04:45:24 -04:00
|
|
|
const auto pos = path.find(ext);
|
|
|
|
if (pos != std::string::npos)
|
|
|
|
{
|
|
|
|
path.replace(pos, ext.size(), "");
|
|
|
|
break;
|
|
|
|
}
|
2017-06-05 02:34:44 -04:00
|
|
|
}
|
|
|
|
|
2017-06-16 04:45:24 -04:00
|
|
|
base_path = {path};
|
2017-06-05 02:34:44 -04:00
|
|
|
}
|
|
|
|
|
2017-06-16 04:45:24 -04:00
|
|
|
private:
|
|
|
|
static bool IsConfigured(const std::string &fileName,
|
|
|
|
const std::vector<boost::filesystem::path> &paths)
|
|
|
|
{
|
|
|
|
for (auto &path : paths)
|
|
|
|
{
|
|
|
|
if (boost::algorithm::ends_with(path.string(), fileName))
|
|
|
|
{
|
2017-06-05 02:34:44 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-16 04:45:24 -04:00
|
|
|
return false;
|
|
|
|
}
|
2017-04-19 02:59:45 -04:00
|
|
|
|
2017-06-16 04:45:24 -04:00
|
|
|
std::vector<boost::filesystem::path> required_input_files;
|
|
|
|
std::vector<boost::filesystem::path> optional_input_files;
|
|
|
|
std::vector<boost::filesystem::path> output_files;
|
2017-04-19 02:59:45 -04:00
|
|
|
};
|
2020-11-26 10:21:39 -05:00
|
|
|
} // namespace storage
|
|
|
|
} // namespace osrm
|
2017-04-19 02:59:45 -04:00
|
|
|
|
|
|
|
#endif
|