Map::GetIfExists and Map::CheckValue

This commit is contained in:
Ricardo Luís Vaz Silva 2023-01-17 16:14:53 -03:00 committed by Christoph Oelckers
parent 0b9fdf2d99
commit decba68225
2 changed files with 158 additions and 16 deletions

View file

@ -142,11 +142,59 @@ template<typename M> void MapGetString(M * self,expand_types_vm<typename M::KeyT
}
}
template<typename M> expand_types_vm<typename M::ValueType> MapGetIfExists(M * self,expand_types_vm<typename M::KeyType> key)
{
typename M::ValueType * v = self->CheckKey(key);
if (v) {
return *v;
}
else
{
return {};
}
}
template<typename M> void MapGetIfExistsString(M * self,expand_types_vm<typename M::KeyType> key, FString &out)
{
FString * v = self->CheckKey(key);
if (v) {
out = *v;
}
else
{
out = FString();
}
}
template<typename M> int MapCheckKey(M * self, expand_types_vm<typename M::KeyType> key)
{
return self->CheckKey(key) != nullptr;
}
template<typename M> expand_types_vm<typename M::ValueType> MapCheckValue(M * self,expand_types_vm<typename M::KeyType> key, int * exists)
{
typename M::ValueType * v = self->CheckKey(key);
if ((*exists = !!v)) {
return *v;
}
else
{
return {};
}
}
template<typename M> void MapCheckValueString(M * self,expand_types_vm<typename M::KeyType> key, int * exists, FString &out)
{
FString * v = self->CheckKey(key);
if ((*exists = !!v)) {
out = *v;
}
else
{
out = FString();
}
}
//==========================================================================
//
@ -345,6 +393,19 @@ template<typename I> void MapIteratorSetValue(I * self, expand_types_vm<typename
PARAM_SELF_STRUCT_PROLOGUE( name ); \
PARAM_KEY( key ); \
ACTION_RETURN_VALUE( MapGet(self, key) ); \
} \
DEFINE_ACTION_FUNCTION_NATIVE( name, GetIfExists, MapGetIfExists< name >) \
{ \
PARAM_SELF_STRUCT_PROLOGUE( name ); \
PARAM_KEY( key ); \
ACTION_RETURN_VALUE( MapGetIfExists(self, key) ); \
} \
DEFINE_ACTION_FUNCTION_NATIVE( name, CheckValue, MapCheckValue< name >) \
{ \
PARAM_SELF_STRUCT_PROLOGUE( name ); \
PARAM_KEY( key ); \
PARAM_OUTPOINTER( exists, int); \
ACTION_RETURN_VALUE( MapCheckValue(self, key, exists) ); \
}
#define DEF_MAP_X_S( name, key_type, PARAM_KEY ) \
@ -356,6 +417,23 @@ template<typename I> void MapIteratorSetValue(I * self, expand_types_vm<typename
FString out; \
MapGetString(self, key, out); \
ACTION_RETURN_STRING( out ); \
} \
DEFINE_ACTION_FUNCTION_NATIVE( name, GetIfExists, MapGetIfExistsString< name >) \
{ \
PARAM_SELF_STRUCT_PROLOGUE( name ); \
PARAM_KEY( key ); \
FString out; \
MapGetIfExistsString(self, key, out); \
ACTION_RETURN_STRING( out ); \
} \
DEFINE_ACTION_FUNCTION_NATIVE( name, CheckValue, MapCheckValueString< name >) \
{ \
PARAM_SELF_STRUCT_PROLOGUE( name ); \
PARAM_KEY( key ); \
PARAM_OUTPOINTER( exists, int); \
FString out; \
MapCheckValueString(self, key, exists, out); \
ACTION_RETURN_STRING( out ); \
}
#define COMMA ,

View file

@ -9,7 +9,11 @@ struct Map_I32_I8 native
native int Get(int key);
native bool CheckKey(int key);
native void Insert(int key,int value);
native version("4.11") int GetIfExists(int key);
native version("4.11") int CheckValue(int key, out bool exists);
native void Insert(int key, int value);
native void InsertNew(int key);
native void Remove(int key);
}
@ -37,7 +41,11 @@ struct Map_I32_I16 native
native int Get(int key);
native bool CheckKey(int key);
native void Insert(int key,int value);
native version("4.11") int GetIfExists(int key);
native version("4.11") int CheckValue(int key, out bool exists);
native void Insert(int key, int value);
native void InsertNew(int key);
native void Remove(int key);
}
@ -65,7 +73,11 @@ struct Map_I32_I32 native
native int Get(int key);
native bool CheckKey(int key);
native void Insert(int key,int value);
native version("4.11") int GetIfExists(int key);
native version("4.11") int CheckValue(int key, out bool exists);
native void Insert(int key, int value);
native void InsertNew(int key);
native void Remove(int key);
}
@ -93,7 +105,11 @@ struct Map_I32_F32 native
native double Get(int key);
native bool CheckKey(int key);
native void Insert(int key,double value);
native version("4.11") double GetIfExists(int key);
native version("4.11") double CheckValue(int key, out bool exists);
native void Insert(int key, double value);
native void InsertNew(int key);
native void Remove(int key);
}
@ -121,7 +137,11 @@ struct Map_I32_F64 native
native double Get(int key);
native bool CheckKey(int key);
native void Insert(int key,double value);
native version("4.11") double GetIfExists(int key);
native version("4.11") double CheckValue(int key, out bool exists);
native void Insert(int key, double value);
native void InsertNew(int key);
native void Remove(int key);
}
@ -149,7 +169,11 @@ struct Map_I32_Obj native
native Object Get(int key);
native bool CheckKey(int key);
native void Insert(int key,Object value);
native version("4.11") Object GetIfExists(int key);
native version("4.11") Object CheckValue(int key, out bool exists);
native void Insert(int key, Object value);
native void InsertNew(int key);
native void Remove(int key);
}
@ -177,7 +201,11 @@ struct Map_I32_Ptr native
native voidptr Get(int key);
native bool CheckKey(int key);
native void Insert(int key,voidptr value);
native version("4.11") voidptr GetIfExists(int key);
native version("4.11") voidptr CheckValue(int key, out bool exists);
native void Insert(int key, voidptr value);
native void InsertNew(int key);
native void Remove(int key);
}
@ -202,7 +230,11 @@ struct Map_I32_Str native
native String Get(int key);
native bool CheckKey(int key);
native void Insert(int key,String value);
native version("4.11") String GetIfExists(int key);
native version("4.11") String CheckValue(int key, out bool exists);
native void Insert(int key, String value);
native void InsertNew(int key);
native void Remove(int key);
}
@ -232,7 +264,11 @@ struct Map_Str_I8 native
native int Get(String key);
native bool CheckKey(String key);
native void Insert(String key,int value);
native version("4.11") int GetIfExists(String key);
native version("4.11") int CheckValue(String key, out bool exists);
native void Insert(String key, int value);
native void InsertNew(String key);
native void Remove(String key);
}
@ -260,7 +296,11 @@ struct Map_Str_I16 native
native int Get(String key);
native bool CheckKey(String key);
native void Insert(String key,int value);
native version("4.11") int GetIfExists(String key);
native version("4.11") int CheckValue(String key, out bool exists);
native void Insert(String key, int value);
native void InsertNew(String key);
native void Remove(String key);
}
@ -288,7 +328,11 @@ struct Map_Str_I32 native
native int Get(String key);
native bool CheckKey(String key);
native void Insert(String key,int value);
native version("4.11") int GetIfExists(String key);
native version("4.11") int CheckValue(String key, out bool exists);
native void Insert(String key, int value);
native void InsertNew(String key);
native void Remove(String key);
}
@ -316,7 +360,11 @@ struct Map_Str_F32 native
native double Get(String key);
native bool CheckKey(String key);
native void Insert(String key,double value);
native version("4.11") double GetIfExists(String key);
native version("4.11") double CheckValue(String key, out bool exists);
native void Insert(String key, double value);
native void InsertNew(String key);
native void Remove(String key);
}
@ -344,7 +392,11 @@ struct Map_Str_F64 native
native double Get(String key);
native bool CheckKey(String key);
native void Insert(String key,double value);
native version("4.11") double GetIfExists(String key);
native version("4.11") double CheckValue(String key, out bool exists);
native void Insert(String key, double value);
native void InsertNew(String key);
native void Remove(String key);
}
@ -372,7 +424,11 @@ struct Map_Str_Obj native
native Object Get(String key);
native bool CheckKey(String key);
native void Insert(String key,Object value);
native version("4.11") Object GetIfExists(String key);
native version("4.11") Object CheckValue(String key, out bool exists);
native void Insert(String key, Object value);
native void InsertNew(String key);
native void Remove(String key);
}
@ -400,7 +456,11 @@ struct Map_Str_Ptr native
native voidptr Get(String key);
native bool CheckKey(String key);
native void Insert(String key,voidptr value);
native version("4.11") voidptr GetIfExists(String key);
native version("4.11") voidptr CheckValue(String key, out bool exists);
native void Insert(String key, voidptr value);
native void InsertNew(String key);
native void Remove(String key);
}
@ -428,7 +488,11 @@ struct Map_Str_Str native
native String Get(String key);
native bool CheckKey(String key);
native void Insert(String key,String value);
native version("4.11") String GetIfExists(String key);
native version("4.11") String CheckValue(String key, out bool exists);
native void Insert(String key, String value);
native void InsertNew(String key);
native void Remove(String key);
}