GCC Code Coverage Report


Directory: libs/url/
File: libs/url/example/router/impl/router.hpp
Date: 2024-03-15 19:37:09
Exec Total Coverage
Lines: 21 21 100.0%
Functions: 4 4 100.0%
Branches: 3 4 75.0%

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 #include <boost/url/detail/except.hpp>
11 #include <boost/url/decode_view.hpp>
12 #include <boost/url/grammar/unsigned_rule.hpp>
13 #include <boost/mp11/algorithm.hpp>
14
15 namespace boost {
16 namespace urls {
17
18 template <class T>
19 template <class U>
20 void
21 113 router<T>::
22 insert(core::string_view pattern, U&& v)
23 {
24 BOOST_STATIC_ASSERT(
25 std::is_same<T, U>::value ||
26 std::is_convertible<U, T>::value ||
27 std::is_base_of<T, U>::value);
28 using U_ = typename std::decay<
29 typename std::conditional<
30 std::is_base_of<T, U>::value, U, T
31 >::type>::type;
32 struct impl : any_resource
33 {
34 U_ u;
35
36 explicit
37 113 impl(U&& u_)
38 113 : u(std::forward<U>(u_))
39 {
40 113 }
41
42 void const*
43 76 get() const noexcept override
44 {
45 76 return static_cast<T const*>(&u);
46 }
47 };
48 113 any_resource const* p = new impl(
49 113 std::forward<U>(v));
50 113 insert_impl( pattern, p );
51 111 }
52
53 template <class T>
54 T const*
55 93 router<T>::
56 find(segments_encoded_view path, matches_base& m) const noexcept
57 {
58 93 core::string_view* matches_it = m.matches();
59 93 core::string_view* ids_it = m.ids();
60 93 any_resource const* p = find_impl(
61 path, matches_it, ids_it );
62
2/2
✓ Branch 0 taken 76 times.
✓ Branch 1 taken 17 times.
93 if (p)
63 {
64
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 76 times.
76 BOOST_ASSERT(matches_it >= m.matches());
65 152 m.resize(static_cast<std::size_t>(
66 76 matches_it - m.matches()));
67 return reinterpret_cast<
68 76 T const*>(p->get());
69 }
70 17 m.resize(0);
71 17 return nullptr;
72 }
73
74 } // urls
75 } // boost
76