Fix route parameters
This commit is contained in:
parent
ef549ce2f5
commit
428ac2f229
@ -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 <code/seafire/server/parameters.hxx>
|
||||
#include <code/seafire/server/request.hxx>
|
||||
|
||||
#include <code/seafire/routing/route-parameters.hxx>
|
||||
|
||||
#include <optional>
|
||||
|
||||
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<value_type>);
|
||||
route_parameter_t(std::optional<value_type> value)
|
||||
: _value{std::move(value)}
|
||||
{}
|
||||
|
||||
std::optional<value_type> const&
|
||||
value() const;
|
||||
value() const
|
||||
{
|
||||
return _value;
|
||||
}
|
||||
|
||||
operator std::optional<value_type> const&() const;
|
||||
operator std::optional<value_type> const&() const
|
||||
{
|
||||
return value();
|
||||
}
|
||||
|
||||
std::optional<value_type> const*
|
||||
operator->() const;
|
||||
operator->() const
|
||||
{
|
||||
return &value();
|
||||
}
|
||||
|
||||
static
|
||||
route_parameter_t<Name, ParameterType>
|
||||
fetch(server::request_t&);
|
||||
fetch(server::request_t& req)
|
||||
{
|
||||
auto v = req.extensions().use<route_parameters_t>().get(name());
|
||||
return parameter_type::try_parse(v);
|
||||
}
|
||||
|
||||
private:
|
||||
std::optional<value_type> value_;
|
||||
std::optional<value_type> _value;
|
||||
|
||||
};
|
||||
|
||||
} // namespace code::seafire::routing
|
||||
|
||||
#include <code/seafire/routing/route-parameters.txx>
|
||||
|
||||
#endif
|
||||
|
@ -1,51 +0,0 @@
|
||||
namespace code::seafire::routing
|
||||
{
|
||||
|
||||
template<server::parameter_name Name, typename ParameterType>
|
||||
std::string const&
|
||||
route_parameter_t<Name, ParameterType>::
|
||||
name()
|
||||
{
|
||||
static std::string const name{Name};
|
||||
return name;
|
||||
}
|
||||
|
||||
template<server::parameter_name Name, typename ParameterType>
|
||||
route_parameter_t<Name, ParameterType>::
|
||||
route_parameter_t(std::optional<value_type> value)
|
||||
: value_{std::move(value)}
|
||||
{}
|
||||
|
||||
template<server::parameter_name Name, typename ParameterType>
|
||||
std::optional<route_parameter_t<Name, ParameterType>::value_type> const&
|
||||
route_parameter_t<Name, ParameterType>::
|
||||
value() const
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
template<server::parameter_name Name, typename ParameterType>
|
||||
route_parameter_t<Name, ParameterType>::
|
||||
operator std::optional<value_type> const&() const
|
||||
{
|
||||
return value();
|
||||
}
|
||||
|
||||
template<server::parameter_name Name, typename ParameterType>
|
||||
std::optional<route_parameter_t<Name, ParameterType>::value_type> const*
|
||||
route_parameter_t<Name, ParameterType>::
|
||||
operator->() const
|
||||
{
|
||||
return &value();
|
||||
}
|
||||
|
||||
template<server::parameter_name Name, typename ParameterType>
|
||||
route_parameter_t<Name, ParameterType>
|
||||
route_parameter_t<Name, ParameterType>::
|
||||
fetch(server::request_t&)
|
||||
{
|
||||
auto v = req.extensions().use<route_parameters_t>().get(name());
|
||||
return parameter_type::try_parse(v);
|
||||
}
|
||||
|
||||
} // namespace code::seafire::routing
|
Loading…
x
Reference in New Issue
Block a user