Remove magic numbers

There's lots of magic numbers in this file that we inherited from crow.
This commit Adds a TypeCode enum class that can be used in place of the
magic numbers.  It keeps the same values as were present previously
(0-6) in case there are places where this abstraction leaked out, but I
believe this catches all of them.

Tested: Redfish service validator passes.

Signed-off-by: Ed Tanous <edtanous@google.com>
Change-Id: I063955adb8bf75d9bb6298e29e6e44c210ee9cc3
diff --git a/http/utility.hpp b/http/utility.hpp
index 7b0af13..431a2fe 100644
--- a/http/utility.hpp
+++ b/http/utility.hpp
@@ -10,6 +10,7 @@
 
 #include <array>
 #include <chrono>
+#include <cstddef>
 #include <cstdint>
 #include <ctime>
 #include <functional>
@@ -27,58 +28,76 @@
 namespace black_magic
 {
 
+enum class TypeCode : uint8_t
+{
+    Unspecified = 0,
+    Integer = 1,
+    UnsignedInteger = 2,
+    Float = 3,
+    String = 4,
+    Path = 5,
+    Max = 6,
+};
+
+// Remove when we have c++23
+template <typename E>
+constexpr typename std::underlying_type<E>::type toUnderlying(E e) noexcept
+{
+    return static_cast<typename std::underlying_type<E>::type>(e);
+}
+
 template <typename T>
-constexpr uint64_t getParameterTag()
+constexpr TypeCode getParameterTag()
 {
     if constexpr (std::is_same_v<int, T>)
     {
-        return 1;
+        return TypeCode::Integer;
     }
     if constexpr (std::is_same_v<char, T>)
     {
-        return 1;
+        return TypeCode::Integer;
     }
     if constexpr (std::is_same_v<short, T>)
     {
-        return 1;
+        return TypeCode::Integer;
     }
     if constexpr (std::is_same_v<long, T>)
     {
-        return 1;
+        return TypeCode::Integer;
     }
     if constexpr (std::is_same_v<long long, T>)
     {
-        return 1;
+        return TypeCode::Integer;
     }
     if constexpr (std::is_same_v<unsigned int, T>)
     {
-        return 2;
+        return TypeCode::UnsignedInteger;
     }
     if constexpr (std::is_same_v<unsigned char, T>)
     {
-        return 2;
+        return TypeCode::UnsignedInteger;
     }
     if constexpr (std::is_same_v<unsigned short, T>)
     {
-        return 2;
+        return TypeCode::UnsignedInteger;
     }
     if constexpr (std::is_same_v<unsigned long, T>)
     {
-        return 2;
+        return TypeCode::UnsignedInteger;
     }
     if constexpr (std::is_same_v<unsigned long long, T>)
     {
-        return 2;
+        return TypeCode::UnsignedInteger;
     }
     if constexpr (std::is_same_v<double, T>)
     {
-        return 3;
+        return TypeCode::Float;
     }
     if constexpr (std::is_same_v<std::string, T>)
     {
-        return 4;
+        return TypeCode::String;
     }
-    return 0;
+    return TypeCode::Unspecified;
 }
 
 template <typename... Args>
@@ -96,8 +115,12 @@
     static constexpr int subValue =
         computeParameterTagFromArgsList<Args...>::value;
     static constexpr int value =
-        getParameterTag<typename std::decay<Arg>::type>() != 0
-            ? subValue * 6 + getParameterTag<typename std::decay<Arg>::type>()
+        getParameterTag<typename std::decay<Arg>::type>() !=
+                TypeCode::Unspecified
+            ? static_cast<unsigned long>(subValue *
+                                         toUnderlying(TypeCode::Max)) +
+                  static_cast<uint64_t>(
+                      getParameterTag<typename std::decay<Arg>::type>())
             : subValue;
 };
 
@@ -113,22 +136,23 @@
         {
             return a == 0;
         }
-        uint64_t sa = a % 6;
-        uint64_t sb = a % 6;
-        if (sa == 5)
+        TypeCode sa = static_cast<TypeCode>(a % toUnderlying(TypeCode::Max));
+        TypeCode sb = static_cast<TypeCode>(b % toUnderlying(TypeCode::Max));
+
+        if (sa == TypeCode::Path)
         {
-            sa = 4;
+            sa = TypeCode::String;
         }
-        if (sb == 5)
+        if (sb == TypeCode::Path)
         {
-            sb = 4;
+            sb = TypeCode::String;
         }
         if (sa != sb)
         {
             return false;
         }
-        a /= 6;
-        b /= 6;
+        a /= toUnderlying(TypeCode::Max);
+        b /= toUnderlying(TypeCode::Max);
     }
     return false;
 }
@@ -172,23 +196,24 @@
 
             if (tag == "<int>")
             {
-                tagValue += insertIndex * 1;
+                tagValue += insertIndex * toUnderlying(TypeCode::Integer);
             }
             if (tag == "<uint>")
             {
-                tagValue += insertIndex * 2;
+                tagValue +=
+                    insertIndex * toUnderlying(TypeCode::UnsignedInteger);
             }
             if (tag == "<float>" || tag == "<double>")
             {
-                tagValue += insertIndex * 3;
+                tagValue += insertIndex * toUnderlying(TypeCode::Float);
             }
             if (tag == "<str>" || tag == "<string>")
             {
-                tagValue += insertIndex * 4;
+                tagValue += insertIndex * toUnderlying(TypeCode::String);
             }
             if (tag == "<path>")
             {
-                tagValue += insertIndex * 5;
+                tagValue += insertIndex * toUnderlying(TypeCode::Path);
             }
             paramIndex++;
             urlSegmentIndex = std::string_view::npos;