WIP: devel : travail du mois de mars/avril #28
42
src/model.c
42
src/model.c
|
@ -48,15 +48,15 @@ struct model_t *knownModels = NULL;
|
|||
* @param node The current node being processed.
|
||||
* @param currentPath The path to the current node.
|
||||
*/
|
||||
void model_populate_hashTable (struct model_t *self, xmlNode *node, char *currentPath)
|
||||
void model_populate_hashtable (struct model_t *self, xmlNode *node, char *currentPath)
|
||||
{
|
||||
if (node == NULL) return;
|
||||
|
||||
assert(self->hashTable == NULL);
|
||||
assert(self->hashtable == NULL);
|
||||
|
||||
// Skip text nodes and others that are not element nodes
|
||||
if (node->type != XML_ELEMENT_NODE) {
|
||||
model_populate_hashTable (node->next, self->hashTable, currentPath);
|
||||
model_populate_hashtable (node->next, self->hashtable, currentPath);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -69,13 +69,13 @@ void model_populate_hashTable (struct model_t *self, xmlNode *node, char *curren
|
|||
}
|
||||
|
||||
// Add current node to hash table with its path as the key
|
||||
xmlHashAddEntry (self->hashTable, (const xmlChar *)newPath, node);
|
||||
xmlHashAddEntry (self->hashtable, (const xmlChar *)newPath, node);
|
||||
|
||||
// Recurse into child nodes with the updated path
|
||||
model_populate_hashTable (self, node->children, newPath);
|
||||
model_populate_hashtable (self, node->children, newPath);
|
||||
|
||||
// Continue with the next sibling
|
||||
model_populate_hashTable (self, node->next, currentPath);
|
||||
model_populate_hashtable (self, node->next, currentPath);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -88,9 +88,9 @@ void model_populate_hashTable (struct model_t *self, xmlNode *node, char *curren
|
|||
*/
|
||||
xmlNodePtr model_get_node (struct model_t *self, const char *path)
|
||||
{
|
||||
assert(self->hashTable != NULL);
|
||||
assert(self->hashtable != NULL);
|
||||
|
||||
return (xmlNodePtr)xmlHashLookup (self->hashTable, (const xmlChar *)path);
|
||||
return (xmlNodePtr)xmlHashLookup (self->hashtable, (const xmlChar *)path);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -106,7 +106,7 @@ int model_modify_node (struct model_t *self,
|
|||
const char *path,
|
||||
const char *newContent)
|
||||
{
|
||||
assert(self->hashTable != NULL);
|
||||
assert(self->hashtable != NULL);
|
||||
|
||||
xmlNodePtr node = model_get_node (self, path);
|
||||
if (node) {
|
||||
|
@ -132,9 +132,9 @@ char *model_get_attribute (struct model_t *self,
|
|||
const char* nodePath,
|
||||
const char* attributeName)
|
||||
{
|
||||
assert(self->hashTable != NULL);
|
||||
assert(self->hashtable != NULL);
|
||||
|
||||
xmlNodePtr node = (xmlNodePtr)xmlHashLookup (self->hashTable, (const xmlChar*)nodePath);
|
||||
xmlNodePtr node = (xmlNodePtr)xmlHashLookup (self->hashtable, (const xmlChar*)nodePath);
|
||||
if (node) {
|
||||
return getAttributeValue (node, attributeName);
|
||||
} else {
|
||||
|
@ -157,9 +157,9 @@ int model_set_attribute (struct model_t *self,
|
|||
const char* attributeName,
|
||||
const char* attributeValue)
|
||||
{
|
||||
assert(self->hashTable != NULL);
|
||||
assert(self->hashtable != NULL);
|
||||
|
||||
xmlNodePtr node = (xmlNodePtr)xmlHashLookup (self->hashTable, (const xmlChar*)nodePath);
|
||||
xmlNodePtr node = (xmlNodePtr)xmlHashLookup (self->hashtable, (const xmlChar*)nodePath);
|
||||
if (node) {
|
||||
return setAttributeValue (node, attributeName, attributeValue);
|
||||
} else {
|
||||
|
@ -168,11 +168,11 @@ int model_set_attribute (struct model_t *self,
|
|||
}
|
||||
|
||||
/**
|
||||
* Copies a node recursively to a new sibling node with a modified attribute and updates the self->hashTable.
|
||||
* Copies a node recursively to a new sibling node with a modified attribute and updates the self->hashtable.
|
||||
*
|
||||
* @param node The node to copy.
|
||||
* @param self The self structure for tracking nodes by path.
|
||||
* @param originalNodePath The path of the original node in the self->hashTable.
|
||||
* @param originalNodePath The path of the original node in the self->hashtable.
|
||||
* @param attributeName The name of the attribute to modify in the copied node.
|
||||
* @param newAttributeValue The new value for the specified attribute in the copied node.
|
||||
* @return The copied node with the modified attribute, or NULL on failure.
|
||||
|
@ -183,7 +183,7 @@ xmlNodePtr model_copy_node(struct model_t *self,
|
|||
const char* attributeName,
|
||||
const char* newAttributeValue)
|
||||
{
|
||||
assert(self->hashTable != NULL);
|
||||
assert(self->hashtable != NULL);
|
||||
|
||||
// Deep copy the node
|
||||
xmlNodePtr copiedNode = xmlDocCopyNode(node, self->doc, 1);
|
||||
|
@ -201,8 +201,8 @@ xmlNodePtr model_copy_node(struct model_t *self,
|
|||
char newPath[1024];
|
||||
snprintf (newPath, sizeof(newPath), "%s_copy", originalNodePath);
|
||||
|
||||
// Update the self->hashTable with the new node's path
|
||||
xmlHashAddEntry (self->hashTable, (const xmlChar*)newPath, copiedNode);
|
||||
// Update the self->hashtable with the new node's path
|
||||
xmlHashAddEntry (self->hashtable, (const xmlChar*)newPath, copiedNode);
|
||||
|
||||
return copiedNode;
|
||||
}
|
||||
|
@ -313,9 +313,9 @@ static bool model_init(struct model_t *self)
|
|||
return false;
|
||||
}
|
||||
|
||||
model_populate_hashTable(self, node, "");
|
||||
model_populate_hashtable(self, node, "");
|
||||
|
||||
if (self->hashTable == NULL) {
|
||||
if (self->hashtable == NULL) {
|
||||
printerr("Can't create model hash table !\n");
|
||||
xmlFreeDoc(self->doc);
|
||||
return false;
|
||||
|
@ -327,7 +327,7 @@ static bool model_init(struct model_t *self)
|
|||
static bool model_shutdown(struct model_t *self)
|
||||
{
|
||||
xmlFreeDoc(self->doc);
|
||||
xmlHashFree(self->hashTable, NULL);
|
||||
xmlHashFree(self->hashtable, NULL);
|
||||
// This is to debug memory for regression tests
|
||||
//xmlMemoryDump();
|
||||
|
||||
|
|
Loading…
Reference in New Issue