summaryrefslogtreecommitdiffstats
path: root/xsd2c/Enumeration.c
blob: e795206859695e52d39219619d453b1680f88aaf (plain)
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
/** Generated by xsd2c */
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "Enumeration.h"


struct Enumeration* Enumeration_Create()
{
	struct Enumeration* _res;
	_res = (struct Enumeration*)malloc(sizeof(struct Enumeration));

	_res->value_head = NULL;
	_res->value_tail = NULL;

	return _res;
}

void Enumeration_Free(struct Enumeration* obj)
{
	struct Enumeration_value_List* value_cur;
	struct Enumeration_value_List* value_tmp;
	if (obj == NULL) return;

	value_cur = obj->value_head;
	while (value_cur != NULL)
	{
		if (value_cur->value) free(value_cur->value);
		value_tmp = value_cur->next;
		free(value_cur);
		value_cur = value_tmp;
	}
	free(obj);
}

void Enumeration_Sax_Serialize(struct Enumeration* obj,
		 const char *root_element_name,
		 void (*OnStartElement)(const char* element_name, int attr_count, char **keys, char **values, void* userData),
		 void (*OnCharacters)(const char* element_name, const char* chars, void* userData),
		 void (*OnEndElement)(const char* element_name, void* userData),
		 void* userData)
{
	int attrCount, curCount;
	char **keys;
	char **values;
	char buffer[255];

	struct Enumeration_value_List* value_cur;

	attrCount = 0;

	keys = (char**)malloc(sizeof(char*)*attrCount);
	values = (char**)malloc(sizeof(char*)*attrCount);

	curCount = 0;


	OnStartElement(root_element_name, attrCount, keys, values, userData);
	value_cur = obj->value_head;
	while (value_cur != NULL)
	{

		OnStartElement("value", 0, NULL, NULL, userData);
		if (value_cur->value != NULL)
		OnCharacters("value", value_cur->value, userData);
		OnEndElement("value", userData);
		value_cur = value_cur->next;
	}

	OnEndElement(root_element_name, userData);
}

#ifndef _DESERIALIZER_DISABLED_

struct Enumeration* Enumeration_Deserialize(xmlNodePtr xmlRoot)
{
	xmlNodePtr cur;
	xmlChar *key;
	struct Enumeration* obj;
	obj = Enumeration_Create();
	cur = xmlRoot->xmlChildrenNode;
	while (cur != NULL) {
		if (cur->type != XML_ELEMENT_NODE) {
			cur = cur->next;
			continue;
		}
		if ((!xmlStrcmp(cur->name, (const xmlChar *)"value"))){
			key = xmlNodeListGetString(cur->doc, cur->xmlChildrenNode, 1);
			Enumeration_Add_value(obj, (const char*)key);
/*			xmlFree(key);*/
		}
	// TODO: 
		cur = cur->next;
	}
	return obj;
}

#endif
struct Enumeration_value_List* Enumeration_Get_value(struct Enumeration* obj)
{
	return obj->value_head;
}

void Enumeration_Add_value(struct Enumeration* obj, const char* value)
{
	struct Enumeration_value_List* value_node;
	value_node = (struct Enumeration_value_List*)malloc(sizeof(struct Enumeration_value_List));
	value_node->value = (char*)malloc(strlen(value)+1);
	strcpy(value_node->value, value);
	value_node->next = NULL;
	if (obj->value_tail)
	{
		obj->value_tail->next = value_node;
	}
	if (obj->value_head == NULL)
	{
		obj->value_head = value_node;
	}
	obj->value_tail = value_node;
}