MCPcopy Create free account
hub / github.com/Project-OSRM/osrm-backend / argumentsToTripParameter

Function argumentsToTripParameter

include/nodejs/node_osrm_support.hpp:1511–1603  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1509}
1510
1511inline trip_parameters_ptr argumentsToTripParameter(const Napi::CallbackInfo &args,
1512 bool requires_multiple_coordinates)
1513{
1514 trip_parameters_ptr params = std::make_unique<osrm::TripParameters>();
1515 bool has_base_params = argumentsToParameter(args, params, requires_multiple_coordinates);
1516 if (!has_base_params)
1517 return trip_parameters_ptr();
1518
1519 Napi::Object obj = args[0].As<Napi::Object>();
1520
1521 bool parsedSuccessfully = parseCommonParameters(obj, params);
1522 if (!parsedSuccessfully)
1523 {
1524 return trip_parameters_ptr();
1525 }
1526
1527 if (obj.Has("roundtrip"))
1528 {
1529 auto roundtrip = obj.Get("roundtrip");
1530 if (roundtrip.IsEmpty())
1531 return trip_parameters_ptr();
1532
1533 if (roundtrip.IsBoolean())
1534 {
1535 params->roundtrip = roundtrip.ToBoolean().Value();
1536 }
1537 else
1538 {
1539 ThrowError(args.Env(), "'roundtrip' param must be a boolean");
1540 return trip_parameters_ptr();
1541 }
1542 }
1543
1544 if (obj.Has("source"))
1545 {
1546 Napi::Value source = obj.Get("source");
1547 if (source.IsEmpty())
1548 return trip_parameters_ptr();
1549
1550 if (!source.IsString())
1551 {
1552 ThrowError(args.Env(), "Source must be a string: [any, first]");
1553 return trip_parameters_ptr();
1554 }
1555
1556 std::string source_str = source.ToString().Utf8Value();
1557
1558 if (source_str == "first")
1559 {
1560 params->source = osrm::TripParameters::SourceType::First;
1561 }
1562 else if (source_str == "any")
1563 {
1564 params->source = osrm::TripParameters::SourceType::Any;
1565 }
1566 else
1567 {
1568 ThrowError(args.Env(), "'source' param must be one of [any, first]");

Callers

nothing calls this directly

Calls 6

argumentsToParameterFunction · 0.85
parseCommonParametersFunction · 0.85
ThrowErrorFunction · 0.85
IsEmptyMethod · 0.80
ToStringMethod · 0.80
GetMethod · 0.45

Tested by

no test coverage detected