AGX Dynamics
2.38.0.2
OnScopeExit.h
Go to the documentation of this file.
1
/*
2
Copyright 2007-2024. Algoryx Simulation AB.
3
4
All AGX source code, intellectual property, documentation, sample code,
5
tutorials, scene files and technical white papers, are copyrighted, proprietary
6
and confidential material of Algoryx Simulation AB. You may not download, read,
7
store, distribute, publish, copy or otherwise disseminate, use or expose this
8
material unless having a written signed agreement with Algoryx Simulation AB, or
9
having been advised so by Algoryx Simulation AB for a time limited evaluation,
10
or having purchased a valid commercial license from Algoryx Simulation AB.
11
12
Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13
from using this software, unless otherwise stated in written agreements with
14
Algoryx Simulation AB.
15
*/
16
17
18
#pragma once
19
20
#include <
agx/Logger.h
>
21
#include <
agx/version.h
>
22
23
namespace
agxUtil
24
{
52
template
<
typename
Callback>
53
class
OnScopeExit
54
{
55
public
:
56
OnScopeExit
(Callback&& callback)
57
: m_callback(std::move(callback))
58
{
59
}
60
61
OnScopeExit
(
OnScopeExit
&& other)
62
: m_callback(std::move(other.m_callback))
63
{
64
}
65
66
OnScopeExit
(
const
OnScopeExit
&) =
delete
;
67
OnScopeExit
&
operator=
(
const
OnScopeExit
&) =
delete
;
68
69
~OnScopeExit
()
70
{
71
try
72
{
73
m_callback();
74
}
75
catch
(...)
76
{
77
// What would be a sane thing to do here? Exceptions should not escape destructors.
78
LOGGER_ERROR
() <<
"Exception thrown from a OnScopeExit callback. This is not allowed."
<<
LOGGER_ENDL
();
79
}
80
}
81
82
private
:
83
Callback m_callback;
84
};
85
86
template
<
typename
Callback>
87
OnScopeExit<Callback>
onScopeExit
(Callback&& callback)
88
{
89
return
OnScopeExit<Callback>
(std::forward<Callback>(callback));
90
}
91
}
agxUtil::OnScopeExit::~OnScopeExit
~OnScopeExit()
Definition:
OnScopeExit.h:69
LOGGER_ERROR
#define LOGGER_ERROR()
Definition:
Logger.h:22
agxUtil::OnScopeExit
Register a callback to be called at the end of the current scope.
Definition:
OnScopeExit.h:53
version.h
agxUtil::onScopeExit
OnScopeExit< Callback > onScopeExit(Callback &&callback)
Definition:
OnScopeExit.h:87
agxUtil::OnScopeExit::operator=
OnScopeExit & operator=(const OnScopeExit &)=delete
Logger.h
agxUtil::OnScopeExit::OnScopeExit
OnScopeExit(Callback &&callback)
Definition:
OnScopeExit.h:56
agxUtil::OnScopeExit::OnScopeExit
OnScopeExit(OnScopeExit &&other)
Definition:
OnScopeExit.h:61
LOGGER_ENDL
#define LOGGER_ENDL()
Definition:
Logger.h:27
agxUtil
The agxUtil namespace contain classes and methods for utility functionality.
Definition:
CylindricalJoint.h:20
include
agxUtil
OnScopeExit.h
Generated on Sun Sep 1 2024 11:18:51 for AGX Dynamics by
1.8.17