45class RequestContext
final {
49 RequestContext(RequestContext&&)
noexcept;
51 RequestContext(
const RequestContext&) =
delete;
68 template <
typename Data>
74 template <
typename Data,
typename... Args>
76 USERVER_IMPL_LIFETIME_BOUND;
80 template <
typename Data>
85 template <
typename Data>
89 template <
typename Data>
91 )
noexcept USERVER_IMPL_LIFETIME_BOUND;
94 template <
typename Data>
96 )
const noexcept USERVER_IMPL_LIFETIME_BOUND;
99 template <
typename Data>
105 template <
typename Data>
106 [[deprecated(
"Use SetData with a typed tag instead")]] Data&
SetUserData(Data data);
110 template <
typename Data,
typename... Args>
111 [[deprecated(
"Use EmplaceData with a typed tag instead")]] Data&
EmplaceUserData(Args&&... args);
116 template <
typename Data>
117 [[deprecated(
"Use GetData with a typed tag instead")]] Data&
GetUserData();
122 template <
typename Data>
123 [[deprecated(
"Use GetData with a typed tag instead")]]
const Data&
GetUserData()
const;
127 template <
typename Data>
128 [[deprecated(
"Use GetDataOptional with a typed tag instead")]] std::remove_reference_t<Data>*
GetUserDataOptional();
132 template <
typename Data>
133 [[deprecated(
"Use GetDataOptional with a typed tag instead")]]
const std::remove_reference_t<Data>*
137 [[deprecated(
"Use EraseData with a typed tag instead")]]
void EraseUserData()
noexcept;
142 template <
typename Data>
143 [[deprecated(
"Use SetData with a typed tag instead")]] Data&
SetData(std::string name, Data data);
148 template <
typename Data,
typename... Args>
149 [[deprecated(
"Use EmplaceData with a typed tag instead")]] Data&
EmplaceData(std::string name, Args&&... args);
154 template <
typename Data>
155 [[deprecated(
"Use GetData with a typed tag instead")]] Data&
GetData(std::string_view name);
160 template <
typename Data>
161 [[deprecated(
"Use GetData with a typed tag instead")]]
const Data&
GetData(std::string_view name)
const;
165 template <
typename Data>
166 [[deprecated(
"Use GetDataOptional with a typed tag instead")]] std::remove_reference_t<Data>*
GetDataOptional(
167 std::string_view name
172 template <
typename Data>
173 [[deprecated(
"Use GetDataOptional with a typed tag instead")]]
const std::remove_reference_t<Data>*
GetDataOptional(
174 std::string_view name
178 [[deprecated(
"Use EraseData with a typed tag instead")]]
void EraseData(std::string_view name)
noexcept;
190 impl::InternalRequestContext& GetInternalContext()
noexcept;
197 utils::AnyMovable& SetUserAnyData(
utils::AnyMovable&& data);
198 utils::AnyMovable& GetUserAnyData();
199 utils::AnyMovable* GetUserAnyDataOptional()
noexcept;
200 void EraseUserAnyData()
noexcept;
202 utils::AnyMovable& SetAnyData(std::string&& name,
utils::AnyMovable&& data);
203 utils::AnyMovable& GetAnyData(std::string_view name);
204 utils::AnyMovable* GetAnyDataOptional(std::string_view name)
noexcept;
205 void EraseAnyData(std::string_view name)
noexcept;
210 static constexpr std::size_t kPimplSize = 120;
211 utils::FastPimpl<Impl, kPimplSize,
alignof(
void*)> impl_;
222 USERVER_IMPL_LIFETIME_BOUND {
223 auto& storage = GetStorageContext();
224 if (storage.GetOptional(tag)) {
225 throw std::runtime_error(
"Data for the tag is already stored in RequestContext");
227 return storage.Emplace(tag, std::forward<Args>(args)...);