-
Notifications
You must be signed in to change notification settings - Fork 0
/
Repository.c
112 lines (94 loc) · 2.45 KB
/
Repository.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#include "Repository.h"
#include "Visitor.h"
#define DEBUG 0
#if DEBUG
#define PRINTF(...) printf(__VA_ARGS__)
#else
#define PRINTF(...)
#endif
Repository* new_Repository()
{
Repository* pObj;
/* Allocating memory */
pObj = (Repository*)malloc(sizeof(Repository));
if (pObj == NULL)
{
return NULL;
}
pObj->url = NULL;
pObj->eContainer = NULL;
pObj->internalGetKey = Repository_internalGetKey;
pObj->metaClassName = Repository_metaClassName;
pObj->Delete = delete_Repository;
pObj->VisitAttributes = Repository_VisitAttributes;
pObj->VisitPathAttributes = Repository_VisitPathAttributes;
pObj->FindByPath = Repository_FindByPath;
return pObj;
}
char* Repository_metaClassName(void * const this)
{
char *name;
name = malloc(sizeof(char) * (strlen("Repository")) + 1);
if(name != NULL)
strcpy(name, "Repository");
else
return NULL;
return name;
}
char* Repository_internalGetKey(void * const this)
{
Repository *pObj = (Repository*)this;
return pObj->url;
}
void delete_Repository(void * const this)
{
/* destroy data memebers */
if(this != NULL)
{
Repository *pObj = (Repository*)this;
free(pObj->url);
free(pObj->eContainer);
free(pObj);
/*this = NULL;*/
}
}
void Repository_VisitAttributes(void* const this, char* parent, Visitor* visitor, bool recursive)
{
char path[256];
char *cClass = NULL;
memset(&path[0], 0, sizeof(path));
cClass = malloc(sizeof(char) * (strlen("org.kevoree.") + strlen(((Repository*)this)->metaClassName((Repository*)this))) + 1);
sprintf(cClass, "org.kevoree.%s", ((Repository*)this)->metaClassName((Repository*)this));
sprintf(path,"eClass");
visitor->action(path, STRING, cClass);
visitor->action(NULL, COLON, NULL);
free(cClass);
sprintf(path, "url");
visitor->action(path, STRING, ((Repository*)(this))->url);
visitor->action(NULL, RETURN, NULL);
}
void Repository_VisitPathAttributes(void *const this, char *parent, Visitor *visitor, bool recursive)
{
char path[256];
char *cClass = NULL;
memset(&path[0], 0, sizeof(path));
/*sprintf(path,"%s\\cClass", parent);
cClass = ((Repository*)this)->metaClassName((Repository*)this);
visitor->action(path, STRING, cClass);
free(cClass);*/
sprintf(path,"%s\\url",parent);
visitor->action(path, STRING, ((Repository*)(this))->url);
}
void* Repository_FindByPath(char* attribute, void * const this)
{
Repository *pObj = (Repository*)this;
if(!strcmp("url", attribute))
{
return pObj->url;
}
else
{
PRINTF("Wrong path\n");
return NULL;
}
}