source: icGREP/icgrep-devel/icgrep/combine/pugixml/docs/samples/traverse_predicate.cpp @ 5516

Last change on this file since 5516 was 5516, checked in by faldebey, 21 months ago

added combinatorial testing tool

File size: 1.3 KB
Line 
1#include "pugixml.hpp"
2
3#include <string.h>
4#include <iostream>
5
6// tag::decl[]
7bool small_timeout(pugi::xml_node node)
8{
9    return node.attribute("Timeout").as_int() < 20;
10}
11
12struct allow_remote_predicate
13{
14    bool operator()(pugi::xml_attribute attr) const
15    {
16        return strcmp(attr.name(), "AllowRemote") == 0;
17    }
18
19    bool operator()(pugi::xml_node node) const
20    {
21        return node.attribute("AllowRemote").as_bool();
22    }
23};
24// end::decl[]
25
26int main()
27{
28    pugi::xml_document doc;
29    if (!doc.load_file("xgconsole.xml")) return -1;
30
31    pugi::xml_node tools = doc.child("Profile").child("Tools");
32
33    // tag::find[]
34    // Find child via predicate (looks for direct children only)
35    std::cout << tools.find_child(allow_remote_predicate()).attribute("Filename").value() << std::endl;
36
37    // Find node via predicate (looks for all descendants in depth-first order)
38    std::cout << doc.find_node(allow_remote_predicate()).attribute("Filename").value() << std::endl;
39
40    // Find attribute via predicate
41    std::cout << tools.last_child().find_attribute(allow_remote_predicate()).value() << std::endl;
42
43    // We can use simple functions instead of function objects
44    std::cout << tools.find_child(small_timeout).attribute("Filename").value() << std::endl;
45    // end::find[]
46}
47
48// vim:et
Note: See TracBrowser for help on using the repository browser.