[libxml++] C++11: Some use of range-based for loops.
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libxml++] C++11: Some use of range-based for loops.
- Date: Mon, 20 Jul 2015 09:00:21 +0000 (UTC)
commit 567b267850b8016bf24d52330637769bdfc61ec4
Author: Murray Cumming <murrayc murrayc com>
Date: Mon Jul 20 10:51:48 2015 +0200
C++11: Some use of range-based for loops.
examples/dom_parse_entities/main.cc | 5 ++---
examples/dom_parser/main.cc | 4 ++--
examples/dom_parser_raw/main.cc | 5 ++---
examples/dom_xinclude/main.cc | 5 ++---
examples/dom_xpath/main.cc | 12 ++++++------
examples/sax_exception/myparser.cc | 6 ++----
examples/sax_parser/myparser.cc | 6 +++---
examples/sax_parser_build_dom/svgparser.cc | 6 +++---
examples/sax_parser_entities/myparser.cc | 4 ++--
libxml++/document.cc | 15 +++++++++------
10 files changed, 33 insertions(+), 35 deletions(-)
---
diff --git a/examples/dom_parse_entities/main.cc b/examples/dom_parse_entities/main.cc
index eb4d626..1b22024 100644
--- a/examples/dom_parse_entities/main.cc
+++ b/examples/dom_parse_entities/main.cc
@@ -57,10 +57,9 @@ void print_node(const xmlpp::Node* node, bool substitute_entities, unsigned int
if(!nodeContent)
{
//Recurse through child nodes:
- auto list = node->get_children();
- for(xmlpp::Node::NodeList::iterator iter = list.begin(); iter != list.end(); ++iter)
+ for(const auto& child : node->get_children())
{
- print_node(*iter, substitute_entities, indentation + 2); //recursive
+ print_node(child, substitute_entities, indentation + 2); //recursive
}
}
}
diff --git a/examples/dom_parser/main.cc b/examples/dom_parser/main.cc
index 45375e8..8e9371e 100644
--- a/examples/dom_parser/main.cc
+++ b/examples/dom_parser/main.cc
@@ -106,9 +106,9 @@ void print_node(const xmlpp::Node* node, unsigned int indentation = 0)
{
//Recurse through child nodes:
auto list = node->get_children();
- for(xmlpp::Node::NodeList::iterator iter = list.begin(); iter != list.end(); ++iter)
+ for(const auto& child : node->get_children())
{
- print_node(*iter, indentation + 2); //recursive
+ print_node(child, indentation + 2); //recursive
}
}
}
diff --git a/examples/dom_parser_raw/main.cc b/examples/dom_parser_raw/main.cc
index e3ab1ed..5051784 100644
--- a/examples/dom_parser_raw/main.cc
+++ b/examples/dom_parser_raw/main.cc
@@ -33,10 +33,9 @@ void print_node(const xmlpp::Node* node, unsigned int indentation = 0)
std::cout << "Node name = " << node->get_name() << std::endl;
//Recurse through child nodes:
- auto list = node->get_children();
- for(xmlpp::Node::NodeList::iterator iter = list.begin(); iter != list.end(); ++iter)
+ for(const auto& child : node->get_children())
{
- print_node(*iter, indentation + 2); //recursive
+ print_node(child, indentation + 2); //recursive
}
}
diff --git a/examples/dom_xinclude/main.cc b/examples/dom_xinclude/main.cc
index 878b889..0031287 100644
--- a/examples/dom_xinclude/main.cc
+++ b/examples/dom_xinclude/main.cc
@@ -101,10 +101,9 @@ void print_node(const xmlpp::Node* node, unsigned int indentation = 0)
if (!nodeContent)
{
//Recurse through child nodes:
- auto list = node->get_children();
- for (xmlpp::Node::NodeList::iterator iter = list.begin(); iter != list.end(); ++iter)
+ for(const auto& child : node->get_children())
{
- print_node(*iter, indentation + 2); //recursive
+ print_node(child, indentation + 2); //recursive
}
}
}
diff --git a/examples/dom_xpath/main.cc b/examples/dom_xpath/main.cc
index 965ac64..2dfd080 100644
--- a/examples/dom_xpath/main.cc
+++ b/examples/dom_xpath/main.cc
@@ -55,23 +55,23 @@ bool xpath_test(const xmlpp::Node* node, const Glib::ustring& xpath)
std::cout << set.size() << " nodes have been found:" << std::endl;
//Print the structural paths and the values:
- for(xmlpp::NodeSet::iterator i = set.begin(); i != set.end(); ++i)
+ for(const auto& node : set)
{
- std::cout << " " << (*i)->get_path();
+ std::cout << " " << node->get_path();
- auto attribute = dynamic_cast<xmlpp::Attribute*>(*i);
+ auto attribute = dynamic_cast<xmlpp::Attribute*>(node);
if (attribute)
std::cout << ", value=\"" << attribute->get_value() << "\"";
- auto content_node = dynamic_cast<xmlpp::ContentNode*>(*i);
+ auto content_node = dynamic_cast<xmlpp::ContentNode*>(node);
if (content_node)
std::cout << ", content=\"" << content_node->get_content() << "\"";
- auto entity_reference = dynamic_cast<xmlpp::EntityReference*>(*i);
+ auto entity_reference = dynamic_cast<xmlpp::EntityReference*>(node);
if (entity_reference)
std::cout << ", text=\"" << entity_reference->get_original_text() << "\"";
- auto element = dynamic_cast<xmlpp::Element*>(*i);
+ auto element = dynamic_cast<xmlpp::Element*>(node);
if (element)
{
auto text_node = element->get_child_text();
diff --git a/examples/sax_exception/myparser.cc b/examples/sax_exception/myparser.cc
index 11356c6..19b5417 100644
--- a/examples/sax_exception/myparser.cc
+++ b/examples/sax_exception/myparser.cc
@@ -74,11 +74,9 @@ void MySaxParser::on_start_element(const Glib::ustring& name,
std::cout << "node name=" << name << std::endl;
// Print attributes:
- for(AttributeList::const_iterator iter = attributes.begin();
- iter != attributes.end();
- ++iter)
+ for(const auto& attr_pair : attributes)
{
- std::cout << " Attribute " << iter->name << " = " << iter->value << std::endl;
+ std::cout << " Attribute " << attr_pair.name << " = " << attr_pair.value << std::endl;
}
throw MyException();
diff --git a/examples/sax_parser/myparser.cc b/examples/sax_parser/myparser.cc
index ce023d4..03c694c 100644
--- a/examples/sax_parser/myparser.cc
+++ b/examples/sax_parser/myparser.cc
@@ -49,11 +49,11 @@ void MySaxParser::on_start_element(const Glib::ustring& name,
std::cout << "node name=" << name << std::endl;
// Print attributes:
- for(xmlpp::SaxParser::AttributeList::const_iterator iter = attributes.begin(); iter != attributes.end();
++iter)
+ for(const auto& attr_pair : attributes)
{
try
{
- std::cout << " Attribute name=" << iter->name << std::endl;
+ std::cout << " Attribute name=" << attr_pair.name << std::endl;
}
catch(const Glib::ConvertError& ex)
{
@@ -62,7 +62,7 @@ void MySaxParser::on_start_element(const Glib::ustring& name,
try
{
- std::cout << " , value= " << iter->value << std::endl;
+ std::cout << " , value= " << attr_pair.value << std::endl;
}
catch(const Glib::ConvertError& ex)
{
diff --git a/examples/sax_parser_build_dom/svgparser.cc b/examples/sax_parser_build_dom/svgparser.cc
index 126656a..46438ce 100644
--- a/examples/sax_parser_build_dom/svgparser.cc
+++ b/examples/sax_parser_build_dom/svgparser.cc
@@ -106,10 +106,10 @@ void Parser::on_start_element(const Glib::ustring& name,
// Copy the attributes form the old node to the new derived node:
// In theory, you could change the attributes here.
- for(xmlpp::SaxParser::AttributeList::const_iterator iter = attributes.begin(); iter != attributes.end();
++iter)
+ for(const auto& attr_pair : attributes)
{
- auto name = (*iter).name;
- auto value = (*iter).value;
+ auto name = attr_pair.name;
+ auto value = attr_pair.value;
Glib::ustring::size_type idx = name.find(':');
if (idx == Glib::ustring::npos) // If the separator was not found.
{
diff --git a/examples/sax_parser_entities/myparser.cc b/examples/sax_parser_entities/myparser.cc
index 16f3b1e..c891fcf 100644
--- a/examples/sax_parser_entities/myparser.cc
+++ b/examples/sax_parser_entities/myparser.cc
@@ -48,9 +48,9 @@ void MySaxParser::on_start_element(const Glib::ustring& name,
std::cout << "node name=" << name << std::endl;
// Print attributes:
- for(xmlpp::SaxParser::AttributeList::const_iterator iter = attributes.begin(); iter != attributes.end();
++iter)
+ for(const auto& attr_pair : attributes)
{
- std::cout << " Attribute " << iter->name << " = " << iter->value << std::endl;
+ std::cout << " Attribute " << attr_pair.name << " = " << attr_pair.value << std::endl;
}
}
diff --git a/libxml++/document.cc b/libxml++/document.cc
index e73c942..b289c4a 100644
--- a/libxml++/document.cc
+++ b/libxml++/document.cc
@@ -432,19 +432,22 @@ int Document::process_xinclude(bool generate_xinclude_nodes)
generate_xinclude_nodes ? 0 : XML_PARSE_NOXINCNODE);
remove_found_wrappers(reinterpret_cast<xmlNode*>(impl_), node_map);
- // Delete wrappers of nodes that have been deleted or have got their type changed.
- for (NodeMap::iterator iter = node_map.begin(); iter != node_map.end(); ++iter)
+
+ // Delete wrappers of nodes that have been deleted or have had their type changed.
+ for (auto& the_pair : node_map)
{
- switch (iter->second)
+ auto node = the_pair.first;
+
+ switch (the_pair.second)
{
case XML_DTD_NODE:
- delete reinterpret_cast<Dtd*>(iter->first);
+ delete reinterpret_cast<Dtd*>(node);
break;
case XML_DOCUMENT_NODE:
- delete reinterpret_cast<Document*>(iter->first);
+ delete reinterpret_cast<Document*>(node);
break;
default:
- delete iter->first; // Node*
+ delete node; // Node*
break;
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]