Skip to content

Commit

Permalink
map_has_key
Browse files Browse the repository at this point in the history
  • Loading branch information
IS4Code committed Jul 24, 2018
1 parent b786247 commit 4b8840e
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pawno/include/PawnPlus.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
42 changes: 42 additions & 0 deletions plugins/src/natives/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,20 @@ class key_at
}
return 0;
}

// native bool:map_has_key(Map:map, key, ...);
template <key_ftype KeyFactory>
static cell AMX_NATIVE_CALL map_has_key(AMX *amx, cell *params)
{
auto ptr = reinterpret_cast<map_t*>(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 <key_ftype KeyFactory, size_t TagIndex = 0>
Expand Down Expand Up @@ -811,6 +825,30 @@ namespace Natives
return key_at<2>::map_remove<dyn_func_var>(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<dyn_func>(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<dyn_func_arr>(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<dyn_func_str>(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<dyn_func_var>(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)
{
Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit 4b8840e

Please sign in to comment.