Line data 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/detail/over_allocator.hpp>
15 : #include <cstring>
16 : #include <memory>
17 :
18 : namespace boost {
19 : namespace urls {
20 :
21 : //------------------------------------------------
22 : //
23 : // url_view_base::persist
24 : //
25 : //------------------------------------------------
26 :
27 : struct url_view_base::shared_impl
28 : : url_view
29 : {
30 : virtual
31 3 : ~shared_impl()
32 3 : {
33 3 : }
34 :
35 3 : shared_impl(
36 : url_view const& u) noexcept
37 3 : : url_view(u)
38 : {
39 3 : impl_.cs_ = reinterpret_cast<
40 : char const*>(this + 1);
41 3 : }
42 : };
43 :
44 : inline
45 : std::shared_ptr<url_view const>
46 3 : url_view_base::
47 : persist() const
48 : {
49 : using T = shared_impl;
50 : using Alloc = std::allocator<char>;
51 : Alloc a;
52 : auto p = std::allocate_shared<T>(
53 6 : detail::over_allocator<T, Alloc>(
54 6 : size(), a), url_view(impl()));
55 3 : std::memcpy(
56 : reinterpret_cast<char*>(
57 3 : p.get() + 1), data(), size());
58 6 : return p;
59 3 : }
60 :
61 : } // urls
62 : } // boost
63 :
64 : #endif
|