Botcraft
1.21.5
Loading...
Searching...
No Matches
ScopeLockedWrapper.hpp
Go to the documentation of this file.
1
#pragma once
2
3
#include <mutex>
4
5
namespace
Botcraft::Utilities
6
{
7
/// @brief Mutex protected reference, will be locked until destroyed
8
/// @tparam T Class to store
9
/// @tparam Mutex Mutex type to use
10
/// @tparam Lock Lock type to use
11
template
<
12
class
T,
13
class
Mutex = std::mutex,
14
template
<
class
...>
class
Lock
= std::scoped_lock
15
>
16
class
ScopeLockedWrapper
17
{
18
public
:
19
ScopeLockedWrapper
(T& val, Mutex& mutex) :
v
(val),
lock
(mutex) { }
20
21
T*
operator->
()
const
{
return
&
v
; }
22
T&
operator*
()
const
{
return
v
; }
23
private
:
24
T&
v
;
25
Lock<Mutex>
lock
;
26
};
27
}
Botcraft::Utilities::ScopeLockedWrapper
Mutex protected reference, will be locked until destroyed.
Definition
ScopeLockedWrapper.hpp:17
Botcraft::Utilities::ScopeLockedWrapper::v
T & v
Definition
ScopeLockedWrapper.hpp:24
Botcraft::Utilities::ScopeLockedWrapper::ScopeLockedWrapper
ScopeLockedWrapper(T &val, Mutex &mutex)
Definition
ScopeLockedWrapper.hpp:19
Botcraft::Utilities::ScopeLockedWrapper::operator->
T * operator->() const
Definition
ScopeLockedWrapper.hpp:21
Botcraft::Utilities::ScopeLockedWrapper::operator*
T & operator*() const
Definition
ScopeLockedWrapper.hpp:22
Botcraft::Utilities::ScopeLockedWrapper::lock
Lock< Mutex > lock
Definition
ScopeLockedWrapper.hpp:25
Botcraft::Utilities
Definition
DemanglingUtilities.hpp:8
ProtocolCraft::Components::DataComponentTypes::Lock
@ Lock
botcraft
include
botcraft
Utilities
ScopeLockedWrapper.hpp
Generated by
1.9.8