「Dev:Source/Development/Projects/Blender File Format/XML/TreeEditingFunctions」の版間の差分

提供: wiki
移動先: 案内検索
(Robot: Automated text replacement (-[[dev: +[[Dev:))
 
(1版 をインポートしました)
 
(相違点なし)

2018年6月29日 (金) 02:45時点における最新版

XMLTreeEditingFunctions

<


Back


home


Next


>

Tree Editing Code

xml_object *XML_create_tag(char *name, int content_type, char *content) 
{ xml_object *xml;  xml = MEM_callocN(sizeof(xml_object), "xml");  strcpy(xml->tagName, name); xml->contentType = content_type; strcpy(xml->content, content);  return xml;
}

xml_doc *XML_create_doc(char *name) 
{ /* create the root tag object and set the cursor to it */ xml_doc *doc; xml_object * xml;  xml = XML_create_tag(name, 0, ""); doc = MEM_callocN(sizeof(xml_doc), "doc");  doc->root = xml; doc->cursor = xml;  return doc;   
}

/* tree editing functions */
int XML_insert_tag(xml_doc *doc, int place, xml_object *tag)
{ xml_object *xmlCursor = doc->cursor;
 /* test for Document root and react accordingly. */ if (doc->root == doc->cursor) { /* we are at the document root */ /* insert the tag  Personal note: use BLI_addtail(doc->cursor->parent->child_list, tag) or BLI_addhead for adding to a list - jeremy*/ if (xmlCursor->child_list.first == 0) { /* has no children */ xmlCursor->child_list.first = tag; xmlCursor->child_list.last = tag; } else { BLI_addtail(xmlCursor->child_list, tag); }  } else { /* check whether we are inserting tag before or after */ if (place == 1) { /* inserting after */ BLI_insertlink(xmlCursor->parent->child_list, xmlCursor, tag);  } else { /* inserting before */ BLI_insertlinkbefore(xmlCursor->parent->child_list, xmlCursor, tag); }  } tag->parent = xmlCursor->parent; /* set the tags parent */ doc->cursor = tag; /* set the cursor to the added tag */  return 1;
}

void XML_insert_child(xml_doc *doc, xml_object *tag)
{ BLI_addtail(doc->cursor->child_list, tag); /* insert the tag at the end of the child list */  tag->parent = doc->cursor; doc->cursor = tag;/* set cursor to the inserted tag */
}

int remove_children(xml_object *tag) 
{    xml_object *child; ListBase *child_list = &tag->child_list;  /* test for children */ if (child_list->first) { child = tag->child_list.first; /* loop through children */ while (child) { /* for each child test for children if it has children   call remove_children for that child. */ if (child->child_list.first) {   if (remove_children(child))       return 0; } BLI_remlink(child_list, child); MEM_freeN(child); }  } return 1;
}

int XML_remove_tag(xml_doc *doc, xml_object *tag)
{ /* check for children */ if (tag->child_list.first) { /* remove all children recursively */ if (remove_children(tag)) { printf("Failed to remove %s's Children in function XML_remove_tag", tag->tagName); return 0; } } /* check to see if tag is root */ if (doc->root == tag) { doc->cursor = NULL; doc->root = NULL; } else { /* set cursor to the previous tag or parent */ doc->cursor = tag->parent; }  /* remove curent tag */ if (tag->prop_list.first) BLI_freelistN(tag->prop_list); BLI_remlink(tag->parent->child_list, tag); /* remove tag from list document */ MEM_freeN(tag); /* free memory used by tag */ return 1;
}


/* Tag editing functions and reading functions */
char *XML_get_current_content(xml_doc *doc)
{ char content[128];  strcpy(content, doc->cursor->content);  return content;

}

int XML_set_current_content(char *content, xml_doc *doc)
{ if (strlen(content) < 128) {  strcpy(doc->cursor->content, content);  return 1; } else { return 0; }
}

xml_property *XML_get_current_proplist(xml_doc *doc)
{ xml_property *property;  doc->cursor->prop_list.first = property;  return property;
}

int XML_insert_property(char *propName, char *value)
{ xml_property *property; property = MEM_callocN(sizeof(xml_property), "property");  if (strlen(propName) < 32) {  strcpy(property->propName, propName); return 1; } else { return 0; } if (strlen(propName) < 128) { strcpy(property->value, value); return 1; } else { return 0; } 
}

<


Back


home


Next


>

-- DeveloperWikiJeremyWall - 11 Dec 2004