-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNamedElement.c
131 lines (113 loc) · 2.98 KB
/
NamedElement.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "Visitor.h"
#include "NamedElement.h"
#define DEBUG 0
#if DEBUG
#define PRINTF(...) printf(__VA_ARGS__)
#else
#define PRINTF(...)
#endif
NamedElement* new_NamedElement()
{
NamedElement* pObj = NULL;
/* Allocating memory */
pObj = (NamedElement*)malloc(sizeof(NamedElement));
if (pObj == NULL)
{
return NULL;
}
/* pointing to itself as we are creating base class object*/
pObj->pDerivedObj = pObj;
pObj->name = NULL;
pObj->internalGetKey = NamedElement_internalGetKey;
pObj->metaClassName = NamedElement_metaClassName;
pObj->Delete = delete_NamedElement;
pObj->VisitAttributes = NamedElement_VisitAttributes;
pObj->VisitPathAttributes = NamedElement_VisitPathAttributes;
pObj->VisitReferences = NamedElement_VisitAttributes;
pObj->VisitPathReferences = NamedElement_VisitPathAttributes;
pObj->FindByPath = NamedElement_FindByPath;
return pObj;
}
char* NamedElement_internalGetKey(void * const this)
{
NamedElement *pObj = (NamedElement*)this;
return pObj->name;
}
char* NamedElement_metaClassName(void * const this)
{
char *name;
name = malloc(sizeof(char) * (strlen("NamedElement")) + 1);
if(name != NULL)
strcpy(name, "NamedElement");
else
return NULL;
return name;
}
void delete_NamedElement(void * const this)
{
if(this != NULL)
{
NamedElement *pObj = (NamedElement*)this;
free(pObj->name);
free(pObj);
}
}
void NamedElement_VisitAttributes(void *const this, char *parent, Visitor *visitor, bool recursive)
{
char path[256];
memset(&path[0], 0, sizeof(path));
if(recursive)
{
char* cClass = NULL;
cClass = malloc(sizeof(char) * (strlen("org.kevoree.") + strlen(((NamedElement*)this)->metaClassName((NamedElement*)this))) + 1);
sprintf(cClass, "org.kevoree.%s", ((NamedElement*)this)->metaClassName((NamedElement*)this));
sprintf(path,"eClass");
visitor->action(path, STRING, cClass);
visitor->action(NULL, COLON, NULL);
free(cClass);
sprintf(path, "name");
visitor->action(path, STRING, ((NamedElement*)(this))->name);
visitor->action(NULL, COLON, NULL);
}
else
{
visitor->action("", STRING, ((NamedElement*)(this))->name);
visitor->action(NULL, COLON, NULL);
}
}
void NamedElement_VisitPathAttributes(void *const this, char *parent, Visitor *visitor, bool recursive)
{
char path[256];
memset(&path[0], 0, sizeof(path));
if(recursive)
{
/*char* cClass = NULL;
sprintf(path,"%s\\cClass", parent);
cClass = ((NamedElement*)this)->metaClassName((NamedElement*)this);
visitor->action(path, STRING, cClass);
free(cClass);*/
sprintf(path, "%s\\name", parent);
visitor->action(path, STRING, ((NamedElement*)(this))->name);
}
else
{
sprintf(path, "%s\\name", parent);
visitor->action(path, REFERENCE, ((NamedElement*)(this))->name);
}
}
void* NamedElement_FindByPath(char* attribute, void * const this)
{
NamedElement *pObj = (NamedElement*)this;
if(!strcmp("name", attribute))
{
return pObj->name;
}
else
{
PRINTF("Wrong attribute\n");
return NULL;
}
}