Skip to content

Commit 3398b88

Browse files
committed
C++11: Use auto.
1 parent d51cb2b commit 3398b88

File tree

30 files changed

+209
-209
lines changed

30 files changed

+209
-209
lines changed

examples/dom_build/main.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ main(int /* argc */, char** /* argv */)
4444
document.add_comment("First comment");
4545

4646
//foo is the default namespace prefix.
47-
xmlpp::Element* nodeRoot = document.create_root_node("exampleroot", "http://foo", "foo"); //Declares the namespace and uses its prefix for this node
47+
auto nodeRoot = document.create_root_node("exampleroot", "http://foo", "foo"); //Declares the namespace and uses its prefix for this node
4848
nodeRoot->set_namespace_declaration("http://foobar", "foobar"); //Also associate this prefix with this namespace:
4949

5050
nodeRoot->set_child_text("\n");
51-
xmlpp::Element* nodeChild = nodeRoot->add_child("examplechild");
51+
auto nodeChild = nodeRoot->add_child("examplechild");
5252

5353
//Associate prefix with namespace:
5454
nodeChild->set_namespace_declaration("http://bar", "bar");
@@ -67,7 +67,7 @@ main(int /* argc */, char** /* argv */)
6767
nodeChild = nodeRoot->add_child("examplechild", "foobar"); //foobar is the namespace prefix
6868
nodeChild->set_attribute("id", "2", "foobar"); //foobar is the namespace prefix.
6969

70-
Glib::ustring whole = document.write_to_string();
70+
auto whole = document.write_to_string();
7171
std::cout << "XML built at runtime: " << std::endl << whole << std::endl;
7272
std::cout << "namespace of root node: " << nodeRoot->get_namespace_uri() << std::endl;
7373
}

examples/dom_parse_entities/main.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ void print_node(const xmlpp::Node* node, bool substitute_entities, unsigned int
3535
if (substitute_entities)
3636
{
3737
// Entities have been substituted. Print the text nodes.
38-
const xmlpp::TextNode* nodeText = dynamic_cast<const xmlpp::TextNode*>(node);
38+
const auto nodeText = dynamic_cast<const xmlpp::TextNode*>(node);
3939
if (nodeText && !nodeText->is_white_space())
4040
{
4141
std::cout << indent << "text = " << CatchConvertError(nodeText->get_content()) << std::endl;
@@ -44,7 +44,7 @@ void print_node(const xmlpp::Node* node, bool substitute_entities, unsigned int
4444
else
4545
{
4646
// Entities have not been substituted. Print the entity reference nodes.
47-
const xmlpp::EntityReference* nodeEntityReference = dynamic_cast<const xmlpp::EntityReference*>(node);
47+
const auto nodeEntityReference = dynamic_cast<const xmlpp::EntityReference*>(node);
4848
if (nodeEntityReference)
4949
{
5050
std::cout << indent << "entity reference name = " << CatchConvertError(nodeEntityReference->get_name()) << std::endl;
@@ -53,11 +53,11 @@ void print_node(const xmlpp::Node* node, bool substitute_entities, unsigned int
5353
}
5454
} // end if (substitute_entities)
5555

56-
const xmlpp::ContentNode* nodeContent = dynamic_cast<const xmlpp::ContentNode*>(node);
56+
const auto nodeContent = dynamic_cast<const xmlpp::ContentNode*>(node);
5757
if(!nodeContent)
5858
{
5959
//Recurse through child nodes:
60-
xmlpp::Node::NodeList list = node->get_children();
60+
auto list = node->get_children();
6161
for(xmlpp::Node::NodeList::iterator iter = list.begin(); iter != list.end(); ++iter)
6262
{
6363
print_node(*iter, substitute_entities, indentation + 2); //recursive
@@ -106,7 +106,7 @@ int main(int argc, char* argv[])
106106
if(parser)
107107
{
108108
//Walk the tree:
109-
const xmlpp::Node* pNode = parser.get_document()->get_root_node(); //deleted by DomParser.
109+
const auto pNode = parser.get_document()->get_root_node(); //deleted by DomParser.
110110
print_node(pNode, substitute_entities);
111111
}
112112
}

examples/dom_parser/main.cc

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,18 @@ void print_node(const xmlpp::Node* node, unsigned int indentation = 0)
3333
const Glib::ustring indent(indentation, ' ');
3434
std::cout << std::endl; //Separate nodes by an empty line.
3535

36-
const xmlpp::ContentNode* nodeContent = dynamic_cast<const xmlpp::ContentNode*>(node);
37-
const xmlpp::TextNode* nodeText = dynamic_cast<const xmlpp::TextNode*>(node);
38-
const xmlpp::CommentNode* nodeComment = dynamic_cast<const xmlpp::CommentNode*>(node);
36+
const auto nodeContent = dynamic_cast<const xmlpp::ContentNode*>(node);
37+
const auto nodeText = dynamic_cast<const xmlpp::TextNode*>(node);
38+
const auto nodeComment = dynamic_cast<const xmlpp::CommentNode*>(node);
3939

4040
if(nodeText && nodeText->is_white_space()) //Let's ignore the indenting - you don't always want to do this.
4141
return;
4242

43-
const Glib::ustring nodename = node->get_name();
43+
const auto nodename = node->get_name();
4444

4545
if(!nodeText && !nodeComment && !nodename.empty()) //Let's not say "name: text".
4646
{
47-
const Glib::ustring namespace_prefix = node->get_namespace_prefix();
47+
const auto namespace_prefix = node->get_namespace_prefix();
4848

4949
std::cout << indent << "Node name = ";
5050
if(!namespace_prefix.empty())
@@ -77,11 +77,11 @@ void print_node(const xmlpp::Node* node, unsigned int indentation = 0)
7777
std::cout << indent << " line = " << node->get_line() << std::endl;
7878

7979
//Print attributes:
80-
const xmlpp::Element::AttributeList& attributes = nodeElement->get_attributes();
80+
const auto attributes = nodeElement->get_attributes();
8181
for(xmlpp::Element::AttributeList::const_iterator iter = attributes.begin(); iter != attributes.end(); ++iter)
8282
{
83-
const xmlpp::Attribute* attribute = *iter;
84-
const Glib::ustring namespace_prefix = attribute->get_namespace_prefix();
83+
const auto attribute = *iter;
84+
const auto namespace_prefix = attribute->get_namespace_prefix();
8585

8686
std::cout << indent << " Attribute ";
8787
if(!namespace_prefix.empty())
@@ -90,7 +90,7 @@ void print_node(const xmlpp::Node* node, unsigned int indentation = 0)
9090
<< CatchConvertError(attribute->get_value()) << std::endl;
9191
}
9292

93-
const xmlpp::Attribute* attribute = nodeElement->get_attribute("title");
93+
const auto attribute = nodeElement->get_attribute("title");
9494
if(attribute)
9595
{
9696
std::cout << indent;
@@ -105,7 +105,7 @@ void print_node(const xmlpp::Node* node, unsigned int indentation = 0)
105105
if(!nodeContent)
106106
{
107107
//Recurse through child nodes:
108-
xmlpp::Node::NodeList list = node->get_children();
108+
auto list = node->get_children();
109109
for(xmlpp::Node::NodeList::iterator iter = list.begin(); iter != list.end(); ++iter)
110110
{
111111
print_node(*iter, indentation + 2); //recursive
@@ -178,7 +178,7 @@ int main(int argc, char* argv[])
178178
if(parser)
179179
{
180180
//Walk the tree:
181-
const xmlpp::Node* pNode = parser.get_document()->get_root_node(); //deleted by DomParser.
181+
const auto pNode = parser.get_document()->get_root_node(); //deleted by DomParser.
182182
print_node(pNode);
183183
}
184184
}

examples/dom_parser_raw/main.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ void print_node(const xmlpp::Node* node, unsigned int indentation = 0)
3333
std::cout << "Node name = " << node->get_name() << std::endl;
3434

3535
//Recurse through child nodes:
36-
xmlpp::Node::NodeList list = node->get_children();
36+
auto list = node->get_children();
3737
for(xmlpp::Node::NodeList::iterator iter = list.begin(); iter != list.end(); ++iter)
3838
{
3939
print_node(*iter, indentation + 2); //recursive
@@ -49,7 +49,7 @@ std::string read_from_disk(const std::string& filepath)
4949
{
5050
while(!(fStream.eof()))
5151
{
52-
char chTemp = fStream.get();
52+
auto chTemp = fStream.get();
5353
if(!(fStream.eof()))
5454
result += chTemp;
5555
}
@@ -77,7 +77,7 @@ int main(int argc, char* argv[])
7777
parser.set_substitute_entities(); //We just want the text to be resolved/unescaped automatically.
7878

7979

80-
std::string contents = read_from_disk(filepath);
80+
auto contents = read_from_disk(filepath);
8181
std::string contents_ucs2;
8282

8383
try
@@ -103,7 +103,7 @@ int main(int argc, char* argv[])
103103
if(parser)
104104
{
105105
//Walk the tree:
106-
const xmlpp::Node* pNode = parser.get_document()->get_root_node(); //deleted by DomParser.
106+
const auto pNode = parser.get_document()->get_root_node(); //deleted by DomParser.
107107
print_node(pNode);
108108
}
109109
}

examples/dom_read_write/main.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ main(int argc, char* argv[])
6060
if(parser)
6161
{
6262
//Write it out again.
63-
xmlpp::Document* document = parser.get_document();
63+
auto document = parser.get_document();
6464
if(document)
6565
document->write_to_file(filepath_out);
6666
}
@@ -72,7 +72,7 @@ main(int argc, char* argv[])
7272
if(parser)
7373
{
7474
//Write it out again.
75-
xmlpp::Document* document = parser.get_document();
75+
auto document = parser.get_document();
7676
if(document)
7777
document->write_to_file(filepath_out2);
7878
}

examples/dom_update_namespace/main.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,13 @@ void TestNamespace::setup(const std::string& filename)
8484
parser_.set_substitute_entities(true);
8585
parser_.parse_file(filename);
8686

87-
xmlpp::Document* document = parser_.get_document();
87+
auto document = parser_.get_document();
8888
root_ = document->get_root_node();
8989
}
9090

9191
void TestNamespace::test_create_new_node_with_default_namespace()
9292
{
93-
const Glib::ustring filename = "example1.xml";
93+
const auto filename = "example1.xml";
9494
setup(filename);
9595

9696
// Check original document
@@ -100,7 +100,7 @@ void TestNamespace::test_create_new_node_with_default_namespace()
100100
"Input file shouldn't have any child in alternate default namespace");
101101

102102
// Add child nodes in default namespace and check document again
103-
xmlpp::Element* child = root_->add_child("child");
103+
auto child = root_->add_child("child");
104104
child->set_namespace_declaration(nsmap_["ns1"], "");
105105
root_->add_child_text("\n");
106106
root_->add_child_with_new_ns("child", nsmap_["ns1"]);
@@ -118,7 +118,7 @@ void TestNamespace::test_create_new_node_with_default_namespace()
118118

119119
void TestNamespace::test_create_new_node_using_existing_namespace_prefix()
120120
{
121-
const Glib::ustring filename = "example2.xml";
121+
const auto filename = "example2.xml";
122122
setup(filename);
123123

124124
// Check original document
@@ -128,7 +128,7 @@ void TestNamespace::test_create_new_node_using_existing_namespace_prefix()
128128
"Input file shouldn't have any child in child namespace");
129129

130130
// Add child nodes with specific namespace and check document again
131-
xmlpp::Element* child = root_->add_child("child", "ns0");
131+
auto child = root_->add_child("child", "ns0");
132132
child->set_namespace_declaration(nsmap_["ns1"], "");
133133
root_->add_child_text("\n");
134134
root_->add_child_with_new_ns("child", nsmap_["ns1"]);

examples/dom_xinclude/main.cc

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,19 @@ void print_node(const xmlpp::Node* node, unsigned int indentation = 0)
2828
{
2929
const Glib::ustring indent(indentation, ' ');
3030

31-
const xmlpp::ContentNode* nodeContent = dynamic_cast<const xmlpp::ContentNode*>(node);
32-
const xmlpp::TextNode* nodeText = dynamic_cast<const xmlpp::TextNode*>(node);
33-
const xmlpp::CommentNode* nodeComment = dynamic_cast<const xmlpp::CommentNode*>(node);
31+
const auto nodeContent = dynamic_cast<const xmlpp::ContentNode*>(node);
32+
const auto nodeText = dynamic_cast<const xmlpp::TextNode*>(node);
33+
const auto nodeComment = dynamic_cast<const xmlpp::CommentNode*>(node);
3434

3535
//Let's ignore the indenting - you don't always want to do this.
3636
if (nodeText && nodeText->is_white_space())
3737
return;
3838

39-
const Glib::ustring nodename = node->get_name();
39+
const auto nodename = node->get_name();
4040

4141
if (!nodeText && !nodeComment && !nodename.empty()) //Let's not say "name: text".
4242
{
43-
const Glib::ustring namespace_prefix = node->get_namespace_prefix();
43+
const auto namespace_prefix = node->get_namespace_prefix();
4444

4545
std::cout << indent << "Node name = ";
4646
if (!namespace_prefix.empty())
@@ -71,19 +71,19 @@ void print_node(const xmlpp::Node* node, unsigned int indentation = 0)
7171
std::cout << indent << " Element line = " << node->get_line() << std::endl;
7272

7373
//Print attributes:
74-
const xmlpp::Element::AttributeList attributes = nodeElement->get_attributes();
74+
const auto attributes = nodeElement->get_attributes();
7575
for (xmlpp::Element::AttributeList::const_iterator iter = attributes.begin(); iter != attributes.end(); ++iter)
7676
{
77-
const xmlpp::Attribute* attribute = *iter;
78-
const Glib::ustring namespace_prefix = attribute->get_namespace_prefix();
77+
const auto attribute = *iter;
78+
const auto namespace_prefix = attribute->get_namespace_prefix();
7979

8080
std::cout << indent << " Attribute ";
8181
if (!namespace_prefix.empty())
8282
std::cout << namespace_prefix << ":";
8383
std::cout << attribute->get_name() << " = " << attribute->get_value() << std::endl;
8484
}
8585

86-
const xmlpp::Attribute* attribute = nodeElement->get_attribute("title");
86+
const auto attribute = nodeElement->get_attribute("title");
8787
if (attribute)
8888
{
8989
std::cout << indent << "title = " << attribute->get_value() << std::endl;
@@ -101,7 +101,7 @@ void print_node(const xmlpp::Node* node, unsigned int indentation = 0)
101101
if (!nodeContent)
102102
{
103103
//Recurse through child nodes:
104-
xmlpp::Node::NodeList list = node->get_children();
104+
auto list = node->get_children();
105105
for (xmlpp::Node::NodeList::iterator iter = list.begin(); iter != list.end(); ++iter)
106106
{
107107
print_node(*iter, indentation + 2); //recursive
@@ -173,7 +173,7 @@ int main(int argc, char* argv[])
173173
if (parser)
174174
{
175175
//Walk the tree:
176-
xmlpp::Node* pNode = parser.get_document()->get_root_node(); //deleted by DomParser.
176+
auto pNode = parser.get_document()->get_root_node(); //deleted by DomParser.
177177
print_node(pNode);
178178

179179
std::cout << std::endl << ">>>>> Number of XInclude substitutions: "
@@ -182,7 +182,7 @@ int main(int argc, char* argv[])
182182
pNode = parser.get_document()->get_root_node();
183183
print_node(pNode);
184184

185-
const Glib::ustring whole = parser.get_document()->write_to_string();
185+
const auto whole = parser.get_document()->write_to_string();
186186
std::cout << std::endl << ">>>>> XML after XInclude processing: " << std::endl
187187
<< whole << std::endl;
188188
}

examples/dom_xpath/main.cc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ bool xpath_test(const xmlpp::Node* node, const Glib::ustring& xpath)
5050

5151
try
5252
{
53-
xmlpp::NodeSet set = node->find(xpath);
53+
auto set = node->find(xpath);
5454

5555
std::cout << set.size() << " nodes have been found:" << std::endl;
5656

@@ -59,22 +59,22 @@ bool xpath_test(const xmlpp::Node* node, const Glib::ustring& xpath)
5959
{
6060
std::cout << " " << (*i)->get_path();
6161

62-
xmlpp::Attribute* attribute = dynamic_cast<xmlpp::Attribute*>(*i);
62+
auto attribute = dynamic_cast<xmlpp::Attribute*>(*i);
6363
if (attribute)
6464
std::cout << ", value=\"" << attribute->get_value() << "\"";
6565

66-
xmlpp::ContentNode* content_node = dynamic_cast<xmlpp::ContentNode*>(*i);
66+
auto content_node = dynamic_cast<xmlpp::ContentNode*>(*i);
6767
if (content_node)
6868
std::cout << ", content=\"" << content_node->get_content() << "\"";
6969

70-
xmlpp::EntityReference* entity_reference = dynamic_cast<xmlpp::EntityReference*>(*i);
70+
auto entity_reference = dynamic_cast<xmlpp::EntityReference*>(*i);
7171
if (entity_reference)
7272
std::cout << ", text=\"" << entity_reference->get_original_text() << "\"";
7373

74-
xmlpp::Element* element = dynamic_cast<xmlpp::Element*>(*i);
74+
auto element = dynamic_cast<xmlpp::Element*>(*i);
7575
if (element)
7676
{
77-
xmlpp::TextNode* text_node = element->get_child_text();
77+
auto text_node = element->get_child_text();
7878
if (text_node)
7979
std::cout << ", child_text=\"" << text_node->get_content() << "\"";
8080
}
@@ -121,7 +121,7 @@ int main(int argc, char* argv[])
121121
xmlpp::DomParser parser(filepath);
122122
if(parser)
123123
{
124-
const xmlpp::Node* root = parser.get_document()->get_root_node(); //deleted by DomParser.
124+
const auto root = parser.get_document()->get_root_node(); //deleted by DomParser.
125125

126126
if(root)
127127
{

examples/dtdvalidation/main.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ int main(int argc, char* argv[])
4242

4343
int return_code = EXIT_SUCCESS;
4444
xmlpp::Document document;
45-
/* xmlpp::Element* nodeRoot = */document.create_root_node("incorrect");
45+
/* auto nodeRoot = */document.create_root_node("incorrect");
4646

4747
try
4848
{
@@ -60,8 +60,8 @@ int main(int argc, char* argv[])
6060
std::cout << ex.what() << std::endl;
6161
}
6262

63-
/* xmlpp::Element* nodeRoot2 = */document.create_root_node("example");
64-
xmlpp::Element * child = document.get_root_node()->add_child("examplechild");
63+
/* auto nodeRoot2 = */document.create_root_node("example");
64+
auto child = document.get_root_node()->add_child("examplechild");
6565
child->set_attribute("id", "an_id");
6666
child->add_child("child_of_child");
6767

0 commit comments

Comments
 (0)