MCPcopy Create free account
hub / github.com/cinder/Cinder / clone_node

Method clone_node

include/rapidxml/rapidxml.hpp:497–520  ·  view source on GitHub ↗

Clones an xml_node and its hierarchy of child nodes and attributes. Nodes and attributes are allocated from this memory pool. Names and values are not cloned, they are shared between the clone and the source. Result node can be optionally specified as a second parameter, in which case its contents will be replaced with cloned source node. This is useful when you want to clone entire document. \par

Source from the content-addressed store, hash-verified

495 //! \param result Node to put results in, or 0 to automatically allocate result node
496 //! \return Pointer to cloned node. This pointer will never be NULL.
497 xml_node<Ch> *clone_node(const xml_node<Ch> *source, xml_node<Ch> *result = 0)
498 {
499 // Prepare result node
500 if (result)
501 {
502 result->remove_all_attributes();
503 result->remove_all_nodes();
504 result->type(source->type());
505 }
506 else
507 result = allocate_node(source->type());
508
509 // Clone name and value
510 result->name(source->name(), source->name_size());
511 result->value(source->value(), source->value_size());
512
513 // Clone child nodes and attributes
514 for (xml_node<Ch> *child = source->first_node(); child; child = child->next_sibling())
515 result->append_node(clone_node(child));
516 for (xml_attribute<Ch> *attr = source->first_attribute(); attr; attr = attr->next_attribute())
517 result->append_attribute(allocate_attribute(attr->name(), attr->value(), attr->name_size(), attr->value_size()));
518
519 return result;
520 }
521
522 //! Clears the pool.
523 //! This causes memory occupied by nodes allocated by the pool to be freed.

Callers

nothing calls this directly

Calls 13

remove_all_attributesMethod · 0.80
remove_all_nodesMethod · 0.80
name_sizeMethod · 0.80
value_sizeMethod · 0.80
first_nodeMethod · 0.80
next_siblingMethod · 0.80
append_nodeMethod · 0.80
first_attributeMethod · 0.80
next_attributeMethod · 0.80
append_attributeMethod · 0.80
typeMethod · 0.45
nameMethod · 0.45

Tested by

no test coverage detected