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"
|
|
|
|
|
2017-06-05 02:34:44 -04:00
|
|
|
#include <boost/algorithm/string/predicate.hpp>
|
2024-06-20 15:44:28 -04:00
|
|
|
|
|
|
|
#include <array>
|
|
|
|
#include <filesystem>
|
2017-06-16 04:45:24 -04:00
|
|
|
#include <string>
|
2017-04-19 02:59:45 -04:00
|
|
|
|
2022-12-11 04:10:26 -05:00
|
|
|
namespace osrm::storage
|
2017-04-19 02:59:45 -04:00
|
|
|
{
|
|
|
|
struct IOConfig
|
|
|
|
{
|
2024-06-20 15:44:28 -04:00
|
|
|
IOConfig(std::vector<std::filesystem::path> required_input_files_,
|
|
|
|
std::vector<std::filesystem::path> optional_input_files_,
|
|
|
|
std::vector<std::filesystem::path> output_files_)
|
2022-06-30 09:32:12 -04:00
|
|
|
: required_input_files(std::move(required_input_files_)),
|
|
|
|
optional_input_files(std::move(optional_input_files_)),
|
|
|
|
output_files(std::move(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;
|
2022-08-22 02:32:25 -04:00
|
|
|
std::vector<std::string> GetMissingFiles() const;
|
2024-06-20 15:44:28 -04:00
|
|
|
std::filesystem::path GetPath(const std::string &fileName) const
|
2017-07-07 10:42:07 -04:00
|
|
|
{
|
|
|
|
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};
|
|
|
|
}
|
|
|
|
|
2023-08-04 13:43:37 -04:00
|
|
|
bool IsRequiredConfiguredInput(const std::string &fileName) const
|
|
|
|
{
|
|
|
|
return IsConfigured(fileName, required_input_files);
|
|
|
|
}
|
|
|
|
|
2024-06-20 15:44:28 -04:00
|
|
|
std::filesystem::path base_path;
|
2017-07-07 10:42:07 -04:00
|
|
|
|
|
|
|
protected:
|
2017-06-05 02:34:44 -04:00
|
|
|
// Infer the base path from the path of the .osrm file
|
2024-06-20 15:44:28 -04:00
|
|
|
void UseDefaultOutputNames(const std::filesystem::path &base)
|
2017-06-05 02:34:44 -04:00
|
|
|
{
|
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"}};
|
2022-06-30 09:32:12 -04:00
|
|
|
for (const 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,
|
2024-06-20 15:44:28 -04:00
|
|
|
const std::vector<std::filesystem::path> &paths)
|
2017-06-16 04:45:24 -04:00
|
|
|
{
|
|
|
|
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
|
|
|
|
2024-06-20 15:44:28 -04:00
|
|
|
std::vector<std::filesystem::path> required_input_files;
|
|
|
|
std::vector<std::filesystem::path> optional_input_files;
|
|
|
|
std::vector<std::filesystem::path> output_files;
|
2017-04-19 02:59:45 -04:00
|
|
|
};
|
2022-12-20 12:00:11 -05:00
|
|
|
} // namespace osrm::storage
|
2017-04-19 02:59:45 -04:00
|
|
|
|
|
|
|
#endif
|