1//
2// Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot 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/beast
8//
9
10#ifndef BOOST_BEAST_CORE_IMPL_SAVED_HANDLER_IPP
11#define BOOST_BEAST_CORE_IMPL_SAVED_HANDLER_IPP
12
13#include <boost/beast/core/saved_handler.hpp>
14#include <boost/core/exchange.hpp>
15
16namespace boost {
17namespace beast {
18
19saved_handler::
20~saved_handler()
21{
22 if(p_)
23 p_->destroy();
24}
25
26saved_handler::
27saved_handler(saved_handler&& other) noexcept
28 : p_(boost::exchange(t&: other.p_, u: nullptr))
29{
30 p_->set_owner(this);
31}
32
33saved_handler&
34saved_handler::
35operator=(saved_handler&& other) noexcept
36{
37 // Can't delete a handler before invoking
38 BOOST_ASSERT(! has_value());
39 p_ = boost::exchange(t&: other.p_, u: nullptr);
40 p_->set_owner(this);
41 return *this;
42}
43
44bool
45saved_handler::
46reset() noexcept
47{
48 if(! p_)
49 return false;
50 boost::exchange(t&: p_, u: nullptr)->destroy();
51 return true;
52}
53
54void
55saved_handler::
56invoke()
57{
58 // Can't invoke without a value
59 BOOST_ASSERT(has_value());
60 boost::exchange(
61 t&: p_, u: nullptr)->invoke();
62}
63
64bool
65saved_handler::
66maybe_invoke()
67{
68 if(! p_)
69 return false;
70 boost::exchange(
71 t&: p_, u: nullptr)->invoke();
72 return true;
73}
74
75} // beast
76} // boost
77
78#endif
79

source code of boost/libs/beast/include/boost/beast/core/impl/saved_handler.ipp