From dfcfcd14dc204e279ba74d600e35db139c3f3392 Mon Sep 17 00:00:00 2001 From: 3eef8a28f26fb2bcc514e6f1938929a1f931762 <116031952+3eef8a28f26fb2bcc514e6f1938929a1f931762@users.noreply.github.com> Date: Thu, 16 Feb 2023 21:49:17 -0500 Subject: [PATCH] Replace if-chain with map --- src/CourseOfferingsScraper.cpp | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/CourseOfferingsScraper.cpp b/src/CourseOfferingsScraper.cpp index 6b8ee65..55c1485 100644 --- a/src/CourseOfferingsScraper.cpp +++ b/src/CourseOfferingsScraper.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include namespace fs = std::filesystem; @@ -16,6 +17,13 @@ struct quatalog_data_t { Json::Value prerequisites; Json::Value list_of_terms; }; +const std::unordered_map attr_to_short_attr { + { "Communication Intensive", "[CI]" }, + { "Writing Intensive", "[WI]" }, + { "HASS Inquiry", "[HInq]" }, + { "Culminating Exp/Capstone", "[CulmExp]" }, + { "PDII Option for Engr Majors", "[PDII]" } +}; using course_handler_t = void(const Json::Value&,const std::string&,quatalog_data_t&,const Json::Value&); void handle_term_dirs(const std::set&,quatalog_data_t&); @@ -322,18 +330,9 @@ void handle_attribute(const std::string& attribute, void handle_term_attribute(const std::string& attribute, Json::Value& attributes) { - // These are the attributes we want to display in the - // course years table - if(attribute == "Communication Intensive") { - attributes.append("[CI]"); - } else if(attribute == "Writing Intensive") { - attributes.append("[WI]"); - } else if(attribute == "HASS Inquiry") { - attributes.append("[HInq]"); - } else if(attribute == "Culminating Exp/Capstone") { - attributes.append("[CulmExp]"); - } else if(attribute == "PDII Option for Engr Majors") { - attributes.append("[PDII]"); + const auto& attr_short_itr = attr_to_short_attr.find(attribute); + if(attr_short_itr != attr_to_short_attr.end()) { + attributes.append(attr_short_itr->second); } }