Line data Source code
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 : @par Exception Safety
32 :
33 : @li Functions marked `noexcept` provide the
34 : no-throw guarantee, otherwise:
35 :
36 : @li Functions which throw offer the strong
37 : exception safety guarantee.
38 :
39 : @see
40 : @ref parse_absolute_uri,
41 : @ref parse_relative_ref,
42 : @ref parse_uri,
43 : @ref parse_uri_reference,
44 : @ref resolve.
45 : */
46 : template <class T>
47 : class router
48 : : private detail::router_base
49 : {
50 : public:
51 : /// Constructor
52 95 : router() = default;
53 :
54 : router(router const&) = delete;
55 : router& operator=(router const&) = delete;
56 : router(router&&) noexcept = default;
57 : router& operator=(router&&) noexcept = default;
58 :
59 : /** Route the specified URL path to a resource
60 :
61 : @param path A url path with dynamic segments
62 : @param resource A resource the path corresponds to
63 :
64 : @see
65 : https://fmt.dev/latest/syntax.html
66 : */
67 : template <class U>
68 : void
69 : insert(core::string_view pattern, U&& v);
70 :
71 : /** Match URL path to the corresponding resource
72 :
73 : @param request Request path
74 : @return The match results
75 : */
76 : T const*
77 93 : find(segments_encoded_view path, matches& m) const noexcept
78 : {
79 93 : return find_impl(path, m);
80 : }
81 :
82 : private:
83 : T const*
84 : find_impl(segments_encoded_view path, matches_base& m) const noexcept;
85 : };
86 :
87 : } // urls
88 : } // boost
89 :
90 : #include "impl/router.hpp"
91 :
92 : #endif
|