* Get the road type for a given label. * @param label the roadtype label. * @param allow_alternate_labels Search in the alternate label lists as well. * @return the roadtype. */
| 263 | * @return the roadtype. |
| 264 | */ |
| 265 | RoadType GetRoadTypeByLabel(RoadTypeLabel label, bool allow_alternate_labels) |
| 266 | { |
| 267 | extern RoadTypeInfo _roadtypes[ROADTYPE_END]; |
| 268 | if (label == 0) return INVALID_ROADTYPE; |
| 269 | |
| 270 | auto it = std::ranges::find(_roadtypes, label, &RoadTypeInfo::label); |
| 271 | if (it == std::end(_roadtypes) && allow_alternate_labels) { |
| 272 | /* Test if any road type defines the label as an alternate. */ |
| 273 | it = std::ranges::find_if(_roadtypes, [label](const RoadTypeInfo &rti) { return rti.alternate_labels.contains(label); }); |
| 274 | } |
| 275 | |
| 276 | if (it != std::end(_roadtypes)) return it->Index(); |
| 277 | |
| 278 | /* No matching label was found, so it is invalid */ |
| 279 | return INVALID_ROADTYPE; |
| 280 | } |
no test coverage detected