USRP Hardware Driver and USRP Manual Version: 4.1.0.1
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#pragma once
8
9#include <functional>
10#include <memory>
11
12namespace uhd { namespace utils {
13
23{
24public:
25 using uptr = std::unique_ptr<scope_exit>;
26 using exit_cb_t = std::function<void(void)>;
27
28 // \param exit_b The function object ("exit callback") that gets executed
29 // in the destructor
30 static uptr make(exit_cb_t&& exit_cb)
31 {
32 // When we have C++14, use make_unique instead (TODO)
33 return uptr(new scope_exit(std::forward<exit_cb_t>(exit_cb)));
34 }
35
37 {
38 _exit_cb();
39 }
40
41private:
42 scope_exit(std::function<void(void)>&& exit_cb)
43 : _exit_cb(std::forward<std::function<void(void)>>(exit_cb))
44 {
45 // nop
46 }
47
48 std::function<void(void)> _exit_cb;
49};
50
51}} // namespace uhd::utils
Definition: scope_exit.hpp:23
std::function< void(void)> exit_cb_t
Definition: scope_exit.hpp:26
~scope_exit()
Definition: scope_exit.hpp:36
static uptr make(exit_cb_t &&exit_cb)
Definition: scope_exit.hpp:30
std::unique_ptr< scope_exit > uptr
Definition: scope_exit.hpp:25
STL namespace.
Definition: build_info.hpp:12