From 428ac2f22991d4637d01e9b60a869a71653cbef2 Mon Sep 17 00:00:00 2001 From: Ryan Date: Tue, 31 Dec 2024 03:03:38 +0100 Subject: [PATCH] Fix route parameters --- code/seafire/routing/route-parameter.hxx | 45 +++++++++++++++------ code/seafire/routing/route-parameter.txx | 51 ------------------------ 2 files changed, 32 insertions(+), 64 deletions(-) delete mode 100644 code/seafire/routing/route-parameter.txx diff --git a/code/seafire/routing/route-parameter.hxx b/code/seafire/routing/route-parameter.hxx index 5d55553..a0a146f 100644 --- a/code/seafire/routing/route-parameter.hxx +++ b/code/seafire/routing/route-parameter.hxx @@ -1,17 +1,19 @@ -#ifndef code__seafire__routing__route_parameters_hxx_ -#define code__seafire__routing__route_parameters_hxx_ +#ifndef code__seafire__routing__route_parameter_hxx_ +#define code__seafire__routing__route_parameter_hxx_ #include #include #include +#include + namespace code::seafire::routing { template< - server::parameter_name Name, - typename ParameterType = server::string_parameter + server::parameter_name_t Name, + typename ParameterType = server::string_parameter_t > class route_parameter_t { @@ -21,29 +23,46 @@ namespace code::seafire::routing static std::string const& - name(); + name() + { + static std::string const name{Name}; + return name; + } - route_parameter_t(std::optional); + route_parameter_t(std::optional value) + : _value{std::move(value)} + {} std::optional const& - value() const; + value() const + { + return _value; + } - operator std::optional const&() const; + operator std::optional const&() const + { + return value(); + } std::optional const* - operator->() const; + operator->() const + { + return &value(); + } static route_parameter_t - fetch(server::request_t&); + fetch(server::request_t& req) + { + auto v = req.extensions().use().get(name()); + return parameter_type::try_parse(v); + } private: - std::optional value_; + std::optional _value; }; } // namespace code::seafire::routing -#include - #endif diff --git a/code/seafire/routing/route-parameter.txx b/code/seafire/routing/route-parameter.txx deleted file mode 100644 index ef387ad..0000000 --- a/code/seafire/routing/route-parameter.txx +++ /dev/null @@ -1,51 +0,0 @@ -namespace code::seafire::routing -{ - - template - std::string const& - route_parameter_t:: - name() - { - static std::string const name{Name}; - return name; - } - - template - route_parameter_t:: - route_parameter_t(std::optional value) - : value_{std::move(value)} - {} - - template - std::optional::value_type> const& - route_parameter_t:: - value() const - { - return value; - } - - template - route_parameter_t:: - operator std::optional const&() const - { - return value(); - } - - template - std::optional::value_type> const* - route_parameter_t:: - operator->() const - { - return &value(); - } - - template - route_parameter_t - route_parameter_t:: - fetch(server::request_t&) - { - auto v = req.extensions().use().get(name()); - return parameter_type::try_parse(v); - } - -} // namespace code::seafire::routing