Browse Source

Assign store interface.

Stefano Cossu 1 year ago
parent
commit
c9a6cddd55
1 changed files with 14 additions and 1 deletions
  1. 14 1
      src/graph.c

+ 14 - 1
src/graph.c

@@ -41,6 +41,17 @@ check_backend (LSUP_StoreType be)
 #undef ENTRY
 
 
+#define ENTRY(a, b) case LSUP_STORE_##a: return &b;
+static inline const LSUP_StoreInt *
+select_interface (LSUP_StoreType be) {
+    switch (be) {
+        BACKEND_TBL
+        default: return NULL;
+    }
+}
+#undef ENTRY
+
+
 /*
  * Graph API.
  */
@@ -55,7 +66,8 @@ LSUP_graph_new (
                 "Environment is not initialized. Did you call LSUP_init()?");
         return NULL;
     }
-    if (UNLIKELY (!check_backend (store_type))) {
+    const LSUP_StoreInt *sif = select_interface (store_type);
+    if (UNLIKELY (!sif)) {
         log_error ("Not a valid store type: %d", store_type);
         return NULL;
     }
@@ -67,6 +79,7 @@ LSUP_graph_new (
     MALLOC_GUARD (gr->store, NULL);
 
     gr->store->type = store_type;
+    gr->store->sif = sif;
     gr->store->id = store_id ? strdup (store_id) : NULL;
     // TODO implement custom default context.
     gr->store->data = gr->store->sif->new_fn (store_id, size);