Skip to content

Commit

Permalink
add target escape string check to generator
Browse files Browse the repository at this point in the history
  • Loading branch information
Julian Harbarth authored and felixguendling committed Oct 18, 2021
1 parent 441ef6b commit c3df633
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions modules/routing/src/eval/query_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
#include <fstream>
#include <iostream>
#include <random>
#include <string_view>

#include "boost/algorithm/string.hpp"
#include "boost/date_time/gregorian/gregorian_types.hpp"
#include "boost/date_time/posix_time/posix_time.hpp"
#include "boost/program_options.hpp"

#include "utl/erase.h"
Expand All @@ -30,6 +29,8 @@ using namespace motis::routing;

namespace motis::routing::eval {

constexpr auto const TARGET_ESCAPE = std::string_view{"${target}"};

struct generator_settings : public conf::configuration {
generator_settings() : configuration("Generator Settings") {
param(query_count_, "query_count", "number of queries to generate");
Expand Down Expand Up @@ -250,8 +251,7 @@ std::pair<std::string, std::string> random_station_ids(

std::string replace_target_escape(std::string const& str,
std::string const& target) {
std::string const target_escape = "${target}";
auto const esc_pos = str.find(target_escape);
auto const esc_pos = str.find(TARGET_ESCAPE);
if (esc_pos == std::string::npos) {
return str;
}
Expand All @@ -263,7 +263,7 @@ std::string replace_target_escape(std::string const& str,
std::replace(clean_target.begin(), clean_target.end(), '/', '_');

auto target_str = str;
target_str.replace(esc_pos, target_escape.size(), clean_target);
target_str.replace(esc_pos, TARGET_ESCAPE.size(), clean_target);

return target_str;
}
Expand All @@ -287,6 +287,17 @@ int generate(int argc, char const** argv) {

parser.read_configuration_file();

bool fns_contain_target_esc =
(generator_opt.target_file_fwd_.find(TARGET_ESCAPE) !=
std::string::npos &&
generator_opt.target_file_bwd_.find(TARGET_ESCAPE) != std::string::npos);

if (generator_opt.targets_.size() > 1 && !fns_contain_target_esc) {
std::cout << "Multiple targets specified, but not every filename contains "
"target escape sequence \"${target}\"\n";
return 1;
}

std::cout << "\n\tQuery Generator\n\n";
parser.print_unrecognized(std::cout);
parser.print_used(std::cout);
Expand Down

0 comments on commit c3df633

Please # to comment.