libsapling  0.8.0
typed_adapters.h
Go to the documentation of this file.
1 #ifndef _LIBSAPLING_TYPED_ADAPTERS_H_
2 #define _LIBSAPLING_TYPED_ADAPTERS_H_
3 
17 #include "libsapling/dm/graph.h"
18 
19 // Include typed_common.h for convenience
21 
30 #define CAST_USER_INFO(TYPE, VAR, INFO) \
31 TYPE VAR = ((struct info_insert *)INFO)->info
32 
43 #define IMPLEMENT_TYPED_ADAPTERS(SYM, TYPE, IMPL) \
44  \
45 typedef int (*SYM##__predicate_t)(const TYPE *data, void *info); \
46 typedef void (*SYM##__apply_t)(TYPE *data, void *info); \
47  \
48 static \
49 int SYM##__predicate_0(UNUSED const TYPE *data, UNUSED void *info) \
50 { \
51  return 0; \
52 } \
53  \
54 static \
55 int SYM##__predicate_1(UNUSED const TYPE *data, UNUSED void *info) \
56 { \
57  return 1; \
58 } \
59  \
60 struct SYM##__adapt { \
61  size_t size; \
62  void *data; \
63  void *info; \
64  SYM##__predicate_t predicate; \
65  SYM##__apply_t apply; \
66 }; \
67  \
68 static \
69 int SYM##__predicate_adapter(const node_t *ref, \
70  const struct info_stack *info) \
71 { \
72  node_t node = *ref; \
73  struct SYM##__adapt *user = info->user; \
74  \
75  return user->predicate((const TYPE *)IMPL##__data(node), user); \
76 } \
77  \
78 static \
79 void SYM##__apply_adapter(node_t *ref, const struct info_stack *info) \
80 { \
81  node_t node = *ref; \
82  struct SYM##__adapt *user = info->user; \
83  \
84  if (*ref != NULL) \
85  user->apply((TYPE *)IMPL##__data(node), user); \
86 }
87 
88 #endif
Graph implementation.
Useful common definitions for typed stuff.