UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
TypedElementQueryContextImplementation.inl
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#include <type_traits>
4
6{
7 template<typename QueryContext, ContextCapability... SupportedCapabilities>
8 template<typename... TArgs>
13
14 template<typename QueryContext, ContextCapability... SupportedCapabilities>
15 template<ContextCapability RequestedCapability>
17 {
18 if constexpr (sizeof...(SupportedCapabilities) > 0)
19 {
20 return std::is_base_of_v<RequestedCapability, QueryContext> && (std::is_same_v<RequestedCapability, SupportedCapabilities> || ...);
21 }
22 else
23 {
24 return std::is_base_of_v<RequestedCapability, QueryContext>;
25 }
26 }
27
28 template<typename QueryContext, ContextCapability... SupportedCapabilities>
29 bool TQueryContextImpl<QueryContext, SupportedCapabilities...>::SupportsCapability(const FName& Capability)
30 {
31 if constexpr (sizeof...(SupportedCapabilities) > 0)
32 {
33 return IContextContract::SupportsCapability<QueryContext>(Capability) && ((SupportedCapabilities::Name == Capability) || ...);
34 }
35 else
36 {
37 return IContextContract::SupportsCapability<QueryContext>(Capability);
38 }
39 }
40
41 template<typename QueryContext, ContextCapability... SupportedCapabilities>
43 {
44 for (const FName& Capability : Capabilities)
45 {
46 if (!SupportsCapability(Capability))
47 {
48 return false;
49 }
50 }
51 return true;
52 }
53
54 // Use a macro for this since it's impossible to do with a template since the function pointer that would be needed might not exist.
55 // The macro also has the added benefit that it can print the function name for better reporting.
56#define CallFunction(Capability, ReturnValue, FunctionName, ...) \
57 if constexpr (SupportsCapability< Capability >()) \
58 { \
59 return Implementation.FunctionName( __VA_ARGS__ ); \
60 } \
61 else \
62 { \
63 checkf(false, TEXT("Function '" #FunctionName "' in capability '" #Capability"' is not supported by the current query context implementation.")); \
64 return ReturnValue {} ; \
65 }
66
67#define ArgTypeName(Type, Name) Type Name
68#define ArgName(Type, Name) Name
69
70#define FunctionCommon(ReturnType) \
71 template<typename QueryContext, ContextCapability... SupportedCapabilities> \
72 ReturnType TQueryContextImpl<QueryContext, SupportedCapabilities...>::
73
74#define Function0(Capability, Return, Function) \
75 FunctionCommon(Return) Function() \
76 { \
77 CallFunction(Capability, Return, Function ) \
78 }
79#define Function1(Capability, Return, Function, Arg1) \
80 FunctionCommon(Return) Function(ArgTypeName Arg1) \
81 { \
82 CallFunction(Capability, Return, Function, ArgName Arg1 ) \
83 }
84#define Function2(Capability, Return, Function, Arg1, Arg2) \
85 FunctionCommon(Return) Function(ArgTypeName Arg1, ArgTypeName Arg2) \
86 { \
87 CallFunction(Capability, Return, Function, ArgName Arg1, ArgName Arg2 ) \
88 }
89#define Function3(Capability, Return, Function, Arg1, Arg2, Arg3) \
90 FunctionCommon(Return) Function(ArgTypeName Arg1, ArgTypeName Arg2, ArgTypeName Arg3) \
91 { \
92 CallFunction(Capability, Return, Function, ArgName Arg1, ArgName Arg2, ArgName Arg3 ) \
93 }
94#define Function4(Capability, Return, Function, Arg1, Arg2, Arg3, Arg4) \
95 FunctionCommon(Return) Function(ArgTypeName Arg1, ArgTypeName Arg2, ArgTypeName Arg3, ArgTypeName Arg4) \
96 { \
97 CallFunction(Capability, Return, Function, ArgName Arg1, ArgName Arg2, ArgName Arg3, ArgName Arg4 ) \
98 }
99
100#define ConstFunction0(Capability, Return, Function) \
101 FunctionCommon(Return) Function() const \
102 { \
103 CallFunction(Capability, Return, Function ) \
104 }
105#define ConstFunction1(Capability, Return, Function, Arg1) \
106 FunctionCommon(Return) Function(ArgTypeName Arg1) const \
107 { \
108 CallFunction(Capability, Return, Function, ArgName Arg1 ) \
109 }
110#define ConstFunction2(Capability, Return, Function, Arg1, Arg2) \
111 FunctionCommon(Return) Function(ArgTypeName Arg1, ArgTypeName Arg2) const \
112 { \
113 CallFunction(Capability, Return, Function, ArgName Arg1, ArgName Arg2 ) \
114 }
115#define ConstFunction3(Capability, Return, Function, Arg1, Arg2, Arg3) \
116 FunctionCommon(Return) Function(ArgTypeName Arg1, ArgTypeName Arg2, ArgTypeName Arg3) const \
117 { \
118 CallFunction(Capability, Return, Function, ArgName Arg1, ArgName Arg2, ArgName Arg3 ) \
119 }
120#define ConstFunction4(Capability, Return, Function, Arg1, Arg2, Arg3, Arg4) \
121 FunctionCommon(Return) Function(ArgTypeName Arg1, ArgTypeName Arg2, ArgTypeName Arg3, ArgTypeName Arg4) const \
122 { \
123 CallFunction(Capability, Return, Function, ArgName Arg1, ArgName Arg2, ArgName Arg3, ArgName Arg4 ) \
124 }
125
126#define CapabilityStart(Capability, Flags)
127#define CapabilityEnd(Capability)
128
130
131#undef ArgTypeName
132#undef ArgName
133#undef FunctionCommon
134#undef Function0
135#undef Function1
136#undef Function2
137#undef Function3
138#undef Function4
139#undef ConstFunction0
140#undef ConstFunction1
141#undef ConstFunction2
142#undef ConstFunction3
143#undef ConstFunction4
144#undef CapabilityStart
145#undef CapabilityEnd
146#undef CallFunction
147
148 //
149 // Generic access
150 //
151
152 template<typename QueryContext, ContextCapability... SupportedCapabilities>
153 template<typename ReturnType>
155 {
156 bool Result = true;
157 for (const FName& Capability : Function.Capabilities)
158 {
159 if (!SupportsCapability(Capability))
160 {
161 Result = false;
162 checkf(false, TEXT("Requested query context '%s' is not supported by query context implementation."),
163 *Capability.ToString());
164 }
165 }
166 return Result;
167 }
168
169 template<typename QueryContext, ContextCapability... SupportedCapabilities>
171 {
172 return Implementation;
173 }
174
175 template<typename QueryContext, ContextCapability... SupportedCapabilities>
180}
181// namespace UE::Editor::DataStorage::Queries
#define checkf(expr, format,...)
Definition AssertionMacros.h:315
#define TEXT(x)
Definition Platform.h:1272
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
Definition NameTypes.h:617
Definition TypedElementQueryContextImplementation.h:42
TQueryContextImpl(TArgs &&... Args)
Definition TypedElementQueryContextImplementation.inl:9
const ImplementationType & GetContextImplementation() const
Definition TypedElementQueryContextImplementation.inl:170
bool CheckCompatiblity(const TQueryFunction< ReturnType > &Function) const
Definition TypedElementQueryContextImplementation.inl:154
static bool SupportsCapabilities(TConstArrayView< FName > Capabilities)
Definition TypedElementQueryContextImplementation.inl:42
Definition TypedElementQueryFunctions.h:73
Definition TypedElementQueryContext.h:14
Definition Conditions.cpp:11