smntc
an in-memory multimodal graph database
Loading...
Searching...
No Matches
Tangle.c
Go to the documentation of this file.
1#include <stdlib.h>
2#include "errors.h"
3#include "Graph.h"
4#include "Textual.h"
5#include "Visual.h"
6
7struct Tangle {
8 struct Graph *graph;
9 struct Textual *textual;
10 struct Visual *visual;
11};
12
13struct Tangle *Tangle_construct(struct Graph *graph, int *error)
14{
15 struct Tangle *this = malloc(sizeof(struct Tangle));
16
17 if (0 == this) {
18 *error = ERROR_NO_MEMORY;
19 return 0;
20 }
21
22 this->graph = graph;
23
24 unsigned int modalityCluster[] = { 0, 0 };
25
26 if (Graph_getLength(this->graph) == 1) {
27
28 Graph_readCluster(this->graph, 1, 2, modalityCluster, error);
29
30 if (*error) {
31 return 0;
32 }
33
34 } else {
35
36 Graph_addCluster(this->graph, 2, modalityCluster, error);
37
38 if (*error) {
39 return 0;
40 }
41
42 }
43
44 this->textual = Textual_construct(modalityCluster[0], this->graph, error);
45
46 if (*error) {
47 return 0;
48 }
49
50 this->visual = Visual_construct(modalityCluster[1], this->graph, error);
51
52 if (*error) {
53 return 0;
54 }
55
56 return this;
57}
58
59struct Tangle *Tangle_destruct(struct Tangle *this)
60{
61 if (0 != this) {
64 Graph_destruct(this->graph);
65 free(this);
66 }
67
68 return 0;
69}
70
71const struct Graph *Tangle_getGraph(struct Tangle *this)
72{
73 return this->graph;
74}
unsigned int Graph_getLength(const struct Graph *this)
Definition Graph.c:897
struct Graph * Graph_destruct(struct Graph *this)
It destructs a graph storage.
Definition Graph.c:121
void Graph_readCluster(const struct Graph *this, unsigned int predecessor, unsigned int length, unsigned int *vertices, int *error)
Definition Graph.c:776
void Graph_addCluster(struct Graph *this, unsigned int length, unsigned int *vertices, int *error)
Definition Graph.c:744
struct Tangle * Tangle_destruct(struct Tangle *this)
Definition Tangle.c:59
struct Tangle * Tangle_construct(struct Graph *graph, int *error)
Definition Tangle.c:13
const struct Graph * Tangle_getGraph(struct Tangle *this)
Definition Tangle.c:71
struct Textual * Textual_destruct(struct Textual *this)
Definition Textual.c:72
struct Textual * Textual_construct(unsigned int modality, struct Graph *graph, int *error)
Definition Textual.c:16
struct Visual * Visual_construct(unsigned int modality, struct Graph *graph, int *error)
Definition Visual.c:17
struct Visual * Visual_destruct(struct Visual *this)
Definition Visual.c:83
#define ERROR_NO_MEMORY
Definition errors.h:5
Definition Graph.c:20
Definition Tangle.c:7
struct Graph * graph
Definition Tangle.c:8
struct Visual * visual
Definition Tangle.c:10
struct Textual * textual
Definition Tangle.c:9