mirror of
https://codeberg.org/comaps/comaps
synced 2025-12-20 13:23:59 +00:00
[traffxml] Faster MessageFromXml
Signed-off-by: x7z4w <x7z4w@noreply.codeberg.org>
This commit is contained in:
@@ -3,13 +3,15 @@
|
||||
#include "base/logging.hpp"
|
||||
|
||||
#include <iomanip>
|
||||
#include <regex>
|
||||
#include <unordered_map>
|
||||
|
||||
#include <boost/regex.hpp>
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace traffxml
|
||||
{
|
||||
const std::map<EventType, traffic::SpeedGroup> kEventSpeedGroupMap{
|
||||
const std::unordered_map<EventType, traffic::SpeedGroup> kEventSpeedGroupMap{
|
||||
// TODO Activity*, Authority*, Carpool* (not in enum yet)
|
||||
{EventType::CongestionHeavyTraffic, traffic::SpeedGroup::G4},
|
||||
{EventType::CongestionLongQueue, traffic::SpeedGroup::G0},
|
||||
@@ -54,7 +56,7 @@ const std::map<EventType, traffic::SpeedGroup> kEventSpeedGroupMap{
|
||||
|
||||
// none of the currently define events imply an explicit maxspeed
|
||||
#if 0
|
||||
const std::map<EventType, uint8_t> kEventMaxspeedMap{
|
||||
const std::unordered_map<EventType, uint8_t> kEventMaxspeedMap{
|
||||
// TODO Activity*, Authority*, Carpool* (not in enum yet)
|
||||
// TODO Construction* (not in enum yet)
|
||||
// TODO Environment*, EquipmentStatus*, Hazard*, Incident* (not in enum yet)
|
||||
@@ -63,7 +65,7 @@ const std::map<EventType, uint8_t> kEventMaxspeedMap{
|
||||
};
|
||||
#endif
|
||||
|
||||
const std::map<EventType, uint16_t> kEventDelayMap{
|
||||
const std::unordered_map<EventType, uint16_t> kEventDelayMap{
|
||||
// TODO Activity*, Authority*, Carpool* (not in enum yet)
|
||||
// TODO Construction* (not in enum yet)
|
||||
//{EventType::DelayDelay, }, // mapped to speed group
|
||||
@@ -121,10 +123,10 @@ std::optional<IsoTime> IsoTime::ParseIsoTime(std::string timeString)
|
||||
* 11: :00 (UTC offset, minutes, prefixed with separator)
|
||||
* 12: 00 (UTC offset, minutes, unsigned; blank for Z or if not specified)
|
||||
*/
|
||||
std::regex iso8601Regex("([0-9]{4})-([0-9]{2})-([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2}(\\.[0-9]*)?)(Z|(([+-][0-9]{2})(:?([0-9]{2}))?))?");
|
||||
static boost::regex iso8601Regex("([0-9]{4})-([0-9]{2})-([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2}(\\.[0-9]*)?)(Z|(([+-][0-9]{2})(:?([0-9]{2}))?))?");
|
||||
|
||||
std::smatch iso8601Matcher;
|
||||
if (std::regex_search(timeString, iso8601Matcher, iso8601Regex))
|
||||
boost::smatch iso8601Matcher;
|
||||
if (boost::regex_search(timeString, iso8601Matcher, iso8601Regex))
|
||||
{
|
||||
int offset_h = iso8601Matcher[10].matched ? std::stoi(iso8601Matcher[10]) : 0;
|
||||
int offset_m = iso8601Matcher[12].matched ? std::stoi(iso8601Matcher[12]) : 0;
|
||||
|
||||
@@ -6,11 +6,11 @@
|
||||
#include <cstring>
|
||||
#include <iomanip>
|
||||
#include <optional>
|
||||
#include <regex>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
|
||||
#include <boost/bimap.hpp>
|
||||
#include <boost/regex.hpp>
|
||||
|
||||
#include <pugixml.hpp>
|
||||
|
||||
@@ -504,9 +504,9 @@ bool LatLonFromXml(pugi::xml_node const & node, ms::LatLon & latLon)
|
||||
std::string string;
|
||||
if (StringFromXml(node, string))
|
||||
{
|
||||
std::regex latLonRegex("([+-]?[0-9]*\\.?[0-9]*)\\s+([+-]?[0-9]*\\.?[0-9]*)");
|
||||
std::smatch latLonMatcher;
|
||||
if (std::regex_search(string, latLonMatcher, latLonRegex) && latLonMatcher[1].matched && latLonMatcher[2].matched)
|
||||
static boost::regex latLonRegex("([+-]?[0-9]*\\.?[0-9]*)\\s+([+-]?[0-9]*\\.?[0-9]*)");
|
||||
boost::smatch latLonMatcher;
|
||||
if (boost::regex_search(string, latLonMatcher, latLonRegex) && latLonMatcher[1].matched && latLonMatcher[2].matched)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -689,10 +689,10 @@ std::optional<uint16_t> OptionalDurationFromXml(pugi::xml_attribute const & attr
|
||||
* 1 h
|
||||
* 30 min
|
||||
*/
|
||||
std::regex durationRegex("(([0-9]+):([0-9]{2}))|(([0-9]+) *h)|(([0-9]+) *min)");
|
||||
std::smatch durationMatcher;
|
||||
static boost::regex durationRegex("(([0-9]+):([0-9]{2}))|(([0-9]+) *h)|(([0-9]+) *min)");
|
||||
boost::smatch durationMatcher;
|
||||
|
||||
if (std::regex_search(durationString, durationMatcher, durationRegex))
|
||||
if (boost::regex_search(durationString, durationMatcher, durationRegex))
|
||||
{
|
||||
if (!durationMatcher.str(2).empty() && !durationMatcher.str(3).empty())
|
||||
return std::stoi(durationMatcher[2]) * 60 + std::stoi(durationMatcher[3]);
|
||||
|
||||
Reference in New Issue
Block a user