-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNetworkProperty.c
170 lines (137 loc) · 3.89 KB
/
NetworkProperty.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
#include <stdlib.h>
#include <string.h>
#include "NamedElement.h"
#include "NetworkInfo.h"
#include "NodeLink.h"
#include "Visitor.h"
#include "NetworkProperty.h"
#define DEBUG 0
#if DEBUG
#define PRINTF(...) printf(__VA_ARGS__)
#else
#define PRINTF(...)
#endif
NamedElement* newPoly_NetworkProperty()
{
NetworkProperty* pNetPropObj = NULL;
NamedElement* pObj = new_NamedElement();
/* Allocating memory */
pNetPropObj = (NetworkProperty*)malloc(sizeof(NetworkProperty));
if (pNetPropObj == NULL)
{
pObj->Delete(pObj);
return NULL;
}
pObj->pDerivedObj = pNetPropObj; /* Pointing to derived object */
pNetPropObj->value = NULL;
pNetPropObj->eContainer = NULL;
pObj->metaClassName = NetworkProperty_metaClassName;
pObj->internalGetKey = NetworkProperty_internalGetKey;
pObj->VisitAttributes = NetworkProperty_VisitAttributes;
pObj->VisitPathAttributes = NetworkProperty_VisitPathAttributes;
pObj->FindByPath = NetworkProperty_FindByPath;
pObj->Delete = deletePoly_NetworkProperty;
return pObj;
}
NetworkProperty* new_NetworkProperty()
{
NetworkProperty* pNetPropObj = NULL;
NamedElement* pObj = new_NamedElement();
if(pObj == NULL)
return NULL;
/* Allocating memory */
pNetPropObj = (NetworkProperty*)malloc(sizeof(NetworkProperty));
if (pNetPropObj == NULL)
{
return NULL;
}
pNetPropObj->super = pObj;
pNetPropObj->value = NULL;
pNetPropObj->eContainer = NULL;
pNetPropObj->metaClassName = NetworkProperty_metaClassName;
pObj->metaClassName = NetworkProperty_metaClassName;
pNetPropObj->internalGetKey = NetworkProperty_internalGetKey;
pNetPropObj->VisitAttributes = NetworkProperty_VisitAttributes;
pNetPropObj->VisitPathAttributes = NetworkProperty_VisitPathAttributes;
pNetPropObj->FindByPath = NetworkProperty_FindByPath;
pNetPropObj->Delete = delete_NetworkProperty;
return pNetPropObj;
}
char* NetworkProperty_internalGetKey(void * const this)
{
NetworkProperty *pObj = (NetworkProperty*)this;
return pObj->super->internalGetKey(pObj->super);
}
char* NetworkProperty_metaClassName(void * const this)
{
char *name = NULL;
name = malloc(sizeof(char) * (strlen("NetworkProperty")) + 1);
if(name != NULL)
strcpy(name, "NetworkProperty");
else
return NULL;
return name;
}
void deletePoly_NetworkProperty(void * const this)
{
if(this != NULL)
{
NamedElement *pObj = (NamedElement*)this;
NetworkProperty* pNetPropObj;
pNetPropObj = pObj->pDerivedObj;
/*destroy derived obj*/
free(pNetPropObj->value);
free(pNetPropObj);
/*destroy base Obj*/
delete_NamedElement(pObj);
}
}
void delete_NetworkProperty(void * const this)
{
if(this != NULL)
{
NetworkProperty *pObj = (NetworkProperty*)this;
/* destroy base object */
delete_NamedElement(pObj->super);
/* destroy data memebers */
free(pObj->value);
free(pObj);
/*this = NULL;*/
}
}
void NetworkProperty_VisitAttributes(void *const this, char *parent, Visitor *visitor, bool recursive)
{
char path[256];
memset(&path[0], 0, sizeof(path));
NamedElement_VisitAttributes(((NetworkProperty*)(this))->super, parent, visitor, true);
sprintf(path, "value");
visitor->action(path, STRING, ((NetworkProperty*)this)->value);
visitor->action(NULL, RETURN, NULL);
}
void NetworkProperty_VisitPathAttributes(void *const this, char *parent, Visitor *visitor, bool recursive)
{
char path[256];
memset(&path[0], 0, sizeof(path));
NamedElement_VisitPathAttributes(((NetworkProperty*)(this))->super, parent, visitor, true);
sprintf(path, "%s\\value", parent);
visitor->action(path, STRING, ((NetworkProperty*)this)->value);
}
void* NetworkProperty_FindByPath(char *attribute, void *const this)
{
NetworkProperty *pObj = (NetworkProperty*)this;
/* NamedElement attributes */
if(!strcmp("name", attribute))
{
return pObj->super->FindByPath(attribute, pObj->super);
}
/* Local attributes */
else if(!strcmp("value", attribute))
{
return pObj->value;
}
else
{
PRINTF("Wrong path\n");
return NULL;
}
}