summaryrefslogtreecommitdiffstats
path: root/src/defs.h
blob: 39960d92345b2ae1357d8f3e885f385f69d2022b (plain)
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
/* SPDX-License-Identifier: LGPL-2.1-only */

/* Copyright (C) 2020 Gediminas Jakutis */

#ifndef ALGOS_DEFS_H_INCLUDED
#define ALGOS_DEFS_H_INCLUDED

#include <stddef.h>
#include <stdint.h>
#include <sys/types.h>
#include <rin/diagnostic.h>

#define try_s(a,l) do {\
	if(a) {\
		goto l;\
	}} while (0);

#define try(a,l,e,m,...) do {\
	if(a) {\
		ret = e;\
		rin_err(m __VA_OPT__(,) __VA_ARGS__);\
		goto l;\
	}} while (0);


#define get(in) (in->settings->access == cached ? in->get_next_element_cache(in) : in->get_next_element_direct(in))
#define put(in, data) (in->settings->access == cached ? in->place_next_element_cache(in, data) : in->place_next_element_direct(in, data))

#define stream_blank .fd = -1, .settings = &settings, .get_next_element_direct = stub_getnext, \
		.get_next_element_cache = stub_getnext, .place_next_element_direct = stub_put, \
		.place_next_element_cache = stub_put, .split = stub_split, .flush = stub_flush

/* for array implementation */
struct entry {
	uint64_t val;
};

/* for linked list implementation */
struct entry_l {
	struct entry;
	int64_t next; /* """pointer""" to the next element. */
};

enum opmode {
	mode_normal,
	mode_fetch,
	mode_generate
};

enum accessmode {
	cached,
	direct
};

enum dataformat {
	array,
	list
};

enum streamtype {
	stream_invalid = -1,
	stream_in,
	stream_out,
	stream_outlite,
	stream_chardev
};

struct stream {
	struct stream *parent;
	size_t n;
	int fd;
	enum streamtype type;
	char *name;
	size_t stride;
	size_t index;
	struct entry_l *cnode;
	char *cache;
	struct settings *settings;
	struct entry *cache_a;
	struct entry_l *cache_l;
	struct entry_l *(*get_next_element_direct)(struct stream * const);
	struct entry_l *(*get_next_element_cache)(struct stream * const);
	int (*place_next_element_direct)(struct stream * const, struct entry_l const * const);
	int (*place_next_element_cache)(struct stream * const, struct entry_l const * const);
	int (*split)(struct stream * const, struct stream * const, struct stream * const);
	int (*flush)(struct stream * const);
};

struct settings {
	size_t ss;
	size_t to;
	size_t stride;
	char *filein;
	char *fileout;
	enum opmode opmode;
	enum dataformat format;
	enum accessmode access;
};

#endif /* ALGOS_DEFS_H_INCLUDED */