Remove usage of flat_map for enum lookup

This was a common pattern a few years ago that popped up quite a bit.
It's not very efficient because it constructs the map every loop, and
requires larger binaries than a simpler if/else lookup table.

Transform into the existing pattern used elsewhere.

Tested: WIP

Change-Id: Iafaae412b34a6dcf3b47307b196cb2b26c4cb1a0
Signed-off-by: Ed Tanous <edtanous@google.com>
diff --git a/redfish-core/lib/systems.hpp b/redfish-core/lib/systems.hpp
index 51c5c9c..70f8870 100644
--- a/redfish-core/lib/systems.hpp
+++ b/redfish-core/lib/systems.hpp
@@ -20,6 +20,7 @@
 #include "app.hpp"
 #include "dbus_singleton.hpp"
 #include "dbus_utility.hpp"
+#include "generated/enums/computer_system.hpp"
 #include "health.hpp"
 #include "hypervisor_system.hpp"
 #include "led.hpp"
@@ -1347,6 +1348,30 @@
         std::variant<uint32_t>(retryAttempts));
 }
 
+inline computer_system::PowerRestorePolicyTypes
+    redfishPowerRestorePolicyFromDbus(std::string_view value)
+{
+    if (value ==
+        "xyz.openbmc_project.Control.Power.RestorePolicy.Policy.AlwaysOn")
+    {
+        return computer_system::PowerRestorePolicyTypes::AlwaysOn;
+    }
+    if (value ==
+        "xyz.openbmc_project.Control.Power.RestorePolicy.Policy.AlwaysOff")
+    {
+        return computer_system::PowerRestorePolicyTypes::AlwaysOff;
+    }
+    if (value ==
+        "xyz.openbmc_project.Control.Power.RestorePolicy.Policy.AlwaysRestore")
+    {
+        return computer_system::PowerRestorePolicyTypes::LastState;
+    }
+    if (value == "xyz.openbmc_project.Control.Power.RestorePolicy.Policy.None")
+    {
+        return computer_system::PowerRestorePolicyTypes::AlwaysOff;
+    }
+    return computer_system::PowerRestorePolicyTypes::Invalid;
+}
 /**
  * @brief Retrieves power restore policy over DBUS.
  *
@@ -1370,26 +1395,15 @@
             BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
             return;
         }
-
-        const boost::container::flat_map<std::string, std::string> policyMaps = {
-            {"xyz.openbmc_project.Control.Power.RestorePolicy.Policy.AlwaysOn",
-             "AlwaysOn"},
-            {"xyz.openbmc_project.Control.Power.RestorePolicy.Policy.AlwaysOff",
-             "AlwaysOff"},
-            {"xyz.openbmc_project.Control.Power.RestorePolicy.Policy.Restore",
-             "LastState"},
-            // Return `AlwaysOff` when power restore policy set to "None"
-            {"xyz.openbmc_project.Control.Power.RestorePolicy.Policy.None",
-             "AlwaysOff"}};
-
-        auto policyMapsIt = policyMaps.find(policy);
-        if (policyMapsIt == policyMaps.end())
+        computer_system::PowerRestorePolicyTypes restore =
+            redfishPowerRestorePolicyFromDbus(policy);
+        if (restore == computer_system::PowerRestorePolicyTypes::Invalid)
         {
             messages::internalError(asyncResp->res);
             return;
         }
 
-        asyncResp->res.jsonValue["PowerRestorePolicy"] = policyMapsIt->second;
+        asyncResp->res.jsonValue["PowerRestorePolicy"] = restore;
         });
 }
 
@@ -1931,6 +1945,23 @@
         dbus::utility::DbusVariantType(autoRebootEnabled));
 }
 
+inline std::string dbusPowerRestorePolicyFromRedfish(std::string_view policy)
+{
+    if (policy == "AlwaysOn")
+    {
+        return "xyz.openbmc_project.Control.Power.RestorePolicy.Policy.AlwaysOn";
+    }
+    if (policy == "AlwaysOff")
+    {
+        return "xyz.openbmc_project.Control.Power.RestorePolicy.Policy.AlwaysOff";
+    }
+    if (policy == "LastState")
+    {
+        return "xyz.openbmc_project.Control.Power.RestorePolicy.Policy.Restore";
+    }
+    return "";
+}
+
 /**
  * @brief Sets power restore policy properties.
  *
@@ -1941,30 +1972,19 @@
  */
 inline void
     setPowerRestorePolicy(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
-                          const std::string& policy)
+                          std::string_view policy)
 {
     BMCWEB_LOG_DEBUG << "Set power restore policy.";
 
-    const boost::container::flat_map<std::string, std::string> policyMaps = {
-        {"AlwaysOn",
-         "xyz.openbmc_project.Control.Power.RestorePolicy.Policy.AlwaysOn"},
-        {"AlwaysOff",
-         "xyz.openbmc_project.Control.Power.RestorePolicy.Policy.AlwaysOff"},
-        {"LastState",
-         "xyz.openbmc_project.Control.Power.RestorePolicy.Policy.Restore"}};
+    std::string powerRestorePolicy = dbusPowerRestorePolicyFromRedfish(policy);
 
-    std::string powerRestorPolicy;
-
-    auto policyMapsIt = policyMaps.find(policy);
-    if (policyMapsIt == policyMaps.end())
+    if (powerRestorePolicy.empty())
     {
         messages::propertyValueNotInList(asyncResp->res, policy,
                                          "PowerRestorePolicy");
         return;
     }
 
-    powerRestorPolicy = policyMapsIt->second;
-
     crow::connections::systemBus->async_method_call(
         [asyncResp](const boost::system::error_code& ec) {
         if (ec)
@@ -1977,7 +1997,7 @@
         "/xyz/openbmc_project/control/host0/power_restore_policy",
         "org.freedesktop.DBus.Properties", "Set",
         "xyz.openbmc_project.Control.Power.RestorePolicy", "PowerRestorePolicy",
-        dbus::utility::DbusVariantType(powerRestorPolicy));
+        dbus::utility::DbusVariantType(powerRestorePolicy));
 }
 
 #ifdef BMCWEB_ENABLE_REDFISH_PROVISIONING_FEATURE