Migrated xml_t to INIT/METHOD macros.

This commit is contained in:
Tobias Brunner
2011-10-04 11:20:46 +02:00
parent 99c0fa208f
commit 61ea6e0738
+34 -32
View File
@@ -66,11 +66,8 @@ typedef struct {
xmlNode *node; xmlNode *node;
} child_enum_t; } child_enum_t;
/** METHOD(enumerator_t, child_enumerate, bool,
* Implementation of xml_t.children().enumerate(). child_enum_t *e, private_xml_t **child, char **name, char **value)
*/
static bool child_enumerate(child_enum_t *e, private_xml_t **child,
char **name, char **value)
{ {
while (e->node && e->node->type != XML_ELEMENT_NODE) while (e->node && e->node->type != XML_ELEMENT_NODE)
{ {
@@ -100,18 +97,14 @@ static bool child_enumerate(child_enum_t *e, private_xml_t **child,
return FALSE; return FALSE;
} }
/** METHOD(xml_t, get_attribute, char*,
* Implementation of xml_t.get_attribute. private_xml_t *this, char *name)
*/
static char* get_attribute(private_xml_t *this, char *name)
{ {
return NULL; return NULL;
} }
/** METHOD(enumerator_t, child_destroy, void,
* destroy enumerator, and complete tree if this was the last enumerator child_enum_t *this)
*/
static void child_destroy(child_enum_t *this)
{ {
if (--this->child.root->enums == 0) if (--this->child.root->enums == 0)
{ {
@@ -121,20 +114,25 @@ static void child_destroy(child_enum_t *this)
free(this); free(this);
} }
/** METHOD(xml_t, children, enumerator_t*,
* Implementation of xml_t.children. private_xml_t *this)
*/
static enumerator_t* children(private_xml_t *this)
{ {
child_enum_t *ce = malloc_thing(child_enum_t); child_enum_t *ce;
ce->e.enumerate = (void*)child_enumerate; INIT(ce,
ce->e.destroy = (void*)child_destroy; .e = {
ce->node = this->node; .enumerate = (void*)_child_enumerate,
ce->child.public.children = (void*)children; .destroy = _child_destroy,
ce->child.public.get_attribute = (void*)get_attribute; },
ce->child.node = NULL; .child = {
ce->child.doc = this->doc; .public = {
ce->child.root = this->root; .get_attribute = _get_attribute,
.children = _children,
},
.doc = this->doc,
.root = this->root,
},
.node = this->node,
);
this->root->enums++; this->root->enums++;
return &ce->e; return &ce->e;
} }
@@ -144,20 +142,24 @@ static enumerator_t* children(private_xml_t *this)
*/ */
xml_t *xml_create(char *xml) xml_t *xml_create(char *xml)
{ {
private_xml_t *this = malloc_thing(private_xml_t); private_xml_t *this;
this->public.get_attribute = (char*(*)(xml_t*,char*))get_attribute; INIT(this,
this->public.children = (enumerator_t*(*)(xml_t*))children; .public = {
.get_attribute = _get_attribute,
.children = _children,
},
.doc = xmlReadMemory(xml, strlen(xml), NULL, NULL, 0),
);
this->doc = xmlReadMemory(xml, strlen(xml), NULL, NULL, 0); if (!this->doc)
if (this->doc == NULL)
{ {
free(this); free(this);
return NULL; return NULL;
} }
this->node = xmlDocGetRootElement(this->doc); this->node = xmlDocGetRootElement(this->doc);
this->root = this; this->root = this;
this->enums = 0;
return &this->public; return &this->public;
} }