/src/serenity/AK/SetOnce.h
Line | Count | Source |
1 | | /* |
2 | | * Copyright (c) 2024, Liav A. <liavalb@hotmail.co.il> |
3 | | * |
4 | | * SPDX-License-Identifier: BSD-2-Clause |
5 | | */ |
6 | | |
7 | | #pragma once |
8 | | |
9 | | #include <AK/Noncopyable.h> |
10 | | #include <AK/Types.h> |
11 | | |
12 | | namespace AK { |
13 | | |
14 | | class SetOnce { |
15 | | AK_MAKE_NONCOPYABLE(SetOnce); |
16 | | AK_MAKE_NONMOVABLE(SetOnce); |
17 | | |
18 | | public: |
19 | 1.73k | SetOnce() = default; |
20 | | |
21 | | void set() |
22 | 10.2k | { |
23 | 10.2k | m_value = true; |
24 | 10.2k | } |
25 | | |
26 | 362 | bool was_set() const { return m_value; } |
27 | | |
28 | | private: |
29 | | bool m_value { false }; |
30 | | }; |
31 | | |
32 | | } |
33 | | |
34 | | #if USING_AK_GLOBALLY |
35 | | using AK::SetOnce; |
36 | | #endif |