Line data Source code
1 : #include "data/SUMO/Routes.hpp" 2 : #include "utils/invertMap.hpp" 3 : 4 : using namespace std; 5 : using namespace SUMO; 6 : using namespace utils::stringify; 7 : 8 : // clang-format off 9 : const unordered_map<string, Routes::Flow::DepartPos::Enum> str2departPos = { 10 : {"random" , Routes::Flow::DepartPos::Enum::RANDOM }, 11 : {"free" , Routes::Flow::DepartPos::Enum::FREE }, 12 : {"random_free" , Routes::Flow::DepartPos::Enum::RANDOM_FREE}, 13 : {"base" , Routes::Flow::DepartPos::Enum::BASE }, 14 : {"last" , Routes::Flow::DepartPos::Enum::LAST }, 15 : {"stop" , Routes::Flow::DepartPos::Enum::STOP } 16 : }; 17 : const unordered_map<Routes::Flow::DepartPos::Enum, string> departPos2str = utils::invertMap(str2departPos); 18 : 19 : const unordered_map<string, Routes::Flow::DepartSpeed::Enum> str2departSpeed = { 20 : {"random" , Routes::Flow::DepartSpeed::Enum::RANDOM }, 21 : {"max" , Routes::Flow::DepartSpeed::Enum::MAX }, 22 : {"desired" , Routes::Flow::DepartSpeed::Enum::DESIRED }, 23 : {"speedLimit" , Routes::Flow::DepartSpeed::Enum::SPEED_LIMIT}, 24 : {"last" , Routes::Flow::DepartSpeed::Enum::LAST }, 25 : {"avg" , Routes::Flow::DepartSpeed::Enum::AVG } 26 : }; 27 : const unordered_map<Routes::Flow::DepartSpeed::Enum, string> departSpeed2str = utils::invertMap(str2departSpeed); 28 : // clang-format on 29 : 30 0 : Routes::Flow::DepartPos stringify<Routes::Flow::DepartPos>::fromString(const string &s) { 31 0 : if(str2departPos.count(s)) 32 0 : return {.e = str2departPos.at(s)}; 33 : else 34 0 : return {.f = stringify<float>::fromString(s)}; 35 : } 36 : 37 0 : string stringify<Routes::Flow::DepartPos>::toString(const SUMO::Routes::Flow::DepartPos &t) { 38 0 : if(t.e.has_value()) 39 0 : return departPos2str.at(*t.e); 40 0 : else if(t.f.has_value()) 41 0 : return stringify<float>::toString(*t.f); 42 0 : throw runtime_error("stringify<Routes::Flow::DepartPos>::toString: either f or s must be set, but neither were set."); 43 : } 44 : 45 0 : Routes::Flow::DepartSpeed stringify<Routes::Flow::DepartSpeed>::fromString(const string &s) { 46 0 : if(str2departPos.count(s)) 47 0 : return {.e = str2departSpeed.at(s)}; 48 : else 49 0 : return {.f = stringify<float>::fromString(s)}; 50 : } 51 : 52 0 : string stringify<Routes::Flow::DepartSpeed>::toString(const SUMO::Routes::Flow::DepartSpeed &t) { 53 0 : if(t.e.has_value()) 54 0 : return departSpeed2str.at(*t.e); 55 0 : else if(t.f.has_value()) 56 0 : return stringify<float>::toString(*t.f); 57 0 : throw runtime_error("stringify<Routes::Flow::DepartSpeed>::toString: either f or s must be set, but neither were set."); 58 : }