userver
C++ Async Framework
Toggle main menu visibility
Loading...
Searching...
No Matches
inherited_variable.hpp
Go to the documentation of this file.
1
#pragma once
2
5
6
#include <type_traits>
7
#include <utility>
8
9
#include <userver/engine/impl/task_local_storage.hpp>
10
#include <
userver/engine/task/inherited_variable_options.hpp
>
11
12
USERVER_NAMESPACE_BEGIN
13
14
namespace
engine
{
15
27
template
<
typename
T>
28
class
TaskInheritedVariable
final {
29
static_assert
(!std::is_reference_v<T>);
30
static_assert
(!std::is_const_v<T>);
31
32
public
:
34
TaskInheritedVariable
()
35
:
TaskInheritedVariable
(
TaskInheritedVariablePriority
::
kNormal
)
36
{}
37
39
explicit
TaskInheritedVariable
(
TaskInheritedVariablePriority
priority)
40
: impl_(priority)
41
{}
42
45
const
T*
GetOptional
() const noexcept {
return
Storage().GetOptional<T, kVariableKind>(impl_.GetKey()); }
46
49
const
T&
Get
()
const
{
return
Storage().Get<T, kVariableKind>(impl_.GetKey()); }
50
52
template
<
typename
... Args>
53
void
Emplace
(Args&&... args) {
54
Storage().Emplace<T, kVariableKind>(impl_.GetKey(), std::forward<Args>(args)...);
55
}
56
58
void
Set
(T&& value) {
Emplace
(std::move(value)); }
59
61
void
Set
(
const
T& value) {
Emplace
(value); }
62
66
void
Erase
() { Storage().Erase<T, kVariableKind>(impl_.GetKey()); }
67
68
private
:
69
static
constexpr
auto
kVariableKind = impl::task_local::VariableKind::kInherited;
70
71
static
impl::task_local::Storage& Storage() noexcept {
return
impl::task_local::GetCurrentStorage(); }
72
73
impl::task_local::Variable impl_;
74
};
75
76
}
// namespace engine
77
78
USERVER_NAMESPACE_END
userver
engine
task
inherited_variable.hpp
Generated on
for userver by
Doxygen
1.17.0