named_list.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #ifndef __NAMED_LIST_H__
  2. #define __NAMED_LIST_H__
  3. #pragma once
  4. #include <stddef.h>
  5. #include <stdint.h>
  6. struct __attribute__((__packed__)) named_list {
  7. const char* name;
  8. const uint8_t index;
  9. const uint8_t gen; // Bitfield of compatible generations
  10. };
  11. typedef struct named_list NamedList;
  12. /* Get number of elements in a list
  13. * This is not very efficient as-is since it has to walk the whole list.
  14. */
  15. size_t namedlist_cnt(const NamedList* list);
  16. /* Returns the generation mask of the requested item in the list */
  17. uint32_t namedlist_gen_get_pos(const NamedList* list, uint32_t pos);
  18. /* Returns the generation mask of the item in the list that matches the
  19. * provided index. This will ultimately return the 0th element in the case
  20. * of the provided index not matching any of the list elements.
  21. */
  22. uint32_t namedlist_gen_get_index(const NamedList* list, uint32_t index);
  23. /* Returns the list position based on the provided index. If index is not
  24. * matched, the 0th position is returned. In most lists this is a "NONE"
  25. * indicator. e.g. No Move.
  26. */
  27. uint32_t namedlist_pos_get(const NamedList* list, uint32_t index);
  28. /* Get the item's index value from the position specified */
  29. uint32_t namedlist_index_get(const NamedList* list, uint32_t pos);
  30. /* Get a pointer to the item's name from an item's index */
  31. const char* namedlist_name_get_index(const NamedList* list, uint32_t index);
  32. /* Get a pointer to the item's name from a position */
  33. const char* namedlist_name_get_pos(const NamedList* list, uint32_t pos);
  34. #endif //__NAMED_LIST_H__