虚幻引擎5
宏代码解决了从int32 Id数组中读取变量的问题
template< class T >
static bool IsArray(T A){return std::is_array<A>::value;}
template< class T >
static bool IsStruct(T A){return std::is_struct<A>::value;}
#define FORVALUE(Value, Field) bool Fv(){ \
bool B=false; \
if(UILbr::IsStruct(Value)){FString S=#Struct; B=S.Find(#Field)>-1; if(B){Value=Value.Field;}} \
bool B=UILbr::IsArray(Value) && Value.IsValidIndex(Id); \
if(B){Value=Value[Id];} \
return B; \
}
/* Library (Instance Variable Saver) */
UCLASS(BlueprintType) class IVS_API UILbr:public UBlueprintFunctionLibrary{GENERATED_UCLASS_BODY()
static TArray<FString> InStrings(FBlns V){return BlnsToStrs(V.V);}
static TArray<FString> InStrings(FBlnsA V){return BlnsAToStrs(V);}
static TArray<FString> InStrings(FBrss V){return BrssToStrs(V.V);}
static TArray<FString> InStrings(FBrssA V){return BrssAToStrs(V);}
template <typename A>
static TArray<FString> InStrings(A V){return {InString(V)};}
static FString InString(bool V){return BlnToStr(V);}
static FString InString(FBlns V){return V.ToString();}
static FString InString(FBlnsA V){return V.ToJson();}
static FString InString(FSlateBrush V){return BrsToStr(V);}
static FString InString(FBrss V){return V.ToString();}
static FString InString(FBrssA V){return V.ToJson();}
}
#define ISSI(T) TArray < FString > UV## T::InStringsIds_Implementation(FI32Ss Ids, bool & B) { \
int32 C = Ids.Num(); \
auto A = V; \
for (int32 & Id: Ids.V) { \
B = FORVALUE(A, V); \
if (B) { \
if (Id == C) { \
break; \
} \
} else { \
break; \
} \
} \
if (C == 0) { \
B = true; \
} \
return UILbr::InStrings(A); \
}
请更正代码FString S =#Struct; B = S,求(场)〉-1;如果(B){值=值字段;}
代码解决了从int32 Id数组读取变量的问题
template< class T >
static bool IsArray(T A){return std::is_array<A>::value;}
template< class T >
static bool IsStruct(T A){return std::is_struct<A>::value;}
template< class T, typename R >
static bool ForValue(T &A, R V, int32 Id){
if(UILbr::IsStruct(A)){A=A.V;} //structvar.member
bool B=UILbr::IsArray(A) && A.IsValidIndex(Id);
if(B){A=A[Id];}
return B;
}
#define ISSI(T) TArray < FString > UV## T::InStringsIds_Implementation(FI32Ss Ids, bool & B) {
int32 C = Ids.Num();
auto A = V;
for (int32 & Id: Ids.V) {
B = UILbr::ForValue(A, V, Id);
if (B) {
if (Id == C) {
break;
}
} else {
break;
}
}
if (C == 0) {
B = true;
}
return UILbr::InStrings(A);
}
最小化输入数据,使其更容易解决问题https://www.onlinegdb.com/online_c++_compiler
#include <iostream>
#include <type_traits>
using namespace std;
#define DETECTED_MEMBER(member_name, member_field) bool detected_member(member_name){return member_name.member_field? true: false;}
struct A{A(){}; float v;};
struct B{B(){}; int v;};
int main()
{
//---- true/false
cout<< "DETECTED_MEMBER B.v ? "
<< DETECTED_MEMBER(B,v) <<endl; //true
//---- true/false
cout<< "DETECTED_MEMBER A.v ? "
<< DETECTED_MEMBER(A,v) <<endl; //true
//---- true/false
cout<< "DETECTED_MEMBER A.w ? "
<< DETECTED_MEMBER(A,w) <<endl; //false
}
1条答案
按热度按时间mrzz3bfm1#