// Copyright Epic Games, Inc. All Rights Reserved. #pragma once #include "CoreMinimal.h" #include "UObject/Class.h" #include "UObject/Field.h" #include "Templates/ChooseClass.h" #include "SubclassOf.h" // So we can construct uninitialized TNonNullSubclassOf enum class EDefaultConstructNonNullSubclassOf { UnsafeDoNotUse }; /** * Template to allow TClassType's to be passed around with type safety */ template class TNonNullSubclassOf: public TSubclassOf { public: using TClassType = typename TSubclassOf::TClassType; using TBaseType = typename TSubclassOf::TBaseType; /** Default Constructor, defaults to null */ FORCEINLINE TNonNullSubclassOf(EDefaultConstructNonNullSubclassOf): TSubclassOf(nullptr) {} /** Constructor that takes a UClass and does a runtime check to make sure this is a compatible class */ FORCEINLINE TNonNullSubclassOf(TClassType* From): TSubclassOf(From) { checkf(From, TEXT("Initializing TNonNullSubclassOf with null")); } /** Copy Constructor, will only compile if types are compatible */ template ((TClassA*)nullptr))> FORCEINLINE TNonNullSubclassOf(const TSubclassOf& From): TSubclassOf(From) {} /** Assignment operator, will only compile if types are compatible */ template ((TClassA*)nullptr))> FORCEINLINE TNonNullSubclassOf& operator=(const TSubclassOf& From) { checkf(*From, TEXT("Assigning null to TNonNullSubclassOf")); TSubclassOf::operator=(From); return *this; } /** Assignment operator from UClass, the type is checked on get not on set */ FORCEINLINE TNonNullSubclassOf& operator=(TClassType* From) { checkf(From, TEXT("Assigning null to TNonNullSubclassOf")); TSubclassOf::operator=(From); return *this; } };