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

Function argumentsToMatchParameter

include/nodejs/node_osrm_support.hpp:1605–1761  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1603}
1604
1605inline match_parameters_ptr argumentsToMatchParameter(const Napi::CallbackInfo &args,
1606 bool requires_multiple_coordinates)
1607{
1608 match_parameters_ptr params = std::make_unique<osrm::MatchParameters>();
1609 bool has_base_params = argumentsToParameter(args, params, requires_multiple_coordinates);
1610 if (!has_base_params)
1611 return match_parameters_ptr();
1612
1613 Napi::Object obj = args[0].As<Napi::Object>();
1614
1615 if (obj.Has("timestamps"))
1616 {
1617 Napi::Value timestamps = obj.Get("timestamps");
1618 if (timestamps.IsEmpty())
1619 return match_parameters_ptr();
1620
1621 if (!timestamps.IsArray())
1622 {
1623 ThrowError(args.Env(), "Timestamps must be an array of integers (or undefined)");
1624 return match_parameters_ptr();
1625 }
1626
1627 Napi::Array timestamps_array = timestamps.As<Napi::Array>();
1628
1629 if (params->coordinates.size() != timestamps_array.Length())
1630 {
1631 ThrowError(args.Env(),
1632 "Timestamp array must have the same size as the coordinates "
1633 "array");
1634 return match_parameters_ptr();
1635 }
1636
1637 for (uint32_t i = 0; i < timestamps_array.Length(); ++i)
1638 {
1639 Napi::Value timestamp = timestamps_array.Get(i);
1640 if (timestamp.IsEmpty())
1641 return match_parameters_ptr();
1642
1643 if (!timestamp.IsNumber())
1644 {
1645 ThrowError(args.Env(), "Timestamps array items must be numbers");
1646 return match_parameters_ptr();
1647 }
1648 params->timestamps.emplace_back(timestamp.ToNumber().Int64Value());
1649 }
1650 }
1651
1652 if (obj.Has("gaps"))
1653 {
1654 Napi::Value gaps = obj.Get("gaps");
1655 if (gaps.IsEmpty())
1656 return match_parameters_ptr();
1657
1658 if (!gaps.IsString())
1659 {
1660 ThrowError(args.Env(), "Gaps must be a string: [split, ignore]");
1661 return match_parameters_ptr();
1662 }

Callers

nothing calls this directly

Calls 8

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

Tested by

no test coverage detected