USRP Hardware Driver and USRP Manual Version: 4.8.0.0
UHD and USRP Manual
 
Loading...
Searching...
No Matches
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#pragma once
8
9#include <functional>
10#include <memory>
11#include <utility>
12
13namespace uhd { namespace utils {
14
23class scope_exit
24{
25public:
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
42private:
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::utils
Definition scope_exit.hpp:24
std::function< void(void)> exit_cb_t
Definition scope_exit.hpp:27
~scope_exit()
Definition scope_exit.hpp:37
static uptr make(exit_cb_t &&exit_cb)
Definition scope_exit.hpp:31
std::unique_ptr< scope_exit > uptr
Definition scope_exit.hpp:26
STL namespace.
Definition chdr_packet.hpp:20
Definition build_info.hpp:12