MySQL 8.0.40
Source Code Documentation
ut0bool_scope_guard.h
Go to the documentation of this file.
1/*****************************************************************************
2
3Copyright (c) 2019, 2024, Oracle and/or its affiliates.
4
5This program is free software; you can redistribute it and/or modify it under
6the terms of the GNU General Public License, version 2.0, as published by the
7Free Software Foundation.
8
9This program is designed to work with certain software (including
10but not limited to OpenSSL) that is licensed under separate terms,
11as designated in a particular file or component or in included license
12documentation. The authors of MySQL hereby grant you an additional
13permission to link the program and your derivative works with the
14separately licensed software that they have either included with
15the program or referenced in the documentation.
16
17This program is distributed in the hope that it will be useful, but WITHOUT
18ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
20for more details.
21
22You should have received a copy of the GNU General Public License along with
23this program; if not, write to the Free Software Foundation, Inc.,
2451 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25
26*****************************************************************************/
27
28/** @file include/ut0bool_scope_guard.h
29 The ut_bool_scope_guard class which sets boolean to true for
30 the duration of scope. */
31
32#ifndef ut0bool_scope_guard_h
33#define ut0bool_scope_guard_h
34
35namespace ut {
36/** A RAII-style class, which sets a given boolean to true in constructor, and
37to false in destructor, effectively making sure that it is true for the duration
38of the object lifetime/scope. */
40 /** boolean to be manipulated, or nullptr if the object was moved from, or
41 already destructed */
42 bool *m_active;
43
44 public:
45 /** Creates the RAII guard which sets `active` to true for the duration of
46 its lifetime.
47 @param[in,out] active the boolean which is to be manipulated */
48 explicit bool_scope_guard_t(bool &active) : m_active(&active) {
49 *m_active = true;
50 }
52 if (m_active != nullptr) {
53 *m_active = false;
54 m_active = nullptr;
55 }
56 }
61 m_active = old.m_active;
62 old.m_active = nullptr;
63 }
64};
65} // namespace ut
66#endif /* ut0bool_scope_guard_h */
A RAII-style class, which sets a given boolean to true in constructor, and to false in destructor,...
Definition: ut0bool_scope_guard.h:39
bool_scope_guard_t & operator=(bool_scope_guard_t const &)=delete
bool_scope_guard_t(bool_scope_guard_t &&old)
Definition: ut0bool_scope_guard.h:60
bool_scope_guard_t & operator=(bool_scope_guard_t &&)=delete
~bool_scope_guard_t()
Definition: ut0bool_scope_guard.h:51
bool_scope_guard_t(bool_scope_guard_t const &)=delete
bool * m_active
boolean to be manipulated, or nullptr if the object was moved from, or already destructed
Definition: ut0bool_scope_guard.h:42
bool_scope_guard_t(bool &active)
Creates the RAII guard which sets active to true for the duration of its lifetime.
Definition: ut0bool_scope_guard.h:48
This file contains a set of libraries providing overloads for regular dynamic allocation routines whi...
Definition: aligned_alloc.h:48