]> git.tdb.fi Git - libs/datafile.git/commitdiff
Add a shortcut function for loading something from a file.
authorMikko Rasa <tdb@tdb.fi>
Mon, 27 Nov 2006 19:22:34 +0000 (19:22 +0000)
committerMikko Rasa <tdb@tdb.fi>
Mon, 27 Nov 2006 19:22:34 +0000 (19:22 +0000)
source/loader.h

index 6e9c4f8012e42c952a36bc21f392a7559ef22e47..c6936f96f6eef5869f62ffe3ed9307f34038dd2c 100644 (file)
@@ -6,6 +6,7 @@ Distributed under the LGPL
 #ifndef MSP_PARSER_LOADER_H_
 #define MSP_PARSER_LOADER_H_
 
+#include <fstream>
 #include <map>
 #include <msp/error.h>
 #include "parser.h"
@@ -205,6 +206,18 @@ private:
        }
 };
 
+template<typename T>
+void load(T &obj, const std::string &fn)
+{
+       std::ifstream in(fn.c_str());
+       if(!in)
+               throw Exception("Couldn't open "+fn);
+
+       Parser parser(in, fn);
+       typename T::Loader loader(obj);
+       loader.load(parser);
+}
+
 } // namespace Parser
 } // namespace Msp