Branch
Hash :
adb9e235
Author :
Thomas de Grivel
Date :
2023-01-14T18:26:30
license
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
/* rtbuf
* Copyright 2018-2023 kmx.io <contact@kmx.io>
*
* Permission is hereby granted to use this software excepted
* on Apple computers granted the above copyright notice and
* this permission paragraph are included in all copies and
* substantial portions of this software.
*
* THIS SOFTWARE IS PROVIDED "AS-IS" WITHOUT ANY GUARANTEE OF
* PURPOSE AND PERFORMANCE. IN NO EVENT WHATSOEVER SHALL THE
* AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
* THIS SOFTWARE.
*/
#ifndef DATA_H
#define DATA_H
typedef enum {
DATA_TYPE_BYTES,
DATA_TYPE_VECTOR,
DATA_TYPE_INTEGER,
DATA_TYPE_FLOAT,
DATA_TYPE_STRUCT
} e_data_type;
#define DATA_TYPE_SIGNED 1
#define DATA_TYPE_BIG_ENDIAN 2
typedef struct data_type {
unsigned int bytes;
unsigned int type;
} s_data_type;
typedef struct data_type_vector {
s_data_type t;
s_data_type *element_type;
unsigned int nmemb;
} s_data_type_vector;
typedef struct data_type_integer {
s_data_type t;
unsigned int flags;
} s_data_type_integer;
typedef struct data_type_float {
s_data_type t;
} s_data_type_float;
typedef struct data_type_struct {
s_data_type t;
s_data_type *first;
struct data_type_struct *rest;
} s_data_type_struct;
typedef union data_type_ {
s_data_type t;
s_data_type_vector t_vector;
s_data_type_integer t_integer;
s_data_type_float t_float;
s_data_type_struct t_struct;
} u_data_type;
#define DATA_TYPE_MAX 1024
u_data_type * data_type_new (unsigned int bytes, unsigned int type);
void data_type_delete (s_data_type *t);
typedef void f_data_init (void *data);
typedef void f_data_clean (void *data);
typedef struct data_alloc {
s_data_type *t;
unsigned int max;
void *mem;
unsigned int n;
unsigned int *free;
unsigned int free_n;
f_data_init *init;
f_data_clean *clean;
} s_data_alloc;
#define DATA_ALLOC_MAX 1024
void * data_new (s_data_alloc *da);
int data_new_i (s_data_alloc *da);
void data_delete (s_data_alloc *da, void *data);
void data_alloc_init (s_data_alloc *da, s_data_type *t,
unsigned int max, f_data_init *init,
f_data_clean *clean);
void data_alloc_clean (s_data_alloc *da);
s_data_alloc * data_alloc_new (s_data_type *t,
unsigned int max, f_data_init *init,
f_data_clean *clean);
void data_alloc_delete (s_data_alloc *da);
void data_alloc_delete_all ();
int libdata_init ();
void libdata_shutdown ();
#endif