Ark Server API (ASA) - Wiki
Loading...
Searching...
No Matches
TextFilter.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2#pragma once
3
4#include "CoreTypes.h"
5#include "HAL/PlatformAtomics.h"
6#include "Misc/AssertionMacros.h"
7#include "Templates/RemoveReference.h"
8#include "Containers/Array.h"
9#include "Containers/UnrealString.h"
10#include "Templates/SharedPointer.h"
11#include "Delegates/Delegate.h"
12#include "Internationalization/Text.h"
13#include "Misc/TextFilterExpressionEvaluator.h"
14#include "Misc/IFilter.h"
15
16/**
17 * A generic filter specialized for text restrictions
18 */
19template< typename ItemType >
20class TTextFilter : public IFilter< ItemType >, public TSharedFromThis< TTextFilter< ItemType > >
21{
22public:
23
24 /** Defines a function signature for functions used to transform an Item into an array of FStrings */
25 DECLARE_DELEGATE_TwoParams( FItemToStringArray, ItemType, OUT TArray< FString >& );
26
27 /** Defines a function signature used to test a complex expression for an Item */
28 DECLARE_DELEGATE_RetVal_FiveParams( bool, FItemTestComplexExpression, ItemType, const FName& /*InKey*/, const FTextFilterString& /*InValue*/, ETextFilterComparisonOperation /*InComparisonOperation*/, ETextFilterTextComparisonMode /*InTextComparisonMode*/ );
29
30 /**
31 * TTextFilter Constructor
32 *
33 * @param InTransform A required delegate used to populate an array of strings based on an Item
34 */
35 TTextFilter( FItemToStringArray InTransformDelegate )
38 {
40 }
41
42 TTextFilter( FItemToStringArray InTransformDelegate, FItemTestComplexExpression InTestComplexExpressionDelegate )
45 {
48 }
49
50 DECLARE_DERIVED_EVENT(TTextFilter, IFilter<ItemType>::FChangedEvent, FChangedEvent);
51 virtual FChangedEvent& OnChanged() override { return ChangedEvent; }
52
53 /**
54 * Returns whether the specified Item passes the Filter's text restrictions
55 *
56 * @param InItem The Item to check
57 * @return Whether the specified Item passed the filter
58 */
59 virtual bool PassesFilter( ItemType InItem ) const override
60 {
62 {
63 return true;
64 }
65
69 return bResult;
70 }
71
72 /** Returns the unsanitized and unsplit filter terms */
74 {
76 }
77
78 /** Set the Text to be used as the Filter's restrictions */
79 void SetRawFilterText( const FText& InFilterText )
80 {
82 {
84 }
85 }
86
87 /** Get the last error returned from lexing or compiling the current filter text */
89 {
91 }
92
93private:
94
96 {
97 public:
98 typedef typename TRemoveReference<ItemType>::Type* ItemTypePtr;
99
100 FTextFilterExpressionContext(const FItemToStringArray& InTransformArrayDelegate, const FItemTestComplexExpression& InTestComplexExpressionDelegate)
103 , ItemPtr(nullptr)
104 {
105 }
106
107 void SetItem(ItemTypePtr InItem)
108 {
109 ItemPtr = InItem;
111 }
112
114 {
115 ItemPtr = nullptr;
117 }
118
119 virtual bool TestBasicStringExpression(const FTextFilterString& InValue, const ETextFilterTextComparisonMode InTextComparisonMode) const override
120 {
122 {
124 {
125 return true;
126 }
127 }
128 return false;
129 }
130
131 virtual bool TestComplexExpression(const FName& InKey, const FTextFilterString& InValue, const ETextFilterComparisonOperation InComparisonOperation, const ETextFilterTextComparisonMode InTextComparisonMode) const override
132 {
134 {
136 }
137 return false;
138 }
139
140 private:
141 /** The delegate used to transform an item into an array of strings */
142 FItemToStringArray TransformArrayDelegate;
143
144 /** The delegate used to test a complex expression for an item */
145 FItemTestComplexExpression TestComplexExpressionDelegate;
146
147 /** Pointer to the item we're currently filtering */
149
150 /** The strings extracted from the item we're currently filtering */
152 };
153
154 /** Transient context data, used when calling PassesFilter. Kept around to minimize re-allocations between multiple calls to PassesFilter */
156
157 /** Expression evaluator that can be used to perform complex text filter queries */
159
160 /** The event that fires whenever new search terms are provided */
161 FChangedEvent ChangedEvent;
162};
#define check(expr)
#define DECLARE_DERIVED_EVENT(OwningType, BaseTypeEvent, EventName)
Definition Delegate.h:231
#define DECLARE_DELEGATE_RetVal_FiveParams(ReturnValueType, DelegateName, Param1Type, Param2Type, Param3Type, Param4Type, Param5Type)
#define DECLARE_DELEGATE_TwoParams(DelegateName, Param1Type, Param2Type)
#define OUT
Definition Platform.h:777
ETextFilterTextComparisonMode
ETextFilterComparisonOperation
Definition Text.h:357
FTextFilterExpressionContext(const FItemToStringArray &InTransformArrayDelegate, const FItemTestComplexExpression &InTestComplexExpressionDelegate)
Definition TextFilter.h:100
virtual bool TestBasicStringExpression(const FTextFilterString &InValue, const ETextFilterTextComparisonMode InTextComparisonMode) const override
Definition TextFilter.h:119
FItemTestComplexExpression TestComplexExpressionDelegate
Definition TextFilter.h:145
virtual bool TestComplexExpression(const FName &InKey, const FTextFilterString &InValue, const ETextFilterComparisonOperation InComparisonOperation, const ETextFilterTextComparisonMode InTextComparisonMode) const override
Definition TextFilter.h:131
TRemoveReference< ItemType >::Type * ItemTypePtr
Definition TextFilter.h:98
virtual bool PassesFilter(ItemType InItem) const override
Definition TextFilter.h:59
TTextFilter(FItemToStringArray InTransformDelegate)
Definition TextFilter.h:35
virtual FChangedEvent & OnChanged() override
Definition TextFilter.h:51
void SetRawFilterText(const FText &InFilterText)
Definition TextFilter.h:79
FTextFilterExpressionContext TextFilterExpressionContext
Definition TextFilter.h:155
FChangedEvent ChangedEvent
Definition TextFilter.h:161
TTextFilter(FItemToStringArray InTransformDelegate, FItemTestComplexExpression InTestComplexExpressionDelegate)
Definition TextFilter.h:42
FText GetRawFilterText() const
Definition TextFilter.h:73
FText GetFilterErrorText() const
Definition TextFilter.h:88
FTextFilterExpressionEvaluator TextFilterExpressionEvaluator
Definition TextFilter.h:158