]> git.tdb.fi Git - libs/datafile.git/blobdiff - tool.cpp
More flexible framework for loading substatements with custom loaders
[libs/datafile.git] / tool.cpp
index 8ca4f746017a5466140fb292b57cd54644a0e31e..1e4da9a67e2bc897e12e2e778f7fa19662f89455 100644 (file)
--- a/tool.cpp
+++ b/tool.cpp
@@ -1,8 +1,10 @@
 /* $Id$ */
-#include <fstream>
 #include <iostream>
 #include <msp/core/application.h>
 #include <msp/core/getopt.h>
+#include <msp/io/buffered.h>
+#include <msp/io/console.h>
+#include <msp/io/file.h>
 #include "source/parser.h"
 #include "source/statement.h"
 #include "source/writer.h"
@@ -40,31 +42,40 @@ DataTool::DataTool(int argc, char **argv):
 
 int DataTool::main()
 {
-       istream *in;
+       IO::Base *in;
        if(in_fn=="-")
-               in=&cin;
+               in=&IO::cin;
        else
-               in=new ifstream(in_fn.c_str());
+               in=new IO::File(in_fn);
 
-       ostream *out;
+       IO::Base *out;
        if(out_fn=="-")
-               out=&cout;
+               out=&IO::cout;
        else
-               out=new ofstream(out_fn.c_str());
+               out=new IO::File(out_fn, IO::M_WRITE);
 
-       DataFile::Parser parser(*in, in_fn);
-       DataFile::Writer writer(*out);
-       if(binary)
-               writer.set_binary(true);
-
-       while(parser)
        {
-               DataFile::Statement st=parser.parse();
-               if(st.valid)
-                       writer.write(st);
+               IO::Buffered in_buf(*in);
+               DataFile::Parser parser(in_buf, in_fn);
+               IO::Buffered out_buf(*out);
+               DataFile::Writer writer(out_buf);
+               if(binary)
+                       writer.set_binary(true);
+
+               while(parser)
+               {
+                       DataFile::Statement st=parser.parse();
+                       if(st.valid)
+                       {
+                               writer.write(st);
+                               out_buf.flush();
+                       }
+               }
        }
 
-       if(out!=&cout)
+       if(in!=&IO::cin)
+               delete in;
+       if(out!=&IO::cout)
                delete out;
 
        return 0;