]> git.sesse.net Git - xml-template/blob - c++0x/xml-template.h
Fix the worst (but not all) memory leaks in the C++0x version.
[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 ~Directive();
14         virtual void process(xmlNode *node, bool clean) = 0;
15 };
16
17 class Replace : public Directive {
18  public:
19         Replace(const std::string &str);
20         virtual void process(xmlNode *node, bool clean);
21
22  private:
23         const std::string str;
24 };
25
26 class Clone : public Directive {
27  public:
28         Clone(const std::vector<Directive *> &subdirectives);
29         Clone(std::initializer_list<Directive *> subdirectives);
30         ~Clone();
31         virtual void process(xmlNode *node, bool clean);
32
33  private:
34         const std::vector<Directive *> subdirectives;
35 };
36
37 class Substitute : public Directive {
38  public:
39         Substitute(const std::unordered_map<std::string, Directive*> &substitution_map);
40         Substitute(std::initializer_list<std::pair<const std::string, Directive*>> substitution_map);
41         ~Substitute();
42
43         virtual void process(xmlNode *node, bool clean);
44
45  private:
46         const std::unordered_map<std::string, Directive*> substitution_map;
47 };
48
49 void process_file(const std::string &input_filename,
50                   const std::string &output_filename,
51                   Directive *root_directive);
52
53 #endif  // !defined(_XML_TEMPLATE_H)