blob: 763d7dac5c3d73412cb111577cea30bc7ca0c9ca [file] [log] [blame]
James Kuszmaul82f6c042021-01-17 11:30:16 -08001/**
2 * @file re_odict.h Interface to Ordered Dictionary
3 *
4 * Copyright (C) 2010 - 2015 Creytiv.com
5 */
6
7enum odict_type {
8 ODICT_OBJECT,
9 ODICT_ARRAY,
10 ODICT_STRING,
11 ODICT_INT,
12 ODICT_DOUBLE,
13 ODICT_BOOL,
14 ODICT_NULL,
15};
16
17struct odict {
18 struct list lst;
19 struct hash *ht;
20};
21
22struct odict_entry {
23 struct le le, he;
24 char *key;
25 union {
26 struct odict *odict; /* ODICT_OBJECT / ODICT_ARRAY */
27 char *str; /* ODICT_STRING */
28 int64_t integer; /* ODICT_INT */
29 double dbl; /* ODICT_DOUBLE */
30 bool boolean; /* ODICT_BOOL */
31 } u;
32 enum odict_type type;
33};
34
35int odict_alloc(struct odict **op, uint32_t hash_size);
36const struct odict_entry *odict_lookup(const struct odict *o, const char *key);
37size_t odict_count(const struct odict *o, bool nested);
38int odict_debug(struct re_printf *pf, const struct odict *o);
39
40int odict_entry_add(struct odict *o, const char *key,
41 int type, ...);
42void odict_entry_del(struct odict *o, const char *key);
43int odict_entry_debug(struct re_printf *pf, const struct odict_entry *e);
44
45bool odict_type_iscontainer(enum odict_type type);
46bool odict_type_isreal(enum odict_type type);
47const char *odict_type_name(enum odict_type type);
48
49
50/* Helpers */
51
52const struct odict_entry *odict_get_type(const struct odict *o,
53 enum odict_type type, const char *key);
54const char *odict_string(const struct odict *o, const char *key);
55bool odict_get_number(const struct odict *o, uint64_t *num, const char *key);
56bool odict_get_boolean(const struct odict *o, bool *value, const char *key);