You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

121 lines
2.9 KiB

7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /** Generated by xsd2c */
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <stdlib.h>
  5. #include "Enumeration.h"
  6. struct Enumeration* Enumeration_Create()
  7. {
  8. struct Enumeration* _res;
  9. _res = (struct Enumeration*)malloc(sizeof(struct Enumeration));
  10. _res->value_head = NULL;
  11. _res->value_tail = NULL;
  12. return _res;
  13. }
  14. void Enumeration_Free(struct Enumeration* obj)
  15. {
  16. struct Enumeration_value_List* value_cur;
  17. struct Enumeration_value_List* value_tmp;
  18. if (obj == NULL) return;
  19. value_cur = obj->value_head;
  20. while (value_cur != NULL)
  21. {
  22. if (value_cur->value) free(value_cur->value);
  23. value_tmp = value_cur->next;
  24. free(value_cur);
  25. value_cur = value_tmp;
  26. }
  27. free(obj);
  28. }
  29. void Enumeration_Sax_Serialize(struct Enumeration* obj,
  30. const char *root_element_name,
  31. void (*OnStartElement)(const char* element_name, int attr_count, char **keys, char **values, void* userData),
  32. void (*OnCharacters)(const char* element_name, const char* chars, void* userData),
  33. void (*OnEndElement)(const char* element_name, void* userData),
  34. void* userData)
  35. {
  36. int attrCount, curCount;
  37. char **keys;
  38. char **values;
  39. char buffer[255];
  40. struct Enumeration_value_List* value_cur;
  41. attrCount = 0;
  42. keys = (char**)malloc(sizeof(char*)*attrCount);
  43. values = (char**)malloc(sizeof(char*)*attrCount);
  44. curCount = 0;
  45. OnStartElement(root_element_name, attrCount, keys, values, userData);
  46. value_cur = obj->value_head;
  47. while (value_cur != NULL)
  48. {
  49. OnStartElement("value", 0, NULL, NULL, userData);
  50. if (value_cur->value != NULL)
  51. OnCharacters("value", value_cur->value, userData);
  52. OnEndElement("value", userData);
  53. value_cur = value_cur->next;
  54. }
  55. OnEndElement(root_element_name, userData);
  56. }
  57. #ifndef _DESERIALIZER_DISABLED_
  58. struct Enumeration* Enumeration_Deserialize(xmlNodePtr xmlRoot)
  59. {
  60. xmlNodePtr cur;
  61. xmlChar *key;
  62. struct Enumeration* obj;
  63. obj = Enumeration_Create();
  64. cur = xmlRoot->xmlChildrenNode;
  65. while (cur != NULL) {
  66. if (cur->type != XML_ELEMENT_NODE) {
  67. cur = cur->next;
  68. continue;
  69. }
  70. if ((!xmlStrcmp(cur->name, (const xmlChar *)"value"))){
  71. key = xmlNodeListGetString(cur->doc, cur->xmlChildrenNode, 1);
  72. Enumeration_Add_value(obj, (const char*)key);
  73. /* xmlFree(key);*/
  74. }
  75. // TODO:
  76. cur = cur->next;
  77. }
  78. return obj;
  79. }
  80. #endif
  81. struct Enumeration_value_List* Enumeration_Get_value(struct Enumeration* obj)
  82. {
  83. return obj->value_head;
  84. }
  85. void Enumeration_Add_value(struct Enumeration* obj, const char* value)
  86. {
  87. struct Enumeration_value_List* value_node;
  88. value_node = (struct Enumeration_value_List*)malloc(sizeof(struct Enumeration_value_List));
  89. value_node->value = (char*)malloc(strlen(value)+1);
  90. strcpy(value_node->value, value);
  91. value_node->next = NULL;
  92. if (obj->value_tail)
  93. {
  94. obj->value_tail->next = value_node;
  95. }
  96. if (obj->value_head == NULL)
  97. {
  98. obj->value_head = value_node;
  99. }
  100. obj->value_tail = value_node;
  101. }