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
| 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. |
nothing calls this directly
no test coverage detected