UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
TypedElementQueryFunctions.inl
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#include <functional>
4#include <type_traits>
11
13{
14 namespace Private
15 {
16 template<typename T> concept FunctorType = requires{ &T::operator(); };
17
18 template<typename T>
20 {
22
23 static constexpr bool bIsValidQueryFunction = false;
25 };
26
27 template<typename Return, typename... Args>
28 struct TFunctionInfoImpl<Return(*)(Args...)>
29 {
30 using ArgumentInfo = TArgumentInfo<Args...>;
31
32 static constexpr bool bIsValidQueryFunction = true;
33 using ReturnType = Return;
34 };
35
36 template<typename Class, typename Return, typename... Args>
37 struct TFunctionInfoImpl<Return(Class::*)(Args...)>
38 {
39 using ArgumentInfo = TArgumentInfo<Args...>;
40
41 static constexpr bool bIsValidQueryFunction = true;
42 using ReturnType = Return;
43 };
44
45 template<typename Class, typename Return, typename... Args>
46 struct TFunctionInfoImpl<Return(Class::*)(Args...) const>
47 {
48 using ArgumentInfo = TArgumentInfo<Args...>;
49
50 static constexpr bool bIsValidQueryFunction = true;
51 using ReturnType = Return;
52 };
53
54 template<bool IsFunctor, typename FunctionType>
56
57 template<typename FunctionType>
59 {
60 using Type = TFunctionInfoImpl<decltype(&FunctionType::operator())>;
61 };
62
63 template<typename FunctionType>
69 template<typename FunctionType>
71 {
73
74 using ReturnType = typename Base::ReturnType;
75 using ArgumentInfo = typename Base::ArgumentInfo;
76 using ContextType = typename ArgumentInfo::ContextType;
77
78 static constexpr bool bIsValidQueryFunction =
79 Base::bIsValidQueryFunction &&
80 (ArgumentInfo::bIsSingle || ArgumentInfo::bIsBatch);
81 static constexpr bool bIsSingleRowProcessor = ArgumentInfo::bIsSingle;
82
83 template<typename RequestedReturnType>
84 static constexpr void StaticValidation()
85 {
86 static_assert(bIsValidQueryFunction, "The provided function is not compatible with a query callback. "
87 "One or more arguments are possibly incompatible.");
88
89 static_assert(ArgumentInfo::CountContexts() <= 1, "Only zero or one context can be added as an argument.");
90 static_assert(ArgumentInfo::CountFlowControls() <= 1, "Only zero or one flow control arguments can be added.");
91
92 if constexpr (std::is_same_v<RequestedReturnType, void>)
93 {
94 static_assert(ArgumentInfo::ResultIndex == INDEX_NONE,
95 "The query function being build has no return value and can't therefore accept a TResult.");
96 static_assert(std::is_same_v<ReturnType, void>,
97 "The return type of the provided query is expected to be void.");
98 }
99 else
100 {
101 if constexpr (bIsSingleRowProcessor)
102 {
103 if constexpr (ArgumentInfo::ResultIndex >= 0)
104 {
105 static_assert(ArgumentInfo::CountResults() == 1, "Only one TResult can be present.");
106 static_assert(std::is_same_v<typename ArgumentInfo::ResultType, RequestedReturnType>,
107 "The type used for TResult is not compatible with the result type expected for the query function.");
108 static_assert(std::is_same_v<ReturnType, void>,
109 "The return type of the provided query is expected to be void when a TResult is provided.");
110 }
111 else
112 {
113 static_assert(std::is_convertible_v<ReturnType, RequestedReturnType>,
114 "The type returned is not compatible with the result type expected for the query function.");
115 }
116 }
117 else
118 {
119 static_assert(ArgumentInfo::ResultIndex >= 0,
120 "Batch processing a function that expects a result it's required that a TResult is used.");
121 static_assert(ArgumentInfo::CountResults() == 1, "Only one TResult can be present.");
122 static_assert(std::is_same_v<typename ArgumentInfo::ResultType, RequestedReturnType>,
123 "The type used for TResult is not compatible with the result type expected for the query function.");
124 static_assert(std::is_same_v<ReturnType, void>,
125 "The return type of the provided query is expected to be void for batch processing functions.");
126 }
127 }
128 }
129
130 template<typename RequestedReturnType>
132 {
133 if constexpr (!std::is_same_v<void, ContextType>)
134 {
135 Result.Capabilities = IContextContract::SupportedCapabilitiesList<typename ContextType::Capabilities>();
136 }
137 Result.ConstColumnTypes = ArgumentInfo::ListConstColumns();
138 Result.MutableColumnTypes = ArgumentInfo::ListMutableColumns();
139 Result.bIsSingleRowProcessor = bIsSingleRowProcessor;
140 }
141 };
142
143 template<typename FunctionInfo, typename ArgumentInfo, typename ReturnType, typename FunctionType>
145 TResult<ReturnType>& QueryResult,
146 IContextContract& Contract,
149 FunctionType&& Callback)
150 {
151 using ArgumentList = typename ArgumentInfo::ArgumentList;
152
153 TConstArrayView<const UScriptStruct*> ConstColumnTypes = ArgumentInfo::ListConstColumns();
154 TConstArrayView<const UScriptStruct*> MutableColumnTypes = ArgumentInfo::ListMutableColumns();
155
156 const void** ConstColumnsData = static_cast<const void**>(FMemory_Alloca(sizeof(void*) * ConstColumnTypes.Num()));
157 void** MutableColumnsData = static_cast<void**>(FMemory_Alloca(sizeof(void*) * MutableColumnTypes.Num()));
158
160 TArrayView<void*> MutableColumns(MutableColumnsData, MutableColumnTypes.Num());
161
163
164 ArgumentList Arguments;
165 ArgumentInfo::SetResult(Arguments, QueryResult);
166 ArgumentInfo::SetContext(Arguments, Contract);
167 ArgumentInfo::SetFlowControl(Arguments, Flow);
168
169 do
170 {
171 Response.GetConstColumns(ConstColumns, ConstColumnTypes);
172 Response.GetMutableColumns(MutableColumns, MutableColumnTypes);
173
175 {
176 ArgumentInfo::SetConstColumns(Arguments, ConstColumns);
177 ArgumentInfo::SetMutableColumns(Arguments, MutableColumns);
178
179 if constexpr (FunctionInfo::bIsSingleRowProcessor)
180 {
181 do
182 {
183 if constexpr (ArgumentInfo::ResultIndex >= 0 || std::is_same_v<ReturnType, void>)
184 {
185 Arguments.ApplyBefore(Callback);
186 }
187 else
188 {
189 QueryResult.Add(Arguments.ApplyBefore(Callback));
190 }
191 ArgumentInfo::IncrementColumns(Arguments);
192 } while (Flow == EFlowControl::Continue && Response.NextRow());
193 }
194 else
195 {
196 Arguments.ApplyBefore(Callback);
197 }
198 }
199 else
200 {
201 break;
202 }
203 } while (Flow == EFlowControl::Continue && Response.NextBatch());
204 }
205 } // namespace Private
206
207 template<typename ReturnType>
208 template<EFunctionCallConfig Config>
210 {
212 {
214 {
215 bool bMissingColumn = false;
216 for (const void* Column : ConstColumns)
217 {
218 bMissingColumn = bMissingColumn || Column == nullptr;
219 }
220 for (void* Column : MutableColumns)
221 {
222 bMissingColumn = bMissingColumn || Column == nullptr;
223 }
224 return !bMissingColumn;
225 }
226 else
227 {
228 return true;
229 }
230 };
231
232 Function(Result, Contract, Response, Specialization);
233 }
234
235 template<typename Return, FunctionType Function>
237 {
239 using ArgumentInfo = typename FunctionInfo::ArgumentInfo;
240
242 FunctionInfo::template StaticValidation<Return>();
243 FunctionInfo::SetupResult(Result);
244
245 Result.Function =
246 [LocalCallback = Forward<Function>(Callback)](
247 TResult<Return>& QueryResult,
248 IContextContract& Contract,
251 {
252 Private::CallBody<FunctionInfo, ArgumentInfo, Return>(QueryResult, Contract, Response, Specialization, LocalCallback);
253 };
254 return Result;
255 }
256
257 template<typename Return, FunctionType Function>
259 {
261 using ArgumentInfo = typename FunctionInfo::ArgumentInfo;
262
264 FunctionInfo::template StaticValidation<Return>();
265 FunctionInfo::SetupResult(CompositedFunction);
266
267 Result.Function =
268 [&Result, LocalCallback = Forward<Function>(Callback)](
269 TResult<Return>& QueryResult,
270 IContextContract& Contract,
273 {
274 // Ignore QueryResult (which will always be a dummy for TQueryFunction<void>) in favor of the captured TResult.
275 Private::CallBody<FunctionInfo, ArgumentInfo, Return>(Result, Contract, Response, Specialization, LocalCallback);
276 };
277
278 return CompositedFunction;
279 }
280} // namespace UE::Editor::DataStorage::Queries
OODEFFUNC typedef void(OODLE_CALLBACK t_fp_OodleCore_Plugin_Free)(void *ptr)
@ INDEX_NONE
Definition CoreMiscDefines.h:150
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
constexpr bool EnumHasAnyFlags(Enum Flags, Enum Contains)
Definition EnumClassFlags.h:35
return true
Definition ExternalRpcRegistry.cpp:601
auto Response
Definition ExternalRpcRegistry.cpp:598
#define FMemory_Alloca(Size)
Definition GenericPlatformMemory.h:218
TConstArrayView< const UScriptStruct * > TConstArrayView< const UScriptStruct * >
Definition TypedElementQueryCapabilities.inl:16
Definition ArrayView.h:139
bool(*)(IQueryFunctionResponse &Response, TArrayView< const void * > ConstColumns, TArrayView< void * > MutableColumns) FunctionSpecializationCallback
Definition TypedElementQueryFunctions.h:50
void CallInternal(TResult< ReturnType > &Result, IContextContract &Contract, IQueryFunctionResponse &Response)
Definition TypedElementQueryFunctions.inl:209
Definition TypedElementQueryFunctions.h:73
Definition TypedElementQueryFunctions.h:39
Definition TypedElementQueryFunctionArguments.h:21
Definition TypedElementQueryFunctions.inl:16
Definition OverriddenPropertySet.cpp:45
void CallBody(TResult< ReturnType > &QueryResult, IContextContract &Contract, IQueryFunctionResponse &Response, typename TQueryFunction< ReturnType >::FunctionSpecializationCallback Specialization, FunctionType &&Callback)
Definition TypedElementQueryFunctions.inl:144
Definition Conditions.cpp:11
const UScriptStruct * Type(FTopLevelAssetPath Name)
Definition TypedElementQueryBuilder.cpp:15
EFlowControl
Definition TypedElementQueryFunctionArgumentTypes.h:32
TQueryFunction< Return > BuildQueryFunction(Function &&Callback)
Definition TypedElementQueryFunctions.inl:236
@ false
Definition radaudio_common.h:23
Definition TypedElementQueryContract.h:113
Definition TypedElementQueryFunctions.h:20
Definition TypedElementQueryFunctionArguments.h:190
Definition TypedElementQueryFunctions.inl:20
void ReturnType
Definition TypedElementQueryFunctions.inl:24
static constexpr bool bIsValidQueryFunction
Definition TypedElementQueryFunctions.inl:23
Definition TypedElementQueryFunctions.inl:55
Definition TypedElementQueryFunctions.inl:71
static constexpr void StaticValidation()
Definition TypedElementQueryFunctions.inl:84
typename Base::ReturnType ReturnType
Definition TypedElementQueryFunctions.inl:74
static constexpr void SetupResult(TQueryFunction< RequestedReturnType > &Result)
Definition TypedElementQueryFunctions.inl:131
static constexpr bool bIsValidQueryFunction
Definition TypedElementQueryFunctions.inl:78
typename Base::ArgumentInfo ArgumentInfo
Definition TypedElementQueryFunctions.inl:75
static constexpr bool bIsSingleRowProcessor
Definition TypedElementQueryFunctions.inl:81
TFunctionInfoSelection< FunctorType< FunctionType >, FunctionType >::Type Base
Definition TypedElementQueryFunctions.inl:72
Definition TypedElementQueryFunctionArgumentTypes.h:46
virtual void Add(ResultType ResultValue)=0