Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
Actor Framework
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cpp-libs
Actor Framework
Commits
be17f214
Commit
be17f214
authored
Nov 06, 2012
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added a lightweight scope guard implementation
parent
0aa5c6c0
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
88 additions
and
0 deletions
+88
-0
cppa/util/scope_guard.hpp
cppa/util/scope_guard.hpp
+88
-0
No files found.
cppa/util/scope_guard.hpp
0 → 100644
View file @
be17f214
/******************************************************************************\
* ___ __ *
* /\_ \ __/\ \ *
* \//\ \ /\_\ \ \____ ___ _____ _____ __ *
* \ \ \ \/\ \ \ '__`\ /'___\/\ '__`\/\ '__`\ /'__`\ *
* \_\ \_\ \ \ \ \L\ \/\ \__/\ \ \L\ \ \ \L\ \/\ \L\.\_ *
* /\____\\ \_\ \_,__/\ \____\\ \ ,__/\ \ ,__/\ \__/.\_\ *
* \/____/ \/_/\/___/ \/____/ \ \ \/ \ \ \/ \/__/\/_/ *
* \ \_\ \ \_\ *
* \/_/ \/_/ *
* *
* Copyright (C) 2011, 2012 *
* Dominik Charousset <dominik.charousset@haw-hamburg.de> *
* *
* This file is part of libcppa. *
* libcppa is free software: you can redistribute it and/or modify it under *
* the terms of the GNU Lesser General Public License as published by the *
* Free Software Foundation, either version 3 of the License *
* or (at your option) any later version. *
* *
* libcppa is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with libcppa. If not, see <http://www.gnu.org/licenses/>. *
\******************************************************************************/
#ifndef CPPA_SCOPE_GUARD_HPP
#define CPPA_SCOPE_GUARD_HPP
#include <utility>
namespace
cppa
{
namespace
util
{
/**
* @brief A lightweight scope guard implementation.
*/
template
<
typename
Fun
>
class
scope_guard
{
scope_guard
()
=
delete
;
scope_guard
(
const
scope_guard
&
)
=
delete
;
scope_guard
&
operator
=
(
const
scope_guard
&
)
=
delete
;
public:
scope_guard
(
Fun
f
)
:
m_fun
(
std
::
move
(
f
)),
m_enabled
(
true
)
{
}
scope_guard
(
scope_guard
&&
other
)
:
m_fun
(
std
::
move
(
other
.
m_fun
)),
m_enabled
(
other
.
m_enabled
)
{
other
.
m_enabled
=
false
;
}
~
scope_guard
()
{
if
(
m_enabled
)
m_fun
();
}
/**
* @brief Disables this guard, i.e., the guard does not
* run its cleanup code as it goes out of scope.
*/
inline
void
disable
()
{
m_enabled
=
false
;
}
private:
Fun
m_fun
;
bool
m_enabled
;
};
/**
* @brief Creates a guard that executes @p f as soon as it
* goes out of scope.
* @relates scope_guard
*/
template
<
typename
Fun
>
scope_guard
<
Fun
>
make_scope_guard
(
Fun
f
)
{
return
{
std
::
move
(
f
)};
}
}
}
// namespace cppa::util
#endif // CPPA_SCOPE_GUARD_HPP
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment