AI 24/25 Project Software
Documentation for the AI 24/25 course programming project software
Loading...
Searching...
No Matches
guards.h
1
2#ifndef PROBFD_UTILS_GUARDS_H
3#define PROBFD_UTILS_GUARDS_H
4
5#include <exception>
6#include <utility>
7
8namespace utils {
9class Timer;
10}
11
12namespace probfd {
13
14template <typename F>
15class scope_success {
16 F f_;
17
18public:
19 explicit scope_success(F&& f)
20 : f_(std::move(f))
21 {
22 }
23 ~scope_success()
24 {
25 if (!std::uncaught_exceptions()) f_();
26 }
27};
28
29template <typename F>
30class scope_fail {
31 F f_;
32
33public:
34 explicit scope_fail(F&& f)
35 : f_(std::move(f))
36 {
37 }
38 ~scope_fail()
39 {
40 if (std::uncaught_exceptions()) f_();
41 }
42};
43
44template <typename F>
45class scope_exit {
46 F f_;
47
48public:
49 explicit scope_exit(F&& f)
50 : f_(std::move(f))
51 {
52 }
53 ~scope_exit() { f_(); }
54};
55
56class TimerScope {
57 utils::Timer& timer_;
58
59public:
60 explicit TimerScope(utils::Timer& timer);
61 ~TimerScope();
62};
63
64} // namespace probfd
65
66#endif
The top-level namespace of probabilistic Fast Downward.
Definition command_line.h:8
STL namespace.