int main(int argc, char **argv)
{
- vector<Directive *> things;
+ Substitute master_directive = {
+ make_pair("color", new Replace("blue")),
+ make_pair("#things", new Clone {
+ new Substitute { make_pair("li", new Replace("Raindrops on roses")) },
+ new Substitute { make_pair("li", new Replace("Whiskers on kittens")) },
+ new Substitute { make_pair("li", new Replace("Bright copper kettles")) },
+ new Substitute { make_pair("li", new Replace("Warm, woolen mittens")) },
+ }),
+ };
- {
- unordered_map<string, Directive *> submap;
- submap.insert(make_pair("li", new Replace("Raindrops on roses")));
- things.push_back(new Substitute(submap));
- }
- {
- unordered_map<string, Directive *> submap;
- submap.insert(make_pair("li", new Replace("Whiskers on kittens")));
- things.push_back(new Substitute(submap));
- }
- {
- unordered_map<string, Directive *> submap;
- submap.insert(make_pair("li", new Replace("Bright copper kettles")));
- things.push_back(new Substitute(submap));
- }
- {
- unordered_map<string, Directive *> submap;
- submap.insert(make_pair("li", new Replace("Warm, woolen mittens")));
- things.push_back(new Substitute(submap));
- }
-
- unordered_map<string, Directive *> master_map;
- master_map.insert(make_pair("color", new Replace("blue")));
- master_map.insert(make_pair("#things", new Clone(things)));
-
- process_file("../xml/clone.xml", argv[1], new Substitute(master_map));
+ process_file("../xml/clone.xml", argv[1], &master_directive);
return(0);
}
int main(int argc, char **argv)
{
- unordered_map<string, Directive*> master_map;
- process_file("../xml/passthru.xml", argv[1], new Substitute(master_map));
+ Substitute master_directive = {};
+ process_file("../xml/passthru.xml", argv[1], &master_directive);
return(0);
}
int main(int argc, char **argv)
{
- unordered_map<string, Directive*> master_map;
- master_map.insert(make_pair("title", new Replace("A very basic example")));
- master_map.insert(make_pair("#hello", new Replace("Hello world!")));
+ Substitute master_directive = {
+ make_pair("title", new Replace("A very basic example")),
+ make_pair("#hello", new Replace("Hello world!")),
+ };
- process_file("../xml/simple.xml", argv[1], new Substitute(master_map));
+ process_file("../xml/simple.xml", argv[1], &master_directive);
return(0);
}
Clone::Clone(const std::vector<Directive *> &subdirectives)
: subdirectives(subdirectives) {}
+
+Clone::Clone(std::initializer_list<Directive *> subdirectives)
+ : subdirectives(subdirectives) {}
void Clone::process(xmlNode *node, bool clean) {
// We can't use xmlNewDocFragment, since xmlDOMWrapCloneNode only knows
Substitute::Substitute(const unordered_map<string, Directive*> &substitution_map)
: substitution_map(substitution_map) {}
+
+Substitute::Substitute(std::initializer_list<std::pair<const std::string, Directive*>> substitution_map)
+ : substitution_map(substitution_map) {}
void Substitute::process(xmlNode *node, bool clean) {
for (xmlNode *child = node->children; child != NULL; child = child->next) {
class Clone : public Directive {
public:
Clone(const std::vector<Directive *> &subdirectives);
+ Clone(std::initializer_list<Directive *> subdirectives);
virtual void process(xmlNode *node, bool clean);
private:
class Substitute : public Directive {
public:
Substitute(const std::unordered_map<std::string, Directive*> &substitution_map);
+ Substitute(std::initializer_list<std::pair<const std::string, Directive*>> substitution_map);
virtual void process(xmlNode *node, bool clean);