Commit 567b2678 authored by Murray Cumming's avatar Murray Cumming

C++11: Some use of range-based for loops.

parent 3398b888
......@@ -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
}
}
}
......
......@@ -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
}
}
}
......
......@@ -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
}
}
......
......@@ -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
}
}
}
......
......@@ -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();
......
......@@ -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();
......
......@@ -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)
{
......
......@@ -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.
{
......
......@@ -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;
}
}
......
......@@ -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;
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment