Skip to content

Commit

Permalink
also have a JSON_PBF_DEFAULT_V2 for non-oneof options (actually lots …
Browse files Browse the repository at this point in the history
…more/most of them, should refactor some), similar to the ranged equivalent
  • Loading branch information
nilsnolde committed Mar 4, 2024
1 parent 0e717b3 commit 2ce6b8b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/sif/dynamiccost.cc
Expand Up @@ -392,8 +392,8 @@ void ParseBaseCostOptions(const rapidjson::Value& json,
JSON_PBF_DEFAULT(co, false, json, "/ignore_oneways", ignore_oneways);
JSON_PBF_DEFAULT(co, false, json, "/ignore_access", ignore_access);
JSON_PBF_DEFAULT(co, false, json, "/ignore_closures", ignore_closures);
JSON_PBF_DEFAULT(co, false, json, "/ignore_non_vehicular_restrictions",
ignore_non_vehicular_restrictions);
JSON_PBF_DEFAULT_V2(co, false, json, "/ignore_non_vehicular_restrictions",
ignore_non_vehicular_restrictions);

// shortest
JSON_PBF_DEFAULT(co, false, json, "/shortest", shortest);
Expand Down
20 changes: 20 additions & 0 deletions valhalla/sif/dynamiccost.h
Expand Up @@ -87,6 +87,26 @@
: def)); \
}

/**
* same as above, but for costing options without pbf's awful oneof
*
* @param costing_options pointer to protobuf costing options object
* @param def the default value which is used when neither json nor pbf is provided
* @param json rapidjson value object which should contain user provided costing options
* @param json_key the json key to use to pull a user provided value out of the json
* @param option_name the name of the option will be set on the costing options object
*/

#define JSON_PBF_DEFAULT_V2(costing_options, def, json, json_key, option_name) \
{ \
costing_options->set_##option_name( \
rapidjson::get<std::remove_cv< \
std::remove_reference<decltype(def)>::type>::type>(json, json_key, \
costing_options->option_name() \
? costing_options->option_name() \
: def)); \
}

using namespace valhalla::midgard;

namespace valhalla {
Expand Down

0 comments on commit 2ce6b8b

Please sign in to comment.