-
Notifications
You must be signed in to change notification settings - Fork 0
/
FragmentDictionary.c
183 lines (147 loc) · 4.85 KB
/
FragmentDictionary.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
#include "Dictionary.h"
#include "Instance.h"
#include "Visitor.h"
#include "FragmentDictionary.h"
#define DEBUG 0
#if DEBUG
#define PRINTF(...) printf(__VA_ARGS__)
#else
#define PRINTF(...)
#endif
Dictionary* newPoly_FragmentDictionary()
{
FragmentDictionary* pFragDicObj = NULL;
Dictionary* pObj = new_Dictionary();
/* Allocating memory */
pFragDicObj = (FragmentDictionary*)malloc(sizeof(FragmentDictionary));
if (pFragDicObj == NULL)
{
pObj->Delete(pObj);
return NULL;
}
pObj->pDerivedObj = pFragDicObj; /* Pointing to derived object */
((FragmentDictionary*)pObj->pDerivedObj)->super = pObj;
pObj->VisitAttributes = FragmentDictionary_VisitAttributes;
pObj->VisitPathAttributes = FragmentDictionary_VisitPathAttributes;
pObj->VisitReferences = FragmentDictionary_VisitReferences;
pObj->VisitPathReferences = FragmentDictionary_VisitPathReferences;
pObj->metaClassName = FragmentDictionary_metaClassName;
pObj->internalGetKey = FragmentDictionary_internalGetKey;
pFragDicObj->name = NULL;
pFragDicObj->eContainer = NULL;
pObj->FindByPath = FragmentDictionary_FindByPath;
pObj->Delete = deletePoly_FragmentDictionary;
return pObj;
}
FragmentDictionary* new_FragmentDictionary(void)
{
FragmentDictionary* pFragDicObj = NULL;
Dictionary* pObj = new_Dictionary();
if(pObj == NULL)
return NULL;
/* Allocating memory */
pFragDicObj = (FragmentDictionary*)malloc(sizeof(FragmentDictionary));
if (pFragDicObj == NULL)
{
return NULL;
}
pFragDicObj->super = pObj;
pFragDicObj->VisitAttributes = FragmentDictionary_VisitAttributes;
pFragDicObj->VisitPathAttributes = FragmentDictionary_VisitPathAttributes;
pFragDicObj->VisitReferences = FragmentDictionary_VisitReferences;
pFragDicObj->VisitPathReferences = FragmentDictionary_VisitPathReferences;
pFragDicObj->name = NULL;
pFragDicObj->eContainer = NULL;
pFragDicObj->metaClassName = FragmentDictionary_metaClassName;
pObj->metaClassName = FragmentDictionary_metaClassName;
pFragDicObj->internalGetKey = FragmentDictionary_internalGetKey;
pFragDicObj->FindByPath = FragmentDictionary_FindByPath;
pFragDicObj->Delete = delete_FragmentDictionary;
return pFragDicObj;
}
void deletePoly_FragmentDictionary(void* const this)
{
if(this != NULL)
{
FragmentDictionary* pFragDicObj;
pFragDicObj = (FragmentDictionary*)((Dictionary*)this)->pDerivedObj;
/*destroy derived obj*/
free(pFragDicObj->name);
free(pFragDicObj->eContainer);
free(pFragDicObj);
/*destroy base Obj*/
delete_Dictionary(((Dictionary*)this));
}
}
void delete_FragmentDictionary(void* const this)
{
if(this != NULL)
{
/* destroy base object */
delete_Dictionary(((FragmentDictionary*)this)->super);
/* destroy data memebers */
FragmentDictionary* pDicAttrObj = (FragmentDictionary*)this;
free(pDicAttrObj->name);
free(pDicAttrObj->eContainer);
free(this);
/*this = NULL;*/
}
}
char* FragmentDictionary_internalGetKey(void* const this)
{
FragmentDictionary *pObj = (FragmentDictionary*)this;
return pObj->name;
}
char* FragmentDictionary_metaClassName(void* const this)
{
char *name;
name = malloc(sizeof(char) * (strlen("FragmentDictionary")) + 1);
if(name != NULL)
strcpy(name, "FragmentDictionary");
else
return NULL;
return name;
}
void FragmentDictionary_VisitAttributes(void *const this, char *parent, Visitor *visitor, bool recursive)
{
char path[256];
memset(&path[0], 0, sizeof(path));
/* Dictionary attributes */
Dictionary_VisitAttributes(((FragmentDictionary*)this)->super, parent, visitor, recursive);
/* Local attributes */
sprintf(path, "name");
visitor->action(path, STRING, ((FragmentDictionary*)(this))->name);
visitor->action(NULL, COLON, NULL);
}
void FragmentDictionary_VisitPathAttributes(void *const this, char *parent, Visitor *visitor, bool recursive)
{
char path[256];
memset(&path[0], 0, sizeof(path));
/* Dictionary attributes */
Dictionary_VisitPathAttributes(((FragmentDictionary*)this)->super, parent, visitor, recursive);
/* Local attributes */
sprintf(path, "%s\\name", parent);
visitor->action(path, STRING, ((FragmentDictionary*)(this))->name);
}
void FragmentDictionary_VisitReferences(void *const this, char *parent, Visitor *visitor, bool recursive)
{
Dictionary_VisitReferences(((FragmentDictionary*)(this))->super, parent, visitor, recursive);
}
void FragmentDictionary_VisitPathReferences(void *const this, char *parent, Visitor *visitor, bool recursive)
{
Dictionary_VisitPathReferences(((FragmentDictionary*)(this))->super, parent, visitor, recursive);
}
void* FragmentDictionary_FindByPath(char* attribute, void* const this)
{
FragmentDictionary *pObj = (FragmentDictionary*)this;
/* Local attributes */
if(!strcmp("name", attribute))
{
return pObj->name;
}
/* Dictionary attributes and references */
else /*(!strcmp("generated_KMF_ID", attribute) || !strcmp("values", attribute))*/
{
return Dictionary_FindByPath(attribute, pObj->super);
}
}