homl.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // Humming Owl's Multipurpose Library
  2. #ifndef homl_h
  3. #define homl_h
  4. // HOML header includes
  5. #include "basic_types.h"
  6. #include "mem_space.h"
  7. #include "endian.h"
  8. #include "other_types/byte_arr.h"
  9. // useful definitions for a kind of "typeof" function (might be a dumb addition)
  10. // using the enums chained between headers (first one is in basic_types.h)
  11. // typeof
  12. owl_char * OWL_TYPE_NAMES[] =
  13. {
  14. "OWL_BYTE",
  15. "OWL_CHAR",
  16. "OWL_UMAX",
  17. "OWL_SMAX",
  18. "OWL_FMAX",
  19. "OWL_BOOL",
  20. "OWL_MEM_SPACE",
  21. "OWL_MEM_SPACE_ERR",
  22. "OWL_ENDIAN",
  23. "OWL_BYTESHIFT_DIR",
  24. "OWL_BYTARR",
  25. "OWL_ARR",
  26. "OWL_WCHAR_ENC",
  27. "OWL_WCHAR",
  28. "OWL_STR",
  29. };
  30. // sizeof
  31. owl_umax OWL_TYPE_SIZES[] =
  32. {
  33. sizeof(owl_byte),
  34. sizeof(owl_char),
  35. sizeof(owl_umax),
  36. sizeof(owl_smax),
  37. sizeof(owl_fmax),
  38. sizeof(owl_bool),
  39. sizeof(owl_endian),
  40. sizeof(owl_mem_space),
  41. sizeof(owl_mem_space_err),
  42. sizeof(owl_byteshift_dir),
  43. sizeof(owl_bytarr),
  44. sizeof(owl_arr),
  45. sizeof(owl_wchar_enc),
  46. sizeof(owl_wchar),
  47. sizeof(owl_str),
  48. };
  49. // function to return the type string of a type integer
  50. owl_char * owl_type_name(owl_umax type_id)
  51. {
  52. // check params
  53. if (type_id > sizeof(OWL_TYPE_NAMES) - 1)
  54. return NULL;
  55. return OWL_TYPE_NAMES[type_id];
  56. }
  57. // function to return the type size of a type integer
  58. owl_umax owl_type_size(owl_umax type_id)
  59. {
  60. // check params
  61. if (type_id > sizeof(OWL_TYPE_NAMES) - 1)
  62. return 0;
  63. return OWL_TYPE_SIZES[type_id];
  64. }
  65. #endif // homl_h