summaryrefslogtreecommitdiff
path: root/http/utility.hpp
diff options
context:
space:
mode:
authorEd Tanous <edtanous@google.com>2023-06-26 22:47:24 +0300
committerEd Tanous <ed@tanous.net>2023-06-28 18:14:01 +0300
commitcfe3bc0aaf2589e76924e56232e723b42779b3fe (patch)
treee847fca25e8530f8116ceee2f7ad069f93ea6761 /http/utility.hpp
parent8b24275d7696c9df071d11e16a0f905b1e800163 (diff)
downloadbmcweb-cfe3bc0aaf2589e76924e56232e723b42779b3fe.tar.xz
Simplify the router
There's a lot of complexity left in the router. The recent decision to only support string arguments means that this can be significantly cleaned up. In some cases, this is done to simply expand the variadic template and handle all parameter cases up to 5 (which should be the max we ever see). While this might seem like it's not very DRY friendly (Don't repeat yourself) this is significantly better than what we had, which was very tough to deciper. Tested: Redfish service validator passes Change-Id: Ic72e54cffd7b9f4a85e6c9d143c45fa20530a2cd Signed-off-by: Ed Tanous <edtanous@google.com>
Diffstat (limited to 'http/utility.hpp')
-rw-r--r--http/utility.hpp53
1 files changed, 12 insertions, 41 deletions
diff --git a/http/utility.hpp b/http/utility.hpp
index 59ddf98832..94d89fb1a7 100644
--- a/http/utility.hpp
+++ b/http/utility.hpp
@@ -101,47 +101,6 @@ constexpr inline uint64_t getParameterTag(std::string_view url)
}
return tagValue;
}
-
-template <typename... T>
-struct S
-{
- template <typename U>
- using push = S<U, T...>;
- template <typename U>
- using push_back = S<T..., U>;
- template <template <typename... Args> class U>
- using rebind = U<T...>;
-};
-
-template <typename F, typename Set>
-struct CallHelper;
-
-template <typename F, typename... Args>
-struct CallHelper<F, S<Args...>>
-{
- template <typename F1, typename... Args1,
- typename = decltype(std::declval<F1>()(std::declval<Args1>()...))>
- static char test(int);
-
- template <typename...>
- static int test(...);
-
- static constexpr bool value = sizeof(test<F, Args...>(0)) == sizeof(char);
-};
-
-template <uint64_t Tag>
-struct Arguments
-{
- using subarguments = typename Arguments<Tag / 3>::type;
- using type = typename subarguments::template push<std::string>;
-};
-
-template <>
-struct Arguments<0>
-{
- using type = S<>;
-};
-
} // namespace black_magic
namespace utility
@@ -154,6 +113,18 @@ struct FunctionTraits
using arg = std::tuple_element_t<i, boost::callable_traits::args_t<T>>;
};
+constexpr size_t numArgsFromTag(int tag)
+{
+ size_t ret = 0;
+ while (tag > 0)
+ {
+ // Move to the next tag by removing the bottom bits from the number
+ tag /= black_magic::toUnderlying(black_magic::TypeCode::Max);
+ ret++;
+ }
+ return ret;
+};
+
inline std::string base64encode(std::string_view data)
{
const std::array<char, 64> key = {