diff options
author | Toni Uhlig <Toni.Uhlig@tq-group.com> | 2017-12-01 10:51:06 +0100 |
---|---|---|
committer | Toni Uhlig <Toni.Uhlig@tq-group.com> | 2017-12-01 10:51:06 +0100 |
commit | a41e35bfa12d8afff0477b36e8ebe79ae63b6621 (patch) | |
tree | fbd35e23221f47505a90da211395accf87a92737 /src | |
parent | 91bf72d7da36fe3883fd702d2bf1a74684d6b46a (diff) |
version mapping: unordered_map was the wrong choice, switched to a vector
Diffstat (limited to 'src')
-rw-r--r-- | src/JobQueue.cpp | 3 | ||||
-rw-r--r-- | src/UpdateFactory.cpp | 30 |
2 files changed, 21 insertions, 12 deletions
diff --git a/src/JobQueue.cpp b/src/JobQueue.cpp index 9310844..af9a7e1 100644 --- a/src/JobQueue.cpp +++ b/src/JobQueue.cpp @@ -89,7 +89,8 @@ void WorkerThread::doJob() if (!isEmcVersionLowerThen(uf.getEmcVersion(), uf.getFwVersion())) { m_pQueue->Report(Job::eID_THREAD_MSGERR, wxString::Format(wxT("Job #%d: Version mismatch (%s >= %s)"), - job.m_Arg.jobid, mapEmcVersion(uf.getEmcVersion()), mapEmcVersion(uf.getFwVersion()))); + job.m_Arg.jobid, mapEmcVersion(uf.getEmcVersion()), + mapEmcVersion(uf.getFwVersion())), m_ID); break; } diff --git a/src/UpdateFactory.cpp b/src/UpdateFactory.cpp index d3c8921..539835c 100644 --- a/src/UpdateFactory.cpp +++ b/src/UpdateFactory.cpp @@ -26,11 +26,11 @@ static std::string toHex(const std::string& s, bool upper_case) #endif /* Do not use `const char *` as key type, you'll run into trouble in mapEmcVersion! - * We use an unordered map here, so it is easy to check + * We use a simple vector here, so it is easy to check * if a given version requires an update or not. * Remember to retain the order of all mapped versions! */ -static const std::unordered_map<std::string, const EMCVersion> version_map { +static const std::vector<std::pair<std::string, const EMCVersion>> version_map { { "1.30", EMC_130 }, { "1.31", EMC_131 }, { "1.32", EMC_132 }, { "1.33", EMC_133 }, { "1.34", EMC_134 }, { "1.35", EMC_135 }, { "1.36", EMC_136 }, { "1.37", EMC_137 }, { "1.38", EMC_138 }, { "1.39", EMC_139 }, @@ -45,36 +45,44 @@ static const std::unordered_map<std::string, const EMCVersion> version_map { enum EMCVersion mapEmcVersion(std::string& emc_version) { - try { - return version_map.at(emc_version); - } catch (std::out_of_range) { - return EMC_UNKNOWN; + for (auto& v : version_map) { + if (v.first == emc_version) { + return v.second; + } } + return EMC_UNKNOWN; } std::string mapEmcVersion(EMCVersion ver) { - for (auto& v : version_map) - if (v.second == ver) + for (auto& v : version_map) { + if (v.second == ver) { return v.first; + } + } return "Unknown"; } bool isEmcVersionLowerThen(enum EMCVersion ver, enum EMCVersion check_ver) { + bool v_found = false, c_found = false; size_t i = 0, j = 0; for (auto& v : version_map) { i++; - if (v.second == ver) + if (v.second == ver) { + v_found = true; break; + } } for (auto& v : version_map) { j++; - if (v.second == check_ver) + if (v.second == check_ver) { + c_found = true; break; + } } - return (i > j); + return v_found && c_found && (i < j); } static const std::map<const int, const std::string> error_map = { |