| 1 | /* Copyright (C) 2010-2020 The RetroArch team |
| 2 | * |
| 3 | * --------------------------------------------------------------------------------------- |
| 4 | * The following license statement only applies to this file (file_list.h). |
| 5 | * --------------------------------------------------------------------------------------- |
| 6 | * |
| 7 | * Permission is hereby granted, free of charge, |
| 8 | * to any person obtaining a copy of this software and associated documentation files (the "Software"), |
| 9 | * to deal in the Software without restriction, including without limitation the rights to |
| 10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, |
| 11 | * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. |
| 14 | * |
| 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, |
| 16 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
| 19 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 21 | */ |
| 22 | |
| 23 | #ifndef __LIBRETRO_SDK_FILE_LIST_H__ |
| 24 | #define __LIBRETRO_SDK_FILE_LIST_H__ |
| 25 | |
| 26 | #include <retro_common_api.h> |
| 27 | |
| 28 | RETRO_BEGIN_DECLS |
| 29 | |
| 30 | #include <stddef.h> |
| 31 | #include <stdlib.h> |
| 32 | |
| 33 | #include <boolean.h> |
| 34 | |
| 35 | struct item_file |
| 36 | { |
| 37 | void *userdata; |
| 38 | void *actiondata; |
| 39 | char *path; |
| 40 | char *label; |
| 41 | char *alt; |
| 42 | size_t directory_ptr; |
| 43 | size_t entry_idx; |
| 44 | unsigned type; |
| 45 | }; |
| 46 | |
| 47 | typedef struct file_list |
| 48 | { |
| 49 | struct item_file *list; |
| 50 | |
| 51 | size_t capacity; |
| 52 | size_t size; |
| 53 | } file_list_t; |
| 54 | |
| 55 | void *file_list_get_userdata_at_offset(const file_list_t *list, |
| 56 | size_t index); |
| 57 | |
| 58 | void *file_list_get_actiondata_at_offset(const file_list_t *list, |
| 59 | size_t index); |
| 60 | |
| 61 | /** |
| 62 | * @brief frees the list |
| 63 | * |
| 64 | * NOTE: This function will also free() the entries actiondata |
| 65 | * and userdata fields if they are non-null. If you store complex |
| 66 | * or non-contiguous data there, make sure you free it's fields |
| 67 | * before calling this function or you might get a memory leak. |
| 68 | * |
| 69 | * @param list List to be freed |
| 70 | */ |
| 71 | void file_list_free(file_list_t *list); |
| 72 | |
| 73 | bool file_list_deinitialize(file_list_t *list); |
| 74 | |
| 75 | /** |
| 76 | * @brief makes the list big enough to contain at least nitems |
| 77 | * |
| 78 | * This function will not change the capacity if nitems is smaller |
| 79 | * than the current capacity. |
| 80 | * |
| 81 | * @param list The list to open for input |
| 82 | * @param nitems Number of items to reserve space for |
| 83 | * @return whether or not the operation succeeded |
| 84 | */ |
| 85 | bool file_list_reserve(file_list_t *list, size_t nitems); |
| 86 | |
| 87 | bool file_list_append(file_list_t *userdata, const char *path, |
| 88 | const char *label, unsigned type, size_t current_directory_ptr, |
| 89 | size_t entry_index); |
| 90 | |
| 91 | bool file_list_insert(file_list_t *list, |
| 92 | const char *path, const char *label, |
| 93 | unsigned type, size_t directory_ptr, |
| 94 | size_t entry_idx, |
| 95 | size_t idx); |
| 96 | |
| 97 | void file_list_pop(file_list_t *list, size_t *directory_ptr); |
| 98 | |
| 99 | void file_list_clear(file_list_t *list); |
| 100 | |
| 101 | void file_list_free_userdata(const file_list_t *list, size_t index); |
| 102 | |
| 103 | void file_list_free_actiondata(const file_list_t *list, size_t idx); |
| 104 | |
| 105 | void file_list_set_alt_at_offset(file_list_t *list, size_t index, |
| 106 | const char *alt); |
| 107 | |
| 108 | void file_list_sort_on_alt(file_list_t *list); |
| 109 | |
| 110 | void file_list_sort_on_type(file_list_t *list); |
| 111 | |
| 112 | bool file_list_search(const file_list_t *list, const char *needle, |
| 113 | size_t *index); |
| 114 | |
| 115 | RETRO_END_DECLS |
| 116 | |
| 117 | #endif |