diff --git a/pawno/include/PawnPlus.inc b/pawno/include/PawnPlus.inc index 645fce4..7728a9f 100644 --- a/pawno/include/PawnPlus.inc +++ b/pawno/include/PawnPlus.inc @@ -510,6 +510,11 @@ native bool:map_arr_remove(Map:map, const AnyTag:key[], key_size=sizeof(key), ke native bool:map_str_remove(Map:map, const key[]); native bool:map_var_remove(Map:map, VariantTag:key); +native bool:map_has_key(Map:map, AnyTag:key, key_tag_id=tagof(key)); +native bool:map_has_arr_key(Map:map, const AnyTag:key[], key_size=sizeof(key), key_tag_id=tagof(key)); +native bool:map_has_str_key(Map:map, const key[]); +native bool:map_has_var_key(Map:map, VariantTag:key); + native map_get(Map:map, AnyTag:key, offset=0, key_tag_id=tagof(key)); native map_get_arr(Map:map, AnyTag:key, AnyTag:value[], value_size=sizeof(value), key_tag_id=tagof(key)); native Variant:map_get_var(Map:map, AnyTag:key, key_tag_id=tagof(key)); diff --git a/plugins/src/natives/map.cpp b/plugins/src/natives/map.cpp index e9ae9a2..d0dc7ae 100644 --- a/plugins/src/natives/map.cpp +++ b/plugins/src/natives/map.cpp @@ -67,6 +67,20 @@ class key_at } return 0; } + + // native bool:map_has_key(Map:map, key, ...); + template + static cell AMX_NATIVE_CALL map_has_key(AMX *amx, cell *params) + { + auto ptr = reinterpret_cast(params[1]); + if(!map_pool.contains(ptr)) return 0; + auto it = ptr->find(KeyFactory(amx, params[KeyIndices]...)); + if(it != ptr->end()) + { + return 1; + } + return 0; + } // native bool:map_set_cell(Map:map, key, offset, AnyTag:value, ...); template @@ -811,6 +825,30 @@ namespace Natives return key_at<2>::map_remove(amx, params); } + // native bool:map_has_key(Map:map, AnyTag:key, key_tag_id=tagof(key)); + static cell AMX_NATIVE_CALL map_has_key(AMX *amx, cell *params) + { + return key_at<2, 3>::map_has_key(amx, params); + } + + // native bool:map_has_arr_key(Map:map, const AnyTag:key[], key_size=sizeof(key), key_tag_id=tagof(key)); + static cell AMX_NATIVE_CALL map_has_arr_key(AMX *amx, cell *params) + { + return key_at<2, 3, 4>::map_has_key(amx, params); + } + + // native bool:map_has_str_key(Map:map, const key[]); + static cell AMX_NATIVE_CALL map_has_str_key(AMX *amx, cell *params) + { + return key_at<2>::map_has_key(amx, params); + } + + // native bool:map_has_var_key(Map:map, VariantTag:key); + static cell AMX_NATIVE_CALL map_has_var_key(AMX *amx, cell *params) + { + return key_at<2>::map_has_key(amx, params); + } + // native map_get(Map:map, AnyTag:key, offset=0, key_tag_id=tagof(key)); static cell AMX_NATIVE_CALL map_get(AMX *amx, cell *params) { @@ -1232,6 +1270,10 @@ static AMX_NATIVE_INFO native_list[] = AMX_DECLARE_NATIVE(map_arr_remove), AMX_DECLARE_NATIVE(map_str_remove), AMX_DECLARE_NATIVE(map_var_remove), + AMX_DECLARE_NATIVE(map_has_key), + AMX_DECLARE_NATIVE(map_has_arr_key), + AMX_DECLARE_NATIVE(map_has_str_key), + AMX_DECLARE_NATIVE(map_has_var_key), AMX_DECLARE_NATIVE(map_get), AMX_DECLARE_NATIVE(map_get_arr), AMX_DECLARE_NATIVE(map_get_var),