-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAttribute.c
More file actions
47 lines (42 loc) · 1.33 KB
/
Copy pathAttribute.c
File metadata and controls
47 lines (42 loc) · 1.33 KB
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
#include "Attribute.h"
Attribute_t *attributeConstruct(int attributeIndex, Value_t *value)
{
Attribute_t *newAttribute = (Attribute_t *)malloc(sizeof(Attribute_t));
if(newAttribute == NULL)
{
printf("Not enough memory");
exit(0);
}
newAttribute->attributeIndex = attributeIndex;
newAttribute->value = value;
newAttribute->next = NULL;
return newAttribute;
}
Attribute_t *addAttribute(Attribute_t **startAttribute, Attribute_t *lastAttribute, Value_t *value)
{
if(*startAttribute == NULL)
{
*startAttribute = attributeConstruct(0, value);
return *startAttribute;
}
else
lastAttribute->next = attributeConstruct(lastAttribute->attributeIndex + 1, value);
return lastAttribute->next;
}
Attribute_t *getAttribute(struct Instance *instance, int attributeIndex)
{
Attribute_t *currentAttribute = instance->attribute;
while(currentAttribute != NULL && currentAttribute->attributeIndex != attributeIndex)
currentAttribute = currentAttribute->next;
return currentAttribute;
}
void printAttribute(Attribute_t *startAttribute)
{
Attribute_t *currentAttribute = startAttribute;
while(currentAttribute != NULL)
{
printf("%s ", currentAttribute->value->valueName);
currentAttribute = currentAttribute->next;
}
printf("\n");
}