]> git.sesse.net Git - xml-template/blob - c++0x/xml-template.h
Make the C++0x syntax a lot more concise using initializer lists.
[xml-template] / c++0x / xml-template.h
1 #ifndef _XML_TEMPLATE_H
2 #define _XML_TEMPLATE_H 1
3
4 #include <libxml/tree.h>
5
6 #include <string>
7 #include <utility>
8 #include <unordered_map>
9 #include <vector>
10
11 class Directive {
12  public:
13         virtual void process(xmlNode *node, bool clean) = 0;
14 };
15
16 class Replace : public Directive {
17  public:
18         Replace(const std::string &str);
19         virtual void process(xmlNode *node, bool clean);
20
21  private:
22         const std::string str;
23 };
24
25 class Clone : public Directive {
26  public:
27         Clone(const std::vector<Directive *> &subdirectives);
28         Clone(std::initializer_list<Directive *> subdirectives);
29         virtual void process(xmlNode *node, bool clean);
30
31  private:
32         const std::vector<Directive *> subdirectives;
33 };
34
35 class Substitute : public Directive {
36  public:
37         Substitute(const std::unordered_map<std::string, Directive*> &substitution_map);
38         Substitute(std::initializer_list<std::pair<const std::string, Directive*>> substitution_map);
39
40         virtual void process(xmlNode *node, bool clean);
41
42  private:
43         const std::unordered_map<std::string, Directive*> substitution_map;
44 };
45
46 void process_file(const std::string &input_filename,
47                   const std::string &output_filename,
48                   Directive *root_directive);
49
50 #endif  // !defined(_XML_TEMPLATE_H)