| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // | ||
| 2 | // Copyright (c) 2022 Alan de Freitas (alandefreitas@gmail.com) | ||
| 3 | // | ||
| 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying | ||
| 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | ||
| 6 | // | ||
| 7 | // Official repository: https://github.com/boostorg/url | ||
| 8 | // | ||
| 9 | |||
| 10 | #ifndef BOOST_URL_ROUTER_HPP | ||
| 11 | #define BOOST_URL_ROUTER_HPP | ||
| 12 | |||
| 13 | #include <boost/url/detail/config.hpp> | ||
| 14 | #include <boost/url/parse_path.hpp> | ||
| 15 | #include "detail/router.hpp" | ||
| 16 | #include "matches.hpp" | ||
| 17 | |||
| 18 | namespace boost { | ||
| 19 | namespace urls { | ||
| 20 | |||
| 21 | /** A URL router. | ||
| 22 | |||
| 23 | This container matches static and dynamic | ||
| 24 | URL requests to an object which represents | ||
| 25 | how the it should be handled. These | ||
| 26 | values are usually callback functions. | ||
| 27 | |||
| 28 | @tparam T type of resource associated with | ||
| 29 | each path template | ||
| 30 | |||
| 31 | @tparam N maximum number of replacement fields | ||
| 32 | in a path template | ||
| 33 | |||
| 34 | @par Exception Safety | ||
| 35 | |||
| 36 | @li Functions marked `noexcept` provide the | ||
| 37 | no-throw guarantee, otherwise: | ||
| 38 | |||
| 39 | @li Functions which throw offer the strong | ||
| 40 | exception safety guarantee. | ||
| 41 | |||
| 42 | @see | ||
| 43 | @ref parse_absolute_uri, | ||
| 44 | @ref parse_relative_ref, | ||
| 45 | @ref parse_uri, | ||
| 46 | @ref parse_uri_reference, | ||
| 47 | @ref resolve. | ||
| 48 | */ | ||
| 49 | template <class T> | ||
| 50 | class router | ||
| 51 | : private detail::router_base | ||
| 52 | { | ||
| 53 | public: | ||
| 54 | /// Constructor | ||
| 55 | 95 | router() = default; | |
| 56 | |||
| 57 | /** Route the specified URL path to a resource | ||
| 58 | |||
| 59 | @param path A url path with dynamic segments | ||
| 60 | @param resource A resource the path corresponds to | ||
| 61 | |||
| 62 | @see | ||
| 63 | https://fmt.dev/latest/syntax.html | ||
| 64 | */ | ||
| 65 | template <class U> | ||
| 66 | void | ||
| 67 | insert(core::string_view pattern, U&& v); | ||
| 68 | |||
| 69 | /** Match URL path to the corresponding resource | ||
| 70 | |||
| 71 | @param request Request path | ||
| 72 | @return The match results | ||
| 73 | */ | ||
| 74 | T const* | ||
| 75 | 93 | find(segments_encoded_view path, matches& m) const noexcept | |
| 76 | { | ||
| 77 | 93 | return find_impl(path, m); | |
| 78 | } | ||
| 79 | |||
| 80 | private: | ||
| 81 | T const* | ||
| 82 | find_impl(segments_encoded_view path, matches_base& m) const noexcept; | ||
| 83 | }; | ||
| 84 | |||
| 85 | } // urls | ||
| 86 | } // boost | ||
| 87 | |||
| 88 | #include "impl/router.hpp" | ||
| 89 | |||
| 90 | #endif | ||
| 91 | |||
| 92 |