smntc
an in-memory multimodal graph database
Loading...
Searching...
No Matches
Visual.c
Go to the documentation of this file.
1#include <stdlib.h>
2#include "errors.h"
3#include "Graph.h"
4#include "Binary.h"
5#include "Colors.h"
6#include "Scene.h"
7
8#define CLUSTER_LENGTH 2
9
10struct Visual {
11 struct Graph *graph;
12 struct Colors *colors;
13 unsigned int modality;
14 unsigned int scenes;
15};
16
17struct Visual *Visual_construct(unsigned int modality, struct Graph *graph, int *error)
18{
19 struct Visual *this = malloc(sizeof(struct Visual));
20
21 if (0 == this) {
22 *error = ERROR_NO_MEMORY;
23 return 0;
24 }
25
26 this->graph = graph;
27 this->modality = modality;
28
29 unsigned int cluster[CLUSTER_LENGTH] = { 0, 0 };
30
31 unsigned int clusterStart = Graph_readLastSource(this->graph, modality, error);
32
33 if (*error) {
34 return 0;
35 }
36
37 if (0 == clusterStart) {
38
39 Graph_addCluster(this->graph, CLUSTER_LENGTH, cluster, error);
40
41 if (*error) {
42 return 0;
43 }
44
45 Graph_addEdge(graph, modality, cluster[0], error);
46
47 if (*error) {
48 return 0;
49 }
50
51 } else {
52
53 Graph_readCluster(this->graph, clusterStart, CLUSTER_LENGTH, cluster, error);
54
55 if (*error) {
56 return 0;
57 }
58 }
59
60 this->scenes = cluster[0];
61
62 struct Binary *colorBinary = Binary_construct(cluster[1], graph, error);
63
64 if (*error) {
65 return 0;
66 }
67
68 this->colors = Colors_construct(cluster[1], colorBinary, graph, error);
69
70 if (*error) {
71 return 0;
72 }
73
74 Colors_initialize(this->colors, error);
75
76 if (*error) {
77 return 0;
78 }
79
80 return this;
81}
82
83struct Visual *Visual_destruct(struct Visual *this)
84{
85 if (0 != this) {
87 free(this);
88 }
89
90 return 0;
91}
92
93struct Scene Visual_addScene(struct Visual *this, int *error)
94{
95 unsigned int vertex = Graph_addVertex(this->graph, error);
96
97 if (*error) {
98 struct Scene scene = {0};
99 return scene;
100 }
101
102 Graph_addEdge(this->graph, this->scenes, vertex, error);
103
104 if (*error) {
105 struct Scene scene = {0};
106 return scene;
107 }
108
109 struct Scene scene = {
110 .vertex = vertex,
111 .graph = this->graph,
112 .colors = this->colors
113 };
114
115 return scene;
116}
struct Binary * Binary_construct(unsigned int root, struct Graph *graph, int *error)
ssssw
Definition Binary.c:42
void Colors_initialize(struct Colors *this, int *error)
Definition Colors.c:56
struct Colors * Colors_construct(unsigned int colorType, struct Binary *binary, struct Graph *graph, int *error)
Definition Colors.c:21
struct Colors * Colors_destruct(struct Colors *this)
Definition Colors.c:45
void Graph_addEdge(struct Graph *this, unsigned int source, unsigned int target, int *error)
It adds a directed edge from a source vertex to a target vertex.
Definition Graph.c:298
unsigned int Graph_readLastSource(const struct Graph *this, unsigned int target, int *error)
It reads the last source vertex of a target vertex, if it exists.
Definition Graph.c:680
void Graph_readCluster(const struct Graph *this, unsigned int predecessor, unsigned int length, unsigned int *vertices, int *error)
Definition Graph.c:776
unsigned int Graph_addVertex(struct Graph *this, int *error)
It adds a vertex into a graph storage.
Definition Graph.c:136
void Graph_addCluster(struct Graph *this, unsigned int length, unsigned int *vertices, int *error)
Definition Graph.c:744
struct Visual * Visual_construct(unsigned int modality, struct Graph *graph, int *error)
Definition Visual.c:17
#define CLUSTER_LENGTH
Definition Visual.c:8
struct Scene Visual_addScene(struct Visual *this, int *error)
Definition Visual.c:93
struct Visual * Visual_destruct(struct Visual *this)
Definition Visual.c:83
#define ERROR_NO_MEMORY
Definition errors.h:5
struct Graph * graph
Definition Binary.c:31
Definition Graph.c:20
Definition Scene.h:7
unsigned int vertex
Definition Scene.h:8
struct Graph * graph
Definition Scene.h:9
struct Colors * colors
Definition Scene.h:10
struct Graph * graph
Definition Visual.c:11
struct Colors * colors
Definition Visual.c:12
unsigned int modality
Definition Visual.c:13
unsigned int scenes
Definition Visual.c:14