mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-11-25 13:31:37 +00:00
Map::GetIfExists and Map::CheckValue
This commit is contained in:
parent
0b9fdf2d99
commit
decba68225
2 changed files with 158 additions and 16 deletions
|
@ -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)
|
template<typename M> int MapCheckKey(M * self, expand_types_vm<typename M::KeyType> key)
|
||||||
{
|
{
|
||||||
return self->CheckKey(key) != nullptr;
|
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_SELF_STRUCT_PROLOGUE( name ); \
|
||||||
PARAM_KEY( key ); \
|
PARAM_KEY( key ); \
|
||||||
ACTION_RETURN_VALUE( MapGet(self, 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 ) \
|
#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; \
|
FString out; \
|
||||||
MapGetString(self, key, out); \
|
MapGetString(self, key, out); \
|
||||||
ACTION_RETURN_STRING( 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 ,
|
#define COMMA ,
|
||||||
|
|
|
@ -9,6 +9,10 @@ struct Map_I32_I8 native
|
||||||
|
|
||||||
native int Get(int key);
|
native int Get(int key);
|
||||||
native bool CheckKey(int key);
|
native bool CheckKey(int key);
|
||||||
|
|
||||||
|
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 Insert(int key, int value);
|
||||||
native void InsertNew(int key);
|
native void InsertNew(int key);
|
||||||
native void Remove(int key);
|
native void Remove(int key);
|
||||||
|
@ -37,6 +41,10 @@ struct Map_I32_I16 native
|
||||||
|
|
||||||
native int Get(int key);
|
native int Get(int key);
|
||||||
native bool CheckKey(int key);
|
native bool CheckKey(int key);
|
||||||
|
|
||||||
|
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 Insert(int key, int value);
|
||||||
native void InsertNew(int key);
|
native void InsertNew(int key);
|
||||||
native void Remove(int key);
|
native void Remove(int key);
|
||||||
|
@ -65,6 +73,10 @@ struct Map_I32_I32 native
|
||||||
|
|
||||||
native int Get(int key);
|
native int Get(int key);
|
||||||
native bool CheckKey(int key);
|
native bool CheckKey(int key);
|
||||||
|
|
||||||
|
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 Insert(int key, int value);
|
||||||
native void InsertNew(int key);
|
native void InsertNew(int key);
|
||||||
native void Remove(int key);
|
native void Remove(int key);
|
||||||
|
@ -93,6 +105,10 @@ struct Map_I32_F32 native
|
||||||
|
|
||||||
native double Get(int key);
|
native double Get(int key);
|
||||||
native bool CheckKey(int key);
|
native bool CheckKey(int key);
|
||||||
|
|
||||||
|
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 Insert(int key, double value);
|
||||||
native void InsertNew(int key);
|
native void InsertNew(int key);
|
||||||
native void Remove(int key);
|
native void Remove(int key);
|
||||||
|
@ -121,6 +137,10 @@ struct Map_I32_F64 native
|
||||||
|
|
||||||
native double Get(int key);
|
native double Get(int key);
|
||||||
native bool CheckKey(int key);
|
native bool CheckKey(int key);
|
||||||
|
|
||||||
|
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 Insert(int key, double value);
|
||||||
native void InsertNew(int key);
|
native void InsertNew(int key);
|
||||||
native void Remove(int key);
|
native void Remove(int key);
|
||||||
|
@ -149,6 +169,10 @@ struct Map_I32_Obj native
|
||||||
|
|
||||||
native Object Get(int key);
|
native Object Get(int key);
|
||||||
native bool CheckKey(int key);
|
native bool CheckKey(int key);
|
||||||
|
|
||||||
|
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 Insert(int key, Object value);
|
||||||
native void InsertNew(int key);
|
native void InsertNew(int key);
|
||||||
native void Remove(int key);
|
native void Remove(int key);
|
||||||
|
@ -177,6 +201,10 @@ struct Map_I32_Ptr native
|
||||||
|
|
||||||
native voidptr Get(int key);
|
native voidptr Get(int key);
|
||||||
native bool CheckKey(int key);
|
native bool CheckKey(int key);
|
||||||
|
|
||||||
|
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 Insert(int key, voidptr value);
|
||||||
native void InsertNew(int key);
|
native void InsertNew(int key);
|
||||||
native void Remove(int key);
|
native void Remove(int key);
|
||||||
|
@ -202,6 +230,10 @@ struct Map_I32_Str native
|
||||||
|
|
||||||
native String Get(int key);
|
native String Get(int key);
|
||||||
native bool CheckKey(int key);
|
native bool CheckKey(int key);
|
||||||
|
|
||||||
|
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 Insert(int key, String value);
|
||||||
native void InsertNew(int key);
|
native void InsertNew(int key);
|
||||||
native void Remove(int key);
|
native void Remove(int key);
|
||||||
|
@ -232,6 +264,10 @@ struct Map_Str_I8 native
|
||||||
|
|
||||||
native int Get(String key);
|
native int Get(String key);
|
||||||
native bool CheckKey(String key);
|
native bool CheckKey(String key);
|
||||||
|
|
||||||
|
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 Insert(String key, int value);
|
||||||
native void InsertNew(String key);
|
native void InsertNew(String key);
|
||||||
native void Remove(String key);
|
native void Remove(String key);
|
||||||
|
@ -260,6 +296,10 @@ struct Map_Str_I16 native
|
||||||
|
|
||||||
native int Get(String key);
|
native int Get(String key);
|
||||||
native bool CheckKey(String key);
|
native bool CheckKey(String key);
|
||||||
|
|
||||||
|
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 Insert(String key, int value);
|
||||||
native void InsertNew(String key);
|
native void InsertNew(String key);
|
||||||
native void Remove(String key);
|
native void Remove(String key);
|
||||||
|
@ -288,6 +328,10 @@ struct Map_Str_I32 native
|
||||||
|
|
||||||
native int Get(String key);
|
native int Get(String key);
|
||||||
native bool CheckKey(String key);
|
native bool CheckKey(String key);
|
||||||
|
|
||||||
|
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 Insert(String key, int value);
|
||||||
native void InsertNew(String key);
|
native void InsertNew(String key);
|
||||||
native void Remove(String key);
|
native void Remove(String key);
|
||||||
|
@ -316,6 +360,10 @@ struct Map_Str_F32 native
|
||||||
|
|
||||||
native double Get(String key);
|
native double Get(String key);
|
||||||
native bool CheckKey(String key);
|
native bool CheckKey(String key);
|
||||||
|
|
||||||
|
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 Insert(String key, double value);
|
||||||
native void InsertNew(String key);
|
native void InsertNew(String key);
|
||||||
native void Remove(String key);
|
native void Remove(String key);
|
||||||
|
@ -344,6 +392,10 @@ struct Map_Str_F64 native
|
||||||
|
|
||||||
native double Get(String key);
|
native double Get(String key);
|
||||||
native bool CheckKey(String key);
|
native bool CheckKey(String key);
|
||||||
|
|
||||||
|
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 Insert(String key, double value);
|
||||||
native void InsertNew(String key);
|
native void InsertNew(String key);
|
||||||
native void Remove(String key);
|
native void Remove(String key);
|
||||||
|
@ -372,6 +424,10 @@ struct Map_Str_Obj native
|
||||||
|
|
||||||
native Object Get(String key);
|
native Object Get(String key);
|
||||||
native bool CheckKey(String key);
|
native bool CheckKey(String key);
|
||||||
|
|
||||||
|
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 Insert(String key, Object value);
|
||||||
native void InsertNew(String key);
|
native void InsertNew(String key);
|
||||||
native void Remove(String key);
|
native void Remove(String key);
|
||||||
|
@ -400,6 +456,10 @@ struct Map_Str_Ptr native
|
||||||
|
|
||||||
native voidptr Get(String key);
|
native voidptr Get(String key);
|
||||||
native bool CheckKey(String key);
|
native bool CheckKey(String key);
|
||||||
|
|
||||||
|
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 Insert(String key, voidptr value);
|
||||||
native void InsertNew(String key);
|
native void InsertNew(String key);
|
||||||
native void Remove(String key);
|
native void Remove(String key);
|
||||||
|
@ -428,6 +488,10 @@ struct Map_Str_Str native
|
||||||
|
|
||||||
native String Get(String key);
|
native String Get(String key);
|
||||||
native bool CheckKey(String key);
|
native bool CheckKey(String key);
|
||||||
|
|
||||||
|
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 Insert(String key, String value);
|
||||||
native void InsertNew(String key);
|
native void InsertNew(String key);
|
||||||
native void Remove(String key);
|
native void Remove(String key);
|
||||||
|
|
Loading…
Reference in a new issue