Routines to find exactly one

This commit is contained in:
2026-03-18 21:48:56 -04:00
parent ce7b8bc39a
commit a18cff3fc9
6 changed files with 80 additions and 47 deletions

View File

@@ -89,8 +89,33 @@ public:
return FormatName(std::forward<T>(Obj)).Equals(Name, ESearchCase::IgnoreCase);
}
// UEdGraphNode also matches by GUID.
static bool Identifies(const FString &Name, const UEdGraphNode* Node);
template<typename T>
static TArray<T*> FindAllNamed(const FString &Name, const TArray<T*> &Array)
{
TArray<T*> Result;
for (T* Elt : Array) if (Identifies(Name, Elt)) Result.Add(Elt);
return Result;
}
template<typename T>
T* FindExactlyOneNamed(const FString &Name, const TArray<T*> &Array)
{
int Count = 0;
T* Result = nullptr;
for (T* Elt : Array) if (Identifies(Name, Elt)) { Count++; Result = Elt; }
if (!CheckExactlyOneNamed(Count, T::StaticClass(), Name)) return nullptr;
return Result;
}
template<typename T>
bool FindExactlyNoneNamed(const FString &Name, const TArray<T*> &Array)
{
for (T* Elt: Array) if (Identifies(Name, Elt))
{
return CheckExactlyNoneNamed(1, T::StaticClass(), Name);
}
return true;
}
////////////////////////////////////////////////////////
@@ -117,7 +142,6 @@ public:
// ----- Blueprint helpers -----
static TArray<UEdGraph*> AllGraphs(UBlueprint* BP);
static TArray<UEdGraph*> AllGraphsNamed(UBlueprint* BP, const FString& Name);
static TArray<UEdGraphNode*> AllNodes(UBlueprint* BP);
template<class T> static TArray<T*> AllNodes(UBlueprint* BP)
{
@@ -136,6 +160,7 @@ public:
Result.Add(Typed);
return Result;
}
static bool SaveBlueprintPackage(UBlueprint* BP);
static UClass* FindClassByName(const FString& ClassName);
@@ -173,6 +198,12 @@ public:
static FString GetHandlerGroup(UClass* HandlerClass);
static void FormatCommandHelp(UClass* HandlerClass);
// ----- Common Error Reporting -----
bool CheckExactlyOneNamed(int Count, const FString &Kind, const FString &Name);
bool CheckExactlyOneNamed(int Count, UClass *Class, const FString &Name);
bool CheckExactlyNoneNamed(int Count, const FString &Kind, const FString &Name);
bool CheckExactlyNoneNamed(int Count, UClass *Class, const FString &Name);
private:
static void AppendNumericSuffix(FString &Name, int32 N);
};