MySQL 8.1.0
Source Code Documentation
sentry.h
Go to the documentation of this file.
1/* Copyright (c) 2020, 2023, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is also distributed with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have included with MySQL.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License, version 2.0, for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22
23#ifndef CONTAINER_SENTRY_INCLUDED
24#define CONTAINER_SENTRY_INCLUDED
25
26#include <functional>
27
28namespace raii {
29/**
30 Generic sentry class that invokes some callable object of type F upon disposal
31 of an instance of this class.
32
33 Check C++ documentation for the definition of `Callable` named requirement for
34 more information.
35 */
36template <typename F = std::function<void()>>
37class Sentry {
38 public:
39 /**
40 Constructor for the class that stores the callable object passed as
41 argument, to be invoked upon disposal of the object.
42
43 @param dispose The callable object to be invoked upon disposal of the
44 object.
45 */
46 Sentry(F dispose);
47 /**
48 Destructor for the class. It will call the stored callable.
49 */
50 virtual ~Sentry();
51
52 private:
53 /** The callable to be invoked upon disposal of the object. */
55};
56} // namespace raii
57
58template <typename F>
59raii::Sentry<F>::Sentry(F dispose) : m_dispose{dispose} {}
60
61template <typename F>
63 this->m_dispose();
64}
65
66#endif // CONTAINER_SENTRY_INCLUDED
Generic sentry class that invokes some callable object of type F upon disposal of an instance of this...
Definition: sentry.h:37
virtual ~Sentry()
Destructor for the class.
Definition: sentry.h:62
Sentry(F dispose)
Constructor for the class that stores the callable object passed as argument, to be invoked upon disp...
Definition: sentry.h:59
F m_dispose
The callable to be invoked upon disposal of the object.
Definition: sentry.h:54
Definition: sentry.h:28