libxlsxwriter/include/xlsxwriter/shared_strings.h
2015-12-11 21:10:37 +00:00

86 lines
1.9 KiB
C

/*
* libxlsxwriter
*
* Copyright 2014-2015, John McNamara, jmcnamara@cpan.org. See LICENSE.txt.
*
* shared_strings - A libxlsxwriter library for creating Excel XLSX
* sst files.
*
*/
#ifndef __LXW_SST_H__
#define __LXW_SST_H__
#include <string.h>
#include <stdint.h>
#include "common.h"
/* STAILQ_HEAD() declaration. */
struct sst_order_list {
struct sst_element *stqh_first;
struct sst_element **stqh_last;
};
/* Define a tree.h RB structure for storing shared strings. */
RB_HEAD(sst_rb_tree, sst_element);
/* Wrapper around RB_GENERATE_STATIC from tree.h to avoid unused function
* warnings and to avoid portability issues with the _unused attribute. */
#define LXW_RB_GENERATE_ELEMENT(name, type, field, cmp) \
RB_GENERATE_INSERT_COLOR(name, type, field, static) \
RB_GENERATE_INSERT(name, type, field, cmp, static) \
/* Add unused struct to allow adding a semicolon */ \
struct lxw_rb_generate_element{int unused;}
/*
* Elements of the SST table. They contain pointers to allow them to
* be stored in a RB tree and also pointers to track the insertion order
* in a separate list.
*/
struct sst_element {
uint32_t index;
char *string;
STAILQ_ENTRY (sst_element) sst_order_pointers;
RB_ENTRY (sst_element) sst_tree_pointers;
};
/*
* Struct to represent a sst.
*/
typedef struct lxw_sst {
FILE *file;
uint32_t string_count;
uint32_t unique_count;
struct sst_order_list *order_list;
struct sst_rb_tree *rb_tree;
} lxw_sst;
/* *INDENT-OFF* */
#ifdef __cplusplus
extern "C" {
#endif
/* *INDENT-ON* */
lxw_sst *_new_sst();
void _free_sst(lxw_sst *sst);
int32_t _get_sst_index(lxw_sst *sst, const char *string);
void _sst_assemble_xml_file(lxw_sst *self);
/* Declarations required for unit testing. */
#ifdef TESTING
STATIC void _sst_xml_declaration(lxw_sst *self);
#endif /* TESTING */
/* *INDENT-OFF* */
#ifdef __cplusplus
}
#endif
/* *INDENT-ON* */
#endif /* __LXW_SST_H__ */