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 +
    ~shared_impl()
 
32 +
    {
 
33 +
    }
 
34 +

 
35 +
    shared_impl(
 
36 +
        url_view const& u) noexcept
 
37 +
        : url_view(u)
 
38 +
    {
 
39 +
        impl_.cs_ = reinterpret_cast<
 
40 +
            char const*>(this + 1);
 
41 +
    }
 
42 +
};
 
43 +

 
44 +
inline
 
45 +
std::shared_ptr<url_view const>
 
46 +
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 +
        detail::over_allocator<T, Alloc>(
 
54 +
            size(), a), url_view(impl()));
 
55 +
    std::memcpy(
 
56 +
        reinterpret_cast<char*>(
 
57 +
            p.get() + 1), data(), size());
 
58 +
    return p;
 
59 +
}
 
60 +

 
61 +
} // urls
 
62 +
} // boost
 
63 +

 
64 +
#endif