diff --git a/src/libs/antares/study/parts/renewable/cluster.cpp b/src/libs/antares/study/parts/renewable/cluster.cpp index a8d65647fb..c2a974d5e9 100644 --- a/src/libs/antares/study/parts/renewable/cluster.cpp +++ b/src/libs/antares/study/parts/renewable/cluster.cpp @@ -97,6 +97,19 @@ void Data::RenewableCluster::copyFrom(const RenewableCluster& cluster) parentArea->forceReload(); } +const std::map < RenewableCluster::RenewableGroup, const char* > groupToName = +{ + {RenewableCluster::thermalSolar, "solar thermal"}, + {RenewableCluster::PVSolar, "solar pv"}, + {RenewableCluster::rooftopSolar, "solar rooftop"}, + {RenewableCluster::windOnShore, "wind onshore"}, + {RenewableCluster::windOffShore,"wind offshore"}, + {RenewableCluster::renewableOther1, "other res 1"}, + {RenewableCluster::renewableOther2, "other res 2"}, + {RenewableCluster::renewableOther3, "other res 3"}, + {RenewableCluster::renewableOther4, "other res 4"} +}; + void Data::RenewableCluster::setGroup(Data::ClusterName newgrp) { if (newgrp.empty()) @@ -108,51 +121,15 @@ void Data::RenewableCluster::setGroup(Data::ClusterName newgrp) pGroup = newgrp; boost::to_lower(newgrp); - if (newgrp == "solar thermal") - { - groupID = thermalSolar; - return; - } - if (newgrp == "solar pv") - { - groupID = PVSolar; - return; - } - if (newgrp == "solar rooftop") - { - groupID = rooftopSolar; - return; - } - if (newgrp == "wind onshore") - { - groupID = windOnShore; - return; - } - if (newgrp == "wind offshore") + for (const auto& [group, name] : groupToName) { - groupID = windOffShore; - return; - } - if (newgrp == "other res 1") - { - groupID = renewableOther1; - return; - } - if (newgrp == "other res 2") - { - groupID = renewableOther2; - return; - } - if (newgrp == "other res 3") - { - groupID = renewableOther3; - return; - } - if (newgrp == "other res 4") - { - groupID = renewableOther4; - return; + if (newgrp == name) + { + groupID = group; + return; + } } + // assigning a default value groupID = renewableOther1; } @@ -198,29 +175,10 @@ bool Data::RenewableCluster::integrityCheck() const char* Data::RenewableCluster::GroupName(enum RenewableGroup grp) { - switch (grp) - { - case windOffShore: - return "Wind offshore"; - case windOnShore: - return "Wind onshore"; - case thermalSolar: - return "Solar thermal"; - case PVSolar: - return "Solar PV"; - case rooftopSolar: - return "Solar rooftop"; - case renewableOther1: - return "Other RES 1"; - case renewableOther2: - return "Other RES 2"; - case renewableOther3: - return "Other RES 3"; - case renewableOther4: - return "Other RES 4"; - case groupMax: - return ""; - } + auto it = groupToName.find(grp); + if (it != groupToName.end()) + return it->second; + return ""; }