X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=c%2B%2B0x%2Fxml-template.cpp;h=9e19f0914c03a9a14f7a6d9ad8db6dcf68920441;hb=a87410331a3cf42444d92930a9a796a384278c8d;hp=fda97fc7ca97b83e28b8b4ab1f3d35558cd3011f;hpb=9479feb34459b0d1fcdaa6a6545827f3243cb513;p=xml-template diff --git a/c++0x/xml-template.cpp b/c++0x/xml-template.cpp index fda97fc..9e19f09 100644 --- a/c++0x/xml-template.cpp +++ b/c++0x/xml-template.cpp @@ -49,7 +49,14 @@ string Replace::get_contents() { return str; } Clone::Clone(const vector &subdirectives) : subdirectives(subdirectives) {} - + +Clone::Clone(const vector &subdirectives_subs) +{ + for (auto it : subdirectives_subs) { + subdirectives.push_back(static_cast(it)); + } +} + Clone::Clone(initializer_list subdirectives) : subdirectives(subdirectives) {} @@ -89,6 +96,19 @@ void Clone::process(xmlNode *node, bool clean) clean_node(node); } } + +Alternate::Alternate(const string &attribute, + const vector &subdirectives_subs, + const vector &alternatives) + : Clone(subdirectives_subs) +{ + for (unsigned ix = 0; ix < subdirectives_subs.size(); ++ix) { + string value = alternatives[ix % alternatives.size()]; + subdirectives_subs[ix]->substitution_map.insert(make_pair( + attribute, + new Replace { value })); + } +} Substitute::Substitute(const unordered_map &substitution_map) : substitution_map(substitution_map) {}