]> git.sesse.net Git - xml-template/commitdiff
Move the C++0x file processing logic into a shared function.
authorsgunderson@bigfoot.com <>
Wed, 21 Sep 2011 19:51:11 +0000 (21:51 +0200)
committersgunderson@bigfoot.com <>
Wed, 21 Sep 2011 19:51:11 +0000 (21:51 +0200)
c++0x/passthru.cpp
c++0x/simple.cpp
c++0x/xml-template.cpp
c++0x/xml-template.h

index 2db2e3d9adafc10288dd5d9997cd882e311a8f64..afc38ec129bc9d8f6a0b3337706efc404fa8847f 100644 (file)
@@ -8,15 +8,7 @@ using namespace std;
 
 int main(int argc, char **argv)
 {
-       LIBXML_TEST_VERSION
-
        unordered_map<string, Directive*> master_map;
-
-       xmlDocPtr doc = xmlParseFile("../xml/passthru.xml");
-       Substitute(master_map).process(xmlDocGetRootElement(doc), false);
-       xmlSaveFile(argv[1], doc);
-
-       xmlCleanupParser();
-       xmlMemoryDump();
+       process_file("../xml/passthru.xml", argv[1], new Substitute(master_map));
        return(0);
 }
index cfc504181d25584d906fb61b922918ca15152bc1..36766f80c1ffa4acb01e647a7dd723691e6a0a0f 100644 (file)
@@ -1,6 +1,4 @@
 #include <stdio.h>
-#include <string.h>
-#include <libxml/parser.h>
 
 #include "xml-template.h"
 
@@ -8,17 +6,10 @@ using namespace std;
 
 int main(int argc, char **argv)
 {
-       LIBXML_TEST_VERSION
-
        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!")));
 
-       xmlDocPtr doc = xmlParseFile("../xml/simple.xml");
-       Substitute(master_map).process(xmlDocGetRootElement(doc), false);
-       xmlSaveFile(argv[1], doc);
-
-       xmlCleanupParser();
-       xmlMemoryDump();
+       process_file("../xml/simple.xml", argv[1], new Substitute(master_map));
        return(0);
 }
index a158f31023c2feb9c93ee42dd729faf40b94d916..3be1407b3b5592d93b6768859135a90dfc26481f 100644 (file)
@@ -1,6 +1,7 @@
 #include "xml-template.h"
 
 #include <string.h>
+#include <libxml/parser.h>
 
 using namespace std;
 
@@ -44,3 +45,17 @@ void Substitute::process(xmlNode *node, bool clean) {
                }
        }
 }
+       
+void process_file(const string &input_filename,
+                  const string &output_filename,
+                  Directive *root_directive)
+{
+       LIBXML_TEST_VERSION
+
+       xmlDocPtr doc = xmlParseFile(input_filename.c_str());
+       root_directive->process(xmlDocGetRootElement(doc), false);
+       xmlSaveFile(output_filename.c_str(), doc);
+
+       xmlCleanupParser();
+       xmlMemoryDump();
+}
index cd417e26465a3be7fba5d59d247af700a2735cdd..95d485f62bef446262480a104ef5bce8ec904377 100644 (file)
@@ -31,4 +31,8 @@ class Substitute : public Directive {
        const std::unordered_map<std::string, Directive*> &substitution_map;
 };
 
+void process_file(const std::string &input_filename,
+                  const std::string &output_filename,
+                  Directive *root_directive);
+
 #endif  // !defined(_XML_TEMPLATE_H)