]> git.tdb.fi Git - libs/datafile.git/commitdiff
Move mspdatatool source to its own directory
authorMikko Rasa <tdb@tdb.fi>
Fri, 12 Sep 2008 16:07:50 +0000 (16:07 +0000)
committerMikko Rasa <tdb@tdb.fi>
Fri, 12 Sep 2008 16:07:50 +0000 (16:07 +0000)
Add an overload of LoaderFunc1 that passes the statement as-is
Make Loader::load(const Statement &) private since it's called through a base class reference now

Build
source/loader.h
source/loaderaction.h
tool.cpp [deleted file]
tool/tool.cpp [new file with mode: 0644]
tool/tool.h [new file with mode: 0644]

diff --git a/Build b/Build
index d7e7238d862f70dcde1718be4dd70256fbbc33ae..53a4ebde438a6eb05beeb9e0dc0846e6bf0300f2 100644 (file)
--- a/Build
+++ b/Build
@@ -21,7 +21,7 @@ package "mspdatafile"
 
        program "mspdatatool"
        {
-               source "tool.cpp";
+               source "tool";
                install true;
                build_info
                {
index 9314ab3a8108e110e0dc3be39daf03511a4d8982..0c1dda2cc776db8d293b8696ba6e0e4739aab016 100644 (file)
@@ -43,14 +43,13 @@ See also classes BasicLoader and BasicLoader2.
 */
 class Loader
 {
-public:
+private:
        /**
-       Loads data from a statement.  This is normally only used by the Loader class
-       itself for loading sub-items, but needs to be public so it can be accessed
-       in derived objects.
+       Loads data from a statement.
        */
        void load(const Statement &st);
 
+public:
        /**
        Loads statements from a parser.
        */
index 2a2a8fc0ef61dfb41624a3451ba8f4606219bf1a..ff478ec2df7aa8ed651914922516781e3f519278 100644 (file)
@@ -95,6 +95,25 @@ private:
 };
 
 
+/**
+Loads a statement by calling a function with the statement itself as argument.
+*/
+template<typename L>
+class LoaderFunc1<L, const Statement &>: public LoaderAction
+{
+public:
+       typedef void (L::*FuncType)(const Statement &);
+
+       LoaderFunc1(FuncType f): func(f) { }
+       void execute(Loader &l, const Statement &st) const
+       {
+               (dynamic_cast<L &>(l).*func)(st);
+       }
+private:
+       FuncType func;
+};
+
+
 template<typename L, typename A0, typename A1>
 class LoaderFunc2: public LoaderAction
 {
diff --git a/tool.cpp b/tool.cpp
deleted file mode 100644 (file)
index 1e4da9a..0000000
--- a/tool.cpp
+++ /dev/null
@@ -1,84 +0,0 @@
-/* $Id$ */
-#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"
-
-using namespace std;
-using namespace Msp;
-
-class DataTool: public Application
-{
-private:
-       string in_fn;
-       string out_fn;
-       bool binary;
-public:
-       DataTool(int argc, char **argv);
-       int main();
-
-       static Application::RegApp<DataTool> reg;
-};
-
-
-DataTool::DataTool(int argc, char **argv):
-       in_fn("-"),
-       out_fn("-")
-{
-       GetOpt getopt;
-       getopt.add_option('o', "output", out_fn, GetOpt::REQUIRED_ARG);
-       getopt.add_option('b', "binary", binary, GetOpt::NO_ARG);
-       getopt(argc, argv);
-
-       const vector<string> &args=getopt.get_args();
-       if(!args.empty())
-               in_fn=args[0];
-}
-
-int DataTool::main()
-{
-       IO::Base *in;
-       if(in_fn=="-")
-               in=&IO::cin;
-       else
-               in=new IO::File(in_fn);
-
-       IO::Base *out;
-       if(out_fn=="-")
-               out=&IO::cout;
-       else
-               out=new IO::File(out_fn, IO::M_WRITE);
-
-       {
-               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(in!=&IO::cin)
-               delete in;
-       if(out!=&IO::cout)
-               delete out;
-
-       return 0;
-}
-
-Application::RegApp<DataTool> DataTool::reg;
diff --git a/tool/tool.cpp b/tool/tool.cpp
new file mode 100644 (file)
index 0000000..ca415d3
--- /dev/null
@@ -0,0 +1,75 @@
+/* $Id$
+
+This file is part of libmspdatafile
+Copyright © 2008  Mikko Rasa, Mikkosoft Productions
+Distributed under the LGPL
+*/
+
+#include <msp/core/getopt.h>
+#include <msp/io/buffered.h>
+#include <msp/io/console.h>
+#include <msp/io/file.h>
+#include <msp/datafile/parser.h>
+#include <msp/datafile/statement.h>
+#include <msp/datafile/writer.h>
+#include "tool.h"
+
+using namespace std;
+using namespace Msp;
+
+DataTool::DataTool(int argc, char **argv):
+       in_fn("-"),
+       out_fn("-")
+{
+       GetOpt getopt;
+       getopt.add_option('o', "output", out_fn, GetOpt::REQUIRED_ARG);
+       getopt.add_option('b', "binary", binary, GetOpt::NO_ARG);
+       getopt(argc, argv);
+
+       const vector<string> &args=getopt.get_args();
+       if(!args.empty())
+               in_fn=args[0];
+}
+
+int DataTool::main()
+{
+       IO::Base *in;
+       if(in_fn=="-")
+               in=&IO::cin;
+       else
+               in=new IO::File(in_fn);
+
+       IO::Base *out;
+       if(out_fn=="-")
+               out=&IO::cout;
+       else
+               out=new IO::File(out_fn, IO::M_WRITE);
+
+       {
+               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(in!=&IO::cin)
+               delete in;
+       if(out!=&IO::cout)
+               delete out;
+
+       return 0;
+}
+
+Application::RegApp<DataTool> DataTool::reg;
diff --git a/tool/tool.h b/tool/tool.h
new file mode 100644 (file)
index 0000000..99e8297
--- /dev/null
@@ -0,0 +1,22 @@
+/* $Id$
+
+This file is part of libmspdatafile
+Copyright © 2008  Mikko Rasa, Mikkosoft Productions
+Distributed under the LGPL
+*/
+
+#include <string>
+#include <msp/core/application.h>
+
+class DataTool: public Msp::Application
+{
+private:
+       std::string in_fn;
+       std::string out_fn;
+       bool binary;
+public:
+       DataTool(int argc, char **argv);
+       int main();
+
+       static Application::RegApp<DataTool> reg;
+};