libsapling
0.8.0
include
libsapling
dm
typed
typed_path.h
Go to the documentation of this file.
1
#ifndef _LIBSAPLING_TYPED_PATH_H_
2
#define _LIBSAPLING_TYPED_PATH_H_
3
9
#include "
libsapling/dm/typed/typed_adapters.h
"
10
11
#define IMPLEMENT_TYPED_PATH(SYM, TYPE, FPF, EQU) \
12
\
13
IMPLEMENT_TYPED_ADAPTERS(SYM, TYPE, path) \
14
\
15
static \
16
void SYM##__access(enum qt qt, node_t *ref, void *info, \
17
SYM##__predicate_t predicate, SYM##__apply_t apply) \
18
{ \
19
struct SYM##__adapt a = { 0, NULL, info, predicate, apply }; \
20
path__access(qt, ref, &a, SYM##__predicate_adapter, SYM##__apply_adapter);\
21
} \
22
\
23
static \
24
void SYM##__insert(node_t *ref, TYPE val, SYM##__predicate_t predicate) \
25
{ \
26
struct SYM##__adapt a = { sizeof(TYPE), &val, NULL, predicate }; \
27
path__insert(ref, &a, SYM##__predicate_adapter); \
28
} \
29
\
30
static \
31
void SYM##__delete(enum qt qt, node_t *ref, void *info, \
32
SYM##__predicate_t predicate) \
33
{ \
34
struct SYM##__adapt a = { 0, NULL, info, predicate, NULL }; \
35
path__delete(qt, ref, &a, SYM##__predicate_adapter); \
36
} \
37
\
38
static \
39
void SYM##__print(FILE *stream, node_t *ref) \
40
{ \
41
path__print(stream, ref, FPF); \
42
} \
43
\
44
static \
45
void SYM##__dump_dot(FILE *stream, node_t *ref) \
46
{ \
47
path__dump_dot(stream, ref, FPF); \
48
} \
49
\
50
static \
51
int SYM##__length(const node_t *ref) \
52
{ \
53
return path__length(ref); \
54
} \
55
\
56
static \
57
int SYM##__equ_predicate(const TYPE *data, void *info) \
58
{ \
59
struct info_insert *ins = info; \
60
\
61
return EQU(ins->data, data); \
62
} \
63
static \
64
void SYM##__a_in(UNUSED TYPE *data, void *info) \
65
{ \
66
CAST_USER_INFO(int *, in, info); \
67
\
68
*in = 1; \
69
} \
70
static \
71
int SYM##__in(node_t *ref, TYPE val) \
72
{ \
73
int in = 0; \
74
struct SYM##__adapt a = { sizeof(TYPE), &val, &in, SYM##__equ_predicate, \
75
SYM##__a_in }; \
76
path__access(E_QT, ref, &a, SYM##__predicate_adapter, \
77
SYM##__apply_adapter); \
78
return in; \
79
} \
80
\
81
static \
82
TYPE *SYM##__position(node_t *ref, int pos) \
83
{ \
84
node_t *subpath = path__position(ref, pos); \
85
if (subpath != NULL && *subpath != NULL) \
86
return (TYPE *)path__data(*subpath); \
87
return NULL; \
88
}
89
90
#endif
typed_adapters.h
Implementation of typed adapters for predicate and apply functions.
Generated by
1.9.1