|
| 1 | +// SPDX-License-Identifier: MIT WITH bisoin-exception WITH swig-exception |
| 2 | +// Copyright © 2020 Matthew Stern, Benjamin Michalowicz |
| 3 | + |
| 4 | +%module topologicsharp |
| 5 | +%{ |
| 6 | +#include "../include/topologic.h" |
| 7 | +%} |
| 8 | + |
| 9 | +%include "../include/stack.h" |
| 10 | +%extend stack{ |
| 11 | + stack(){ |
| 12 | + return init_stack(); |
| 13 | + } |
| 14 | + |
| 15 | + ~stack(){ |
| 16 | + destroy_stack($self); |
| 17 | + } |
| 18 | + |
| 19 | + void* pop(){ |
| 20 | + void* ret = pop($self); |
| 21 | + return (!ret ? NULL : ret); |
| 22 | + } |
| 23 | + |
| 24 | + int push(void* data){ |
| 25 | + return push($self, data); |
| 26 | + } |
| 27 | +}; |
| 28 | + |
| 29 | +%include "../include/AVL.h" |
| 30 | +%extend AVLTree{ |
| 31 | + AVLTree() { return init_avl(); } |
| 32 | + ~AVLTree() { destroy_avl($self); } |
| 33 | + |
| 34 | + int insert(void* data, int id){ |
| 35 | + return insert($self, data, id); |
| 36 | + } |
| 37 | + void* remove_ID(int id){ |
| 38 | + void* ret = remove_ID($self, id); |
| 39 | + if(!ret) return NULL; |
| 40 | + return ret; |
| 41 | + } |
| 42 | + void* find(int id){ |
| 43 | + void* ret = find($self, id); |
| 44 | + if(!ret) return NULL; |
| 45 | + return ret; |
| 46 | + } |
| 47 | + void inorder(struct stack *stack) { |
| 48 | + return inorder($self, stack); |
| 49 | + } |
| 50 | + |
| 51 | + void preorder(struct stack *stack){ |
| 52 | + return preorder($self, stack); |
| 53 | + } |
| 54 | + |
| 55 | + void postorder(struct stack *stack){ |
| 56 | + return postorder($self, stack); |
| 57 | + } |
| 58 | + |
| 59 | + void stackify(struct stack *stack){ |
| 60 | + return stackify($self, stack); |
| 61 | + } |
| 62 | +}; |
| 63 | + |
| 64 | +%include "../include/graph.h" |
| 65 | +%include "../include/vertex.h" |
| 66 | +%include "../include/edge.h" |
| 67 | +%extend graph { |
| 68 | + graph(int max_state_changes = -1, |
| 69 | + unsigned int snapshot_timestamp = START_STOP, |
| 70 | + unsigned int max_loop = MAX_LOOPS, |
| 71 | + enum VERBOSITY lvl_verbose = VERTICES | EDGES | FUNCTIONS | GLOBALS, |
| 72 | + enum CONTEXT context = SINGLE, |
| 73 | + enum MEM_OPTION mem_option = CONTINUE) { |
| 74 | + return graph_init(max_state_changes, snapshot_timestamp, max_loop, lvl_verbose, context, mem_option); |
| 75 | + } |
| 76 | + |
| 77 | + ~graph() { |
| 78 | + destroy_graph($self); |
| 79 | + } |
| 80 | + |
| 81 | + int run(struct vertex_result **vertex_args) { |
| 82 | + printf("%p\n", vertex_args[0]); |
| 83 | + return run($self, vertex_args); |
| 84 | + } |
| 85 | + |
| 86 | + int set_start_set(int *id, int num_vertices) { |
| 87 | + return start_set($self, id, num_vertices); |
| 88 | + } |
| 89 | + |
| 90 | + int pause_graph() { |
| 91 | + return pause_graph($self); |
| 92 | + } |
| 93 | + |
| 94 | + int resume_graph() { |
| 95 | + return resume_graph($self); |
| 96 | + } |
| 97 | + |
| 98 | + void print_graph() { |
| 99 | + return print_graph($self); |
| 100 | + } |
| 101 | + |
| 102 | + struct vertex *create_vertex(void (*f)(struct graph *, struct vertex_result *, void*, void*), int id, void *glbl = NULL) { |
| 103 | + return create_vertex($self, f, id, glbl); |
| 104 | + } |
| 105 | + |
| 106 | + int remove_vertex(struct vertex *vertex) { |
| 107 | + return remove_vertex($self, vertex); |
| 108 | + } |
| 109 | + |
| 110 | + int remove_vertex_id(int id) { |
| 111 | + return remove_vertex_id($self, id); |
| 112 | + } |
| 113 | + |
| 114 | + int modify_vertex(struct vertex *vertex, void(*f)(struct graph*, struct vertex_result *, void*, void*), void *glbl = NULL) { |
| 115 | + return modify_vertex(vertex, f, glbl); |
| 116 | + } |
| 117 | + |
| 118 | + int modify_shared_edge_vars(struct vertex *vertex, void *edge_vars) { |
| 119 | + return modify_shared_edge_vars(vertex, edge_vars); |
| 120 | + } |
| 121 | + |
| 122 | + struct edge *create_edge(struct vertex *a, struct vertex *b, int(*f)(void*,void*, const void* const), void *glbl = NULL) { |
| 123 | + return create_edge(a, b, f, glbl); |
| 124 | + } |
| 125 | + |
| 126 | + int create_bi_edge(struct vertex *a, struct vertex *b, int(*f)(void*,void*, const void* const), void *glbl, struct edge **edge_a_to_b = NULL, struct edge **edge_b_to_a = NULL) { |
| 127 | + return create_bi_edge(a, b,f, glbl, edge_a_to_b, edge_b_to_a); |
| 128 | + } |
| 129 | + |
| 130 | + int remove_edge(struct vertex *a, struct vertex *b) { |
| 131 | + return remove_edge(a, b); |
| 132 | + } |
| 133 | + |
| 134 | + int remove_edge_id(struct vertex *a, int id) { |
| 135 | + return remove_edge_id(a, id); |
| 136 | + } |
| 137 | + |
| 138 | + int remove_bi_edge(struct vertex *a, struct vertex *b) { |
| 139 | + return remove_bi_edge(a, b); |
| 140 | + } |
| 141 | + |
| 142 | + int modify_edge(struct vertex *a, struct vertex *b, int(*f)(void*,void*, const void* const) = NULL, void *glbl = NULL) { |
| 143 | + return modify_edge(a, b, f, glbl); |
| 144 | + } |
| 145 | + |
| 146 | + int modify_bi_edge(struct vertex *a, struct vertex *b, int(*f)(void*, void*, const void* const) = NULL, void *glbl = NULL) { |
| 147 | + return modify_bi_edge(a, b, f, glbl); |
| 148 | + } |
| 149 | + |
| 150 | + struct request *create_request(enum REQUESTS request, void *args, void (*f)(void *) = NULL) { |
| 151 | + return create_request(request, args, f); |
| 152 | + } |
| 153 | + |
| 154 | + int submit_request(struct request *request) { |
| 155 | + return submit_request($self, request); |
| 156 | + } |
| 157 | + |
| 158 | + int process_requests() { |
| 159 | + return process_requests($self); |
| 160 | + } |
| 161 | + |
| 162 | + struct vertex *find_vertex(int id) { |
| 163 | + return find($self->vertices, id); |
| 164 | + } |
| 165 | + |
| 166 | + struct edge *find_edge(struct vertex *v, int id) { |
| 167 | + return find(v->edge_tree, id); |
| 168 | + } |
| 169 | +}; |
| 170 | + |
| 171 | +%extend vertex_result { |
| 172 | + vertex_result(void *vertex_argv = NULL, void *edge_argv = NULL, int edge_size=0, int vertex_size=0) { |
| 173 | + struct vertex_result *v = malloc(sizeof(struct vertex_result)); |
| 174 | + v->vertex_argv = vertex_argv; |
| 175 | + v->edge_argv = edge_argv; |
| 176 | + v->edge_size = edge_size; |
| 177 | + v->vertex_size = vertex_size; |
| 178 | + return v; |
| 179 | + } |
| 180 | + ~vertex_result() { |
| 181 | + free($self); |
| 182 | + } |
| 183 | + |
| 184 | + void set_vertex_args(void *vertex_argv, int vertex_size=0) { |
| 185 | + $self->vertex_argv = vertex_argv; |
| 186 | + $self->vertex_size = vertex_size; |
| 187 | + } |
| 188 | + |
| 189 | + void set_edge_args(void *edge_argv, int edge_size=0) { |
| 190 | + $self->edge_argv = edge_argv; |
| 191 | + $self->edge_size = edge_size; |
| 192 | + } |
| 193 | + |
| 194 | + void *get_vertex_args() { |
| 195 | + return $self->vertex_argv; |
| 196 | + } |
| 197 | + |
| 198 | + void *get_edge_args() { |
| 199 | + return $self->edge_argv; |
| 200 | + } |
| 201 | +}; |
| 202 | + |
| 203 | +%extend vertex_request { |
| 204 | + vertex_request(struct graph *graph, int id, void (*f)(struct graph *, struct vertex_result *, void*, void*)=NULL, void *glbl=NULL) { |
| 205 | + struct vertex_request *v = malloc(sizeof(struct vertex_request)); |
| 206 | + v->graph = graph; |
| 207 | + v->id = id; |
| 208 | + v->f = f; |
| 209 | + v->glbl = glbl; |
| 210 | + return v; |
| 211 | + } |
| 212 | + ~vertex_request() { |
| 213 | + free($self); |
| 214 | + } |
| 215 | +}; |
| 216 | + |
| 217 | +%extend mod_vertex_request { |
| 218 | + mod_vertex_request(struct vertex *vertex, void (*f)(struct graph *, struct vertex_result *, void*, void*)=NULL, void *glbl=NULL) { |
| 219 | + struct mod_vertex_request *v = malloc(sizeof(struct mod_vertex_request)); |
| 220 | + v->vertex = vertex; |
| 221 | + v->f = f; |
| 222 | + v->glbl = glbl; |
| 223 | + return v; |
| 224 | + } |
| 225 | + ~mod_vertex_request() { |
| 226 | + free($self); |
| 227 | + } |
| 228 | +}; |
| 229 | + |
| 230 | +%extend mod_edge_vars_request { |
| 231 | + mod_edge_vars_request(struct vertex *vertex, void *edge_vars=NULL) { |
| 232 | + struct mod_edge_vars_request *v = malloc(sizeof(struct mod_edge_vars_request)); |
| 233 | + v->vertex = vertex; |
| 234 | + v->edge_vars = edge_vars; |
| 235 | + return v; |
| 236 | + } |
| 237 | + ~mod_edge_vars_request() { |
| 238 | + free($self); |
| 239 | + } |
| 240 | +}; |
| 241 | + |
| 242 | +%extend destroy_vertex_request { |
| 243 | + destroy_vertex_request(struct graph *graph, struct vertex *vertex) { |
| 244 | + struct destroy_vertex_request *v = malloc(sizeof(struct destroy_vertex_request)); |
| 245 | + v->vertex = vertex; |
| 246 | + v->graph = graph; |
| 247 | + return v; |
| 248 | + } |
| 249 | + ~destroy_vertex_request() { |
| 250 | + free($self); |
| 251 | + } |
| 252 | +}; |
| 253 | + |
| 254 | +%extend destroy_vertex_id_request { |
| 255 | + destroy_vertex_id_request(struct graph *graph, int id) { |
| 256 | + struct destroy_vertex_id_request *v = malloc(sizeof(struct destroy_vertex_id_request)); |
| 257 | + v->id = id; |
| 258 | + v->graph = graph; |
| 259 | + return v; |
| 260 | + } |
| 261 | + ~destroy_vertex_id_request() { |
| 262 | + free($self); |
| 263 | + } |
| 264 | +}; |
| 265 | + |
| 266 | +%extend edge_request { |
| 267 | + edge_request(struct vertex *a, struct vertex *b, int (*f)(void *, void*, const void* const)=NULL, void *glbl=NULL) { |
| 268 | + struct edge_request *e = malloc(sizeof(struct edge_request)); |
| 269 | + e->a = a; |
| 270 | + e->b = b; |
| 271 | + e->f = f; |
| 272 | + e->glbl = glbl; |
| 273 | + return e; |
| 274 | + } |
| 275 | + ~edge_request() { |
| 276 | + free($self); |
| 277 | + } |
| 278 | +}; |
| 279 | + |
| 280 | +%extend destroy_edge_request { |
| 281 | + destroy_edge_request(struct vertex *a, struct vertex *b) { |
| 282 | + struct destroy_edge_request *e = malloc(sizeof(struct destroy_edge_request)); |
| 283 | + e->a = a; |
| 284 | + e->b = b; |
| 285 | + return e; |
| 286 | + } |
| 287 | + ~destroy_edge_request() { |
| 288 | + free($self); |
| 289 | + } |
| 290 | +}; |
| 291 | + |
| 292 | +%extend destroy_edge_id_request { |
| 293 | + destroy_edge_id_request(struct vertex *a, int id) { |
| 294 | + struct destroy_edge_id_request *e = malloc(sizeof(struct destroy_edge_id_request)); |
| 295 | + e->a = a; |
| 296 | + e->id = id; |
| 297 | + return e; |
| 298 | + } |
| 299 | + ~destroy_edge_id_request() { |
| 300 | + free($self); |
| 301 | + } |
| 302 | +}; |
| 303 | + |
| 304 | + |
0 commit comments