Ark Server API (ASA) - Wiki
Loading...
Searching...
No Matches
FilterCollection.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "CoreTypes.h"
6#include "Containers/Array.h"
7#include "Templates/SharedPointer.h"
8#include "Delegates/Delegate.h"
9#include "Misc/IFilter.h"
10
11/**
12 * A simple collection of Filters, with additional Filter specific functionality.
13 */
14template< typename ItemType >
17{
18public:
19
20 /**
21 * TFilterCollection destructor. Unregisters from all child filter changed delegates.
22 */
24 {
26 {
28
29 if ( Filter.IsValid() )
30 {
31 Filter->OnChanged().RemoveAll( this );
32 }
33 }
34 }
35
36 /**
37 * Adds the specified Filter to the collection
38 *
39 * @param Filter The filter object to add to the collection
40 * @return The index in the collection at which the filter was added
41 */
42 int32 Add( const TSharedPtr< IFilter< ItemType > >& Filter )
43 {
46 {
47 // The filter already exists, don't add a new one but return the index where it was found.
48 return ExistingIdx;
49 }
50
51 if( Filter.IsValid() )
52 {
54 }
55
58
59 return Result;
60 }
61
62 /**
63 * Removes as many instances of the specified Filter as there are in the collection
64 *
65 * @param Filter The filter object to remove from the collection
66 * @return The number of Filters removed from the collection
67 */
68 int32 Remove( const TSharedPtr< IFilter< ItemType > >& Filter )
69 {
70 if (Filter.IsValid())
71 {
72 Filter->OnChanged().RemoveAll(this);
73 }
74
76
77 // Don't broadcast if the collection didn't change
78 if (Result > 0)
79 {
81 }
82
83 return Result;
84 }
85
86 /**
87 * Gets the filter at the specified index
88 *
89 * @param Index The index of the requested filter in the ChildFilters array.
90 * @return Filter at the specified index
91 */
93 {
94 return ChildFilters[Index];
95 }
96
97 /** Returns the number of Filters in the collection */
98 FORCEINLINE int32 Num() const
99 {
100 return ChildFilters.Num();
101 }
102
103 /**
104 * Returns whether the specified Item passes all of the filters in the collection
105 *
106 * @param InItem The Item to check against all child filter restrictions
107 * @return Whether the Item passed all child filter restrictions
108 */
109 bool PassesAllFilters( ItemType InItem ) const
110 {
111 for (int Index = 0; Index < ChildFilters.Num(); Index++)
112 {
114 {
115 return false;
116 }
117 }
118
119 return true;
120 }
121
122 /** Broadcasts anytime the restrictions of any of the child Filters change */
123 DECLARE_EVENT( TFilterCollection<ItemType>, FChangedEvent );
124 FChangedEvent& OnChanged() { return ChangedEvent; }
125
126protected:
127
128 /**
129 * Called when a child Filter restrictions change and broadcasts the FilterChanged delegate
130 * for the collection
131 */
133 {
135 }
136
137 /** The array of child filters */
139
140 /** Fires whenever any filter in the collection changes */
141 FChangedEvent ChangedEvent;
142};
#define DECLARE_EVENT(OwningType, EventName)
#define FORCEINLINE
Definition Platform.h:644
FORCEINLINE int32 Num() const
TArray< TSharedPtr< IFilter< ItemType > > > ChildFilters
int32 Remove(const TSharedPtr< IFilter< ItemType > > &Filter)
FChangedEvent ChangedEvent
FChangedEvent & OnChanged()
TSharedPtr< IFilter< ItemType > > GetFilterAtIndex(int32 Index)
bool PassesAllFilters(ItemType InItem) const
int32 Add(const TSharedPtr< IFilter< ItemType > > &Filter)