-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode.c
More file actions
60 lines (55 loc) · 3.94 KB
/
node.c
File metadata and controls
60 lines (55 loc) · 3.94 KB
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
#include "node.h"
#include <stdlib.h>
#define DEFINE_COMPUTE_NODE_FUNC(TYPE_IN,TYPE_OUT) \
COMPUTE_NODE_FUNC(TYPE_IN,TYPE_OUT) \
{ \
node->func(node->in,node->out); \
}
#define DEFINE_CREATE_NODE_FUNC(TYPE_IN,TYPE_OUT) \
CREATE_NODE_FUNC(TYPE_IN,TYPE_OUT) \
{ \
\
BUFF_T(TYPE_IN)* in = (BUFF_T(TYPE_IN)*)malloc(sizeof(BUFF_T(TYPE_IN))); \
in->len = num_in; \
in->data = (TYPE_IN*)malloc(sizeof(TYPE_IN)*num_in); \
\
BUFF_T(TYPE_OUT)* out = (BUFF_T(TYPE_OUT)*)malloc(sizeof(BUFF_T(TYPE_OUT))); \
out->len = num_out; \
out->data = (TYPE_OUT*)malloc(sizeof(TYPE_OUT)*num_out); \
\
NODE_T(TYPE_IN,TYPE_OUT)* node = (NODE_T(TYPE_IN,TYPE_OUT)*)malloc(sizeof(NODE_T(TYPE_IN,TYPE_OUT))+sizeof(in)+sizeof(out)); \
node->in = in; \
node->out = out; \
node->func = func; \
\
return node; \
}
#define DEFINE_FREE_NODE_FUNC(TYPE_IN,TYPE_OUT) \
FREE_NODE_FUNC(TYPE_IN,TYPE_OUT) \
{ \
if(node->in) \
{ \
if(node->in->data) \
{ \
free(node->in->data); \
} \
free(node->in); \
} \
if(node->out) \
{ \
if(node->out->data) \
{ \
free(node->out->data); \
} \
free(node->out); \
} \
if(node) \
{ \
free(node); \
} \
}
#define DEFINE_NODE(TYPE_IN,TYPE_OUT) \
DEFINE_COMPUTE_NODE_FUNC(TYPE_IN,TYPE_OUT) \
DEFINE_CREATE_NODE_FUNC(TYPE_IN,TYPE_OUT) \
DEFINE_FREE_NODE_FUNC(TYPE_IN,TYPE_OUT)
DEFINE_NODE(float,float)