DDC 0.0.0

a discrete domain computation library

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
17{
18 void discretization_store_initialization() const
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
Definition: scope_guard.hpp:17
ScopeGuard & operator=(ScopeGuard const &x)=delete
~ScopeGuard() noexcept
Definition: scope_guard.hpp:39
ScopeGuard(int argc, char **&argv)
Definition: scope_guard.hpp:30
ScopeGuard(ScopeGuard &&x) noexcept=delete
ScopeGuard & operator=(ScopeGuard &&x) noexcept=delete
ScopeGuard()
Definition: scope_guard.hpp:25
ScopeGuard(ScopeGuard const &x)=delete
The top-level namespace of DDC.
Definition: aligned_allocator.hpp:11