UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
TypedElementAttributeBinding.inl
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
7
9{
10 //
11 // FAttributeBinder
12 //
13
14 template <typename AttributeType, TDataColumnType ColumnType>
15 TAttribute<AttributeType> FAttributeBinder::BindData(AttributeType ColumnType::* InVariable, const AttributeType& InDefaultValue)
16 {
17 using namespace DataStorage::Private;
18
19 if(DataStorage)
20 {
21 // Create a direct property and bind it to the given variable
23 Prop.Bind(InVariable);
24
25 // We don't want any references to this in the lambda because binders are designed to be used and destructed on the stack
26 return TAttribute<AttributeType>::CreateLambda([Property = MoveTemp(Prop), Storage = DataStorage, Row = TargetRow,
27 DefaultValue = InDefaultValue]()
28 {
29 // Get the column from the given row and use that to return the stored property
30 if(ColumnType* Column = GetColumn<ColumnType>(Storage, Row))
31 {
32 return Property.Get(Column, ColumnType::StaticStruct());
33 }
34 return DefaultValue;
35 });
36 }
38 }
39
40 template <typename AttributeType, TDynamicColumnTemplate ColumnType>
41 TAttribute<AttributeType> FAttributeBinder::BindData(const FName& InIdentifier, AttributeType ColumnType::* InVariable, const AttributeType& InDefaultValue)
42 {
43 using namespace DataStorage::Private;
44
45 if(DataStorage)
46 {
47 // Create a direct property and bind it to the given variable
49 Prop.Bind(InVariable);
50
51 // We don't want any references to this in the lambda because binders are designed to be used and destructed on the stack
52 return TAttribute<AttributeType>::CreateLambda([Property = MoveTemp(Prop), Storage = DataStorage, Row = TargetRow,
53 DefaultValue = InDefaultValue, Identifier = InIdentifier]()
54 {
55 // Get the column from the given row and use that to return the stored property
56 if(ColumnType* Column = GetColumn<ColumnType>(Storage, Row, Identifier))
57 {
58 return Property.Get(Column, ColumnType::StaticStruct());
59 }
60 return DefaultValue;
61 });
62 }
64 }
65
66 template <typename AttributeType, typename DataType, TDataColumnType ColumnType>
67 TAttribute<AttributeType> FAttributeBinder::BindData(DataType ColumnType::* InVariable, TFunction<AttributeType(const DataType&)> InConverter, const DataType& InDefaultValue)
68 {
69 using namespace DataStorage::Private;
70
71 if(DataStorage)
72 {
74
75 // Create a convertible property and bind it to the given variable
77 Prop.Bind(InVariable, MoveTemp(InConverter));
78
80 [
81 Property = MoveTemp(Prop),
82 Storage = DataStorage,
83 Row = TargetRow,
84 DefaultValue = InDefaultValue,
86 ]()
87 {
88 if(ColumnType* Column = GetColumn<ColumnType>(Storage, Row))
89 {
90 return Property.Get(Column, ColumnType::StaticStruct());
91 }
92
93 return ConvertedDefault;
94 });
95 }
97 }
98
99 template <typename AttributeType, typename DataType, TDynamicColumnTemplate ColumnType>
101 TFunction<AttributeType(const DataType&)> InConverter, const DataType& InDefaultValue)
102 {
103 using namespace DataStorage::Private;
104
105 if(DataStorage)
106 {
108
109 // Create a convertible property and bind it to the given variable
111 Prop.Bind(InVariable, MoveTemp(InConverter));
112
114 [
115 Property = MoveTemp(Prop),
116 Storage = DataStorage,
117 Row = TargetRow,
118 DefaultValue = InDefaultValue,
121 ]()
122 {
123 if(ColumnType* Column = GetColumn<ColumnType>(Storage, Row, Identifier))
124 {
125 return Property.Get(Column, ColumnType::StaticStruct());
126 }
127
128 return ConvertedDefault;
129 });
130 }
132 }
133
134 template <typename DataType, TDataColumnType ColumnType, typename FunctionType>
136 auto FAttributeBinder::BindData(DataType ColumnType::* InVariable, FunctionType&& InConverter, const DataType& InDefaultValue)
137 {
138 // Deduce the attribute type from the return value of the converter function
139 using AttributeType = decltype(InConverter(std::declval<DataType>()));
140
142 }
143
144 template <typename DataType, TDynamicColumnTemplate ColumnType, typename FunctionType>
146 auto FAttributeBinder::BindData(const FName& InIdentifier, DataType ColumnType::* InVariable, FunctionType&& InConverter, const DataType& InDefaultValue)
147 {
148 // Deduce the attribute type from the return value of the converter function
149 using AttributeType = decltype(InConverter(std::declval<DataType>()));
150
152 }
153
154 template <typename AttributeType, TDataColumnType ColumnType>
156 {
157 if(DataStorage)
158 {
160 [
162 Storage = DataStorage,
163 Row = TargetRow
164 ]()
165 {
166 if(ColumnType* Column = Storage->GetColumn<ColumnType>(Row))
167 {
168 return Convertor(*Column);
169 }
170
171 return AttributeType();
172 });
173 }
175 }
176
177 template <TDataColumnType ColumnType, typename FunctionType>
180 {
181 // Deduce the attribute type from the return value of the converter function
182 using AttributeType = decltype(InConverter(std::declval<const ColumnType&>()));
183
184 return BindColumn<AttributeType, ColumnType>(TFunction<AttributeType(const ColumnType&)>(InConverter));
185 }
186
187 template <typename AttributeType>
189 const TFunction<AttributeType(const TWeakObjectPtr<const UScriptStruct>&, const void*)>& InConverter)
190 {
191 if(DataStorage)
192 {
194 [
195 ColumnType = InColumnType,
197 Storage = DataStorage,
198 Row = TargetRow
199 ]()
200 {
201 if(const void* ColumnData = Storage->GetColumnData(Row, ColumnType.Get()))
202 {
203 return Convertor(ColumnType, ColumnData);
204 }
205
206 return AttributeType();
207 });
208 }
210 }
211
212 template <typename FunctionType>
215 {
216 // Deduce the attribute type from the return value of the converter function
217 using AttributeType = decltype(InConverter(std::declval<const TWeakObjectPtr<const UScriptStruct>&>(), std::declval<const void*>()));
218
220 TFunction<AttributeType(const TWeakObjectPtr<const UScriptStruct>&, const void*)>(InConverter));
221 }
222
223 template <typename InRetValType, typename... ParamTypes, TDataColumnType ColumnType>
225 {
226 using namespace DataStorage::Private;
227
228 // Create a property for the delegate
229 TProperty<TDelegate<InRetValType(ParamTypes...)>> Prop;
230 Prop.Bind(InVariable);
231
232 return TDelegate<InRetValType(ParamTypes...)>::CreateLambda([Property = MoveTemp(Prop), Storage = DataStorage,
233 Row = TargetRow](ParamTypes&&... Params)
234 {
235 if(ColumnType* Column = GetColumn<ColumnType>(Storage, Row))
236 {
237 // Get the delegate in the bound column for the specified row
238 TDelegate<InRetValType(ParamTypes...)> Delegate = Property.Get(Column, ColumnType::StaticStruct());
239
240 // Execute the delegate if it is bound
241 if(Delegate.IsBound())
242 {
243 return Delegate.Execute(Forward<ParamTypes>(Params)...);
244 }
245 }
246 return InRetValType();
247 });
248 }
249
250 template <typename InRetValType, typename... ParamTypes, TDynamicColumnTemplate ColumnType>
252 {
253 using namespace DataStorage::Private;
254
255 // Create a property for the delegate
256 TProperty<TDelegate<InRetValType(ParamTypes...)>> Prop;
257 Prop.Bind(InVariable);
258
259 return TDelegate<InRetValType(ParamTypes...)>::CreateLambda([Property = MoveTemp(Prop), Storage = DataStorage,
260 Row = TargetRow, Identifier = InIdentifier](ParamTypes&&... Params)
261 {
262 if(ColumnType* Column = GetColumn<ColumnType>(Storage, Row, Identifier))
263 {
264 // Get the delegate in the bound column for the specified row
265 TDelegate<InRetValType(ParamTypes...)> Delegate = Property.Get(Column, ColumnType::StaticStruct());
266
267 // Execute the delegate if it is bound
268 if(Delegate.IsBound())
269 {
270 return Delegate.Execute(Forward<ParamTypes>(Params)...);
271 }
272 }
273 return InRetValType();
274 });
275 }
276
277 template <TDataColumnType ColumnType>
279 {
280 return BindData(InFStringVariable, [](const FString& InString)
281 {
283 }, FString());
284 }
285
286 template <TDynamicColumnTemplate ColumnType>
288 {
289 return BindData(InIdentifier, InFStringVariable, [](const FString& InString)
290 {
292 }, FString());
293 }
294
295 template <TDataColumnType ColumnType>
297 {
298 return BindData(InFNameVariable, [](const FName& InName)
299 {
300 return FText::FromName(InName);
301 }, FName());
302 }
303
304 template <TDynamicColumnTemplate ColumnType>
306 {
307 return BindData(InIdentifier, InFNameVariable, [](const FName& InName)
308 {
309 return FText::FromName(InName);
310 }, FName());
311 }
312
313} // namespace UE::Editor::DataStorage
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
UE_INTRINSIC_CAST UE_REWRITE constexpr std::remove_reference_t< T > && MoveTemp(T &&Obj) noexcept
Definition UnrealTemplate.h:520
Definition NameTypes.h:617
static CORE_API FText FromString(const ANSICHAR *String)
Definition Text.cpp:1081
static CORE_API FText FromName(const FName &Val)
Definition Text.cpp:1076
Definition Attribute.h:17
static UE_FORCEINLINE_HINT TAttribute CreateLambda(LambdaType &&InCallable, PayloadTypes &&... InputPayload)
Definition Attribute.h:155
Definition DelegateSignatureImpl.inl:310
Definition AndroidPlatformMisc.h:14
Definition UnrealType.h:1538
TAttribute< AttributeType > BindColumn(TFunction< AttributeType(const ColumnType &)> InConverter)
Definition TypedElementAttributeBinding.inl:155
TAttribute< AttributeType > BindData(AttributeType ColumnType::*InVariable, const AttributeType &InDefaultValue=AttributeType())
Definition TypedElementAttributeBinding.inl:15
TAttribute< FText > BindText(FString ColumnType::*InFStringVariable)
Definition TypedElementAttributeBinding.inl:278
TDelegate< InRetValType(ParamTypes...)> BindEvent(TDelegate< InRetValType(ParamTypes...)> ColumnType::*InVariable)
Definition TypedElementAttributeBinding.inl:224
TAttribute< AttributeType > BindColumnData(const TWeakObjectPtr< const UScriptStruct > &InColumnType, const TFunction< AttributeType(const TWeakObjectPtr< const UScriptStruct > &, const void *)> &InConverter)
Definition TypedElementAttributeBinding.inl:188
Definition TypedElementAttributeBindingProperty.h:25
Definition TypedElementAttributeBindingProperty.h:21
Definition TypedElementAttributeBindingProperty.h:17
Definition CommonTypes.h:95
Definition CommonTypes.cpp:10
Definition WeakObjectPtrTemplates.h:25