Throw an error for invalid classes
This commit is contained in:
parent
6339395cba
commit
c6be2e768a
@ -102,7 +102,11 @@ template <template <typename A> class FacadeT, typename AlgorithmT> class DataFa
|
|||||||
for (const auto &name : params.avoid)
|
for (const auto &name : params.avoid)
|
||||||
{
|
{
|
||||||
auto class_mask_iter = name_to_class.find(name);
|
auto class_mask_iter = name_to_class.find(name);
|
||||||
if (class_mask_iter != name_to_class.end())
|
if (class_mask_iter == name_to_class.end())
|
||||||
|
{
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
mask |= class_mask_iter->second;
|
mask |= class_mask_iter->second;
|
||||||
}
|
}
|
||||||
|
@ -53,6 +53,7 @@ class ScriptingEnvironment
|
|||||||
virtual const ProfileProperties &GetProfileProperties() = 0;
|
virtual const ProfileProperties &GetProfileProperties() = 0;
|
||||||
|
|
||||||
virtual std::vector<std::vector<std::string>> GetAvoidableClasses() = 0;
|
virtual std::vector<std::vector<std::string>> GetAvoidableClasses() = 0;
|
||||||
|
virtual std::vector<std::string> GetClassNames() = 0;
|
||||||
virtual std::vector<std::string> GetNameSuffixList() = 0;
|
virtual std::vector<std::string> GetNameSuffixList() = 0;
|
||||||
virtual std::vector<std::string> GetRestrictions() = 0;
|
virtual std::vector<std::string> GetRestrictions() = 0;
|
||||||
virtual void ProcessTurn(ExtractionTurn &turn) = 0;
|
virtual void ProcessTurn(ExtractionTurn &turn) = 0;
|
||||||
|
@ -60,6 +60,7 @@ class Sol2ScriptingEnvironment final : public ScriptingEnvironment
|
|||||||
|
|
||||||
std::vector<std::vector<std::string>> GetAvoidableClasses() override;
|
std::vector<std::vector<std::string>> GetAvoidableClasses() override;
|
||||||
std::vector<std::string> GetNameSuffixList() override;
|
std::vector<std::string> GetNameSuffixList() override;
|
||||||
|
std::vector<std::string> GetClassNames() override;
|
||||||
std::vector<std::string> GetRestrictions() override;
|
std::vector<std::string> GetRestrictions() override;
|
||||||
void ProcessTurn(ExtractionTurn &turn) override;
|
void ProcessTurn(ExtractionTurn &turn) override;
|
||||||
void ProcessSegment(ExtractionSegment &segment) override;
|
void ProcessSegment(ExtractionSegment &segment) override;
|
||||||
|
@ -100,11 +100,15 @@ function setup()
|
|||||||
'vehicle'
|
'vehicle'
|
||||||
},
|
},
|
||||||
|
|
||||||
|
classes = Sequence {
|
||||||
|
'toll', 'motorway', 'ferry', 'restricted'
|
||||||
|
},
|
||||||
|
|
||||||
-- classes to support for avoid flags
|
-- classes to support for avoid flags
|
||||||
avoidable = Sequence {
|
avoidable = Sequence {
|
||||||
Set {"toll"},
|
Set {'toll'},
|
||||||
Set {"motorway"},
|
Set {'motorway'},
|
||||||
Set {"ferry"}
|
Set {'ferry'}
|
||||||
},
|
},
|
||||||
|
|
||||||
avoid = Set {
|
avoid = Set {
|
||||||
|
@ -68,9 +68,43 @@ namespace extractor
|
|||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
// Converts the class name map into a fixed mapping of index to name
|
// Converts the class name map into a fixed mapping of index to name
|
||||||
void SetClassNames(const ExtractorCallbacks::ClassesMap &classes_map,
|
void SetClassNames(const std::vector<std::string> &class_names,
|
||||||
|
ExtractorCallbacks::ClassesMap &classes_map,
|
||||||
ProfileProperties &profile_properties)
|
ProfileProperties &profile_properties)
|
||||||
{
|
{
|
||||||
|
// if we get a list of class names we can validate if we set invalid classes
|
||||||
|
// and add classes that were never reference
|
||||||
|
if (!class_names.empty())
|
||||||
|
{
|
||||||
|
// add class names that were never used explicitly on a way
|
||||||
|
// this makes sure we can correctly validate unkown class names later
|
||||||
|
for (const auto &name : class_names)
|
||||||
|
{
|
||||||
|
auto iter = classes_map.find(name);
|
||||||
|
if (iter == classes_map.end())
|
||||||
|
{
|
||||||
|
auto index = classes_map.size();
|
||||||
|
if (index > MAX_CLASS_INDEX)
|
||||||
|
{
|
||||||
|
throw util::exception("Maximum number of classes if " +
|
||||||
|
std::to_string(MAX_CLASS_INDEX + 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
classes_map[name] = getClassData(index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// check if class names are only from the list supplied by the user
|
||||||
|
for (const auto &pair : classes_map)
|
||||||
|
{
|
||||||
|
auto iter = std::find(class_names.begin(), class_names.end(), pair.first);
|
||||||
|
if (iter == class_names.end())
|
||||||
|
{
|
||||||
|
throw util::exception("Profile used unknown class name: " + pair.first);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (const auto &pair : classes_map)
|
for (const auto &pair : classes_map)
|
||||||
{
|
{
|
||||||
auto range = getClassIndexes(pair.second);
|
auto range = getClassIndexes(pair.second);
|
||||||
@ -379,7 +413,7 @@ Extractor::ParseOSMData(ScriptingEnvironment &scripting_environment,
|
|||||||
config.GetPath(".osrm.names").string());
|
config.GetPath(".osrm.names").string());
|
||||||
|
|
||||||
auto profile_properties = scripting_environment.GetProfileProperties();
|
auto profile_properties = scripting_environment.GetProfileProperties();
|
||||||
SetClassNames(classes_map, profile_properties);
|
SetClassNames(scripting_environment.GetClassNames(), classes_map, profile_properties);
|
||||||
auto avoidable_classes = scripting_environment.GetAvoidableClasses();
|
auto avoidable_classes = scripting_environment.GetAvoidableClasses();
|
||||||
SetAvoidableClasses(classes_map, avoidable_classes, profile_properties);
|
SetAvoidableClasses(classes_map, avoidable_classes, profile_properties);
|
||||||
files::writeProfileProperties(config.GetPath(".osrm.properties").string(), profile_properties);
|
files::writeProfileProperties(config.GetPath(".osrm.properties").string(), profile_properties);
|
||||||
|
@ -739,6 +739,18 @@ std::vector<std::vector<std::string>> Sol2ScriptingEnvironment::GetAvoidableClas
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<std::string> Sol2ScriptingEnvironment::GetClassNames()
|
||||||
|
{
|
||||||
|
auto &context = GetSol2Context();
|
||||||
|
switch (context.api_version)
|
||||||
|
{
|
||||||
|
case 2:
|
||||||
|
return Sol2ScriptingEnvironment::GetStringListFromTable("classes");
|
||||||
|
default:
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<std::string> Sol2ScriptingEnvironment::GetNameSuffixList()
|
std::vector<std::string> Sol2ScriptingEnvironment::GetNameSuffixList()
|
||||||
{
|
{
|
||||||
auto &context = GetSol2Context();
|
auto &context = GetSol2Context();
|
||||||
|
@ -28,6 +28,7 @@ class MockScriptingEnvironment : public extractor::ScriptingEnvironment
|
|||||||
|
|
||||||
std::vector<std::string> GetNameSuffixList() override final { return {}; }
|
std::vector<std::string> GetNameSuffixList() override final { return {}; }
|
||||||
std::vector<std::vector<std::string>> GetAvoidableClasses() override final { return {}; };
|
std::vector<std::vector<std::string>> GetAvoidableClasses() override final { return {}; };
|
||||||
|
std::vector<std::string> GetClassNames() override { return {}; };
|
||||||
|
|
||||||
std::vector<std::string> GetRestrictions() override final { return {}; }
|
std::vector<std::string> GetRestrictions() override final { return {}; }
|
||||||
void ProcessTurn(extractor::ExtractionTurn &) override final {}
|
void ProcessTurn(extractor::ExtractionTurn &) override final {}
|
||||||
|
Loading…
Reference in New Issue
Block a user