Seafire-Routing/seafire/routing/routing-table.hxx
2025-03-08 20:55:07 +01:00

79 lines
1.4 KiB
C++

#ifndef seafire__routing__routing_table_hxx_
#define seafire__routing__routing_table_hxx_
#include <seafire/routing/endpoint.hxx>
#include <seafire/routing/route-parameters.hxx>
#include <seafire/routing/route.hxx>
#include <seafire/server/request-handler.hxx>
#include <list>
#include <optional>
#include <string>
#include <vector>
namespace seafire::routing
{
class routing_table_t
{
public:
class builder_t;
struct find_result_t
{
server::request_handler_t const& handler;
route_parameters_t params;
};
explicit
routing_table_t(std::vector<endpoint_t>);
std::vector<endpoint_t> const&
endpoints() const;
std::optional<find_result_t>
find_route(std::string const&) const;
private:
std::vector<endpoint_t> endpoints_;
};
class routing_table_t::builder_t {
public:
builder_t();
builder_t(builder_t const&) = delete;
builder_t(builder_t&&) = delete;
~builder_t() noexcept;
route_t&
add_route();
route_t&
add_route(route_t);
route_t&
add_route(std::string);
route_t&
add_route(std::string, server::request_handler_t);
routing_table_t
build() const;
builder_t& operator=(builder_t const&) = delete;
builder_t& operator=(builder_t&&) = delete;
private:
std::list<route_t> roots_;
};
} // namespace seafire::routing
#endif