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