]> git.sesse.net Git - xml-template/commitdiff
Add a clone test for C++0x (no cloning logic yet, so test fails).
authorsgunderson@bigfoot.com <>
Wed, 21 Sep 2011 20:08:04 +0000 (22:08 +0200)
committersgunderson@bigfoot.com <>
Wed, 21 Sep 2011 20:08:04 +0000 (22:08 +0200)
c++0x/Makefile
c++0x/clone.cpp [new file with mode: 0644]
c++0x/xml-template.cpp
c++0x/xml-template.h

index 9c74fc073ec6d096ca70b2edcb774334dafca50e..939c74828cb853beb0c401397c7140a6c8d6844d 100644 (file)
@@ -9,3 +9,5 @@ passthru: passthru.o $(LIBS)
 simple: simple.o $(LIBS)
        $(CXX) -o $@ $< $(LIBS) $(LDFLAGS)
 
+clone: clone.o $(LIBS)
+       $(CXX) -o $@ $< $(LIBS) $(LDFLAGS)
diff --git a/c++0x/clone.cpp b/c++0x/clone.cpp
new file mode 100644 (file)
index 0000000..5bdfbc6
--- /dev/null
@@ -0,0 +1,38 @@
+#include <stdio.h>
+
+#include "xml-template.h"
+
+using namespace std;
+
+int main(int argc, char **argv)
+{
+       vector<Directive *> things;
+
+       {
+               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));
+       return(0);
+}
index f2d2d6b7926dc5c58b1b94fd1b8f6baff261cd9f..a3156e7b9ff888d644eb6424d23101ca8836e00b 100644 (file)
@@ -12,6 +12,12 @@ void Replace::process(xmlNode *node, bool clean) {
        node->children = xmlNewTextLen(reinterpret_cast<const xmlChar *>(str.data()), str.size());
 }
 
+Clone::Clone(const std::vector<Directive *> &subdirectives)
+       : subdirectives(subdirectives) {}
+
+void Clone::process(xmlNode *node, bool clean) {
+}
+
 Substitute::Substitute(const unordered_map<string, Directive*> &substitution_map)
        : substitution_map(substitution_map) {}
 
index 95d485f62bef446262480a104ef5bce8ec904377..afd688a6a6dc0e76c8f9fda48a553db4fa3b4191 100644 (file)
@@ -6,6 +6,7 @@
 #include <string>
 #include <utility>
 #include <unordered_map>
+#include <vector>
 
 class Directive {
  public:
@@ -21,6 +22,15 @@ class Replace : public Directive {
        const std::string str;
 };
 
+class Clone : public Directive {
+ public:
+       Clone(const std::vector<Directive *> &subdirectives);
+       virtual void process(xmlNode *node, bool clean);
+
+ private:
+       const std::vector<Directive *> subdirectives;
+};
+
 class Substitute : public Directive {
  public:
        Substitute(const std::unordered_map<std::string, Directive*> &substitution_map);