LCOV - code coverage report
Current view: top level - libs/url/example/router/impl - router.hpp (source / functions) Hit Total Coverage
Test: coverage_filtered.info Lines: 21 21 100.0 %
Date: 2024-02-29 20:02:55 Functions: 4 4 100.0 %

          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             : #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          93 :     if (p)
      63             :     {
      64          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

Generated by: LCOV version 1.15