7 std::vector<std::string> matchSingleRegex(
const std::regex& regex,
const std::vector<std::string>& toMatch) {
8 std::vector<std::string> matches;
9 for (
const auto& str : toMatch) {
10 if (std::regex_match(str, regex)) {
11 matches.push_back(str);
17 template <
typename RegistryT>
18 std::vector<std::string> matchValidators(
const Regexes& regexes,
const RegistryT& registry) {
19 auto getKeys = [](
auto& map) {
return utils::transform(map, [](
auto elem) {
return elem.first; }); };
20 auto toMatch = getKeys(registry);
21 if (regexes.empty()) {
24 auto matches =
utils::concatenate(regexes, [&toMatch](
auto& regex) {
return matchSingleRegex(regex, toMatch); });
25 std::sort(matches.begin(), matches.end());
26 auto eraseIt = std::unique(matches.begin(), matches.end());
27 matches.erase(eraseIt, matches.end());
31 template <
typename Val
idatorT>
32 ValidatorsWithName<ValidatorT> createValidators(
33 const Regexes& regexes,
const std::map<std::string, ValidatorFactory::CreationFcn<ValidatorT>>& registry) {
34 auto matches = matchValidators(regexes, registry);
36 return std::make_pair(match, std::unique_ptr<ValidatorT>(registry.at(match)()));
43 return validatorFactory;
std::map< std::string, CreationFcn< TrafficRuleValidator > > trafficRuleValidatorRegistry_
std::map< std::string, CreationFcn< RoutingGraphValidator > > routingGraphValidatorRegistry_
ValidatorsWithName< MapValidator > createMapValidators(const Regexes ®exes)
std::map< std::string, CreationFcn< MapValidator > > mapValidatorRegistry_
auto transform(Iterator begin, Iterator end, const Func f)
ValidatorsWithName< RoutingGraphValidator > createRoutingGraphValidators(const Regexes ®exes)
void registerMapValidator(const std::string &name, const CreationFcn< MapValidator > &creator)
std::function< ValidatorT *()> CreationFcn
auto concatenate(ContainerT &&c)
ValidatorsWithName< TrafficRuleValidator > createTrafficRuleValidators(const Regexes ®exes)
std::vector< std::regex > Regexes
void registerTrafficRuleValidator(const std::string &name, const CreationFcn< TrafficRuleValidator > &creator)
std::vector< std::string > availableValidators(const Regexes ®exes={})
returns all available parsers as vector
void registerRoutingGraphValidator(const std::string &name, const CreationFcn< RoutingGraphValidator > &creator)
std::vector< ValidatorWithName< ValidatorT > > ValidatorsWithName
static ValidatorFactory & instance()