USRP Hardware Driver and USRP Manual: scope_exit.hpp Source File

| USRP Hardware Driver and USRP Manual Version: 4.8.0.makepkg-0-g308126a4 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
23 class 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
37 ~scope_exit()
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
uhd::utils::scope_exit
Definition scope_exit.hpp:24
uhd::utils::scope_exit::exit_cb_t
std::function< void(void)> exit_cb_t
Definition scope_exit.hpp:27
uhd::utils::scope_exit::~scope_exit
~scope_exit()
Definition scope_exit.hpp:37
uhd::utils::scope_exit::make
static uptr make(exit_cb_t &&exit_cb)
Definition scope_exit.hpp:31
uhd::utils::scope_exit::uptr
std::unique_ptr< scope_exit > uptr
Definition scope_exit.hpp:26
std
STL namespace.
uhd::utils
Definition chdr_packet.hpp:20
uhd
Definition build_info.hpp:12