USRP Hardware Driver and USRP Manual  Version: 3.15.0.HEAD-0-g6563c537
UHD and USRP Manual
scope_exit.hpp
Go to the documentation of this file.
1 //
2 // Copyright 2019 Ettus Research, a National Instruments Brand
3 //
4 // SPDX-License-Identifier: GPL-3.0-or-later
5 //
6 
7 #ifndef INCLUDED_UHD_SCOPE_EXIT_HPP
8 #define INCLUDED_UHD_SCOPE_EXIT_HPP
9 
10 #include <functional>
11 #include <memory>
12 
13 namespace uhd { namespace utils {
14 
24 {
25 public:
26  using uptr = std::unique_ptr<scope_exit>;
27  using exit_cb_t = std::function<void(void)>;
28 
29  // \param exit_b The function object ("exit callback") that gets executed
30  // in the destructor
31  static uptr make(exit_cb_t&& exit_cb)
32  {
33  // When we have C++14, use make_unique instead (TODO)
34  return uptr(new scope_exit(std::forward<exit_cb_t>(exit_cb)));
35  }
36 
38  {
39  _exit_cb();
40  }
41 
42 private:
43  scope_exit(std::function<void(void)>&& exit_cb)
44  : _exit_cb(std::forward<std::function<void(void)>>(exit_cb))
45  {
46  // nop
47  }
48 
49  std::function<void(void)> _exit_cb;
50 };
51 
52 }} /* namespace uhd::rfnoc */
53 
54 #endif /* INCLUDED_UHD_SCOPE_EXIT_HPP */
55 
std::function< void(void)> exit_cb_t
Definition: scope_exit.hpp:27
static uptr make(exit_cb_t &&exit_cb)
Definition: scope_exit.hpp:31
Definition: build_info.hpp:13
~scope_exit()
Definition: scope_exit.hpp:37
std::unique_ptr< scope_exit > uptr
Definition: scope_exit.hpp:26
Definition: scope_exit.hpp:23