include/boost/url/impl/url_view.hpp

100.0% Lines (19/19) 100.0% List of functions (4/4)
url_view.hpp
f(x) Functions (4)
Line TLA Hits Source Code
1 //
2 // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com)
3 // Copyright (c) 2022 Alan de Freitas (alandefreitas@gmail.com)
4 //
5 // Distributed under the Boost Software License, Version 1.0. (See accompanying
6 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 //
8 // Official repository: https://github.com/boostorg/url
9 //
10
11 #ifndef BOOST_URL_IMPL_URL_VIEW_HPP
12 #define BOOST_URL_IMPL_URL_VIEW_HPP
13
14 #include <boost/url/parse.hpp>
15 #include <boost/url/detail/over_allocator.hpp>
16 #include <cstring>
17 #include <memory>
18
19 namespace boost {
20 namespace urls {
21
22 //------------------------------------------------
23 //
24 // url_view
25 //
26 //------------------------------------------------
27
28 inline
29 378x url_view::
30 378x url_view(core::string_view s)
31 378x : url_view(parse_uri_reference(s
32 378x ).value(BOOST_URL_POS))
33 {
34 377x }
35
36 //------------------------------------------------
37 //
38 // url_view_base::persist
39 //
40 //------------------------------------------------
41
42 struct url_view_base::shared_impl
43 : url_view
44 {
45 virtual
46 3x ~shared_impl()
47 3x {
48 3x }
49
50 3x shared_impl(
51 url_view const& u) noexcept
52 3x : url_view(u)
53 {
54 3x impl_.cs_ = reinterpret_cast<
55 char const*>(this + 1);
56 3x }
57 };
58
59 inline
60 std::shared_ptr<url_view const>
61 3x url_view_base::
62 persist() const
63 {
64 using T = shared_impl;
65 using Alloc = std::allocator<char>;
66 Alloc a;
67 auto p = std::allocate_shared<T>(
68 6x detail::over_allocator<T, Alloc>(
69 6x size(), a), url_view(impl()));
70 3x std::memcpy(
71 reinterpret_cast<char*>(
72 3x p.get() + 1), data(), size());
73 6x return p;
74 3x }
75
76 } // urls
77 } // boost
78
79 #endif
80