Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:29:27

0001 //
0002 // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
0003 //
0004 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0005 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0006 //
0007 // Official repository: https://github.com/boostorg/beast
0008 //
0009 
0010 #ifndef BOOST_BEAST_CORE_IMPL_SAVED_HANDLER_IPP
0011 #define BOOST_BEAST_CORE_IMPL_SAVED_HANDLER_IPP
0012 
0013 #include <boost/beast/core/saved_handler.hpp>
0014 #include <boost/core/exchange.hpp>
0015 
0016 namespace boost {
0017 namespace beast {
0018 
0019 saved_handler::
0020 ~saved_handler()
0021 {
0022     if(p_)
0023         p_->destroy();
0024 }
0025 
0026 saved_handler::
0027 saved_handler(saved_handler&& other) noexcept
0028     : p_(boost::exchange(other.p_, nullptr))
0029 {
0030     p_->set_owner(this);
0031 }
0032 
0033 saved_handler&
0034 saved_handler::
0035 operator=(saved_handler&& other) noexcept
0036 {
0037     // Can't delete a handler before invoking
0038     BOOST_ASSERT(! has_value());
0039     p_ = boost::exchange(other.p_, nullptr);
0040     p_->set_owner(this);
0041     return *this;
0042 }
0043 
0044 bool
0045 saved_handler::
0046 reset() noexcept
0047 {
0048     if(! p_)
0049         return false;
0050     boost::exchange(p_, nullptr)->destroy();
0051     return true;
0052 }
0053 
0054 void
0055 saved_handler::
0056 invoke()
0057 {
0058     // Can't invoke without a value
0059     BOOST_ASSERT(has_value());
0060     boost::exchange(
0061         p_, nullptr)->invoke();
0062 }
0063 
0064 bool
0065 saved_handler::
0066 maybe_invoke()
0067 {
0068     if(! p_)
0069         return false;
0070     boost::exchange(
0071         p_, nullptr)->invoke();
0072     return true;
0073 }
0074 
0075 } // beast
0076 } // boost
0077 
0078 #endif