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

Function parseCommonParameters

include/nodejs/node_osrm_support.hpp:868–1026  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

866
867template <typename ParamType>
868inline bool parseCommonParameters(const Napi::Object &obj, ParamType &params)
869{
870 if (obj.Has("steps"))
871 {
872 auto steps = obj.Get("steps");
873 if (steps.IsEmpty())
874 return false;
875
876 if (steps.IsBoolean())
877 {
878 params->steps = steps.ToBoolean().Value();
879 }
880 else
881 {
882 ThrowError(obj.Env(), "'steps' param must be a boolean");
883 return false;
884 }
885 }
886
887 if (obj.Has("annotations"))
888 {
889 auto annotations = obj.Get("annotations");
890 if (annotations.IsEmpty())
891 return false;
892
893 if (annotations.IsBoolean())
894 {
895 params->annotations = annotations.ToBoolean().Value();
896 params->annotations_type = params->annotations
897 ? osrm::RouteParameters::AnnotationsType::All
898 : osrm::RouteParameters::AnnotationsType::None;
899 }
900 else if (annotations.IsArray())
901 {
902 Napi::Array annotations_array = annotations.As<Napi::Array>();
903 for (std::size_t i = 0; i < annotations_array.Length(); i++)
904 {
905 std::string annotations_str = annotations_array.Get(i).ToString().Utf8Value();
906
907 if (annotations_str == "duration")
908 {
909 params->annotations_type =
910 params->annotations_type | osrm::RouteParameters::AnnotationsType::Duration;
911 }
912 else if (annotations_str == "nodes")
913 {
914 params->annotations_type =
915 params->annotations_type | osrm::RouteParameters::AnnotationsType::Nodes;
916 }
917 else if (annotations_str == "distance")
918 {
919 params->annotations_type =
920 params->annotations_type | osrm::RouteParameters::AnnotationsType::Distance;
921 }
922 else if (annotations_str == "weight")
923 {
924 params->annotations_type =
925 params->annotations_type | osrm::RouteParameters::AnnotationsType::Weight;

Callers 3

argumentsToTripParameterFunction · 0.85

Calls 4

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

Tested by

no test coverage detected