-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChannelType.c
247 lines (208 loc) · 6.91 KB
/
ChannelType.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
#include "NamedElement.h"
#include "TypeDefinition.h"
#include "Visitor.h"
#include "ChannelType.h"
#define DEBUG 0
#if DEBUG
#define PRINTF(...) printf(__VA_ARGS__)
#else
#define PRINTF(...)
#endif
TypeDefinition* newPoly_ChannelType()
{
ChannelType* pChanTypeObj = NULL;
TypeDefinition* pObj = new_TypeDefinition();
if(pObj == NULL)
return NULL;
/* Allocating memory */
pChanTypeObj = (ChannelType*)malloc(sizeof(ChannelType));
if (pChanTypeObj == NULL)
{
pObj->Delete(pObj);
return NULL;
}
pObj->pDerivedObj = pChanTypeObj; /* Pointing to derived object */
pChanTypeObj->super = pObj;
pChanTypeObj->path = NULL;
pChanTypeObj->eContainer = NULL;
pChanTypeObj->refs = NULL;
pChanTypeObj->lowerBindings = -1;
pChanTypeObj->upperBindings = -1;
pChanTypeObj->lowerFragments = -1;
pChanTypeObj->upperFragments = -1;
pObj->metaClassName = ChannelType_metaClassName;
pObj->super->metaClassName = ChannelType_metaClassName;
pObj->internalGetKey = ChannelType_internalGetKey;
pObj->VisitAttributes = ChannelType_VisitAttributes;
pObj->VisitPathAttributes = ChannelType_VisitPathAttributes;
pObj->VisitReferences = ChannelType_VisitReferences;
pObj->VisitPathReferences = ChannelType_VisitPathReferences;
pObj->FindByPath = ChannelType_FindByPath;
pObj->Delete = deletePoly_ChannelType;
return pObj;
}
ChannelType* new_ChannelType()
{
ChannelType* pChanTypeObj = NULL;
TypeDefinition* pObj = new_TypeDefinition();
if(pObj == NULL)
return NULL;
/* Allocating memory */
pChanTypeObj = (ChannelType*)malloc(sizeof(ChannelType));
if (pChanTypeObj == NULL)
{
pObj->Delete(pObj);
return NULL;
}
/*pObj->pDerivedObj = pChanTypeObj; Pointing to derived object */
pObj->pDerivedObj = NULL;
pChanTypeObj->super = pObj;
pChanTypeObj->eContainer = NULL;
pChanTypeObj->path = NULL;
pChanTypeObj->refs = NULL;
pChanTypeObj->lowerBindings = -1;
pChanTypeObj->upperBindings = -1;
pChanTypeObj->lowerFragments = -1;
pChanTypeObj->upperFragments = -1;
pChanTypeObj->metaClassName = ChannelType_metaClassName;
pChanTypeObj->internalGetKey = ChannelType_internalGetKey;
pChanTypeObj->VisitAttributes = ChannelType_VisitAttributes;
pChanTypeObj->VisitPathAttributes = ChannelType_VisitPathAttributes;
pChanTypeObj->VisitReferences = ChannelType_VisitReferences;
pChanTypeObj->VisitPathReferences = ChannelType_VisitPathReferences;
pChanTypeObj->Delete = delete_ChannelType;
return pChanTypeObj;
}
void deletePoly_ChannelType(void* const this)
{
if(this != NULL)
{
ChannelType* pChanTypeObj;
pChanTypeObj = (ChannelType*)((TypeDefinition*)this)->pDerivedObj;
/*destroy derived obj*/
free(pChanTypeObj);
/*destroy base Obj*/
delete_TypeDefinition((TypeDefinition*)this);
}
}
void delete_ChannelType(void* const this)
{
/* destroy base object */
delete_TypeDefinition(((ChannelType*)this)->super);
/* destroy data memebers */
free(this);
}
char* ChannelType_internalGetKey(void* const this)
{
if (this == NULL)
return NULL;
return TypeDefinition_internalGetKey((TypeDefinition*)this);
}
char* ChannelType_metaClassName(void* const this)
{
ChannelType *pObj = (ChannelType*)this;
char *name = NULL;
/*
* TODO Avoid return an allocated string
*/
name = malloc(sizeof(char) * (strlen("ChannelType")) + 1);
if(name != NULL)
strcpy(name, "ChannelType");
else
return NULL;
return name;
}
void ChannelType_VisitAttributes(void* const this, char* parent, Visitor* visitor, bool recursive)
{
/* Local attributes */
if(recursive)
{
char path[256];
memset(&path[0], 0, sizeof(path));
/* TypeDefinition attributes */
TypeDefinition_VisitAttributes(((TypeDefinition*)(this)), parent, visitor, recursive);
sprintf(path, "lowerBindings");
visitor->action(path, INTEGER, (void*)((ChannelType*)(((TypeDefinition*)this)->pDerivedObj))->lowerBindings);
visitor->action(NULL, COLON, NULL);
sprintf(path, "upperBindings");
visitor->action(path, INTEGER, (void*)((ChannelType*)(((TypeDefinition*)this)->pDerivedObj))->upperBindings);
visitor->action(NULL, COLON, NULL);
sprintf(path, "lowerFragments");
visitor->action(path, INTEGER, (void*)((ChannelType*)(((TypeDefinition*)this)->pDerivedObj))->lowerFragments);
visitor->action(NULL, COLON, NULL);
sprintf(path, "upperFragments");
visitor->action(path, INTEGER, (void*)((ChannelType*)(((TypeDefinition*)this)->pDerivedObj))->upperFragments);
visitor->action(NULL, COLON, NULL);
}
else
{
/* TypeDefinition attributes */
TypeDefinition_VisitAttributes(((TypeDefinition*)(this)), parent, visitor, recursive);
}
}
void ChannelType_VisitPathAttributes(void* const this, char* parent, Visitor* visitor, bool recursive)
{
/* Local attributes */
if(recursive)
{
char path[256];
memset(&path[0], 0, sizeof(path));
/* TypeDefinition attributes */
TypeDefinition_VisitPathAttributes(((TypeDefinition*)(this)), parent, visitor, recursive);
sprintf(path, "%s\\lowerBindings", parent);
visitor->action(path, BOOL, (void*)((ChannelType*)(((TypeDefinition*)this)->pDerivedObj))->lowerBindings);
sprintf(path, "%s\\upperBindings", parent);
visitor->action(path, BOOL, (void*)((ChannelType*)(((TypeDefinition*)this)->pDerivedObj))->upperBindings);
sprintf(path, "%s\\lowerFragments", parent);
visitor->action(path, BOOL, (void*)((ChannelType*)(((TypeDefinition*)this)->pDerivedObj))->lowerFragments);
sprintf(path, "%s\\upperFragments", parent);
visitor->action(path, BOOL, (void*)((ChannelType*)(((TypeDefinition*)this)->pDerivedObj))->upperFragments);
}
else
{
/* TypeDefinition attributes */
TypeDefinition_VisitPathAttributes(((TypeDefinition*)(this)), parent, visitor, recursive);
}
}
void ChannelType_VisitReferences(void* const this, char* parent, Visitor* visitor, bool recursive)
{
TypeDefinition_VisitReferences((TypeDefinition*)this, parent, visitor, recursive);
}
void ChannelType_VisitPathReferences(void* const this, char* parent, Visitor* visitor, bool recursive)
{
TypeDefinition_VisitPathReferences((TypeDefinition*)this, parent, visitor, recursive);
}
void* ChannelType_FindByPath(char* attribute, void* const this)
{
TypeDefinition *pObj = (TypeDefinition*)this;
/*
* TODO Fix polymorphism
*/
/* TypeDefinition attributes */
if(!strcmp("name",attribute) || !strcmp("version",attribute) || !strcmp("factoryBean",attribute) || !strcmp("bean",attribute) || !strcmp("abstract",attribute))
{
return TypeDefinition_FindByPath(attribute, pObj);
}
/* Local attributes */
else if(!strcmp("lowerBindings",attribute))
{
return (void*)((ChannelType*)pObj->pDerivedObj)->lowerBindings;
}
else if(!strcmp("upperBindings",attribute))
{
return (void*)((ChannelType*)pObj->pDerivedObj)->upperBindings;
}
else if(!strcmp("lowerFragments",attribute))
{
return (void*)((ChannelType*)pObj->pDerivedObj)->lowerFragments;
}
else if(!strcmp("upperFragments",attribute))
{
return (void*)((ChannelType*)pObj->pDerivedObj)->upperFragments;
}
/* TypeDefinition references */
else
{
return TypeDefinition_FindByPath(attribute, pObj);
}
}