Advertisement
HOPL

ds_exists_any

May 26th, 2022
790
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2. * Checks if any data structures under any id_string exist on calling instance
  3. *
  4. * @function     ds_exists_any(_id_string)
  5. * @param        {string}        id_string           id string of data structure
  6. * @return       ds_type or false
  7. * @see          variable_instance_get, ds_exists
  8. */
  9. function ds_exists_any(_id_string) {
  10.     // Get ds variable from instance calling this function
  11.     var ds = variable_instance_get(self, _id_string);
  12.  
  13.     // Exit early if variable doesn't exist on calling instance
  14.     if (ds == undefined) {
  15.         return false;
  16.     }
  17.  
  18.     // Initiate ds types array for looping
  19.     var ds_types = [ds_type_map, ds_type_list, ds_type_stack, ds_type_grid, ds_type_queue, ds_type_priority];
  20.  
  21.     for (var i = 0; i < array_length(ds_types); i++) {
  22.         // Return type if ds of type exists
  23.         if (ds_exists(ds, ds_types[i])) {
  24.             return ds_types[i];
  25.         }
  26.     }
  27.  
  28.     return false;
  29. }
  30.  
  31. /**
  32. * Destroys all data structures by name on calling instance
  33. *
  34. * @function     ds_destroy_all([names])
  35. * @param        {string}        [names]         Names of data structures to destroy
  36. * @return       {undefined}
  37. * @see          ds_exists_any, variable_instance_get, ds_grid_destroy
  38. */
  39. function ds_destroy_all() {
  40.     // For each name given
  41.     for (var i = 0; i < argument_count; i++) {
  42.         // Get ds name
  43.         var name = argument[i];
  44.  
  45.         // Get ds type
  46.         var ds_type = ds_exists_any(name);
  47.  
  48.         // Exit early if it doesn't exist
  49.         if (not ds_type) {
  50.             continue;
  51.         }
  52.  
  53.         // Get ds index in memory
  54.         var ds_index = variable_instance_get(self, name);
  55.  
  56.         // Destroy ds based on type
  57.         switch (ds_type) {
  58.             case ds_type_grid:
  59.                 ds_grid_destroy(ds_index);
  60.             break;
  61.             case ds_type_list:
  62.                 ds_list_destroy(ds_index);
  63.             break;
  64.             case ds_type_map:
  65.                 ds_map_destroy(ds_index);
  66.             break;
  67.             case ds_type_priority:
  68.                 ds_priority_destroy(ds_index);
  69.             break;
  70.             case ds_type_queue:
  71.                 ds_queue_destroy(ds_index);
  72.             break;
  73.             case ds_type_stack:
  74.                 ds_stack_destroy(ds_index);
  75.             break;
  76.         }
  77.     }
  78. }
  79.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement