shared_strings.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * libxlsxwriter
  3. *
  4. * Copyright 2014-2018, John McNamara, [email protected]. See LICENSE.txt.
  5. *
  6. * shared_strings - A libxlsxwriter library for creating Excel XLSX
  7. * sst files.
  8. *
  9. */
  10. #ifndef __LXW_SST_H__
  11. #define __LXW_SST_H__
  12. #include <string.h>
  13. #include <stdint.h>
  14. #include "common.h"
  15. /* Define a tree.h RB structure for storing shared strings. */
  16. RB_HEAD(sst_rb_tree, sst_element);
  17. /* Define a queue.h structure for storing shared strings in insertion order. */
  18. STAILQ_HEAD(sst_order_list, sst_element);
  19. /* Wrapper around RB_GENERATE_STATIC from tree.h to avoid unused function
  20. * warnings and to avoid portability issues with the _unused attribute. */
  21. #define LXW_RB_GENERATE_ELEMENT(name, type, field, cmp) \
  22. RB_GENERATE_INSERT_COLOR(name, type, field, static) \
  23. RB_GENERATE_INSERT(name, type, field, cmp, static) \
  24. /* Add unused struct to allow adding a semicolon */ \
  25. struct lxw_rb_generate_element{int unused;}
  26. /*
  27. * Elements of the SST table. They contain pointers to allow them to
  28. * be stored in a RB tree and also pointers to track the insertion order
  29. * in a separate list.
  30. */
  31. struct sst_element {
  32. uint32_t index;
  33. char *string;
  34. STAILQ_ENTRY (sst_element) sst_order_pointers;
  35. RB_ENTRY (sst_element) sst_tree_pointers;
  36. };
  37. /*
  38. * Struct to represent a sst.
  39. */
  40. typedef struct lxw_sst {
  41. FILE *file;
  42. uint32_t string_count;
  43. uint32_t unique_count;
  44. struct sst_order_list *order_list;
  45. struct sst_rb_tree *rb_tree;
  46. } lxw_sst;
  47. /* *INDENT-OFF* */
  48. #ifdef __cplusplus
  49. extern "C" {
  50. #endif
  51. /* *INDENT-ON* */
  52. lxw_sst *lxw_sst_new();
  53. void lxw_sst_free(lxw_sst *sst);
  54. struct sst_element *lxw_get_sst_index(lxw_sst *sst, const char *string);
  55. void lxw_sst_assemble_xml_file(lxw_sst *self);
  56. /* Declarations required for unit testing. */
  57. #ifdef TESTING
  58. STATIC void _sst_xml_declaration(lxw_sst *self);
  59. #endif /* TESTING */
  60. /* *INDENT-OFF* */
  61. #ifdef __cplusplus
  62. }
  63. #endif
  64. /* *INDENT-ON* */
  65. #endif /* __LXW_SST_H__ */