From 8e0c64401f1b6f7b8a1ad5cc68227fc344f149dc Mon Sep 17 00:00:00 2001 From: "arseny.kapoulkine" Date: Tue, 6 Jul 2010 18:51:29 +0000 Subject: xml_node::all_elements_by_name is now deprecated git-svn-id: http://pugixml.googlecode.com/svn/trunk@563 99668b35-9821-0410-8761-19e4c4f06640 --- docs/manual.qbk | 5 ++--- src/pugixml.hpp | 39 +++++++++++++++++++++++---------------- tests/test_deprecated.cpp | 20 ++++++++++++++++++++ tests/test_dom_traverse.cpp | 20 -------------------- 4 files changed, 45 insertions(+), 39 deletions(-) diff --git a/docs/manual.qbk b/docs/manual.qbk index dd8e985..27cb691 100644 --- a/docs/manual.qbk +++ b/docs/manual.qbk @@ -432,7 +432,7 @@ The only exception is `set_memory_management_functions`; it modifies global vari With the exception of XPath, pugixml itself does not throw any exceptions. Additionally, most pugixml functions have a no-throw exception guarantee. -This is not applicable to functions that operate on STL strings or IOstreams; such functions have either strong guarantee (functions that operate on strings) or basic guarantee (functions that operate on streams). Also functions that call user-defined callbacks (i.e. `xml_node::traverse` or `xml_node::all_elements_by_name`) do not provide any exception guarantees beyond the ones provided by callback. +This is not applicable to functions that operate on STL strings or IOstreams; such functions have either strong guarantee (functions that operate on strings) or basic guarantee (functions that operate on streams). Also functions that call user-defined callbacks (i.e. `xml_node::traverse` or `xml_node::find_node`) do not provide any exception guarantees beyond the ones provided by callback. XPath functions may throw `xpath_exception` on parsing error; also, XPath implementation uses STL, and thus may throw i.e. `std::bad_alloc` in low memory conditions. Still, XPath functions provide strong exception guarantee. @@ -915,7 +915,7 @@ Major release, featuring extended and improved Unicode support, miscellaneous pe * Compatibility: # parse() and as_utf16 are left for compatibility (these functions are deprecated and will be removed in version 1.0) - # Wildcard functions, document_order/precompute_document_order functions and format_write_bom_utf8 flag are deprecated and will be removed in version 1.0 + # Wildcard functions, document_order/precompute_document_order functions, all_elements_by_name function and format_write_bom_utf8 flag are deprecated and will be removed in version 1.0 # xpath_type_t enumeration was renamed to xpath_value_type; xpath_type_t is deprecated and will be removed in version 1.0 [h5 8.11.2009 - version 0.5] @@ -1265,7 +1265,6 @@ Classes: * void remove_attribute(const char_t* name); * void remove_child(const xml_node& n); * void remove_child(const char_t* name); - * template void all_elements_by_name(const char_t* name, OutputIterator it) const * template xml_attribute find_attribute(Predicate pred) const * template xml_node find_child(Predicate pred) const * template xml_node find_node(Predicate pred) const diff --git a/src/pugixml.hpp b/src/pugixml.hpp index 376d4e4..a1254b6 100644 --- a/src/pugixml.hpp +++ b/src/pugixml.hpp @@ -791,6 +791,25 @@ namespace pugi explicit xml_node(xml_node_struct* p); private: + template void all_elements_by_name_helper(const char_t* name, OutputIterator it) const + { + if (!_root) return; + + for (xml_node node = first_child(); node; node = node.next_sibling()) + { + if (node.type() == node_element) + { + if (impl::strequal(name, node.name())) + { + *it = node; + ++it; + } + + if (node.first_child()) node.all_elements_by_name_helper(name, it); + } + } + } + template void all_elements_by_name_w_helper(const char_t* name, OutputIterator it) const { if (!_root) return; @@ -1241,24 +1260,12 @@ namespace pugi * * \param name - node name * \param it - output iterator (for example, std::back_insert_iterator (result of std::back_inserter)) + * + * \deprecated This function is deprecated */ - template void all_elements_by_name(const char_t* name, OutputIterator it) const + template PUGIXML_DEPRECATED void all_elements_by_name(const char_t* name, OutputIterator it) const { - if (!_root) return; - - for (xml_node node = first_child(); node; node = node.next_sibling()) - { - if (node.type() == node_element) - { - if (impl::strequal(name, node.name())) - { - *it = node; - ++it; - } - - if (node.first_child()) node.all_elements_by_name(name, it); - } - } + all_elements_by_name_helper(name, it); } /** diff --git a/tests/test_deprecated.cpp b/tests/test_deprecated.cpp index bcf9695..d81810e 100644 --- a/tests/test_deprecated.cpp +++ b/tests/test_deprecated.cpp @@ -132,6 +132,26 @@ TEST_XML(dom_node_find_child_by_attribute_w, "") +{ + std::vector v; + + v.clear(); + xml_node().all_elements_by_name(STR("node"), std::back_inserter(v)); + CHECK(v.empty()); + + v.clear(); + doc.all_elements_by_name(STR("node"), std::back_inserter(v)); + CHECK(v.size() == 1 && v[0] == doc.child(STR("node"))); + + v.clear(); + doc.all_elements_by_name(STR("child"), std::back_inserter(v)); + CHECK(v.size() == 3); + CHECK(v[0] == doc.child(STR("node")).child(STR("child"))); + CHECK(v[1] == doc.child(STR("node")).child(STR("child")).first_child()); + CHECK(v[2] == doc.child(STR("node")).child(STR("child")).last_child()); +} + TEST_XML(dom_node_all_elements_by_name_w, "") { std::vector v; diff --git a/tests/test_dom_traverse.cpp b/tests/test_dom_traverse.cpp index 0ca554a..1a4835b 100644 --- a/tests/test_dom_traverse.cpp +++ b/tests/test_dom_traverse.cpp @@ -391,26 +391,6 @@ TEST_XML(dom_node_find_child_by_attribute, "") -{ - std::vector v; - - v.clear(); - xml_node().all_elements_by_name(STR("node"), std::back_inserter(v)); - CHECK(v.empty()); - - v.clear(); - doc.all_elements_by_name(STR("node"), std::back_inserter(v)); - CHECK(v.size() == 1 && v[0] == doc.child(STR("node"))); - - v.clear(); - doc.all_elements_by_name(STR("child"), std::back_inserter(v)); - CHECK(v.size() == 3); - CHECK(v[0] == doc.child(STR("node")).child(STR("child"))); - CHECK(v[1] == doc.child(STR("node")).child(STR("child")).first_child()); - CHECK(v[2] == doc.child(STR("node")).child(STR("child")).last_child()); -} - struct find_predicate_const { bool result; -- cgit v1.2.3