libcortex
Event loop library following a "batteries included" approach
Loading...
Searching...
No Matches
dict.h
1#ifndef CRTX_DICT_H
2#define CRTX_DICT_H
3
4/*
5 * Mario Kicherer (dev@kicherer.org) 2016
6 *
7 */
8
9#include <stdio.h>
10
11#include "intern.h"
12
13#define CRTX_DICT_GET_NUMBER(dict_item) ( \
14 (dict_item)->type == 'u' ? (dict_item)->uint32 : \
15 (dict_item)->type == 'i' ? (dict_item)->int32 : \
16 (dict_item)->type == 'U' ? (dict_item)->uint64 : \
17 (dict_item)->type == 'I' ? (dict_item)->int64 : \
18 (dict_item)->type == 'd' ? (dict_item)->double_fp : \
19 ( crtx_printf(CRTX_VLEVEL_ERR, "invalid type %c for get_int32\n", (dict_item)->type), 0) \
20 )
21
22#define CRTX_DIF_ALLOCATED_KEY (1<<0) // key was allocated for this dict_item
23#define CRTX_DIF_DONT_FREE_DATA (1<<1) // data was not allocated for the dict_item
24#define CRTX_DIF_CREATE_DATA_COPY (1<<2) // only used while creating a dict_item
25#define CRTX_DIF_CREATE_KEY_COPY (1<<3)
26#define CRTX_DIF_LAST_ITEM (1<<7)
27
28#define CRTX_DIF_IS_LAST(di) ( ((di)->flags & CRTX_DIF_LAST_ITEM) != 0 )
29
30#include <stdint.h>
31#include <stdarg.h>
32
33#include "threads.h"
34
36 char type;
37// char key_type;
38 unsigned char flags;
39
40 char *key;
41 size_t size; // memory size - except for strings it is the strlen (for user convenience)
42
43 union {
44// uint8_t uint8; // c
45// int8_t int8; // C
46 uint32_t uint32; // u
47 int32_t int32; // i
48 uint64_t uint64; // U
49 int64_t int64; // I
50 double double_fp; // d
51 size_t sizet; // z
52 ssize_t ssizet; // Z
53
54 char *string; // s
55 void *pointer; // p
56 struct crtx_dict *dict; // D
57// char payload[0]; // P
58 };
59};
60
61struct crtx_dict {
62 char *id;
63
64 char *signature;
65 uint32_t signature_length;
66 unsigned long size;
67
68// struct crtx_dict_item items[0];
69 struct crtx_dict_item *items;
70
71 MUTEX_TYPE mutex;
72 unsigned int ref_count;
73};
74
76 const char *key;
77 char type;
78 char flag;
79
80 const char *format;
81};
82
84 char *signature;
85 struct crtx_dict_transformation *transformation;
86
87 struct crtx_graph *graph;
88 char *type;
89};
90
91
92struct crtx_dict_item * crtx_alloc_dict_item();
93struct crtx_dict_item * crtx_dict_alloc_next_item(struct crtx_dict *dict);
94struct crtx_dict * crtx_dict_transform(struct crtx_dict *dict, char *signature, struct crtx_dict_transformation *transf);
95struct crtx_dict_item * crtx_get_item(struct crtx_dict *ds, const char *key);
96struct crtx_dict_item * crtx_dict_get_item(struct crtx_dict *ds, const char *key);
97struct crtx_dict * crtx_init_dict(char *signature, uint32_t sign_length, size_t payload_size);
98struct crtx_dict * crtx_create_dict_va(char *signature, va_list *va);
99struct crtx_dict * crtx_create_dict(char *signature, ...);
100char crtx_fill_data_item(struct crtx_dict_item *di, unsigned char type, char *key, ...);
101char crtx_fill_data_item_va2(struct crtx_dict_item *di, unsigned char type, char *key, va_list *va);
102char crtx_fill_data_item_va(struct crtx_dict_item *di, unsigned char type, va_list *va);
103// void crtx_free_dict(struct crtx_dict *ds);
104char crtx_get_value(struct crtx_dict *ds, const char *key, char type, void *buffer, size_t buffer_size);
105char crtx_copy_value(struct crtx_dict_item *di, void *buffer, size_t buffer_size);
106void crtx_print_dict(struct crtx_dict *ds);
107struct crtx_dict_item *crtx_get_first_item(struct crtx_dict *ds);
108struct crtx_dict_item *crtx_get_next_item(struct crtx_dict *ds, struct crtx_dict_item *di);
109// char crtx_add_item(struct crtx_dict **dict, char type, ...);
110
111char *crtx_get_string(struct crtx_dict *ds, const char *key);
112char *crtx_dict_get_string(struct crtx_dict *ds, const char *key);
113struct crtx_dict *crtx_get_dict(struct crtx_dict *ds, const char *key);
114
115struct crtx_task *crtx_create_transform_task(struct crtx_graph *in_graph, char *name, struct crtx_transform_dict_handler *trans);
116
117struct crtx_dict_item * crtx_get_item_by_idx(struct crtx_dict *ds, size_t idx);
118
119char crtx_cmp_item(struct crtx_dict_item *a, struct crtx_dict_item *b);
120void crtx_print_dict_item(struct crtx_dict_item *di, unsigned char level);
121void crtx_free_dict_item_data(struct crtx_dict_item *di);
122struct crtx_dict *crtx_dict_copy(struct crtx_dict *orig);
123void crtx_dict_copy_item(struct crtx_dict_item *dst, struct crtx_dict_item *src, char data_only);
124char crtx_get_item_value(struct crtx_dict_item *di, char type, void *buffer, size_t buffer_size);
125
126char crtx_resize_dict(struct crtx_dict *dict, size_t n_items);
127int crx_append_to_dict(struct crtx_dict **dictionary, char *signature, ...);
128
129void crtx_dict_ref(struct crtx_dict *dict);
130void crtx_dict_unref(struct crtx_dict *dict);
131struct crtx_dict_item * crtx_dict_locate(struct crtx_dict *dict, const char *path);
132char crtx_dict_locate_value(struct crtx_dict *dict, const char *path, char type, void *buffer, size_t buffer_size);
133char *crtx_dict_locate_string(struct crtx_dict *dict, const char *path);
134void crtx_dict_remove_item(struct crtx_dict *dict, char *key);
135char crtx_dict_new_item(struct crtx_dict *dict, unsigned char type, char *key, ...);
136struct crtx_dict *crtx_dict_create_copy(struct crtx_dict *orig);
137
138char crtx_is_string_in_dict(struct crtx_dict *dict, char *str);
139
140void crtx_dict_item_print(struct crtx_dict_item *di, unsigned char level, FILE *f);
141void crtx_dict_print(struct crtx_dict *ds, FILE *f);
142int crtx_dict_snaprintf(char **result, size_t *rlen, size_t *alloc, char *format, struct crtx_dict *ds);
143
144#endif
Definition dict.h:35
Definition dict.h:75
Definition dict.h:61
structure that represents a graph of tasks (crtx_task) that will be traversed with every crtx_event
Definition core.h:115
a task basically represents a function that will be executed for an crtx_event
Definition core.h:91
Definition dict.h:83