Replace if-chain with map

This commit is contained in:
3eef8a28f26fb2bcc514e6f1938929a1f931762 2023-02-16 21:49:17 -05:00
parent 3e83afa523
commit dfcfcd14dc

View file

@ -4,6 +4,7 @@
#include<iostream> #include<iostream>
#include<filesystem> #include<filesystem>
#include<unordered_set> #include<unordered_set>
#include<unordered_map>
#include<json/json.h> #include<json/json.h>
namespace fs = std::filesystem; namespace fs = std::filesystem;
@ -16,6 +17,13 @@ struct quatalog_data_t {
Json::Value prerequisites; Json::Value prerequisites;
Json::Value list_of_terms; Json::Value list_of_terms;
}; };
const std::unordered_map<std::string,std::string> 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&); using course_handler_t = void(const Json::Value&,const std::string&,quatalog_data_t&,const Json::Value&);
void handle_term_dirs(const std::set<fs::directory_entry>&,quatalog_data_t&); void handle_term_dirs(const std::set<fs::directory_entry>&,quatalog_data_t&);
@ -322,18 +330,9 @@ void handle_attribute(const std::string& attribute,
void handle_term_attribute(const std::string& attribute, void handle_term_attribute(const std::string& attribute,
Json::Value& attributes) { Json::Value& attributes) {
// These are the attributes we want to display in the const auto& attr_short_itr = attr_to_short_attr.find(attribute);
// course years table if(attr_short_itr != attr_to_short_attr.end()) {
if(attribute == "Communication Intensive") { attributes.append(attr_short_itr->second);
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]");
} }
} }