DDC 0.1.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
12#include "discrete_space.hpp"
13
14namespace ddc {
15
16class ScopeGuard
17{
18 static void discretization_store_initialization()
19 {
20 detail::g_discretization_store
21 = std::make_optional<std::map<std::string, std::function<void()>>>();
22 }
23
24public:
26 {
27 discretization_store_initialization();
28 }
29
30 ScopeGuard([[maybe_unused]] int argc, [[maybe_unused]] char**& argv)
31 {
32 discretization_store_initialization();
33 }
34
35 ScopeGuard(ScopeGuard const& x) = delete;
36
37 ScopeGuard(ScopeGuard&& x) noexcept = delete;
38
39 ~ScopeGuard() noexcept
40 {
41 for (auto const& [name, fn] : *detail::g_discretization_store) {
42 fn();
43 }
44 detail::g_discretization_store.reset();
45 }
46
47 ScopeGuard& operator=(ScopeGuard const& x) = delete;
48
49 ScopeGuard& operator=(ScopeGuard&& x) noexcept = delete;
50};
51
52} // 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.