DDC 0.10.0
Loading...
Searching...
No Matches
scope_guard.hpp
1// Copyright (C) The DDC development team, see COPYRIGHT.md file
2//
3// SPDX-License-Identifier: MIT
4
5#pragma once
6
7#include <functional>
8#include <map>
9#include <optional>
10#include <string>
11#include <utility>
12
13#include "discrete_space.hpp"
14
15namespace ddc {
16
17class ScopeGuard
18{
19 static void discretization_store_initialization()
20 {
21 detail::g_discretization_store
22 = std::make_optional<std::map<std::string, std::function<void()>>>();
23 }
24
25public:
27 {
28 discretization_store_initialization();
29 }
30
31 ScopeGuard([[maybe_unused]] int argc, [[maybe_unused]] char**& argv)
32 {
33 discretization_store_initialization();
34 }
35
36 ScopeGuard(ScopeGuard const& x) = delete;
37
38 ScopeGuard(ScopeGuard&& x) noexcept = delete;
39
40 ~ScopeGuard() noexcept
41 {
42 for (auto const& [name, fn] : *detail::g_discretization_store) {
43 fn();
44 }
45 detail::g_discretization_store.reset();
46 }
47
48 ScopeGuard& operator=(ScopeGuard const& x) = delete;
49
50 ScopeGuard& operator=(ScopeGuard&& x) noexcept = delete;
51};
52
53} // namespace ddc
ScopeGuard & operator=(ScopeGuard const &x)=delete
~ScopeGuard() noexcept
ScopeGuard(int argc, char **&argv)
ScopeGuard(ScopeGuard &&x) noexcept=delete
ScopeGuard & operator=(ScopeGuard &&x) noexcept=delete
ScopeGuard(ScopeGuard const &x)=delete
The top-level namespace of DDC.