From: sgunderson@bigfoot.com <> Date: Wed, 21 Sep 2011 20:08:04 +0000 (+0200) Subject: Add a clone test for C++0x (no cloning logic yet, so test fails). X-Git-Url: https://git.sesse.net/?p=xml-template;a=commitdiff_plain;h=4c1b8f968fe31be2528b49ab8ad956e79b8617f5 Add a clone test for C++0x (no cloning logic yet, so test fails). --- diff --git a/c++0x/Makefile b/c++0x/Makefile index 9c74fc0..939c748 100644 --- a/c++0x/Makefile +++ b/c++0x/Makefile @@ -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 index 0000000..5bdfbc6 --- /dev/null +++ b/c++0x/clone.cpp @@ -0,0 +1,38 @@ +#include + +#include "xml-template.h" + +using namespace std; + +int main(int argc, char **argv) +{ + vector things; + + { + unordered_map submap; + submap.insert(make_pair("li", new Replace("Raindrops on roses"))); + things.push_back(new Substitute(submap)); + } + { + unordered_map submap; + submap.insert(make_pair("li", new Replace("Whiskers on kittens"))); + things.push_back(new Substitute(submap)); + } + { + unordered_map submap; + submap.insert(make_pair("li", new Replace("Bright copper kettles"))); + things.push_back(new Substitute(submap)); + } + { + unordered_map submap; + submap.insert(make_pair("li", new Replace("Warm, woolen mittens"))); + things.push_back(new Substitute(submap)); + } + + unordered_map 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); +} diff --git a/c++0x/xml-template.cpp b/c++0x/xml-template.cpp index f2d2d6b..a3156e7 100644 --- a/c++0x/xml-template.cpp +++ b/c++0x/xml-template.cpp @@ -12,6 +12,12 @@ void Replace::process(xmlNode *node, bool clean) { node->children = xmlNewTextLen(reinterpret_cast(str.data()), str.size()); } +Clone::Clone(const std::vector &subdirectives) + : subdirectives(subdirectives) {} + +void Clone::process(xmlNode *node, bool clean) { +} + Substitute::Substitute(const unordered_map &substitution_map) : substitution_map(substitution_map) {} diff --git a/c++0x/xml-template.h b/c++0x/xml-template.h index 95d485f..afd688a 100644 --- a/c++0x/xml-template.h +++ b/c++0x/xml-template.h @@ -6,6 +6,7 @@ #include #include #include +#include class Directive { public: @@ -21,6 +22,15 @@ class Replace : public Directive { const std::string str; }; +class Clone : public Directive { + public: + Clone(const std::vector &subdirectives); + virtual void process(xmlNode *node, bool clean); + + private: + const std::vector subdirectives; +}; + class Substitute : public Directive { public: Substitute(const std::unordered_map &substitution_map);