LLDB  mainline
CleanUp.h
Go to the documentation of this file.
1 //===-- CleanUp.h -----------------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef liblldb_CleanUp_h_
10 #define liblldb_CleanUp_h_
11 
12 #include "lldb/lldb-public.h"
13 #include <functional>
14 
15 namespace lldb_private {
16 
17 /// Run a cleanup function on scope exit unless it's explicitly disabled.
18 class CleanUp {
19  std::function<void()> Clean;
20 
21 public:
22  /// Register a cleanup function which applies \p Func to a list of arguments.
23  /// Use caution with arguments which are references: they will be copied.
24  template <typename F, typename... Args>
25  CleanUp(F &&Func, Args &&... args)
26  : Clean(std::bind(std::forward<F>(Func), std::forward<Args>(args)...)) {}
27 
29  if (Clean)
30  Clean();
31  }
32 
33  /// Disable the cleanup.
34  void disable() { Clean = nullptr; }
35 
36  // Prevent cleanups from being run more than once.
38 };
39 
40 } // namespace lldb_private
41 
42 #endif // #ifndef liblldb_CleanUp_h_
A command line argument class.
Definition: Args.h:32
Enumerations for broadcasting.
Definition: SBLaunchInfo.h:14
CleanUp(F &&Func, Args &&... args)
Register a cleanup function which applies Func to a list of arguments.
Definition: CleanUp.h:25
void disable()
Disable the cleanup.
Definition: CleanUp.h:34
Run a cleanup function on scope exit unless it&#39;s explicitly disabled.
Definition: CleanUp.h:18
DISALLOW_COPY_AND_ASSIGN(CleanUp)